for-each task discards BuildExceptions when run in parallel mode
"Bill Michell" <[email protected]> Wed, 26 Mar 2008 16:42:32 -0000
| Newsgroups | gmane.comp.java.ant-contrib.devel |
|---|---|
| Message-ID | <79D247FDCE9AC64FB864A3A128E2199104037B5D@bbcxues11.national.core.bbc.co.uk> |
When you run in sequential mode, any BuildExceptions thrown by the
nested tasks are allowed to fall through, and so cause the for-each task
to fail.
However, if you turn on parallel mode, the BuildExceptions are not
caught in the executeParallel method, and so the build does not fail.
I consider this an error, and so submit a candidate patch that catches
any BuildExceptions thrown by the nested tasks. If any are caught, they
are re-thrown when the for-each task completes.
Because I consider the current behaviour to be a bug for the reason I
stated above, I haven't provided any means to turn this behaviour off.
It would be pretty trivial to add a Boolean attribute, though, if that
were considered necessary.
What do you think of the patch? Is this a good way to contribute it?
Index: .
===================================================================
--- . (revision 158)
+++ . (working copy)
@@ -20,10 +20,7 @@
import java.util.StringTokenizer;
import java.util.Vector;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.TaskContainer;
+import org.apache.tools.ant.*;
import org.apache.tools.ant.taskdefs.Ant;
import org.apache.tools.ant.taskdefs.CallTarget;
import org.apache.tools.ant.taskdefs.Property;
@@ -30,7 +27,7 @@
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Mapper;
import org.apache.tools.ant.types.Path;
-import org.apache.tools.ant.util.FileNameMapper;
+import org.apache.tools.ant.util.*;
import net.sf.antcontrib.util.ThreadPool;
import net.sf.antcontrib.util.ThreadPoolThread;
@@ -85,6 +82,7 @@
private boolean trim;
private int maxThreads;
private Mapper mapper;
+ private boolean failOnFailure;
/***
* Default Constructor
@@ -104,7 +102,7 @@
this.maxThreads = 5;
}
- private void executeParallel(Vector tasks)
+ private void executeParallel(Vector tasks) throws BuildException
{
ThreadPool pool = new ThreadPool(maxThreads);
Enumeration e = tasks.elements();
@@ -110,6 +108,7 @@
Enumeration e = tasks.elements();
Runnable r = null;
Vector threads = new Vector();
+ final Vector buildExceptions = new Vector();
// start each task in it's own thread, using the
// pool to ensure that we don't exceed the maximum
@@ -122,7 +121,11 @@
{
public void run()
{
- task.execute();
+ try {
+ task.execute();
+ } catch (BuildException exception) {
+ buildExceptions.add(exception);
+ }
}
};
@@ -140,7 +143,7 @@
{
throw new BuildException(ex);
}
-
+
}
// Wait for all threads to finish before we
@@ -162,9 +165,23 @@
}
}
}
+
+ if (buildExceptions.size()==1) {
+ throw (BuildException)buildExceptions.get(0);
+ }
+ else if (buildExceptions.size()>1)
+ {
+ StringBuffer combinedMessage=new StringBuffer();
+ for (int i = 0; i < buildExceptions.size(); ++i) {
+ BuildException bex = ((BuildException)
buildExceptions.get(i));
+
combinedMessage.append("\n----------------------------------------------
-----\n");
+ combinedMessage.append(bex.getMessage());
+ }
+ throw new BuildException("Multiple Build
failures:"+combinedMessage.toString());
+ }
}
- private void executeSequential(Vector tasks)
+ private void executeSequential(Vector tasks) throws BuildException
{
TaskContainer tc = (TaskContainer)
getProject().createTask("sequential");
Enumeration e = tasks.elements();
--
Bill Michell
Development Team Leader, Broadcast Platforms, BBC FM&T (Journalism).
http://www.bbc.co.uk/
This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated.
If you have received it in error, please delete it from your system.
Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.
Please note that the BBC monitors e-mails sent or received.
Further communication will signify your consent to this.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace