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 enum
Set 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
ConstructorsModifierConstructorDescriptionprotected
CommandLineRunner
(String[] args) Create a new command-line runner.protected
CommandLineRunner
(String[] args, InputStream in, PrintStream out, PrintStream err) protected
CommandLineRunner
(String[] args, PrintStream out, PrintStream err) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addAllowlistWarningsGuard
(CompilerOptions options, File allowlistFile) protected void
Writes whatever runtime libraries are needed to bundle.protected void
checkModuleName
(String name) Validates the module name.protected Compiler
Returns the instance of the Compiler to use whenAbstractCommandLineRunner.run()
is called.protected List
<SourceFile> createExterns
(CompilerOptions options) protected CompilerOptions
Returns 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 String
Some text identifying this binary and its version.boolean
static void
Runs the Compiler.protected void
prepForBundleAndAppendTo
(Appendable out, CompilerInput input, String content) Performs any transformation needed on the given compiler input and appends it to the given output bundle.boolean
Methods 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:AbstractCommandLineRunner
Some text identifying this binary and its version.At minimum, this is what will be printed when `--version` is passed.
- Specified by:
getVersionText
in classAbstractCommandLineRunner<Compiler,
CompilerOptions>
-
addAllowlistWarningsGuard
- Specified by:
addAllowlistWarningsGuard
in classAbstractCommandLineRunner<Compiler,
CompilerOptions>
-
checkModuleName
Description copied from class:AbstractCommandLineRunner
Validates the module name. Can be overridden by subclasses.- Overrides:
checkModuleName
in classAbstractCommandLineRunner<Compiler,
CompilerOptions> - Parameters:
name
- The module name
-
createOptions
Description copied from class:AbstractCommandLineRunner
Returns 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:
createOptions
in classAbstractCommandLineRunner<Compiler,
CompilerOptions>
-
createCompiler
Description copied from class:AbstractCommandLineRunner
Returns the instance of the Compiler to use whenAbstractCommandLineRunner.run()
is called.- Specified by:
createCompiler
in classAbstractCommandLineRunner<Compiler,
CompilerOptions>
-
prepForBundleAndAppendTo
protected void prepForBundleAndAppendTo(Appendable out, CompilerInput input, String content) throws IOException Description copied from class:AbstractCommandLineRunner
Performs any transformation needed on the given compiler input and appends it to the given output bundle.- Specified by:
prepForBundleAndAppendTo
in classAbstractCommandLineRunner<Compiler,
CompilerOptions> - Throws:
IOException
-
appendRuntimeTo
Description copied from class:AbstractCommandLineRunner
Writes whatever runtime libraries are needed to bundle.- Specified by:
appendRuntimeTo
in classAbstractCommandLineRunner<Compiler,
CompilerOptions> - Throws:
IOException
-
createExterns
- Overrides:
createExterns
in 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.
-