Class CommandLineRunner


  • @GwtIncompatible("Unnecessary")
    public class CommandLineRunner
    extends AbstractCommandLineRunner<Compiler,​CompilerOptions>
    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();
         }
         if (runner.hasErrors()) {
           System.exit(-1);
         }
       }
     }
     
    This class is totally not thread-safe.
    • Constructor Detail

      • CommandLineRunner

        protected CommandLineRunner​(java.lang.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​(java.lang.String[] args,
                                    java.io.PrintStream out,
                                    java.io.PrintStream err)
      • CommandLineRunner

        protected CommandLineRunner​(java.lang.String[] args,
                                    java.io.InputStream in,
                                    java.io.PrintStream out,
                                    java.io.PrintStream err)