diff --git a/WHATSNEW b/WHATSNEW index 7ca362571..5a0f1a1e3 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -166,6 +166,9 @@ Fixed bugs: * closes remote connection when it's done. +* tries to include all necessary classes for the task itself + to the classpath when running in fork mode - doesn't work for JDK 1.1 + Changes from Ant 1.2 to Ant 1.3 =========================================== diff --git a/build.xml b/build.xml index 09254e4ed..78eca5a96 100644 --- a/build.xml +++ b/build.xml @@ -711,13 +711,4 @@ - - - - diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java index 30773fdcd..9152ac752 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java @@ -79,6 +79,8 @@ import java.util.Properties; import java.util.Random; import java.util.Vector; +import java.net.URL; + /** * Ant task to run JUnit tests. * @@ -280,6 +282,17 @@ public class JUnitTask extends Task { commandline.setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner"); } + /** + * Adds the jars or directories containing Ant, this task and + * JUnit to the classpath - this should make the forked JVM work + * without having to specify the directly. + */ + public void init() { + addClasspathEntry("/junit/framework/TestCase.class"); + addClasspathEntry("/org/apache/tools/ant/Task.class"); + addClasspathEntry("/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.class"); + } + /** * Runs the testcase. */ @@ -523,4 +536,36 @@ public class JUnitTask extends Task { return null; } + /** + * Search for the given resource and add the directory or archive + * that contains it to the classpath. + * + *

Doesn't work for archives in JDK 1.1 as the URL returned by + * getResource doesn't contain the name of the archive.

+ */ + protected void addClasspathEntry(String resource) { + URL url = getClass().getResource(resource); + if (url != null) { + String u = url.toString(); + if (u.startsWith("jar:file:")) { + int pling = u.indexOf("!"); + String jarName = u.substring(9, pling); + log("Implicitly adding "+jarName+" to classpath", + Project.MSG_DEBUG); + createClasspath().setLocation(new File((new File(jarName)).getAbsolutePath())); + } else if (u.startsWith("file:")) { + int tail = u.indexOf(resource); + String dirName = u.substring(5, tail); + log("Implicitly adding "+dirName+" to classpath", + Project.MSG_DEBUG); + createClasspath().setLocation(new File((new File(dirName)).getAbsolutePath())); + } else { + log("Don\'t know how to handle resource URL "+u, + Project.MSG_DEBUG); + } + } else { + log("Couldn\'t find "+resource, Project.MSG_DEBUG); + } + } + }