@GwtIncompatible(value="Unnecessary")
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 |
---|---|
(package private) 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.FlagUsageException
An exception thrown when command-line flags are used incorrectly.
|
(package private) static class |
AbstractCommandLineRunner.JsModuleSpec
Represents a specification for a js module.
|
private class |
AbstractCommandLineRunner.JsonFileSpec
Representation of a source file from an encoded json stream input
|
protected static class |
AbstractCommandLineRunner.JsSourceType
Flag types for js source files.
|
Modifier and Type | Field and Description |
---|---|
private static java.util.List<java.lang.String> |
BUILTIN_EXTERN_DEP_ORDER |
private static java.util.List<java.lang.String> |
BUILTIN_LANG_EXTERNS |
private A |
compiler |
private AbstractCommandLineRunner.CommandLineConfig |
config |
(package private) static DiagnosticType |
CONFLICTING_DUPLICATE_ZIP_CONTENTS |
private java.io.PrintStream |
defaultJsOutput |
private java.io.PrintStream |
err |
private com.google.common.base.Function<java.lang.Integer,java.lang.Boolean> |
exitCodeReceiverForTesting |
private com.google.common.base.Supplier<java.util.List<SourceFile>> |
externsSupplierForTesting |
private java.util.List<AbstractCommandLineRunner.JsonFileSpec> |
filesToStreamOut |
private com.google.gson.Gson |
gson |
private java.io.InputStream |
in |
private java.nio.charset.Charset |
inputCharset |
private com.google.common.base.Supplier<java.util.List<SourceFile>> |
inputsSupplierForTesting |
(package private) static DiagnosticType |
INVALID_MODULE_SOURCEMAP_PATTERN |
private java.nio.charset.Charset |
legacyOutputCharset |
private com.google.common.base.Supplier<java.util.List<JSModule>> |
modulesSupplierForTesting |
(package private) static DiagnosticType |
NO_TREE_GENERATED_ERROR |
(package private) static java.lang.String |
OUTPUT_MARKER |
private static java.lang.String |
OUTPUT_MARKER_JS_STRING |
(package private) static DiagnosticType |
OUTPUT_SAME_AS_INPUT_ERROR |
private java.nio.charset.Charset |
outputCharset2 |
private java.util.Map<java.lang.String,java.lang.String> |
parsedModuleWrappers |
private java.util.Map<java.lang.String,java.lang.String> |
rootRelativePathsMap |
private boolean |
testMode |
(package private) static java.lang.String |
WAITING_FOR_INPUT_WARNING |
Constructor and Description |
---|
AbstractCommandLineRunner() |
AbstractCommandLineRunner(java.io.InputStream in,
java.io.PrintStream out,
java.io.PrintStream err) |
AbstractCommandLineRunner(java.io.PrintStream out,
java.io.PrintStream err) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
addWhitelistWarningsGuard(CompilerOptions options,
File whitelistFile) |
protected void |
checkModuleName(java.lang.String name)
Validates the module name.
|
private static void |
closeAppendable(java.lang.Appendable output) |
private java.util.Map<java.lang.String,java.lang.String> |
constructRootRelativePathsMap()
Construct and return the input root path map.
|
protected abstract A |
createCompiler()
Returns the instance of the Compiler to use when
run() is
called. |
private java.lang.Appendable |
createDefaultOutput() |
(package private) 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.
|
(package private) static DependencyOptions |
createDependencyOptions(CompilerOptions.DependencyMode dependencyMode,
java.util.List<ModuleIdentifier> entryPoints)
A helper function for creating the dependency options object.
|
private java.util.List<SourceFile> |
createExternInputs(java.util.List<java.lang.String> files)
Creates JS extern inputs from a list of files.
|
protected java.util.List<SourceFile> |
createExterns(CompilerOptions options) |
protected java.util.List<SourceFile> |
createInputs(java.util.List<AbstractCommandLineRunner.FlagEntry<AbstractCommandLineRunner.JsSourceType>> files,
boolean allowStdIn,
java.util.List<AbstractCommandLineRunner.JsModuleSpec> jsModuleSpecs)
Creates inputs from a list of files.
|
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.
|
protected java.util.List<SourceFile> |
createInputs(java.util.List<AbstractCommandLineRunner.FlagEntry<AbstractCommandLineRunner.JsSourceType>> files,
java.util.List<AbstractCommandLineRunner.JsonFileSpec> jsonFiles,
java.util.List<AbstractCommandLineRunner.JsModuleSpec> jsModuleSpecs)
Creates inputs from a list of source files and json files.
|
(package private) 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.
|
(package private) AbstractCommandLineRunner.JsonFileSpec |
createJsonFile(B options,
java.lang.String outputMarker,
com.google.common.base.Function<java.lang.String,java.lang.String> escaper)
Save the compiler output to a JsonFileSpec to be later written to
stdout
|
private AbstractCommandLineRunner.JsonFileSpec |
createJsonFileFromModule(JSModule module)
Given an output module, convert it to a JSONFileSpec with associated
sourcemap
|
protected abstract B |
createOptions()
Returns the instance of the Options to use when
run() is called. |
private java.util.List<SourceFile> |
createSourceInputs(java.util.List<AbstractCommandLineRunner.JsModuleSpec> jsModuleSpecs,
java.util.List<AbstractCommandLineRunner.FlagEntry<AbstractCommandLineRunner.JsSourceType>> files,
java.util.List<AbstractCommandLineRunner.JsonFileSpec> jsonFiles)
Creates JS source code inputs from a list of files.
|
protected int |
doRun()
Parses command-line arguments and runs the compiler.
|
(package private) void |
enableTestMode(com.google.common.base.Supplier<java.util.List<SourceFile>> externsSupplier,
com.google.common.base.Supplier<java.util.List<SourceFile>> inputsSupplier,
com.google.common.base.Supplier<java.util.List<JSModule>> modulesSupplier,
com.google.common.base.Function<java.lang.Integer,java.lang.Boolean> exitCodeReceiver)
Put the command line runner into test mode.
|
private java.lang.String |
expandCommandLinePath(java.lang.String path,
JSModule forModule)
Expand a file path specified on the command-line.
|
(package private) java.lang.String |
expandSourceMapPath(B options,
JSModule forModule)
Expansion function for source map.
|
private java.io.Writer |
fileNameToLegacyOutputWriter(java.lang.String fileName)
Converts a file name into a Writer taking in account the output charset.
|
protected java.io.OutputStream |
filenameToOutputStream(java.lang.String fileName)
Converts a file name into a Outputstream.
|
private java.io.Writer |
fileNameToOutputWriter2(java.lang.String fileName)
Converts a file name into a Writer taking in account the output charset.
|
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.
|
private java.nio.charset.Charset |
getInputCharset()
Query the flag for the input charset, and return a Charset object
representing the selection.
|
(package private) com.google.common.base.Function<java.lang.String,java.lang.String> |
getJavascriptEscaper() |
private java.nio.charset.Charset |
getLegacyOutputCharset()
Query the flag for the output charset.
|
private java.lang.String |
getMapPath(java.lang.String outputFile)
Returns the path at which to output map file(s) based on the path at which
the JS binary will be placed.
|
private java.lang.String |
getModuleOutputFileName(JSModule m) |
private java.nio.charset.Charset |
getOutputCharset2()
Query the flag for the output charset.
|
protected boolean |
isInTestMode()
Returns whether we're in test mode.
|
private boolean |
isOutputInJson()
Returns whether output should be a JSON stream.
|
private static void |
maybeCreateDirsForPath(java.lang.String pathPrefix)
Creates any directories necessary to write a file that will have a given
path prefix.
|
private java.io.Writer |
openExternExportsStream(B options,
java.lang.String path)
Returns a stream for outputting the generated externs file.
|
private void |
outputBundle() |
(package private) void |
outputJsonStream() |
private void |
outputManifest() |
private void |
outputManifestOrBundle(java.util.List<java.lang.String> outputFiles,
boolean isManifest)
Writes the manifest or bundle of all compiler input files that were included
as controlled by --dependency_mode, if requested.
|
private DiagnosticType |
outputModuleBinaryAndSourceMaps(java.util.List<JSModule> modules,
B options) |
private void |
outputModuleGraphJson()
Creates a file containing the current module graph in JSON serialization.
|
private void |
outputNameMaps()
Outputs the variable and property name maps for the specified compiler if
the proper FLAGS are set.
|
(package private) void |
outputSingleBinary(B options) |
private void |
outputSourceMap(B options,
java.lang.String associatedName)
Outputs the source map found in the compiler to the proper path if one
exists.
|
java.util.List<AbstractCommandLineRunner.JsonFileSpec> |
parseJsonFilesFromInputStream() |
(package private) static java.util.Map<java.lang.String,java.lang.String> |
parseModuleWrappers(java.util.List<java.lang.String> specs,
java.util.List<JSModule> modules)
Parses module wrapper specifications.
|
(package private) void |
printBundleTo(java.lang.Iterable<CompilerInput> inputs,
java.lang.Appendable out)
Prints all the input contents, starting with a comment that specifies
the input file name (using root-relative paths) before each file.
|
private void |
printManifestTo(java.lang.Iterable<CompilerInput> inputs,
java.lang.Appendable out)
Prints a list of input names (using root-relative paths), delimited by
newlines, to the manifest file.
|
(package private) void |
printModuleGraphJsonTo(java.lang.Appendable out)
Prints the current module graph as JSON.
|
(package private) void |
printModuleGraphManifestOrBundleTo(JSModuleGraph graph,
java.lang.Appendable out,
boolean isManifest)
Prints a set of modules to the manifest or bundle file.
|
(package private) int |
processResults(Result result,
java.util.List<JSModule> modules,
B options)
Processes the results of the compile job, and returns an error code.
|
static java.util.List<JSError> |
removeDuplicateZipEntries(java.util.List<SourceFile> sourceFiles)
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.
|
protected void |
setRunOptions(CompilerOptions options)
Sets options based on the configurations set flags API.
|
private 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.
|
private boolean |
shouldGenerateOutputPerModule(java.lang.String output)
Returns true if and only if a manifest or bundle should be generated
for each module, as opposed to one unified manifest.
|
private java.io.Writer |
streamToLegacyOutputWriter(java.io.OutputStream stream)
Create a writer with the legacy output charset.
|
private java.io.Writer |
streamToOutputWriter2(java.io.OutputStream stream)
Create a writer with the newer output charset.
|
(package private) void |
writeModuleOutput(java.lang.Appendable out,
JSModule m) |
(package private) static void |
writeOutput(java.lang.Appendable out,
Compiler compiler,
java.lang.String code,
java.lang.String wrapper,
java.lang.String codePlaceholder,
com.google.common.base.Function<java.lang.String,java.lang.String> escaper)
Writes code to an output stream, optionally wrapping it in an arbitrary
wrapper that contains a placeholder where the code should be inserted.
|
static final DiagnosticType OUTPUT_SAME_AS_INPUT_ERROR
static final DiagnosticType NO_TREE_GENERATED_ERROR
static final DiagnosticType INVALID_MODULE_SOURCEMAP_PATTERN
static final DiagnosticType CONFLICTING_DUPLICATE_ZIP_CONTENTS
static final java.lang.String WAITING_FOR_INPUT_WARNING
private static final java.util.List<java.lang.String> BUILTIN_LANG_EXTERNS
private static final java.util.List<java.lang.String> BUILTIN_EXTERN_DEP_ORDER
private final AbstractCommandLineRunner.CommandLineConfig config
private final java.io.InputStream in
private final java.io.PrintStream defaultJsOutput
private final java.io.PrintStream err
private java.nio.charset.Charset inputCharset
private java.nio.charset.Charset outputCharset2
private java.nio.charset.Charset legacyOutputCharset
private boolean testMode
private com.google.common.base.Supplier<java.util.List<SourceFile>> externsSupplierForTesting
private com.google.common.base.Supplier<java.util.List<SourceFile>> inputsSupplierForTesting
private com.google.common.base.Supplier<java.util.List<JSModule>> modulesSupplierForTesting
private com.google.common.base.Function<java.lang.Integer,java.lang.Boolean> exitCodeReceiverForTesting
private java.util.Map<java.lang.String,java.lang.String> rootRelativePathsMap
private java.util.Map<java.lang.String,java.lang.String> parsedModuleWrappers
private final com.google.gson.Gson gson
static final java.lang.String OUTPUT_MARKER
private static final java.lang.String OUTPUT_MARKER_JS_STRING
private final java.util.List<AbstractCommandLineRunner.JsonFileSpec> filesToStreamOut
AbstractCommandLineRunner()
AbstractCommandLineRunner(java.io.PrintStream out, java.io.PrintStream err)
AbstractCommandLineRunner(java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err)
void enableTestMode(com.google.common.base.Supplier<java.util.List<SourceFile>> externsSupplier, com.google.common.base.Supplier<java.util.List<SourceFile>> inputsSupplier, com.google.common.base.Supplier<java.util.List<JSModule>> modulesSupplier, com.google.common.base.Function<java.lang.Integer,java.lang.Boolean> exitCodeReceiver)
externsSupplier
- A provider for externs.inputsSupplier
- A provider for source inputs.modulesSupplier
- A provider for modules. Only one of inputsSupplier
and modulesSupplier may be non-null.exitCodeReceiver
- A receiver for the status code that would
have been passed to System.exit in non-test mode.protected boolean isInTestMode()
private boolean isOutputInJson()
protected AbstractCommandLineRunner.CommandLineConfig getCommandLineConfig()
protected abstract A createCompiler()
run()
is
called.protected abstract B createOptions()
run()
is called.
createCompiler() is called before createOptions(), so getCompiler()
will not return null when createOptions() is called.protected DiagnosticGroups getDiagnosticGroups()
static DependencyOptions createDependencyOptions(CompilerOptions.DependencyMode dependencyMode, java.util.List<ModuleIdentifier> entryPoints)
protected abstract void addWhitelistWarningsGuard(CompilerOptions options, File whitelistFile)
protected void setRunOptions(CompilerOptions options) throws java.io.IOException
java.io.IOException
protected final A getCompiler()
public static java.util.List<SourceFile> getBuiltinExterns(CompilerOptions.Environment env) throws java.io.IOException
java.io.IOException
public final void run()
protected java.io.PrintStream getErrorPrintStream()
public java.util.List<AbstractCommandLineRunner.JsonFileSpec> parseJsonFilesFromInputStream() throws java.io.IOException
java.io.IOException
protected java.util.List<SourceFile> createInputs(java.util.List<AbstractCommandLineRunner.FlagEntry<AbstractCommandLineRunner.JsSourceType>> files, boolean allowStdIn, java.util.List<AbstractCommandLineRunner.JsModuleSpec> jsModuleSpecs) throws java.io.IOException
files
- A list of flag entries indicates js and zip file names.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
protected java.util.List<SourceFile> createInputs(java.util.List<AbstractCommandLineRunner.FlagEntry<AbstractCommandLineRunner.JsSourceType>> files, java.util.List<AbstractCommandLineRunner.JsonFileSpec> jsonFiles, java.util.List<AbstractCommandLineRunner.JsModuleSpec> jsModuleSpecs) throws java.io.IOException
files
- A list of flag entries indicates js and zip file names.jsonFiles
- A list of json encoded files.jsModuleSpecs
- A list js module specs.java.io.IOException
public static java.util.List<JSError> removeDuplicateZipEntries(java.util.List<SourceFile> sourceFiles) throws java.io.IOException
sourceFiles
may be modified if duplicates are removed.java.io.IOException
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
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
private java.util.List<SourceFile> createSourceInputs(java.util.List<AbstractCommandLineRunner.JsModuleSpec> jsModuleSpecs, java.util.List<AbstractCommandLineRunner.FlagEntry<AbstractCommandLineRunner.JsSourceType>> files, java.util.List<AbstractCommandLineRunner.JsonFileSpec> jsonFiles) throws java.io.IOException
java.io.IOException
private java.util.List<SourceFile> createExternInputs(java.util.List<java.lang.String> files) throws java.io.IOException
java.io.IOException
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
protected void checkModuleName(java.lang.String name)
name
- The module namestatic java.util.Map<java.lang.String,java.lang.String> parseModuleWrappers(java.util.List<java.lang.String> specs, java.util.List<JSModule> modules)
specs
- A list of module wrapper specifications, not null. The spec
format is: name:wrapper
. Wrappers.modules
- The JS modules whose wrappers are specifiedprivate java.lang.String getModuleOutputFileName(JSModule m)
void writeModuleOutput(java.lang.Appendable out, JSModule m) throws java.io.IOException
java.io.IOException
static void writeOutput(java.lang.Appendable out, Compiler compiler, java.lang.String code, java.lang.String wrapper, java.lang.String codePlaceholder, @Nullable com.google.common.base.Function<java.lang.String,java.lang.String> escaper) throws java.io.IOException
java.io.IOException
private static void maybeCreateDirsForPath(java.lang.String pathPrefix)
private java.lang.Appendable createDefaultOutput() throws java.io.IOException
java.io.IOException
private static void closeAppendable(java.lang.Appendable output) throws java.io.IOException
java.io.IOException
protected int doRun() throws java.io.IOException
java.io.IOException
int processResults(Result result, java.util.List<JSModule> modules, B options) throws java.io.IOException
java.io.IOException
com.google.common.base.Function<java.lang.String,java.lang.String> getJavascriptEscaper()
void outputSingleBinary(B options) throws java.io.IOException
java.io.IOException
AbstractCommandLineRunner.JsonFileSpec createJsonFile(B options, java.lang.String outputMarker, com.google.common.base.Function<java.lang.String,java.lang.String> escaper) throws java.io.IOException
java.io.IOException
void outputJsonStream() throws java.io.IOException
java.io.IOException
private DiagnosticType outputModuleBinaryAndSourceMaps(java.util.List<JSModule> modules, B options) throws AbstractCommandLineRunner.FlagUsageException, java.io.IOException
AbstractCommandLineRunner.FlagUsageException
java.io.IOException
private AbstractCommandLineRunner.JsonFileSpec createJsonFileFromModule(JSModule module) throws AbstractCommandLineRunner.FlagUsageException, java.io.IOException
AbstractCommandLineRunner.FlagUsageException
java.io.IOException
private java.nio.charset.Charset getInputCharset()
AbstractCommandLineRunner.FlagUsageException
- if flag is not a valid Charset name.private java.nio.charset.Charset getLegacyOutputCharset()
AbstractCommandLineRunner.FlagUsageException
- if flag is not a valid Charset name.private java.nio.charset.Charset getOutputCharset2()
AbstractCommandLineRunner.FlagUsageException
- if flag is not a valid Charset name.protected java.util.List<SourceFile> createExterns(CompilerOptions options) throws java.io.IOException
java.io.IOException
private boolean shouldGenerateMapPerModule(B options)
private java.io.Writer openExternExportsStream(B options, java.lang.String path) throws java.io.IOException
options
- The options to the Compiler.path
- The path of the generated JS source file.java.io.IOException
private java.lang.String expandCommandLinePath(java.lang.String path, JSModule forModule)
java.lang.String expandSourceMapPath(B options, JSModule forModule)
private java.io.Writer fileNameToLegacyOutputWriter(java.lang.String fileName) throws java.io.IOException
java.io.IOException
private java.io.Writer fileNameToOutputWriter2(java.lang.String fileName) throws java.io.IOException
java.io.IOException
protected java.io.OutputStream filenameToOutputStream(java.lang.String fileName) throws java.io.IOException
java.io.IOException
private java.io.Writer streamToLegacyOutputWriter(java.io.OutputStream stream) throws java.io.IOException
java.io.IOException
private java.io.Writer streamToOutputWriter2(java.io.OutputStream stream)
private void outputSourceMap(B options, java.lang.String associatedName) throws java.io.IOException
options
- The options to the Compiler.java.io.IOException
private java.lang.String getMapPath(java.lang.String outputFile)
private void outputNameMaps() throws java.io.IOException
java.io.IOException
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 private boolean shouldGenerateOutputPerModule(java.lang.String output)
private void outputManifest() throws java.io.IOException
java.io.IOException
private void outputBundle() throws java.io.IOException
java.io.IOException
private void outputManifestOrBundle(java.util.List<java.lang.String> outputFiles, boolean isManifest) throws java.io.IOException
java.io.IOException
private void outputModuleGraphJson() throws java.io.IOException
java.io.IOException
void printModuleGraphJsonTo(java.lang.Appendable out) throws java.io.IOException
java.io.IOException
void printModuleGraphManifestOrBundleTo(JSModuleGraph graph, java.lang.Appendable out, boolean isManifest) throws java.io.IOException
java.io.IOException
private void printManifestTo(java.lang.Iterable<CompilerInput> inputs, java.lang.Appendable out) throws java.io.IOException
java.io.IOException
void printBundleTo(java.lang.Iterable<CompilerInput> inputs, java.lang.Appendable out) throws java.io.IOException
java.io.IOException
private java.util.Map<java.lang.String,java.lang.String> constructRootRelativePathsMap()