public class CommandLineRunner extends Object
class MyCommandLineRunner extends CommandLineRunner {
MyCommandLineRunner(String[] args) {
super(args);
}
@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);
}
}
}
This class is totally not thread-safe.Modifier and Type | Class and Description |
---|---|
static class |
AbstractCommandLineRunner.FlagUsageException
An exception thrown when command-line flags are used incorrectly.
|
protected static class |
AbstractCommandLineRunner.WarningGuardSpec
A little helper class to make it easier to collect warning types
from --jscomp_error, --jscomp_warning, and --jscomp_off.
|
Modifier and Type | Field and Description |
---|---|
static String |
OUTPUT_MARKER |
static int |
UTF8_BOM_CODE |
Modifier | Constructor and Description |
---|---|
protected |
CommandLineRunner(String[] args)
Create a new command-line runner.
|
protected |
CommandLineRunner(String[] args,
PrintStream out,
PrintStream err) |
Modifier and Type | Method and Description |
---|---|
protected void |
addWhitelistWarningsGuard(CompilerOptions options,
File whitelistFile) |
protected void |
checkModuleName(String name)
Validates the module name.
|
protected Compiler |
createCompiler()
Returns the instance of the Compiler to use when
run() is
called. |
protected List<SourceFile> |
createExterns() |
protected List<SourceFile> |
createInputs(List<String> files,
boolean allowStdIn)
Creates inputs from a list of files.
|
protected CompilerOptions |
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 OutputStream |
filenameToOutputStream(String fileName)
Converts a file name into a Outputstream.
|
static List<String> |
findJsFiles(Collection<String> patterns)
Returns all the JavaScript files from the set of patterns.
|
protected com.google.javascript.jscomp.AbstractCommandLineRunner.CommandLineConfig |
getCommandLineConfig()
Get the command line config, so that it can be initialized.
|
protected A |
getCompiler() |
static List<SourceFile> |
getDefaultExterns() |
protected DiagnosticGroups |
getDiagnosticGroups()
The warning classes that are available from the command-line.
|
protected PrintStream |
getErrorPrintStream()
Returns the PrintStream for writing errors associated with this
AbstractCommandLineRunner.
|
boolean |
hasErrors() |
protected boolean |
isInTestMode()
Returns whether we're in test mode.
|
static void |
main(String[] args)
Runs the Compiler.
|
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.
|
boolean |
shouldRunCompiler() |
public static final String OUTPUT_MARKER
public static final int UTF8_BOM_CODE
protected CommandLineRunner(String[] args)
protected CommandLineRunner(String[] args, PrintStream out, PrintStream err)
protected void addWhitelistWarningsGuard(CompilerOptions options, File whitelistFile)
protected CompilerOptions createOptions()
run()
is called.
createCompiler() is called before createOptions(), so getCompiler()
will not return null when createOptions() is called.protected Compiler createCompiler()
run()
is
called.protected List<SourceFile> createExterns() throws AbstractCommandLineRunner.FlagUsageException, IOException
public static List<SourceFile> getDefaultExterns() throws IOException
IOException
public static List<String> findJsFiles(Collection<String> patterns) throws IOException
IOException
public boolean shouldRunCompiler()
public boolean hasErrors()
public static void main(String[] args)
protected boolean isInTestMode()
protected com.google.javascript.jscomp.AbstractCommandLineRunner.CommandLineConfig getCommandLineConfig()
protected DiagnosticGroups getDiagnosticGroups()
protected void setRunOptions(CompilerOptions options) throws AbstractCommandLineRunner.FlagUsageException, IOException
protected final A getCompiler()
public final void run()
protected PrintStream getErrorPrintStream()
protected List<SourceFile> createInputs(List<String> files, boolean allowStdIn) throws AbstractCommandLineRunner.FlagUsageException, IOException
files
- A list of filenamesallowStdIn
- Whether '-' is allowed appear as a filename to represent
stdin. If true, '-' is only allowed to appear once.AbstractCommandLineRunner.FlagUsageException
IOException
protected void checkModuleName(String name) throws AbstractCommandLineRunner.FlagUsageException
name
- The module nameAbstractCommandLineRunner.FlagUsageException
- if the validation failsprotected int doRun() throws AbstractCommandLineRunner.FlagUsageException, IOException
AbstractCommandLineRunner.FlagUsageException
IOException
protected OutputStream filenameToOutputStream(String fileName) throws IOException
IOException
Copyright © 2009-2014 Google. All Rights Reserved.