protected String compileJs(SourceFile input, String filename) throws ResourceMinificationException, IOException { Compiler compiler = getCompiler(); List<SourceFile> builtinExterns = AbstractCommandLineRunner.getBuiltinExterns(CompilerOptions.Environment.CUSTOM); Result result = compiler.compile(builtinExterns, Arrays.asList(input), getCompilerOptions()); String compiled = compiler.toSource(); if (!result.success || StringUtils.isBlank(compiled)) { StringBuilder errorString = new StringBuilder("\n"); if (result.errors != null) { for (int i = 0; i < result.errors.length; i++) { errorString.append(result.errors[i].description + "\n"); } } throw new ResourceMinificationException("Error minifying js file " + filename + errorString); } return compiler.toSource(); }
compiler = createCompiler(); B options = createOptions(); setRunOptions(options); List<SourceFile> externs = createExterns(options); List<JSModule> modules = null; Result result = null; rootRelativePathsMap = constructRootRelativePathsMap(); jsonFiles = parseJsonFilesFromInputStream(); createSourceInputs(jsModuleSpecs, config.mixedJsSources, jsonFiles); if (!jsModuleSpecs.isEmpty()) { if (isInTestMode()) { modules = modulesSupplierForTesting.get(); } else { || JsonStreamMode.NONE.equals(config.jsonStreamMode)) { for (JsModuleSpec m : jsModuleSpecs) { checkModuleName(m.getName()); modules = createJsModules(jsModuleSpecs, inputs); outputFileNames.add(getModuleOutputFileName(m)); result = compiler.getResult(); } else if (options.getInstrumentForCoverageOnly()) { result = instrumentForCoverage();
return 1; } else { Appendable jsOutput = createDefaultOutput(); jsOutput.append( DotFormatter.toDot(compiler.getPassConfig().getPassGraph())); jsOutput.append('\n'); closeAppendable(jsOutput); return 0; return 1; } else { Appendable jsOutput = createDefaultOutput(); ControlFlowGraph<Node> cfg = compiler.computeCFG(); DotFormatter.appendDot( compiler.getRoot().getLastChild(), cfg, jsOutput); jsOutput.append('\n'); closeAppendable(jsOutput); return 0; return 1; } else { Appendable jsOutput = createDefaultOutput(); compiler.getRoot().appendStringTree(jsOutput); jsOutput.append("\n"); closeAppendable(jsOutput); return 0; rootRelativePathsMap = constructRootRelativePathsMap();
Compiler.setLoggingLevel(Level.parse(config.loggingLevel)); compiler = createCompiler(); B options = createOptions(); List<SourceFile> externs = createExterns(options); setRunOptions(options); jsonFiles = parseJsonFilesFromInputStream(); createSourceInputs(jsModuleSpecs, config.mixedJsSources, jsonFiles); if (!jsModuleSpecs.isEmpty()) { modules = createJsModules(jsModuleSpecs, inputs); for (JSModule m : modules) { outputFileNames.add(getModuleOutputFileName(m)); .getAllModules()); for (JSModule m : modules) { outputFileNames.add(getModuleOutputFileName(m)); return processResults(result, modules, options);
DiagnosticGroups diagnosticGroups = getDiagnosticGroups(); setWarningGuardOptions(options, config.warningGuards, diagnosticGroups); addWhitelistWarningsGuard(options, new File(config.warningsWhitelistFile)); createDefineOrTweakReplacements(config.define, options, false); createDefineOrTweakReplacements(config.tweak, options, true); createDependencyOptions(config.dependencyMode, config.entryPoints); if (depOptions != null) { options.setDependencyOptions(depOptions); options.setTrustedStrings(true); legacyOutputCharset = options.outputCharset = getLegacyOutputCharset(); outputCharset2 = getOutputCharset2(); inputCharset = getInputCharset(); } else if (isOutputInJson()) { options.sourceMapOutputPath = "%outname%";
@GwtIncompatible("Unnecessary") void outputSingleBinary(B options) throws IOException { Function<String, String> escaper = null; String marker = OUTPUT_MARKER; if (config.outputWrapper.contains(OUTPUT_MARKER_JS_STRING)) { marker = OUTPUT_MARKER_JS_STRING; escaper = getJavascriptEscaper(); } if (isOutputInJson()) { this.filesToStreamOut.add(createJsonFile(options, marker, escaper)); } else { if (!config.jsOutputFile.isEmpty()) { maybeCreateDirsForPath(config.jsOutputFile); } Appendable jsOutput = createDefaultOutput(); writeOutput( jsOutput, compiler, (JSModule) null, config.outputWrapper, marker, escaper); closeAppendable(jsOutput); } }
protected List<SourceFile> createExterns(CompilerOptions options) throws IOException { return isInTestMode() ? externsSupplierForTesting.get() : createExternInputs(config.externs); }
if (isInTestMode()) { return modulesSupplierForTesting.get(); int numJsFilesExpected = 0, minJsFilesRequired = 0; for (JsModuleSpec spec : specs) { checkModuleName(spec.name); if (modulesByName.containsKey(spec.name)) { throw new FlagUsageException("Duplicate module name: " + spec.name);
@Override protected List<SourceFile> createExterns(CompilerOptions options) throws IOException { List<SourceFile> externs = super.createExterns(options); if (isInTestMode()) { return externs; } else { List<SourceFile> builtinExterns = getBuiltinExterns(options.getEnvironment()); builtinExterns.addAll(externs); return builtinExterns; } }
return 1; } else { Appendable jsOutput = createDefaultOutput(); jsOutput.append( DotFormatter.toDot(compiler.getPassConfig().getPassGraph())); jsOutput.append('\n'); closeAppendable(jsOutput); return 0; return 1; } else { Appendable jsOutput = createDefaultOutput(); ControlFlowGraph<Node> cfg = compiler.computeCFG(); DotFormatter.appendDot( compiler.getRoot().getLastChild(), cfg, jsOutput); jsOutput.append('\n'); closeAppendable(jsOutput); return 0; return 1; } else { Appendable jsOutput = createDefaultOutput(); compiler.getRoot().appendStringTree(jsOutput); jsOutput.append("\n"); closeAppendable(jsOutput); return 0; outputManifest(); outputBundle();
DiagnosticGroups diagnosticGroups = getDiagnosticGroups(); setWarningGuardOptions(options, config.warningGuards, diagnosticGroups); addWhitelistWarningsGuard(options, new File(config.warningsWhitelistFile)); createDefineOrTweakReplacements(config.define, options, false); createDefineOrTweakReplacements(config.tweak, options, true); options.setTrustedStrings(true); legacyOutputCharset = options.outputCharset = getLegacyOutputCharset(); outputCharset2 = getOutputCharset2(); inputCharset = getInputCharset(); } else if (isOutputInJson()) { options.sourceMapOutputPath = "%outname%"; new JsonErrorReportGenerator(getErrorPrintStream(), compiler); compiler.setErrorManager(new SortingErrorManager(ImmutableSet.of(errorGenerator)));
void outputSingleBinary(B options) throws IOException { Function<String, String> escaper = null; String marker = OUTPUT_MARKER; if (config.outputWrapper.contains(OUTPUT_MARKER_JS_STRING)) { marker = OUTPUT_MARKER_JS_STRING; escaper = getJavascriptEscaper(); } if (isOutputInJson()) { this.filesToStreamOut.add(createJsonFile(options, marker, escaper)); } else { if(!config.jsOutputFile.isEmpty()) { maybeCreateDirsForPath(config.jsOutputFile); } Appendable jsOutput = createDefaultOutput(); writeOutput( jsOutput, compiler, compiler.toSource(), config.outputWrapper, marker, escaper); closeAppendable(jsOutput); } }
@GwtIncompatible("Unnecessary") protected List<SourceFile> createExterns(CompilerOptions options) throws IOException { return isInTestMode() ? externsSupplierForTesting.get() : createExternInputs(config.externs); }
@Override protected List<SourceFile> createExterns(CompilerOptions options) throws IOException { List<SourceFile> externs = super.createExterns(options); if (isInTestMode()) { return externs; } else { List<SourceFile> builtinExterns = getBuiltinExterns(options.getEnvironment()); builtinExterns.addAll(externs); return builtinExterns; } }
static List<SourceFile> getDefaultExterns(Options opts) { try { return AbstractCommandLineRunner.getBuiltinExterns( opts.getCompilerOptions().getEnvironment()); } catch (IOException e) { throw new RuntimeException("Could not locate builtin externs", e); } }
externs.addAll(AbstractCommandLineRunner.getBuiltinExterns(options.getEnvironment())); for (String path : CommandLineRunner.findJsFiles(args.externsPatterns)) { externs.add(SourceFile.fromFile(path));