|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.javascript.jscomp.CommandLineRunner
public class CommandLineRunner
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);
}
@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();
} else {
System.exit(-1);
}
}
}
This class is totally not thread-safe.
Nested Class Summary | |
---|---|
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. |
Constructor Summary | |
---|---|
protected |
CommandLineRunner(String[] args)
Create a new command-line runner. |
protected |
CommandLineRunner(String[] args,
PrintStream out,
PrintStream err)
|
Method Summary | |
---|---|
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 Ouputstream. |
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. |
protected void |
initOptionsFromFlags(CompilerOptions options)
Deprecated. |
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()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected CommandLineRunner(String[] args)
protected CommandLineRunner(String[] args, PrintStream out, PrintStream err)
Method Detail |
---|
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
AbstractCommandLineRunner.FlagUsageException
IOException
public static List<SourceFile> getDefaultExterns() throws IOException
IOException
public boolean shouldRunCompiler()
public static void main(String[] args)
protected boolean isInTestMode()
protected com.google.javascript.jscomp.AbstractCommandLineRunner.CommandLineConfig getCommandLineConfig()
protected DiagnosticGroups getDiagnosticGroups()
@Deprecated protected void initOptionsFromFlags(CompilerOptions options)
protected void setRunOptions(CompilerOptions options) throws AbstractCommandLineRunner.FlagUsageException, IOException
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 name
AbstractCommandLineRunner.FlagUsageException
- if the validation failsprotected int doRun() throws AbstractCommandLineRunner.FlagUsageException, IOException
AbstractCommandLineRunner.FlagUsageException
IOException
protected OutputStream filenameToOutputStream(String fileName) throws IOException
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |