private Compiler createCompiler( List<SourceFile> inputs, List<SourceFile> externs, CompilerOptions compilerOptions) { Compiler compiler = new Compiler(); compiler.disableThreads(); compiler.compile(externs, inputs, compilerOptions); return compiler; }
/** * Minimize the output using google closure compiler. * * @param output The input file to minimize. * @throws IOException If something goes wrong. * @throws MojoFailureException If something goes wrong. */ private void minimize(final File output) throws IOException, MojoFailureException { final CompilerOptions options = new CompilerOptions(); options.setCodingConvention(new ClosureCodingConvention()); options.setOutputCharset("UTF-8"); options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options); Compiler.setLoggingLevel(Level.SEVERE); Compiler compiler = new Compiler(); compiler.disableThreads(); compiler.initOptions(options); Result result = compiler.compile( Collections.<SourceFile>emptyList(), Arrays.asList(SourceFile.fromFile(output)), options); if (result.success) { FileUtils.fileWrite(output, compiler.toSource()); } else { JSError[] errors = result.errors; throw new MojoFailureException(errors[0].toString()); } }