ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject cvs commit: ant/docs/manual/CoreTasks fail.html
Date Thu, 17 Jun 2004 20:33:13 GMT
mbenson     2004/06/17 13:33:13

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant Main.java
               src/main/org/apache/tools/ant/taskdefs Exit.java
               docs/manual/CoreTasks fail.html
  Added:       src/main/org/apache/tools/ant ExitStatusException.java
  Log:
  Add status attribute to <fail>.  Idea/design by Aurele Venet.
  
  Revision  Changes    Path
  1.625     +3 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.624
  retrieving revision 1.625
  diff -u -r1.624 -r1.625
  --- WHATSNEW	16 Jun 2004 16:41:38 -0000	1.624
  +++ WHATSNEW	17 Jun 2004 20:33:13 -0000	1.625
  @@ -37,6 +37,9 @@
     which will allow nonexistent files specified via <filelist>s to
     be passed to the executable.  Bugzilla Report 29585.
   
  +* <fail> has a status attribute that can be used to pass an exit
  +  status back to the command line.
  +
   Changes from Ant 1.6.1 to current Ant 1.6 CVS version
   =====================================================
   
  
  
  
  1.107     +9 -2      ant/src/main/org/apache/tools/ant/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Main.java,v
  retrieving revision 1.106
  retrieving revision 1.107
  diff -u -r1.106 -r1.107
  --- Main.java	20 Apr 2004 19:27:54 -0000	1.106
  +++ Main.java	17 Jun 2004 20:33:13 -0000	1.107
  @@ -184,8 +184,15 @@
           // expect the worst
           int exitCode = 1;
           try {
  -            runBuild(coreLoader);
  -            exitCode = 0;
  +            try {
  +                runBuild(coreLoader);
  +                exitCode = 0;
  +            } catch (ExitStatusException ese) {
  +                exitCode = ese.getStatus();
  +                if (exitCode > 0) {
  +                    throw ese;
  +                }
  +            }
           } catch (BuildException be) {
               if (err != System.err) {
                   printMessage(be);
  
  
  
  1.1                  ant/src/main/org/apache/tools/ant/ExitStatusException.java
  
  Index: ExitStatusException.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  package org.apache.tools.ant;
  
  /**
   * BuildException + exit status.
   *
   * @since Ant 1.7
   */
  public class ExitStatusException extends BuildException {
  
      /** Status code */
      private int status;
  
      /**
       * Constructs an <CODE>ExitStatusException</CODE>.
       * @param status the associated status code
       */
      public ExitStatusException(int status) {
          super();
          this.status = status;
      }
  
      /**
       * Constructs an exit exception.
       * @param msg the associated message
       * @param status the associated status code
       */
      public ExitStatusException(String msg, int status) {
          super(msg);
          this.status = status;
      }
  
      /**
       * Get the status code
       *
       * @return <CODE>int</CODE>
       */
      public int getStatus() {
          return status;
      }
  }
  
  
  
  1.33      +12 -1     ant/src/main/org/apache/tools/ant/taskdefs/Exit.java
  
  Index: Exit.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Exit.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Exit.java	29 Apr 2004 22:10:56 -0000	1.32
  +++ Exit.java	17 Jun 2004 20:33:13 -0000	1.33
  @@ -19,6 +19,7 @@
   
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.ExitStatusException;
   import org.apache.tools.ant.taskdefs.condition.Condition;
   import org.apache.tools.ant.taskdefs.condition.ConditionBase;
   
  @@ -58,6 +59,7 @@
       private String message;
       private String ifCondition, unlessCondition;
       private NestedCondition nestedCondition;
  +    private Integer status;
   
       /**
        * A message giving further information on why the build exited.
  @@ -86,6 +88,14 @@
       }
   
       /**
  +     * Set the status code to associate with the thrown Exception.
  +     * @param i   the <CODE>int</CODE> status
  +     */
  +    public void setStatus(int i) {
  +        status = new Integer(i);
  +    }
  +
  +    /**
        * Throw a <CODE>BuildException</CODE> to exit (fail) the build.
        * If specified, evaluate conditions:
        * A single nested condition is accepted, but requires that the
  @@ -126,7 +136,8 @@
                       }
                   }
               }
  -            throw new BuildException(text);
  +            throw ((status == null) ? new BuildException(text)
  +             : new ExitStatusException(text, status.intValue()));
           }
       }
   
  
  
  
  1.12      +7 -0      ant/docs/manual/CoreTasks/fail.html
  
  Index: fail.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/fail.html,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- fail.html	29 Apr 2004 21:25:40 -0000	1.11
  +++ fail.html	17 Jun 2004 20:33:13 -0000	1.12
  @@ -36,6 +36,13 @@
         exist in the current project</td>
       <td align="center" valign="top">No</td>
     </tr>
  +  <tr>
  +    <td valign="top">status</td>
  +    <td valign="top">Exit using the specified status code;
  +      assuming the generated Exception is not caught, the
  +      JVM will exit with this status. <em>Since Ant 1.7</em></td>
  +    <td align="center" valign="top">No</td>
  +  </tr>
   </table>
   
   <h3>Parameters specified as nested elements</h3>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message