diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index 7a78b0bd4..ebbe93520 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -1782,7 +1782,7 @@ public class Project { */ protected void fireTaskStarted(Task task) { // register this as the current task on the current thread. - threadTasks.put(Thread.currentThread(), task); + registerThreadTask(Thread.currentThread(), task); BuildEvent event = new BuildEvent(task); for (int i = 0; i < listeners.size(); i++) { BuildListener listener = (BuildListener) listeners.elementAt(i); @@ -1801,7 +1801,7 @@ public class Project { * a successful build. */ protected void fireTaskFinished(Task task, Throwable exception) { - threadTasks.remove(Thread.currentThread()); + registerThreadTask(Thread.currentThread(), null); System.out.flush(); System.err.flush(); BuildEvent event = new BuildEvent(task); @@ -1876,16 +1876,31 @@ public class Project { } /** - * Treat messages generated in the given thread as messages that - * come from the same task that is performed on the current - * thread. + * Register a task as the current task for a thread. + * If the task is null, the thread's entry is removed. * + * @param thread the thread on which the task is registered. + * @param task the task to be registered. * @since 1.102, Ant 1.5 */ - public void registerThreadLikeCurrent(Thread thread) { - Task task = (Task) threadTasks.get(Thread.currentThread()); + public void registerThreadTask(Thread thread, Task task) { if (task != null) { threadTasks.put(thread, task); + } else { + threadTasks.remove(thread); } } + + /** + * Get the current task assopciated with a thread, if any + * + * @param thread the thread for which the task is required. + * @return the task which is currently registered for the given thread or + * null if no task is registered. + */ + public Task getThreadTask(Thread thread) { + return (Task)threadTasks.get(thread); + } + + } diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java b/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java index aa922314f..8beb83541 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java @@ -57,7 +57,7 @@ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; - +import org.apache.tools.ant.Task; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.CommandlineJava; @@ -139,7 +139,9 @@ public class ExecuteJava implements Runnable, TimeoutObserver { run(); } else { thread = new Thread(this, "ExecuteJava"); - project.registerThreadLikeCurrent(thread); + Task currentThreadTask + = project.getThreadTask(Thread.currentThread()); + project.registerThreadTask(thread, currentThreadTask); // if we run into a timout, the run-away thread shall not // make the VM run forever - if no timeout occurs, Ant's // main thread will still be there to let the new thread