Browse Source

Refector the new method into a separate set and get methods

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272270 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 23 years ago
parent
commit
45fd3ec75d
2 changed files with 26 additions and 9 deletions
  1. +22
    -7
      src/main/org/apache/tools/ant/Project.java
  2. +4
    -2
      src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java

+ 22
- 7
src/main/org/apache/tools/ant/Project.java View File

@@ -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);
}
}

+ 4
- 2
src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java View File

@@ -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


Loading…
Cancel
Save