Package com.google.javascript.jscomp
Class CommandLineRunner
java.lang.Object
com.google.javascript.jscomp.AbstractCommandLineRunner<Compiler,CompilerOptions>
com.google.javascript.jscomp.CommandLineRunner
CommandLineRunner translates flags into Java API calls on the Compiler.
This class may be extended and used to create other Java classes that behave the same as running the Compiler from the command line. If you want to run the compiler in-process in Java, you should look at this class for hints on what API calls to make, but you should not use this class directly.
Example:
class MyCommandLineRunner extends CommandLineRunner {
MyCommandLineRunner(String[] args) {
super(args);
}
@Override protected CompilerOptions createOptions() {
CompilerOptions options = super.createOptions();
addMyCrazyCompilerPassThatOutputsAnExtraFile(options);
return options;
}
public static void main(String[] args) {
MyCommandLineRunner runner = new MyCommandLineRunner(args);
if (runner.shouldRunCompiler()) {
runner.run();
}
if (runner.hasErrors()) {
System.exit(-1);
}
}
}
This class is totally not thread-safe.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSet of options that can be used with the --formatting flag.Nested classes/interfaces inherited from class com.google.javascript.jscomp.AbstractCommandLineRunner
AbstractCommandLineRunner.CommandLineConfig, AbstractCommandLineRunner.FlagEntry<T>, AbstractCommandLineRunner.JsChunkSpec, AbstractCommandLineRunner.JsonFileSpec, AbstractCommandLineRunner.JsSourceType -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCommandLineRunner(String[] args) Create a new command-line runner.protectedCommandLineRunner(String[] args, InputStream in, PrintStream out, PrintStream err) protectedCommandLineRunner(String[] args, PrintStream out, PrintStream err) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddAllowlistWarningsGuard(CompilerOptions options, File allowlistFile) protected voidWrites whatever runtime libraries are needed to bundle.protected voidcheckModuleName(String name) Validates the module name.protected CompilerReturns the instance of the Compiler to use whenAbstractCommandLineRunner.run()is called.protected List<SourceFile> createExterns(CompilerOptions options) protected CompilerOptionsReturns the instance of the Options to use whenAbstractCommandLineRunner.run()is called.findJsFiles(Collection<String> patterns) Returns all the JavaScript files from the set of patterns.static List<SourceFile> Deprecated.protected final StringSome text identifying this binary and its version.booleanstatic voidRuns the Compiler.protected voidprepForBundleAndAppendTo(Appendable out, CompilerInput input, String content) Performs any transformation needed on the given compiler input and appends it to the given output bundle.booleanMethods inherited from class com.google.javascript.jscomp.AbstractCommandLineRunner
createDefineReplacements, createInputs, createJsChunks, doRun, filenameToOutputStream, getBuiltinExterns, getCommandLineConfig, getCompileMetricsRecorder, getCompiler, getDiagnosticGroups, getErrorPrintStream, isInTestMode, parseJsonFilesFromInputStream, parseModuleWrappers, run, setExitCodeReceiver, setRunOptions, setWarningGuardOptions, shouldGenerateMapPerModule
-
Field Details
-
OUTPUT_MARKER
- See Also:
-
UTF8_BOM_CODE
public static final int UTF8_BOM_CODE- See Also:
-
-
Constructor Details
-
CommandLineRunner
Create a new command-line runner. You should only need to call the constructor if you're extending this class. Otherwise, the main method should instantiate it. -
CommandLineRunner
-
CommandLineRunner
-
-
Method Details
-
getVersionText
Description copied from class:AbstractCommandLineRunnerSome text identifying this binary and its version.At minimum, this is what will be printed when `--version` is passed.
- Specified by:
getVersionTextin classAbstractCommandLineRunner<Compiler,CompilerOptions>
-
addAllowlistWarningsGuard
- Specified by:
addAllowlistWarningsGuardin classAbstractCommandLineRunner<Compiler,CompilerOptions>
-
checkModuleName
Description copied from class:AbstractCommandLineRunnerValidates the module name. Can be overridden by subclasses.- Overrides:
checkModuleNamein classAbstractCommandLineRunner<Compiler,CompilerOptions> - Parameters:
name- The module name
-
createOptions
Description copied from class:AbstractCommandLineRunnerReturns the instance of the Options to use whenAbstractCommandLineRunner.run()is called. createCompiler() is called before createOptions(), so getCompiler() will not return null when createOptions() is called.- Specified by:
createOptionsin classAbstractCommandLineRunner<Compiler,CompilerOptions>
-
createCompiler
Description copied from class:AbstractCommandLineRunnerReturns the instance of the Compiler to use whenAbstractCommandLineRunner.run()is called.- Specified by:
createCompilerin classAbstractCommandLineRunner<Compiler,CompilerOptions>
-
prepForBundleAndAppendTo
protected void prepForBundleAndAppendTo(Appendable out, CompilerInput input, String content) throws IOException Description copied from class:AbstractCommandLineRunnerPerforms any transformation needed on the given compiler input and appends it to the given output bundle.- Specified by:
prepForBundleAndAppendToin classAbstractCommandLineRunner<Compiler,CompilerOptions> - Throws:
IOException
-
appendRuntimeTo
Description copied from class:AbstractCommandLineRunnerWrites whatever runtime libraries are needed to bundle.- Specified by:
appendRuntimeToin classAbstractCommandLineRunner<Compiler,CompilerOptions> - Throws:
IOException
-
createExterns
- Overrides:
createExternsin classAbstractCommandLineRunner<Compiler,CompilerOptions> - Throws:
IOException
-
getDefaultExterns
@InlineMe(replacement="CommandLineRunner.getBuiltinExterns(CompilerOptions.Environment.BROWSER)", imports={"com.google.javascript.jscomp.CommandLineRunner","com.google.javascript.jscomp.CompilerOptions"}) @Deprecated public static List<SourceFile> getDefaultExterns() throws IOExceptionDeprecated.- Throws:
IOException
-
findJsFiles
Returns all the JavaScript files from the set of patterns. The patterns support globs, such as '*.js' for all JS files in a directory and '**.js' for all JS files within the directory and sub-directories.- Throws:
IOException
-
shouldRunCompiler
public boolean shouldRunCompiler()- Returns:
- Whether the configuration is valid and specifies to run the compiler.
-
hasErrors
public boolean hasErrors()- Returns:
- Whether the configuration has errors.
-
main
Runs the Compiler. Exits cleanly in the event of an error.
-