@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); }
@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; }
/** * @return default {@link CompilerOptions} object to be used by compressor. */ protected CompilerOptions newCompilerOptions() { final CompilerOptions options = new CompilerOptions(); /** * According to John Lenz from the Closure Compiler project, if you are using the Compiler API directly, you should * specify a CodingConvention. {@link http://code.google.com/p/wro4j/issues/detail?id=155} */ options.setCodingConvention(new ClosureCodingConvention()); // use the wro4j encoding by default options.setOutputCharset(Charset.forName(getEncoding())); // set it to warning, otherwise compiler will fail options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); return options; }
/** * @return default {@link com.google.javascript.jscomp.CompilerOptions} object to be used by compressor. */ protected CompilerOptions newCompilerOptions() { final CompilerOptions options = new CompilerOptions(); /** * According to John Lenz from the Closure Compiler project, if you are using the Compiler API directly, you * should specify a CodingConvention. {@link http://code.google.com/p/wro4j/issues/detail?id=155} */ options.setCodingConvention(new ClosureCodingConvention()); options.setOutputCharset(getEncoding()); //set it to warning, otherwise compiler will fail options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); return options; }
options.setOutputCharset(OUTPUT_CHARSET); options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING);
/** * @return default {@link com.google.javascript.jscomp.CompilerOptions} object to be used by compressor. */ protected CompilerOptions newCompilerOptions() { final CompilerOptions options = new CompilerOptions(); /** * According to John Lenz from the Closure Compiler project, if you are using the Compiler API directly, you * should specify a CodingConvention. {@link http://code.google.com/p/wro4j/issues/detail?id=155} */ options.setCodingConvention(new ClosureCodingConvention()); options.setOutputCharset(getEncoding()); //set it to warning, otherwise compiler will fail options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); return options; }
/** * @return default {@link CompilerOptions} object to be used by compressor. */ protected CompilerOptions newCompilerOptions() { final CompilerOptions options = new CompilerOptions(); /** * According to John Lenz from the Closure Compiler project, if you are using the Compiler API directly, you should * specify a CodingConvention. {@link http://code.google.com/p/wro4j/issues/detail?id=155} */ options.setCodingConvention(new ClosureCodingConvention()); // use the wro4j encoding by default options.setOutputCharset(getEncoding()); // set it to warning, otherwise compiler will fail options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); return options; }
options.setOutputCharset(OUTPUT_CHARSET); options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING);
@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()); }
options.setOutputCharset(charset); options.setLanguageIn(closureConfig.getLanguageIn()); options.setLanguageOut(closureConfig.getLanguageOut());
options.setOutputCharset(charset); options.setLanguageIn(closureConfig.getLanguageIn()); options.setLanguageOut(closureConfig.getLanguageOut());
options.setOutputCharset(this.outputEncoding);
options.setOutputCharset(this.outputEncoding);