Package com.google.javascript.jscomp
Class AbstractCommandLineRunner<A extends Compiler,B extends CompilerOptions>
- java.lang.Object
-
- com.google.javascript.jscomp.AbstractCommandLineRunner<A,B>
-
- Direct Known Subclasses:
CommandLineRunner
public abstract class AbstractCommandLineRunner<A extends Compiler,B extends CompilerOptions> extends java.lang.ObjectImplementations of AbstractCommandLineRunner translate flags into Java API calls on the Compiler. AbstractCompiler contains common flags and logic to make that happen. This class may be extended and used to create other Java classes that behave the same as running the Compiler from the command line. Example:class MyCommandLineRunner extends AbstractCommandLineRunner<MyCompiler, MyOptions> { MyCommandLineRunner(String[] args) { super(args); } @Override protected MyOptions createOptions() { MyOptions options = new MyOptions(); CompilerFlagTranslator.setOptionsFromFlags(options); addMyCrazyCompilerPassThatOutputsAnExtraFile(options); return options; } @Override protected MyCompiler createCompiler() { return new MyCompiler(); } public static void main(String[] args) { (new MyCommandLineRunner(args)).run(); } }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractCommandLineRunner.CommandLineConfigConfigurations for the command line configs.protected static classAbstractCommandLineRunner.FlagEntry<T>A pair from flag to its value.static classAbstractCommandLineRunner.JsModuleSpecRepresents a specification for a js module.static classAbstractCommandLineRunner.JsonFileSpecRepresentation of a source file from an encoded json stream inputprotected static classAbstractCommandLineRunner.JsSourceTypeFlag types for JavaScript source files.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidaddAllowlistWarningsGuard(CompilerOptions options, java.io.File allowlistFile)protected abstract voidappendRuntimeTo(java.lang.Appendable out)Writes whatever runtime libraries are needed to bundle.protected voidcheckModuleName(java.lang.String name)Validates the module name.protected abstract AcreateCompiler()Returns the instance of the Compiler to use whenrun()is called.static voidcreateDefineOrTweakReplacements(java.util.List<java.lang.String> definitions, CompilerOptions options, boolean tweaks)Create a map of constant names to constant values from a textual description of the map.protected java.util.List<SourceFile>createExterns(CompilerOptions options)protected java.util.List<SourceFile>createInputs(java.util.List<AbstractCommandLineRunner.FlagEntry<AbstractCommandLineRunner.JsSourceType>> files, java.util.List<AbstractCommandLineRunner.JsonFileSpec> jsonFiles, boolean allowStdIn, java.util.List<AbstractCommandLineRunner.JsModuleSpec> jsModuleSpecs)Creates inputs from a list of source files, zips and json files.static java.util.List<JSModule>createJsModules(java.util.List<AbstractCommandLineRunner.JsModuleSpec> specs, java.util.List<SourceFile> inputs)Creates module objects from a list of js module specifications.protected abstract BcreateOptions()Returns the instance of the Options to use whenrun()is called.protected intdoRun()Parses command-line arguments and runs the compiler.protected java.io.OutputStreamfilenameToOutputStream(java.lang.String fileName)Converts a file name into a Outputstream.static java.util.List<SourceFile>getBuiltinExterns(CompilerOptions.Environment env)protected AbstractCommandLineRunner.CommandLineConfiggetCommandLineConfig()Get the command line config, so that it can be initialized.protected AgetCompiler()protected DiagnosticGroupsgetDiagnosticGroups()The warning classes that are available from the command-line.protected java.io.PrintStreamgetErrorPrintStream()Returns the PrintStream for writing errors associated with this AbstractCommandLineRunner.protected booleanisInTestMode()Returns whether we're in test mode.java.util.List<AbstractCommandLineRunner.JsonFileSpec>parseJsonFilesFromInputStream()static java.util.Map<java.lang.String,java.lang.String>parseModuleWrappers(java.util.List<java.lang.String> specs, java.lang.Iterable<JSModule> chunks)Parses module wrapper specifications.protected abstract 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.voidrun()Runs the Compiler and calls System.exit() with the exit status of the compiler.voidsetExitCodeReceiver(com.google.common.base.Function<java.lang.Integer,java.lang.Void> newExitCodeReceiver)protected voidsetRunOptions(CompilerOptions options)Sets options based on the configurations set flags API.protected static voidsetWarningGuardOptions(CompilerOptions options, java.util.ArrayList<AbstractCommandLineRunner.FlagEntry<CheckLevel>> warningGuards, DiagnosticGroups diagnosticGroups)protected booleanshouldGenerateMapPerModule(B options)Returns true if and only if a source map file should be generated for each module, as opposed to one unified map.voidvalidateBrowserFeaturesetYearFlag(java.lang.Integer inputYear)Validates whether --browser_featureset_year input value is legal
-
-
-
Method Detail
-
setExitCodeReceiver
@GwtIncompatible("Unnecessary") public void setExitCodeReceiver(com.google.common.base.Function<java.lang.Integer,java.lang.Void> newExitCodeReceiver)- Parameters:
newExitCodeReceiver- receives a non-zero integer to indicate a problem during execution or 0i to indicate success.
-
isInTestMode
@GwtIncompatible("Unnecessary") protected boolean isInTestMode()Returns whether we're in test mode.
-
getCommandLineConfig
@GwtIncompatible("Unnecessary") protected AbstractCommandLineRunner.CommandLineConfig getCommandLineConfig()Get the command line config, so that it can be initialized.
-
createCompiler
@GwtIncompatible("Unnecessary") protected abstract A createCompiler()Returns the instance of the Compiler to use whenrun()is called.
-
prepForBundleAndAppendTo
@GwtIncompatible("Unnecessary") protected abstract void prepForBundleAndAppendTo(java.lang.Appendable out, CompilerInput input, java.lang.String content) throws java.io.IOExceptionPerforms any transformation needed on the given compiler input and appends it to the given output bundle.- Throws:
java.io.IOException
-
appendRuntimeTo
@GwtIncompatible("Unnecessary") protected abstract void appendRuntimeTo(java.lang.Appendable out) throws java.io.IOExceptionWrites whatever runtime libraries are needed to bundle.- Throws:
java.io.IOException
-
createOptions
@GwtIncompatible("Unnecessary") protected abstract B createOptions()Returns the instance of the Options to use whenrun()is called. createCompiler() is called before createOptions(), so getCompiler() will not return null when createOptions() is called.
-
getDiagnosticGroups
@GwtIncompatible("Unnecessary") protected DiagnosticGroups getDiagnosticGroups()The warning classes that are available from the command-line.
-
addAllowlistWarningsGuard
@GwtIncompatible("Unnecessary") protected abstract void addAllowlistWarningsGuard(CompilerOptions options, java.io.File allowlistFile)
-
setWarningGuardOptions
@GwtIncompatible("Unnecessary") protected static void setWarningGuardOptions(CompilerOptions options, java.util.ArrayList<AbstractCommandLineRunner.FlagEntry<CheckLevel>> warningGuards, DiagnosticGroups diagnosticGroups)
-
validateBrowserFeaturesetYearFlag
@GwtIncompatible("java.time") public void validateBrowserFeaturesetYearFlag(java.lang.Integer inputYear)Validates whether --browser_featureset_year input value is legal- Parameters:
inputYear- integer value passed as input
-
setRunOptions
@GwtIncompatible("Unnecessary") protected void setRunOptions(CompilerOptions options) throws java.io.IOExceptionSets options based on the configurations set flags API. Called during the run() run() method. If you want to ignore the flags API, or interpret flags your own way, then you should override this method.- Throws:
java.io.IOException
-
getCompiler
@GwtIncompatible("Unnecessary") protected final A getCompiler()
-
getBuiltinExterns
@GwtIncompatible("Unnecessary") public static java.util.List<SourceFile> getBuiltinExterns(CompilerOptions.Environment env) throws java.io.IOException- Returns:
- a mutable list
- Throws:
java.io.IOException
-
run
@GwtIncompatible("Unnecessary") public final void run()Runs the Compiler and calls System.exit() with the exit status of the compiler.
-
getErrorPrintStream
@GwtIncompatible("Unnecessary") protected final java.io.PrintStream getErrorPrintStream()Returns the PrintStream for writing errors associated with this AbstractCommandLineRunner.
-
parseJsonFilesFromInputStream
@GwtIncompatible("Unnecessary") public java.util.List<AbstractCommandLineRunner.JsonFileSpec> parseJsonFilesFromInputStream() throws java.io.IOException- Throws:
java.io.IOException
-
createInputs
@GwtIncompatible("Unnecessary") protected java.util.List<SourceFile> createInputs(java.util.List<AbstractCommandLineRunner.FlagEntry<AbstractCommandLineRunner.JsSourceType>> files, java.util.List<AbstractCommandLineRunner.JsonFileSpec> jsonFiles, boolean allowStdIn, java.util.List<AbstractCommandLineRunner.JsModuleSpec> jsModuleSpecs) throws java.io.IOExceptionCreates inputs from a list of source files, zips and json files.Can be overridden by subclasses who want to pull files from different places.
- Parameters:
files- A list of flag entries indicates js and zip file namesjsonFiles- A list of json encoded files.allowStdIn- Whether '-' is allowed appear as a filename to represent stdin. If true, '-' is only allowed to appear once.jsModuleSpecs- A list js module specs.- Returns:
- An array of inputs
- Throws:
java.io.IOException
-
createJsModules
public static java.util.List<JSModule> createJsModules(java.util.List<AbstractCommandLineRunner.JsModuleSpec> specs, java.util.List<SourceFile> inputs) throws java.io.IOException
Creates module objects from a list of js module specifications.- Parameters:
specs- A list of js module specifications, not null or empty.inputs- A list of JS file paths, not null- Returns:
- An array of module objects
- Throws:
java.io.IOException
-
checkModuleName
@GwtIncompatible("Unnecessary") protected void checkModuleName(java.lang.String name)Validates the module name. Can be overridden by subclasses.- Parameters:
name- The module name
-
parseModuleWrappers
public static java.util.Map<java.lang.String,java.lang.String> parseModuleWrappers(java.util.List<java.lang.String> specs, java.lang.Iterable<JSModule> chunks)Parses module wrapper specifications.- Parameters:
specs- A list of module wrapper specifications, not null. The spec format is:name:wrapper. Wrappers.chunks- The JS chunks whose wrappers are specified- Returns:
- A map from module name to module wrapper. Modules with no wrapper will have the empty string as their value in this map.
-
doRun
@GwtIncompatible("Unnecessary") protected int doRun() throws java.io.IOExceptionParses command-line arguments and runs the compiler.- Returns:
- system exit status
- Throws:
java.io.IOException
-
createExterns
@GwtIncompatible("Unnecessary") protected java.util.List<SourceFile> createExterns(CompilerOptions options) throws java.io.IOException- Throws:
java.io.IOException
-
shouldGenerateMapPerModule
@GwtIncompatible("Unnecessary") protected boolean shouldGenerateMapPerModule(B options)Returns true if and only if a source map file should be generated for each module, as opposed to one unified map. This is specified by having the source map pattern include the %outname% variable.
-
filenameToOutputStream
@GwtIncompatible("Unnecessary") protected java.io.OutputStream filenameToOutputStream(java.lang.String fileName) throws java.io.IOExceptionConverts a file name into a Outputstream. Returns null if the file name is null.- Throws:
java.io.IOException
-
createDefineOrTweakReplacements
public static void createDefineOrTweakReplacements(java.util.List<java.lang.String> definitions, CompilerOptions options, boolean tweaks)Create a map of constant names to constant values from a textual description of the map.- Parameters:
definitions- A list of overriding definitions for defines in the form<name>[=<val>], where<val>is a number, boolean, or single-quoted string without single quotes.
-
-