## com.google.javascript.jscomp
Class CommandLineRunner

    java.lang.Object
      com.google.javascript.jscomp.CommandLineRunner

    public class CommandLineRunner

extends Object

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

### CommandLineRunner

    protected CommandLineRunner(String[] args)

  Create a new command-line runner. You should only need to call the constructor if you're extending this class. Otherwise, the main method should instantiate it.

### CommandLineRunner

    protected CommandLineRunner(String[] args,
                                PrintStream out,
                                PrintStream err)

Method Detail

### createOptions

    protected CompilerOptions createOptions()

  Returns the instance of the Options to use when `run()` is called. createCompiler() is called before createOptions(), so getCompiler() will not return null when createOptions() is called.

### createCompiler

    protected Compiler createCompiler()

  Returns the instance of the Compiler to use when `run()` is called.

### createExterns

    protected List<SourceFile> createExterns()
                                      throws AbstractCommandLineRunner.FlagUsageException,
                                             IOException

  Throws:
    `AbstractCommandLineRunner.FlagUsageException`
    `IOException`

### getDefaultExterns

    public static List<SourceFile> getDefaultExterns()
                                              throws IOException

  Returns:
    a mutable list
  Throws:
    `IOException`

### shouldRunCompiler

    public boolean shouldRunCompiler()

  Returns:
    Whether the configuration is valid.

### main

    public static void main(String[] args)

  Runs the Compiler. Exits cleanly in the event of an error.

### isInTestMode

    protected boolean isInTestMode()

  Returns whether we're in test mode.

### getCommandLineConfig

    protected com.google.javascript.jscomp.AbstractCommandLineRunner.CommandLineConfig getCommandLineConfig()

  Get the command line config, so that it can be initialized.

### getDiagnosticGroups

    protected DiagnosticGroups getDiagnosticGroups()

  The warning classes that are available from the command-line.

### initOptionsFromFlags

    @Deprecated
    protected void initOptionsFromFlags(CompilerOptions options)

  Deprecated.

  No longer does anything.

### setRunOptions

    protected void setRunOptions(CompilerOptions options)
                          throws AbstractCommandLineRunner.FlagUsageException,
                                 IOException

  Sets options based on the configurations set flags API. Called during the run() run() method. If you want to ignore the flags API, or intepret flags your own way, then you should override this method.

  Throws:
    `AbstractCommandLineRunner.FlagUsageException`
    `IOException`

### getCompiler

    protected final A getCompiler()

### run

    public final void run()

  Runs the Compiler and calls System.exit() with the exit status of the compiler.

### getErrorPrintStream

    protected PrintStream getErrorPrintStream()

  Returns the PrintStream for writing errors associated with this AbstractCommandLineRunner.

### createInputs

    protected List<SourceFile> createInputs(List<String> files,
                                            boolean allowStdIn)
                                     throws AbstractCommandLineRunner.FlagUsageException,
                                            IOException

  Creates inputs from a list of files. Can be overridden by subclasses who want to pull files from different places.

  Parameters:
    `files` - A list of filenames
    `allowStdIn` - Whether '-' is allowed appear as a filename to represent stdin. If true, '-' is only allowed to appear once.
  Returns:
    An array of inputs
  Throws:
    `AbstractCommandLineRunner.FlagUsageException`
    `IOException`

### checkModuleName

    protected void checkModuleName(String name)
                            throws AbstractCommandLineRunner.FlagUsageException

  Validates the module name. Can be overridden by subclasses.

  Parameters:
    `name` - The module name
  Throws:
    `AbstractCommandLineRunner.FlagUsageException` - if the validation fails

### doRun

    protected int doRun()
                 throws AbstractCommandLineRunner.FlagUsageException,
                        IOException

  Parses command-line arguments and runs the compiler.

  Returns:
    system exit status
  Throws:
    `AbstractCommandLineRunner.FlagUsageException`
    `IOException`

### filenameToOutputStream

    protected OutputStream filenameToOutputStream(String fileName)
                                           throws IOException

  Converts a file name into a Ouputstream. Returns null if the file name is null.

  Throws:
    `IOException`