Package com.google.javascript.jscomp
Class CommandLineRunner
- java.lang.Object
-
- com.google.javascript.jscomp.AbstractCommandLineRunner<Compiler,CompilerOptions>
-
- com.google.javascript.jscomp.CommandLineRunner
-
@GwtIncompatible("Unnecessary") public class CommandLineRunner extends AbstractCommandLineRunner<Compiler,CompilerOptions>
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); }
This class is totally not thread-safe.@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); } } }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CommandLineRunner.FormattingOption
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 Modifier and Type Field Description static java.lang.String
OUTPUT_MARKER
static int
UTF8_BOM_CODE
-
Constructor Summary
Constructors Modifier Constructor Description protected
CommandLineRunner(java.lang.String[] args)
Create a new command-line runner.protected
CommandLineRunner(java.lang.String[] args, java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err)
protected
CommandLineRunner(java.lang.String[] args, java.io.PrintStream out, java.io.PrintStream err)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
addAllowlistWarningsGuard(CompilerOptions options, java.io.File allowlistFile)
protected void
appendRuntimeTo(java.lang.Appendable out)
Writes whatever runtime libraries are needed to bundle.protected void
checkModuleName(java.lang.String name)
Validates the module name.protected Compiler
createCompiler()
Returns the instance of the Compiler to use whenAbstractCommandLineRunner.run()
is called.protected java.util.List<SourceFile>
createExterns(CompilerOptions options)
protected CompilerOptions
createOptions()
Returns the instance of the Options to use whenAbstractCommandLineRunner.run()
is called.static java.util.List<java.lang.String>
findJsFiles(java.util.Collection<java.lang.String> patterns)
Returns all the JavaScript files from the set of patterns.static java.util.List<SourceFile>
getDefaultExterns()
Deprecated.protected java.lang.String
getVersionText()
Some text identifying this binary and its version.boolean
hasErrors()
static void
main(java.lang.String[] args)
Runs the Compiler.protected void
prepForBundleAndAppendTo(java.lang.Appendable out, CompilerInput input, java.lang.String content)
Performs any transformation needed on the given compiler input and appends it to the given output bundle.boolean
shouldRunCompiler()
-
Methods inherited from class com.google.javascript.jscomp.AbstractCommandLineRunner
createDefineReplacements, createInputs, createJsModules, doRun, filenameToOutputStream, getBuiltinExterns, getCommandLineConfig, getCompileMetricsRecorder, getCompiler, getDiagnosticGroups, getErrorPrintStream, isInTestMode, parseJsonFilesFromInputStream, parseModuleWrappers, run, setExitCodeReceiver, setRunOptions, setWarningGuardOptions, shouldGenerateMapPerModule
-
-
-
-
Field Detail
-
OUTPUT_MARKER
public static final java.lang.String OUTPUT_MARKER
- See Also:
- Constant Field Values
-
UTF8_BOM_CODE
public static final int UTF8_BOM_CODE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CommandLineRunner
protected CommandLineRunner(java.lang.String[] args)
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
protected CommandLineRunner(java.lang.String[] args, java.io.PrintStream out, java.io.PrintStream err)
-
CommandLineRunner
protected CommandLineRunner(java.lang.String[] args, java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err)
-
-
Method Detail
-
getVersionText
protected final java.lang.String 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
protected void addAllowlistWarningsGuard(CompilerOptions options, java.io.File allowlistFile)
- Specified by:
addAllowlistWarningsGuard
in classAbstractCommandLineRunner<Compiler,CompilerOptions>
-
checkModuleName
protected void checkModuleName(java.lang.String name)
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
protected CompilerOptions 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
protected Compiler 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(java.lang.Appendable out, CompilerInput input, java.lang.String content) throws java.io.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:
java.io.IOException
-
appendRuntimeTo
protected void appendRuntimeTo(java.lang.Appendable out) throws java.io.IOException
Description copied from class:AbstractCommandLineRunner
Writes whatever runtime libraries are needed to bundle.- Specified by:
appendRuntimeTo
in classAbstractCommandLineRunner<Compiler,CompilerOptions>
- Throws:
java.io.IOException
-
createExterns
protected java.util.List<SourceFile> createExterns(CompilerOptions options) throws java.io.IOException
- Overrides:
createExterns
in classAbstractCommandLineRunner<Compiler,CompilerOptions>
- Throws:
java.io.IOException
-
getDefaultExterns
@Deprecated public static java.util.List<SourceFile> getDefaultExterns() throws java.io.IOException
Deprecated.- Throws:
java.io.IOException
-
findJsFiles
public static java.util.List<java.lang.String> findJsFiles(java.util.Collection<java.lang.String> patterns) throws java.io.IOException
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:
java.io.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
public static void main(java.lang.String[] args)
Runs the Compiler. Exits cleanly in the event of an error.
-
-