@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) throws Exception { final CompilerOptions copts = new CompilerOptions(); copts.setCodingConvention(new ClosureCodingConvention()); copts.setOutputCharset(StandardCharsets.UTF_8); copts.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); CompilationLevel level = level(get("level")); level.setOptionsForCompilationLevel(copts); Compiler.setLoggingLevel(Level.SEVERE); Compiler compiler = new Compiler(); compiler.disableThreads(); compiler.initOptions(copts); List<SourceFile> externs = externs(copts); Result result = compiler.compile(externs, ImmutableList.of(SourceFile.fromCode(filename, source)), copts); if (result.success) { return compiler.toSource(); } List<AssetProblem> errors = Arrays.stream(result.errors) .map(error -> new AssetProblem(error.sourceName, error.lineNumber, error.getCharno(), error.description, null)) .collect(Collectors.toList()); throw new AssetException(name(), errors); }
public JSClosureCompilerWrapper(List<String> args) { Compiler.setLoggingLevel(Level.INFO); compiler_ = new Compiler(); ArrayList<String> splitArgs = new ArrayList<String>(); for (String s : args) { if (s.contains(" ")) { String[] parts = s.split(" "); Collections.addAll(splitArgs, parts); } else splitArgs.add(s); } String[] stringArgs = new String[splitArgs.size()]; splitArgs.toArray(stringArgs); options_ = new CompilerOptionsParser(stringArgs).getOptions(); jsSourceFiles_ = new ArrayList<SourceFile>(); jsExternsFiles_ = new ArrayList<SourceFile>(); initOptions(args); initExterns(); }
private void compress() throws UnsupportedEncodingException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream is = new ByteArrayInputStream(content); Writer out = new OutputStreamWriter(baos, charset); CompilerOptions options = new CompilerOptions(); CompilationLevel.SIMPLE_OPTIMIZATIONS .setOptionsForCompilationLevel(options); Compiler.setLoggingLevel(Level.OFF); Compiler compiler = new Compiler(); compiler.disableThreads(); Result result = compiler.compile(new JSSourceFile[] {}, new JSSourceFile[] { JSSourceFile.fromInputStream("is", is) }, options); if (result.success) { Pattern pattern = Pattern.compile("^/\\*.*?\\*/\\s?", Pattern.DOTALL); Matcher matcher = pattern.matcher(new String(content, charset)); while (matcher.find()) { out.write(matcher.group()); } out.write(compiler.toSource()); out.flush(); content = baos.toByteArray(); } is.close(); out.close(); } }
public JSClosureCompilerWrapper(List<String> args) { Compiler.setLoggingLevel(Level.INFO); compiler_ = new Compiler(); jsSourceFiles_ = new ArrayList<SourceFile>(); jsExternsFiles_ = new ArrayList<SourceFile>(); filterOptions(args); ArrayList<String> splitArgs = new ArrayList<String>(); for (String s : args) { if (s.contains(" ")) { String[] parts = s.split(" "); Collections.addAll(splitArgs, parts); } else splitArgs.add(s); } String[] stringArgs = new String[splitArgs.size()]; splitArgs.toArray(stringArgs); options_ = new CompilerOptionsParser(stringArgs).getOptions(); initOptions(args); initExterns(); }
@SuppressWarnings("unchecked") private static CompilerOptions buildCompilerOptionsFromConfig(FilterConfig config) { CompilerOptions compilerOptions = new CompilerOptions(); compilerOptions.setCodingConvention(CodingConventions.getDefault()); Enumeration<String> initParams = config.getInitParameterNames(); while (initParams.hasMoreElements()) { String name = initParams.nextElement().trim(); String value = config.getInitParameter(name); if ("charset".equals(name)) { if (value != null && Charset.isSupported(value)) { compilerOptions.setOutputCharset(Charset.forName(value)); } else { compilerOptions.setOutputCharset(StandardCharsets.UTF_8); } } else if ("compilationLevel".equals(name)) { CompilationLevel compilationLevel = CompilationLevel.valueOf(value); compilationLevel.setOptionsForCompilationLevel(compilerOptions); } else if ("formatting".equals(name)) { if ("PRETTY_PRINT".equals(value)) { compilerOptions.prettyPrint = true; } else if ("PRINT_INPUT_DELIMITER".equals(value)) { compilerOptions.printInputDelimiter = true; } } else if ("loggingLevel".equals(name)) { Compiler.setLoggingLevel(Level.parse(value)); //warning or error } } return compilerOptions; }
private Compiler newCompiler(final CompilerOptions compilerOptions) { Compiler.setLoggingLevel(Level.SEVERE); final Compiler compiler = new Compiler(); compilationLevel.setOptionsForCompilationLevel(compilerOptions); // make it play nice with GAE compiler.disableThreads(); compiler.initOptions(compilerOptions); return compiler; }
private Compiler newCompiler(CompilerOptions compilerOptions, CompilationLevel compilationLevel) { Compiler.setLoggingLevel(Level.SEVERE); Compiler compiler = new Compiler(); compilationLevel.setOptionsForCompilationLevel(compilerOptions); // make it play nice with GAE compiler.disableThreads(); compiler.initOptions(compilerOptions); return compiler; }
private Compiler newCompiler(final CompilerOptions compilerOptions) { Compiler.setLoggingLevel(Level.SEVERE); final Compiler compiler = new Compiler(); compilationLevel.setOptionsForCompilationLevel(compilerOptions); // make it play nice with GAE compiler.disableThreads(); compiler.initOptions(compilerOptions); return compiler; }
Compiler.setLoggingLevel(Level.OFF);
final String originalJsSourceCode = IOUtils.toString(reader); try { Compiler.setLoggingLevel(Level.SEVERE); final Compiler compiler = new Compiler(); final CompilerOptions compilerOptions = newCompilerOptions();
final String originalJsSourceCode = IOUtils.toString(reader); try { Compiler.setLoggingLevel(Level.SEVERE); final Compiler compiler = new Compiler(); final CompilerOptions compilerOptions = newCompilerOptions();
Compiler.setLoggingLevel(loggingLevel);
Compiler.setLoggingLevel(loggingLevel);
Compiler.setLoggingLevel(Level.OFF);
@Override public CharSequence minify(final Config config, final CharSequence source) { final CompilerOptions options = new CompilerOptions(); options.setCodingConvention(new ClosureCodingConvention()); options.setOutputCharset("UTF-8"); options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); compilationLevel.setOptionsForCompilationLevel(options); Compiler.setLoggingLevel(Level.SEVERE); Compiler compiler = new Compiler(); compiler.disableThreads(); compiler.initOptions(options); String fname = removeExtension(config.getName()) + ".js"; Result result = compiler.compile(defaultExterns, Arrays.asList(SourceFile.fromCode(fname, source.toString())), options); if (result.success) { return compiler.toSource(); } JSError[] errors = result.errors; throw new IllegalStateException(errors[0].toString()); }
Compiler.setLoggingLevel(Level.parse(config.loggingLevel));
Compiler.setLoggingLevel(Level.parse(config.loggingLevel));