diff --git a/WHATSNEW b/WHATSNEW index 9b30e00d0..9ba763066 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -17,6 +17,9 @@ Other changes: * tar entries with long link names are now handled the same way as entries with long names. + * swallowed the status code of nested tasks. + Bugzilla Report 55539 + Changes from Ant 1.9.1 TO Ant 1.9.2 =================================== diff --git a/src/etc/testcases/taskdefs/parallel.xml b/src/etc/testcases/taskdefs/parallel.xml index 6c1681c54..9a3434c1d 100644 --- a/src/etc/testcases/taskdefs/parallel.xml +++ b/src/etc/testcases/taskdefs/parallel.xml @@ -142,6 +142,20 @@ + + + + + + + + + + + + + + Test build file for the <parallel> task. Use the various targets to run the tests. diff --git a/src/main/org/apache/tools/ant/taskdefs/Parallel.java b/src/main/org/apache/tools/ant/taskdefs/Parallel.java index 9641a940d..4e65f23b2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Parallel.java +++ b/src/main/org/apache/tools/ant/taskdefs/Parallel.java @@ -22,6 +22,7 @@ import java.util.Vector; import java.util.List; import java.util.ArrayList; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.ExitStatusException; import org.apache.tools.ant.Location; import org.apache.tools.ant.Task; import org.apache.tools.ant.TaskContainer; @@ -109,6 +110,9 @@ public class Parallel extends Task /** The location of the first exception */ private Location firstLocation; + /** The status of the first ExitStatusException. */ + private Integer firstExitStatus; + /** * Add a group of daemon threads * @param daemonTasks The tasks to be executed as daemon. @@ -230,6 +234,14 @@ public class Parallel extends Task && firstLocation == Location.UNKNOWN_LOCATION) { firstLocation = ((BuildException) t).getLocation(); } + if (t instanceof ExitStatusException + && firstExitStatus == null) { + ExitStatusException ex = (ExitStatusException) t; + firstExitStatus = ex.getStatus(); + // potentially overwriting existing value but the + // location should match the exit status + firstLocation = ex.getLocation(); + } exceptionMessage.append(StringUtils.LINE_SEP); exceptionMessage.append(t.getMessage()); } @@ -366,6 +378,7 @@ public class Parallel extends Task exceptionMessage = new StringBuffer(); numExceptions = 0; firstException = null; + firstExitStatus = null; firstLocation = Location.UNKNOWN_LOCATION; processExceptions(daemons); processExceptions(runnables); @@ -377,8 +390,13 @@ public class Parallel extends Task throw new BuildException(firstException); } } else if (numExceptions > 1) { - throw new BuildException(exceptionMessage.toString(), - firstLocation); + if (firstExitStatus == null) { + throw new BuildException(exceptionMessage.toString(), + firstLocation); + } else { + throw new ExitStatusException(exceptionMessage.toString(), + firstExitStatus, firstLocation); + } } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java index b3b3cb77c..fcd67bd7b 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java @@ -16,12 +16,14 @@ * */ package org.apache.tools.ant.taskdefs; + import java.io.PrintStream; import junit.framework.AssertionFailedError; import org.apache.tools.ant.BuildFileTest; import org.apache.tools.ant.DemuxOutputStream; +import org.apache.tools.ant.ExitStatusException; import org.apache.tools.ant.Project; /** @@ -150,5 +152,27 @@ public class ParallelTest extends BuildFileTest { } } + /** + * @see "https://issues.apache.org/bugzilla/show_bug.cgi?id=55539" + */ + public void testSingleExit() { + try { + executeTarget("testSingleExit"); + } catch (ExitStatusException ex) { + assertEquals(42, ex.getStatus()); + } + } + + /** + * @see "https://issues.apache.org/bugzilla/show_bug.cgi?id=55539" + */ + public void testExitAndOtherException() { + try { + executeTarget("testExitAndOtherException"); + } catch (ExitStatusException ex) { + assertEquals(42, ex.getStatus()); + } + } + }