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.@Overrideprotected 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 classCommandLineRunner.FormattingOptionSet 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.StringOUTPUT_MARKERstatic intUTF8_BOM_CODE
-
Constructor Summary
Constructors Modifier Constructor Description protectedCommandLineRunner(java.lang.String[] args)Create a new command-line runner.protectedCommandLineRunner(java.lang.String[] args, java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err)protectedCommandLineRunner(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 voidaddAllowlistWarningsGuard(CompilerOptions options, java.io.File allowlistFile)protected voidappendRuntimeTo(java.lang.Appendable out)Writes whatever runtime libraries are needed to bundle.protected voidcheckModuleName(java.lang.String name)Validates the module name.protected CompilercreateCompiler()Returns the instance of the Compiler to use whenAbstractCommandLineRunner.run()is called.protected java.util.List<SourceFile>createExterns(CompilerOptions options)protected CompilerOptionscreateOptions()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.StringgetVersionText()Some text identifying this binary and its version.booleanhasErrors()static voidmain(java.lang.String[] args)Runs the Compiler.protected voidprepForBundleAndAppendTo(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.booleanshouldRunCompiler()-
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: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
protected void addAllowlistWarningsGuard(CompilerOptions options, java.io.File allowlistFile)
- Specified by:
addAllowlistWarningsGuardin classAbstractCommandLineRunner<Compiler,CompilerOptions>
-
checkModuleName
protected void checkModuleName(java.lang.String name)
Description copied from class:AbstractCommandLineRunnerValidates the module name. Can be overridden by subclasses.- Overrides:
checkModuleNamein classAbstractCommandLineRunner<Compiler,CompilerOptions>- Parameters:
name- The module name
-
createOptions
protected CompilerOptions 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
protected Compiler 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(java.lang.Appendable out, CompilerInput input, java.lang.String content) throws java.io.IOExceptionDescription 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:
java.io.IOException
-
appendRuntimeTo
protected void appendRuntimeTo(java.lang.Appendable out) throws java.io.IOExceptionDescription copied from class:AbstractCommandLineRunnerWrites whatever runtime libraries are needed to bundle.- Specified by:
appendRuntimeToin classAbstractCommandLineRunner<Compiler,CompilerOptions>- Throws:
java.io.IOException
-
createExterns
protected java.util.List<SourceFile> createExterns(CompilerOptions options) throws java.io.IOException
- Overrides:
createExternsin 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.IOExceptionReturns 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.
-
-