I sit behind a firewall and therefore can use CVS directly. Hopefully I have put enough information to get this patch through.
DESCRIPTION:
When you fork off processes in Ant, they don't get notified when Ant is
destroyed. This patch registers a shutdown hook (if
Runtime.addShutdownHook() is available) that destroys all processes that
have been registered with it. After the process finishes, it is removed
from the list.
ATTACHED FILES:
ProcessDestroyer.java (new file, currently in the
org.apache.tools.ant.taskdefs package)
patchfile.txt
testcase.zip (contains test case for fix)
TEST CASE:
testcase.zip contains:
TestProcess.java
build.xml
TestProcess.java just loops 5 times (sleeping for 2 seconds) then exits. If
you press ctrl-C, the shutdown hook runs and terminates the thread early.
When you run with Ant 1.4.1, and hit ctrl-C, you get the following output
(shutdown hook doesn't run):
C:\TEMP\tmp>ant
Buildfile: build.xml
compile:
[javac] Compiling 1 source file
main:
[java] TestProcess thread
[java] TestProcess thread
[java] TestProcess thread
C:\TEMP\tmp>
When you run with the patch, and hit ctrl-C, you get the following output
(shutdown hook runs):
C:\TEMP\tmp>ant
Buildfile: build.xml
compile:
main:
[java] TestProcess thread
[java] TestProcess thread
[java] shutting down TestProcess
C:\TEMP\tmp>
<<ProcessDestroyer.java>> <<patchfile.txt>> <<testcase.zip>>
ProcessDestroyer.java
Description: Binary data
--- Execute.java.orig Fri Oct 12 00:58:28 2001
+++ Execute.java Wed Nov 21 15:35:59 2001
@@ -97,6 +97,9 @@
private static CommandLauncher shellLauncher = null;
private static Vector procEnvironment = null;
+ /** Used to destroy processes when the VM exits. */
+ private static ProcessDestroyer processDestroyer = new ProcessDestroyer();
+
/**
* Builds a command launcher for the OS and JVM we are running under
*/
@@ -391,8 +394,18 @@
throw e;
}
streamHandler.start();
+
+ // add the process to the list of those to destroy if the VM exits
+ //
+ processDestroyer.add(process);
+
if (watchdog != null) watchdog.start(process);
waitFor(process);
+
+ // remove the process to the list of those to destroy if the VM exits
+ //
+ processDestroyer.remove(process);
+
if (watchdog != null) watchdog.stop();
streamHandler.stop();
if (watchdog != null) watchdog.checkException();
<<attachment: testcase.zip>>
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
