diff --git a/WHATSNEW b/WHATSNEW
index 52e5e1288..4198302db 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -37,6 +37,9 @@ Other changes:
which will allow nonexistent files specified via
ExitStatusException
.
+ * @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 int
+ */
+ public int getStatus() {
+ return status;
+ }
+}
diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java
index 6dd940dd7..05b19440c 100644
--- a/src/main/org/apache/tools/ant/Main.java
+++ b/src/main/org/apache/tools/ant/Main.java
@@ -184,8 +184,15 @@ public class Main implements AntMain {
// 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);
diff --git a/src/main/org/apache/tools/ant/taskdefs/Exit.java b/src/main/org/apache/tools/ant/taskdefs/Exit.java
index 8d339d41f..731750c08 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Exit.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Exit.java
@@ -19,6 +19,7 @@ package org.apache.tools.ant.taskdefs;
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 @@ public class Exit extends Task {
private String message;
private String ifCondition, unlessCondition;
private NestedCondition nestedCondition;
+ private Integer status;
/**
* A message giving further information on why the build exited.
@@ -85,6 +87,14 @@ public class Exit extends Task {
unlessCondition = c;
}
+ /**
+ * Set the status code to associate with the thrown Exception.
+ * @param i the int
status
+ */
+ public void setStatus(int i) {
+ status = new Integer(i);
+ }
+
/**
* Throw a BuildException
to exit (fail) the build.
* 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()));
}
}