Browse Source

Add status attribute to <fail>. Idea/design by Aurele Venet.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276588 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 21 years ago
parent
commit
00b218efe5
5 changed files with 87 additions and 3 deletions
  1. +3
    -0
      WHATSNEW
  2. +7
    -0
      docs/manual/CoreTasks/fail.html
  3. +56
    -0
      src/main/org/apache/tools/ant/ExitStatusException.java
  4. +9
    -2
      src/main/org/apache/tools/ant/Main.java
  5. +12
    -1
      src/main/org/apache/tools/ant/taskdefs/Exit.java

+ 3
- 0
WHATSNEW View File

@@ -37,6 +37,9 @@ Other changes:
which will allow nonexistent files specified via <filelist>s to which will allow nonexistent files specified via <filelist>s to
be passed to the executable. Bugzilla Report 29585. 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 Changes from Ant 1.6.1 to current Ant 1.6 CVS version
===================================================== =====================================================




+ 7
- 0
docs/manual/CoreTasks/fail.html View File

@@ -36,6 +36,13 @@ or character data nested into the element.</p>
exist in the current project</td> exist in the current project</td>
<td align="center" valign="top">No</td> <td align="center" valign="top">No</td>
</tr> </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> </table>


<h3>Parameters specified as nested elements</h3> <h3>Parameters specified as nested elements</h3>


+ 56
- 0
src/main/org/apache/tools/ant/ExitStatusException.java View File

@@ -0,0 +1,56 @@
/*
* 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;
}
}

+ 9
- 2
src/main/org/apache/tools/ant/Main.java View File

@@ -184,8 +184,15 @@ public class Main implements AntMain {
// expect the worst // expect the worst
int exitCode = 1; int exitCode = 1;
try { try {
runBuild(coreLoader);
exitCode = 0;
try {
runBuild(coreLoader);
exitCode = 0;
} catch (ExitStatusException ese) {
exitCode = ese.getStatus();
if (exitCode > 0) {
throw ese;
}
}
} catch (BuildException be) { } catch (BuildException be) {
if (err != System.err) { if (err != System.err) {
printMessage(be); printMessage(be);


+ 12
- 1
src/main/org/apache/tools/ant/taskdefs/Exit.java View File

@@ -19,6 +19,7 @@ package org.apache.tools.ant.taskdefs;


import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException; 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.Condition;
import org.apache.tools.ant.taskdefs.condition.ConditionBase; import org.apache.tools.ant.taskdefs.condition.ConditionBase;


@@ -58,6 +59,7 @@ public class Exit extends Task {
private String message; private String message;
private String ifCondition, unlessCondition; private String ifCondition, unlessCondition;
private NestedCondition nestedCondition; private NestedCondition nestedCondition;
private Integer status;


/** /**
* A message giving further information on why the build exited. * A message giving further information on why the build exited.
@@ -85,6 +87,14 @@ public class Exit extends Task {
unlessCondition = c; unlessCondition = c;
} }


/**
* 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. * Throw a <CODE>BuildException</CODE> to exit (fail) the build.
* If specified, evaluate conditions: * If specified, evaluate conditions:
@@ -126,7 +136,8 @@ public class Exit extends Task {
} }
} }
} }
throw new BuildException(text);
throw ((status == null) ? new BuildException(text)
: new ExitStatusException(text, status.intValue()));
} }
} }




Loading…
Cancel
Save