ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Javac.java
Date Thu, 04 Jan 2001 10:08:59 GMT
conor       01/01/04 02:08:59

  Modified:    src/main/org/apache/tools/ant/taskdefs Javac.java
  Log:
  Provide a failonerror attribute for javac. This defaults to true. If you set it to
  false, an error is logged but the build will continue.
  
  Based on the idea by Ken Wood.
  
  Revision  Changes    Path
  1.61      +50 -26    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java
  
  Index: Javac.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- Javac.java	2001/01/03 14:18:30	1.60
  +++ Javac.java	2001/01/04 10:08:59	1.61
  @@ -116,6 +116,7 @@
       private Path extdirs;
       private static String lSep = System.getProperty("line.separator");
   
  +    protected boolean failOnError = true;
       protected File[] compileList = new File[0];
   
       /**
  @@ -230,6 +231,20 @@
       }
   
       /**
  +     * Throw a BuildException if compilation fails
  +     */
  +    public void setFailonerror(boolean fail) {
  +        failOnError = fail;
  +    }
  +
  +    /**
  +     * Proceed if compilation fails
  +     */
  +    public void setProceed(boolean proceed) {
  +        failOnError = !proceed;
  +    }
  +
  +    /**
        * Set the deprecation flag.
        */
       public void setDeprecation(boolean deprecation) {
  @@ -330,18 +345,29 @@
                   + (compileList.length == 1 ? "" : "s")
                   + (destDir != null ? " to " + destDir : ""));
   
  +            boolean compileSucceeded = false;
  +
               if (compiler.equalsIgnoreCase("classic")) {
  -                doClassicCompile();
  +                compileSucceeded = doClassicCompile();
               } else if (compiler.equalsIgnoreCase("modern")) {
  -                doModernCompile();
  +                compileSucceeded = doModernCompile();
               } else if (compiler.equalsIgnoreCase("jikes")) {
  -                doJikesCompile();
  +                compileSucceeded = doJikesCompile();
               } else if (compiler.equalsIgnoreCase("jvc")) {
  -                doJvcCompile();
  +                compileSucceeded = doJvcCompile();
               } else {
                   String msg = "Don't know how to use compiler " + compiler;
                   throw new BuildException(msg, location);
               }
  +            
  +            if (!compileSucceeded) {
  +                if (failOnError) {
  +                    throw new BuildException(FAIL_MSG, location);
  +                }
  +                else {
  +                    log(FAIL_MSG, Project.MSG_ERR);
  +                }
  +            }
           }
       }
   
  @@ -456,9 +482,10 @@
       /**
        * Peforms a compile using the classic compiler that shipped with
        * JDK 1.1 and 1.2.
  +     *
  +     * @return true if the compile succeeded
        */
  -
  -    private void doClassicCompile() throws BuildException {
  +    private boolean doClassicCompile() throws BuildException {
           log("Using classic compiler", Project.MSG_VERBOSE);
           Commandline cmd = setupJavacCommand();
   
  @@ -483,9 +510,7 @@
               // Call the compile() method
               Method compile = c.getMethod("compile", new Class [] { String[].class });
               Boolean ok = (Boolean)compile.invoke(compiler, new Object[] {cmd.getArguments()});
  -            if (!ok.booleanValue()) {
  -                throw new BuildException(FAIL_MSG, location);
  -            }
  +            return ok.booleanValue();
           }
           catch (ClassNotFoundException ex) {
               throw new BuildException("Cannot use classic compiler, as it is not available"+
  @@ -503,15 +528,15 @@
   
       /**
        * Performs a compile using the newer compiler that ships with JDK 1.3
  +     *
  +     * @return true if the compile succeeded
        */
  -
  -    private void doModernCompile() throws BuildException {
  +    private boolean doModernCompile() throws BuildException {
           try {
               Class.forName("com.sun.tools.javac.Main");
           } catch (ClassNotFoundException cnfe) {
               log("Modern compiler is not available - using classic compiler", Project.MSG_WARN);
  -            doClassicCompile();
  -            return;
  +            return doClassicCompile();
           }
   
           log("Using modern compiler", Project.MSG_VERBOSE);
  @@ -532,9 +557,7 @@
                   new Class [] {(new String [] {}).getClass ()});
               int result = ((Integer) compile.invoke
                             (compiler, new Object[] {cmd.getArguments()})) .intValue ();
  -            if (result != MODERN_COMPILER_SUCCESS) {
  -                throw new BuildException(FAIL_MSG, location);
  -            }
  +            return (result == MODERN_COMPILER_SUCCESS);
           } catch (Exception ex) {
               if (ex instanceof BuildException) {
                   throw (BuildException) ex;
  @@ -653,9 +676,10 @@
        * It has been successfully tested with jikes >1.10
        *
        * @author skanthak@muehlheim.de
  +     *
  +     * @return true if the compile succeeded
        */
  -
  -    private void doJikesCompile() throws BuildException {
  +    private boolean doJikesCompile() throws BuildException {
           log("Using jikes compiler", Project.MSG_VERBOSE);
   
           Path classpath = new Path(project);
  @@ -762,9 +786,7 @@
           int firstFileName = cmd.size();
           logAndAddFilesToCompile(cmd);
   
  -        if (executeJikesCompile(cmd.getCommandline(), firstFileName) != 0) {
  -            throw new BuildException(FAIL_MSG, location);
  -        }
  +        return executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
       }
   
       /**
  @@ -772,7 +794,7 @@
        * @param args - arguments to pass to process on command line
        * @param firstFileName - index of the first source file in args
        */
  -    protected int executeJikesCompile(String[] args, int firstFileName) {
  +    protected int executeExternalCompile(String[] args, int firstFileName) {
           String[] commandArray = null;
           File tmpFile = null;
   
  @@ -856,7 +878,11 @@
           }
       }
   
  -    private void doJvcCompile() throws BuildException {
  +    /*
  +     *
  +     * @return true if the compile succeeded
  +     */
  +    private boolean doJvcCompile() throws BuildException {
           log("Using jvc compiler", Project.MSG_VERBOSE);
   
           Path classpath = new Path(project);
  @@ -906,9 +932,7 @@
           int firstFileName = cmd.size();
           logAndAddFilesToCompile(cmd);
   
  -        if (executeJikesCompile(cmd.getCommandline(), firstFileName) != 0) {
  -            throw new BuildException(FAIL_MSG, location);
  -        }
  +        return executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
       }
   }
   
  
  
  

Mime
View raw message