diff --git a/WHATSNEW b/WHATSNEW index a84976e69..41ffed3e5 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -183,6 +183,11 @@ Other changes: * now supports a 'prefix' attribute when loading from a file or resource. +* In Ant 1.4 a feature has been added to the task that would + add ant.jar, optional.jar and junit.jar implicitly to the classpath - + this feature can now be disabled by setting the new includeantruntime + attribute to false. + Changes from Ant 1.4 to Ant 1.4.1 =========================================== diff --git a/docs/manual/OptionalTasks/junit.html b/docs/manual/OptionalTasks/junit.html index a373b3c27..75ae0e53e 100644 --- a/docs/manual/OptionalTasks/junit.html +++ b/docs/manual/OptionalTasks/junit.html @@ -99,6 +99,12 @@ elements.

disabled. No, default is "false". + + includeantruntime + implicitly add the Ant classes required to run + the tests and JUnit to the classpath in forked mode. + No, default is "true". +

Nested Elements

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 be3f8621b..d9672e1ac 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 @@ -162,6 +162,9 @@ public class JUnitTask extends Task { private boolean newEnvironment = false; private Environment env = new Environment(); + private boolean includeAntRuntime = true; + private Path antRuntimeClasses = null; + /** * Tells this task whether to smartly filter the stack frames of JUnit testcase * errors and failures before reporting them. This property is applied on all @@ -394,6 +397,15 @@ public class JUnitTask extends Task { formatters.addElement(fe); } + /** + * Whether to include ant.jar, optional.jar and junit.jar in the forked VM. + * + * @since 1.37, Ant 1.5 + */ + public void setIncludeantruntime(boolean b) { + includeAntRuntime = b; + } + /** * Creates a new JUnitRunner and enables fork of a new Java VM. */ @@ -407,6 +419,7 @@ public class JUnitTask extends Task { * without having to specify them directly. */ public void init() { + antRuntimeClasses = new Path(getProject()); addClasspathEntry("/junit/framework/TestCase.class"); addClasspathEntry("/org/apache/tools/ant/Task.class"); addClasspathEntry("/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.class"); @@ -493,6 +506,13 @@ public class JUnitTask extends Task { cmd.createArgument().setValue("filtertrace=" + test.getFiltertrace()); cmd.createArgument().setValue("haltOnError=" + test.getHaltonerror()); cmd.createArgument().setValue("haltOnFailure=" + test.getHaltonfailure()); + if (includeAntRuntime) { + log("Implicitly adding "+antRuntimeClasses+" to CLASSPATH", + Project.MSG_VERBOSE); + cmd.createClasspath(getProject()).createPath() + .append(antRuntimeClasses); + } + if (summary) { log("Running " + test.getName(), Project.MSG_INFO); cmd.createArgument().setValue("formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter"); @@ -606,7 +626,13 @@ public class JUnitTask extends Task { AntClassLoader cl = null; try { log("Using System properties " + System.getProperties(), Project.MSG_VERBOSE); - Path classpath = commandline.getClasspath(); + Path classpath = (Path) commandline.getClasspath().clone(); + if (includeAntRuntime) { + log("Implicitly adding "+antRuntimeClasses+" to CLASSPATH", + Project.MSG_VERBOSE); + classpath.append(antRuntimeClasses); + } + if (classpath != null) { cl = new AntClassLoader(null, project, classpath, false); log("Using CLASSPATH " + cl.getClasspath(), @@ -722,15 +748,13 @@ public class JUnitTask extends Task { 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())); + log("Found "+jarName, Project.MSG_DEBUG); + antRuntimeClasses.createPath().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())); + log("Found "+dirName, Project.MSG_DEBUG); + antRuntimeClasses.createPath().setLocation(new File((new File(dirName)).getAbsolutePath())); } else { log("Don\'t know how to handle resource URL "+u, Project.MSG_DEBUG);