langtools/src/share/classes/com/sun/tools/javac/main/Main.java
changeset 9071 88cd61b4e5aa
parent 8623 cc57bd7697a2
child 10193 3e1ef5e9f4fd
equal deleted inserted replaced
9070:f847fe5cad3d 9071:88cd61b4e5aa
    63     /** The writer to use for diagnostic output.
    63     /** The writer to use for diagnostic output.
    64      */
    64      */
    65     PrintWriter out;
    65     PrintWriter out;
    66 
    66 
    67     /**
    67     /**
    68      * If true, any command line arg errors will cause an exception.
    68      * If true, certain errors will cause an exception, such as command line
    69      */
    69      * arg errors, or exceptions in user provided code.
    70     boolean fatalErrors;
    70      */
       
    71     boolean apiMode;
       
    72 
    71 
    73 
    72     /** Result codes.
    74     /** Result codes.
    73      */
    75      */
    74     static final int
    76     static final int
    75         EXIT_OK = 0,        // Compilation completed with no errors.
    77         EXIT_OK = 0,        // Compilation completed with no errors.
   161     }
   163     }
   162 
   164 
   163     /** Report a usage error.
   165     /** Report a usage error.
   164      */
   166      */
   165     void error(String key, Object... args) {
   167     void error(String key, Object... args) {
   166         if (fatalErrors) {
   168         if (apiMode) {
   167             String msg = getLocalizedString(key, args);
   169             String msg = getLocalizedString(key, args);
   168             throw new PropagatedException(new IllegalStateException(msg));
   170             throw new PropagatedException(new IllegalStateException(msg));
   169         }
   171         }
   170         warning(key, args);
   172         warning(key, args);
   171         Log.printLines(out, getLocalizedString("msg.usage", ownName));
   173         Log.printLines(out, getLocalizedString("msg.usage", ownName));
   190         if (options == null)
   192         if (options == null)
   191             throw new NullPointerException();
   193             throw new NullPointerException();
   192         this.options = options;
   194         this.options = options;
   193     }
   195     }
   194 
   196 
   195     public void setFatalErrors(boolean fatalErrors) {
   197     public void setAPIMode(boolean apiMode) {
   196         this.fatalErrors = fatalErrors;
   198         this.apiMode = apiMode;
   197     }
   199     }
   198 
   200 
   199     /** Process command line arguments: store all command line options
   201     /** Process command line arguments: store all command line options
   200      *  in `options' table and return all source filenames.
   202      *  in `options' table and return all source filenames.
   201      *  @param flags    The array of command line arguments.
   203      *  @param flags    The array of command line arguments.
   438             resourceMessage(ex);
   440             resourceMessage(ex);
   439             return EXIT_SYSERR;
   441             return EXIT_SYSERR;
   440         } catch (FatalError ex) {
   442         } catch (FatalError ex) {
   441             feMessage(ex);
   443             feMessage(ex);
   442             return EXIT_SYSERR;
   444             return EXIT_SYSERR;
   443         } catch(AnnotationProcessingError ex) {
   445         } catch (AnnotationProcessingError ex) {
       
   446             if (apiMode)
       
   447                 throw new RuntimeException(ex.getCause());
   444             apMessage(ex);
   448             apMessage(ex);
   445             return EXIT_SYSERR;
   449             return EXIT_SYSERR;
   446         } catch (ClientCodeException ex) {
   450         } catch (ClientCodeException ex) {
   447             // as specified by javax.tools.JavaCompiler#getTask
   451             // as specified by javax.tools.JavaCompiler#getTask
   448             // and javax.tools.JavaCompiler.CompilationTask#call
   452             // and javax.tools.JavaCompiler.CompilationTask#call
   456             if (comp == null || comp.errorCount() == 0 ||
   460             if (comp == null || comp.errorCount() == 0 ||
   457                 options == null || options.isSet("dev"))
   461                 options == null || options.isSet("dev"))
   458                 bugMessage(ex);
   462                 bugMessage(ex);
   459             return EXIT_ABNORMAL;
   463             return EXIT_ABNORMAL;
   460         } finally {
   464         } finally {
   461             if (comp != null) comp.close();
   465             if (comp != null) {
       
   466                 try {
       
   467                     comp.close();
       
   468                 } catch (ClientCodeException ex) {
       
   469                     throw new RuntimeException(ex.getCause());
       
   470                 }
       
   471             }
   462             filenames = null;
   472             filenames = null;
   463             options = null;
   473             options = null;
   464         }
   474         }
   465         return EXIT_OK;
   475         return EXIT_OK;
   466     }
   476     }