Browse Source

don't swallow fail's status in parallel - PR 55539

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1524979 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 11 years ago
parent
commit
6b9311408e
4 changed files with 61 additions and 2 deletions
  1. +3
    -0
      WHATSNEW
  2. +14
    -0
      src/etc/testcases/taskdefs/parallel.xml
  3. +20
    -2
      src/main/org/apache/tools/ant/taskdefs/Parallel.java
  4. +24
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java

+ 3
- 0
WHATSNEW View File

@@ -17,6 +17,9 @@ Other changes:
* tar entries with long link names are now handled the same way as * tar entries with long link names are now handled the same way as
entries with long names. entries with long names.


* <parallel> swallowed the status code of nested <fail> tasks.
Bugzilla Report 55539

Changes from Ant 1.9.1 TO Ant 1.9.2 Changes from Ant 1.9.1 TO Ant 1.9.2
=================================== ===================================




+ 14
- 0
src/etc/testcases/taskdefs/parallel.xml View File

@@ -142,6 +142,20 @@
</parallel> </parallel>
</target> </target>
<target name="testSingleExit">
<parallel>
<echo message="all is well"/>
<fail message="no it isn't" status="42"/>
</parallel>
</target>

<target name="testExitAndOtherException">
<parallel>
<fail message="no it isn't"/>
<fail message="no it isn't" status="42"/>
</parallel>
</target>

<target name="help"> <target name="help">
<echo>Test build file for the &lt;parallel&gt; task.</echo> <echo>Test build file for the &lt;parallel&gt; task.</echo>
<echo>Use the various targets to run the tests.</echo> <echo>Use the various targets to run the tests.</echo>


+ 20
- 2
src/main/org/apache/tools/ant/taskdefs/Parallel.java View File

@@ -22,6 +22,7 @@ import java.util.Vector;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ExitStatusException;
import org.apache.tools.ant.Location; import org.apache.tools.ant.Location;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.TaskContainer; import org.apache.tools.ant.TaskContainer;
@@ -109,6 +110,9 @@ public class Parallel extends Task
/** The location of the first exception */ /** The location of the first exception */
private Location firstLocation; private Location firstLocation;


/** The status of the first ExitStatusException. */
private Integer firstExitStatus;

/** /**
* Add a group of daemon threads * Add a group of daemon threads
* @param daemonTasks The tasks to be executed as daemon. * @param daemonTasks The tasks to be executed as daemon.
@@ -230,6 +234,14 @@ public class Parallel extends Task
&& firstLocation == Location.UNKNOWN_LOCATION) { && firstLocation == Location.UNKNOWN_LOCATION) {
firstLocation = ((BuildException) t).getLocation(); 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(StringUtils.LINE_SEP);
exceptionMessage.append(t.getMessage()); exceptionMessage.append(t.getMessage());
} }
@@ -366,6 +378,7 @@ public class Parallel extends Task
exceptionMessage = new StringBuffer(); exceptionMessage = new StringBuffer();
numExceptions = 0; numExceptions = 0;
firstException = null; firstException = null;
firstExitStatus = null;
firstLocation = Location.UNKNOWN_LOCATION; firstLocation = Location.UNKNOWN_LOCATION;
processExceptions(daemons); processExceptions(daemons);
processExceptions(runnables); processExceptions(runnables);
@@ -377,8 +390,13 @@ public class Parallel extends Task
throw new BuildException(firstException); throw new BuildException(firstException);
} }
} else if (numExceptions > 1) { } 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);
}
} }
} }




+ 24
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java View File

@@ -16,12 +16,14 @@
* *
*/ */
package org.apache.tools.ant.taskdefs; package org.apache.tools.ant.taskdefs;

import java.io.PrintStream; import java.io.PrintStream;


import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;


import org.apache.tools.ant.BuildFileTest; import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.DemuxOutputStream; import org.apache.tools.ant.DemuxOutputStream;
import org.apache.tools.ant.ExitStatusException;
import org.apache.tools.ant.Project; 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());
}
}

} }



Loading…
Cancel
Save