src/share/classes/com/sun/tools/apt/main/Main.java

Print this page




  47 import com.sun.tools.javac.file.JavacFileManager;
  48 import com.sun.tools.javac.code.Source;
  49 import com.sun.tools.javac.code.Symbol;
  50 import com.sun.tools.javac.code.Type;
  51 import com.sun.tools.javac.jvm.Target;
  52 import com.sun.tools.javac.util.*;
  53 
  54 import com.sun.tools.apt.comp.AnnotationProcessingError;
  55 import com.sun.tools.apt.comp.UsageMessageNeededException;
  56 import com.sun.tools.apt.util.Bark;
  57 import com.sun.mirror.apt.AnnotationProcessorFactory;
  58 
  59 /** This class provides a commandline interface to the apt build-time
  60  *  tool.
  61  *
  62  *  <p><b>This is NOT part of any API supported by Sun Microsystems.
  63  *  If you write code that depends on this, you do so at your own
  64  *  risk.  This code and its internal interfaces are subject to change
  65  *  or deletion without notice.</b>
  66  */

  67 public class Main {
  68 
  69     /** For testing: enter any options you want to be set implicitly
  70      *  here.
  71      */
  72     static String[] forcedOpts = {
  73         // Preserve parameter names from class files if the class was
  74         // compiled with debug enabled
  75         "-XDsave-parameter-names"
  76     };
  77 
  78     /** The name of the compiler, for use in diagnostics.
  79      */
  80     String ownName;
  81 
  82     /** The writer to use for diagnostic output.
  83      */
  84     PrintWriter out;
  85 
  86 


 763      */
 764     public int compile(String[] args, AnnotationProcessorFactory factory) {
 765         int returnCode = 0;
 766         providedFactory = factory;
 767 
 768         Context context = new Context();
 769         JavacFileManager.preRegister(context);
 770         options = Options.instance(context);
 771         Bark bark;
 772 
 773         /*
 774          * Process the command line options to create the intial
 775          * options data.  This processing is at least partially reused
 776          * by any recursive apt calls.
 777          */
 778 
 779         // For testing: assume all arguments in forcedOpts are
 780         // prefixed to command line arguments.
 781         processArgs(forcedOpts);
 782 
 783 
 784         /*
 785          * A run of apt only gets passed the most recently generated
 786          * files; the initial run of apt gets passed the files from
 787          * the command line.
 788          */
 789 
 790         java.util.List<String> origFilenames;
 791         try {
 792             // assign args the result of parse to capture results of
 793             // '@file' expansion
 794             origFilenames = processArgs((args=CommandLine.parse(args)));





 795             if (origFilenames == null) {
 796                 return EXIT_CMDERR;
 797             } else if (origFilenames.size() == 0) {
 798                 // it is allowed to compile nothing if just asking for help
 799                 if (options.get("-help") != null ||
 800                     options.get("-X") != null)
 801                     return EXIT_OK;
 802             }
 803         } catch (java.io.FileNotFoundException e) {
 804             Bark.printLines(out, ownName + ": " +
 805                            getLocalizedString("err.file.not.found",
 806                                               e.getMessage()));
 807             return EXIT_SYSERR;
 808         } catch (IOException ex) {
 809             ioMessage(ex);
 810             return EXIT_SYSERR;
 811         } catch (OutOfMemoryError ex) {
 812             resourceMessage(ex);
 813             return EXIT_SYSERR;
 814         } catch (StackOverflowError ex) {




  47 import com.sun.tools.javac.file.JavacFileManager;
  48 import com.sun.tools.javac.code.Source;
  49 import com.sun.tools.javac.code.Symbol;
  50 import com.sun.tools.javac.code.Type;
  51 import com.sun.tools.javac.jvm.Target;
  52 import com.sun.tools.javac.util.*;
  53 
  54 import com.sun.tools.apt.comp.AnnotationProcessingError;
  55 import com.sun.tools.apt.comp.UsageMessageNeededException;
  56 import com.sun.tools.apt.util.Bark;
  57 import com.sun.mirror.apt.AnnotationProcessorFactory;
  58 
  59 /** This class provides a commandline interface to the apt build-time
  60  *  tool.
  61  *
  62  *  <p><b>This is NOT part of any API supported by Sun Microsystems.
  63  *  If you write code that depends on this, you do so at your own
  64  *  risk.  This code and its internal interfaces are subject to change
  65  *  or deletion without notice.</b>
  66  */
  67 @SuppressWarnings("deprecation")
  68 public class Main {
  69 
  70     /** For testing: enter any options you want to be set implicitly
  71      *  here.
  72      */
  73     static String[] forcedOpts = {
  74         // Preserve parameter names from class files if the class was
  75         // compiled with debug enabled
  76         "-XDsave-parameter-names"
  77     };
  78 
  79     /** The name of the compiler, for use in diagnostics.
  80      */
  81     String ownName;
  82 
  83     /** The writer to use for diagnostic output.
  84      */
  85     PrintWriter out;
  86 
  87 


 764      */
 765     public int compile(String[] args, AnnotationProcessorFactory factory) {
 766         int returnCode = 0;
 767         providedFactory = factory;
 768 
 769         Context context = new Context();
 770         JavacFileManager.preRegister(context);
 771         options = Options.instance(context);
 772         Bark bark;
 773 
 774         /*
 775          * Process the command line options to create the intial
 776          * options data.  This processing is at least partially reused
 777          * by any recursive apt calls.
 778          */
 779 
 780         // For testing: assume all arguments in forcedOpts are
 781         // prefixed to command line arguments.
 782         processArgs(forcedOpts);
 783 

 784         /*
 785          * A run of apt only gets passed the most recently generated
 786          * files; the initial run of apt gets passed the files from
 787          * the command line.
 788          */
 789 
 790         java.util.List<String> origFilenames;
 791         try {
 792             // assign args the result of parse to capture results of
 793             // '@file' expansion
 794             origFilenames = processArgs((args=CommandLine.parse(args)));
 795 
 796             if (options.get("suppress-tool-api-removal-message") == null) {
 797                 Bark.printLines(out, getLocalizedString("misc.Deprecation"));
 798             }
 799 
 800             if (origFilenames == null) {
 801                 return EXIT_CMDERR;
 802             } else if (origFilenames.size() == 0) {
 803                 // it is allowed to compile nothing if just asking for help
 804                 if (options.get("-help") != null ||
 805                     options.get("-X") != null)
 806                     return EXIT_OK;
 807             }
 808         } catch (java.io.FileNotFoundException e) {
 809             Bark.printLines(out, ownName + ": " +
 810                            getLocalizedString("err.file.not.found",
 811                                               e.getMessage()));
 812             return EXIT_SYSERR;
 813         } catch (IOException ex) {
 814             ioMessage(ex);
 815             return EXIT_SYSERR;
 816         } catch (OutOfMemoryError ex) {
 817             resourceMessage(ex);
 818             return EXIT_SYSERR;
 819         } catch (StackOverflowError ex) {