public abstract class AbstractCommandLineRunner<A extends Compiler,B extends CompilerOptions>
extends java.lang.Object
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(); } }
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractCommandLineRunner.CommandLineConfig
Configurations for the command line configs.
|
protected static class |
AbstractCommandLineRunner.FlagEntry<T>
A pair from flag to its value.
|
static class |
AbstractCommandLineRunner.JsModuleSpec
Represents a specification for a js module.
|
static class |
AbstractCommandLineRunner.JsonFileSpec
Representation of a source file from an encoded json stream input
|
protected static class |
AbstractCommandLineRunner.JsSourceType
Flag types for JavaScript source files.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
addWhitelistWarningsGuard(CompilerOptions options,
java.io.File whitelistFile) |
protected abstract 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 abstract A |
createCompiler()
Returns the instance of the Compiler to use when
run() is called. |
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.
|
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 B |
createOptions()
Returns the instance of the Options to use when
run() is called. |
protected int |
doRun()
Parses command-line arguments and runs the compiler.
|
protected java.io.OutputStream |
filenameToOutputStream(java.lang.String fileName)
Converts a file name into a Outputstream.
|
static java.util.List<SourceFile> |
getBuiltinExterns(CompilerOptions.Environment env) |
protected AbstractCommandLineRunner.CommandLineConfig |
getCommandLineConfig()
Get the command line config, so that it can be initialized.
|
protected A |
getCompiler() |
protected DiagnosticGroups |
getDiagnosticGroups()
The warning classes that are available from the command-line.
|
protected java.io.PrintStream |
getErrorPrintStream()
Returns the PrintStream for writing errors associated with this AbstractCommandLineRunner.
|
protected boolean |
isInTestMode()
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 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.
|
static com.google.common.collect.ImmutableList<JSError> |
removeDuplicateZipEntries(java.util.List<SourceFile> sourceFiles,
java.util.List<AbstractCommandLineRunner.JsModuleSpec> jsModuleSpecs)
Check that relative paths inside zip files are unique, since multiple files with the same path
inside different zips are considered duplicate inputs.
|
void |
run()
Runs the Compiler and calls System.exit() with the exit status of the compiler.
|
void |
setExitCodeReceiver(com.google.common.base.Function<java.lang.Integer,java.lang.Void> newExitCodeReceiver) |
protected void |
setRunOptions(CompilerOptions options)
Sets options based on the configurations set flags API.
|
protected static void |
setWarningGuardOptions(CompilerOptions options,
java.util.ArrayList<AbstractCommandLineRunner.FlagEntry<CheckLevel>> warningGuards,
DiagnosticGroups diagnosticGroups) |
@GwtIncompatible(value="Unnecessary") public void setExitCodeReceiver(com.google.common.base.Function<java.lang.Integer,java.lang.Void> newExitCodeReceiver)
newExitCodeReceiver
- receives a non-zero integer to indicate a problem during execution
or 0i to indicate success.@GwtIncompatible(value="Unnecessary") protected boolean isInTestMode()
@GwtIncompatible(value="Unnecessary") protected AbstractCommandLineRunner.CommandLineConfig getCommandLineConfig()
@GwtIncompatible(value="Unnecessary") protected abstract A createCompiler()
run()
is called.@GwtIncompatible(value="Unnecessary") protected abstract void prepForBundleAndAppendTo(java.lang.Appendable out, CompilerInput input, java.lang.String content) throws java.io.IOException
java.io.IOException
@GwtIncompatible(value="Unnecessary") protected abstract void appendRuntimeTo(java.lang.Appendable out) throws java.io.IOException
java.io.IOException
@GwtIncompatible(value="Unnecessary") protected abstract B createOptions()
run()
is called. createCompiler() is
called before createOptions(), so getCompiler() will not return null when createOptions() is
called.@GwtIncompatible(value="Unnecessary") protected DiagnosticGroups getDiagnosticGroups()
@GwtIncompatible(value="Unnecessary") protected abstract void addWhitelistWarningsGuard(CompilerOptions options, java.io.File whitelistFile)
@GwtIncompatible(value="Unnecessary") protected static void setWarningGuardOptions(CompilerOptions options, java.util.ArrayList<AbstractCommandLineRunner.FlagEntry<CheckLevel>> warningGuards, DiagnosticGroups diagnosticGroups)
@GwtIncompatible(value="Unnecessary") protected void setRunOptions(CompilerOptions options) throws java.io.IOException
java.io.IOException
@GwtIncompatible(value="Unnecessary") protected final A getCompiler()
@GwtIncompatible(value="Unnecessary") public static java.util.List<SourceFile> getBuiltinExterns(CompilerOptions.Environment env) throws java.io.IOException
java.io.IOException
@GwtIncompatible(value="Unnecessary") public final void run()
@GwtIncompatible(value="Unnecessary") protected final java.io.PrintStream getErrorPrintStream()
@GwtIncompatible(value="Unnecessary") public java.util.List<AbstractCommandLineRunner.JsonFileSpec> parseJsonFilesFromInputStream() throws java.io.IOException
java.io.IOException
@GwtIncompatible(value="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.IOException
Can be overridden by subclasses who want to pull files from different places.
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.java.io.IOException
@GwtIncompatible(value="Unnecessary") public static com.google.common.collect.ImmutableList<JSError> removeDuplicateZipEntries(java.util.List<SourceFile> sourceFiles, java.util.List<AbstractCommandLineRunner.JsModuleSpec> jsModuleSpecs) throws java.io.IOException
sourceFiles
may be
modified if duplicates are removed.java.io.IOException
public static java.util.List<JSModule> createJsModules(java.util.List<AbstractCommandLineRunner.JsModuleSpec> specs, java.util.List<SourceFile> inputs) throws java.io.IOException
specs
- A list of js module specifications, not null or empty.inputs
- A list of JS file paths, not nulljava.io.IOException
@GwtIncompatible(value="Unnecessary") protected void checkModuleName(java.lang.String name)
name
- The module namepublic static java.util.Map<java.lang.String,java.lang.String> parseModuleWrappers(java.util.List<java.lang.String> specs, java.lang.Iterable<JSModule> chunks)
specs
- A list of module wrapper specifications, not null. The spec format is:
name:wrapper
. Wrappers.chunks
- The JS chunks whose wrappers are specified@GwtIncompatible(value="Unnecessary") protected int doRun() throws java.io.IOException
java.io.IOException
@GwtIncompatible(value="Unnecessary") protected java.util.List<SourceFile> createExterns(CompilerOptions options) throws java.io.IOException
java.io.IOException
@GwtIncompatible(value="Unnecessary") protected java.io.OutputStream filenameToOutputStream(java.lang.String fileName) throws java.io.IOException
java.io.IOException
public static void createDefineOrTweakReplacements(java.util.List<java.lang.String> definitions, CompilerOptions options, boolean tweaks)
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.Copyright © 2009-2019 Google. All Rights Reserved.