Browse Source

Add an attribute to avoid <junit>'s classpath magic.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271554 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
cf72dc9e50
3 changed files with 42 additions and 7 deletions
  1. +5
    -0
      WHATSNEW
  2. +6
    -0
      docs/manual/OptionalTasks/junit.html
  3. +31
    -7
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java

+ 5
- 0
WHATSNEW View File

@@ -183,6 +183,11 @@ Other changes:
* <property> now supports a 'prefix' attribute when loading from a file
or resource.

* In Ant 1.4 a feature has been added to the <junit> 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
===========================================



+ 6
- 0
docs/manual/OptionalTasks/junit.html View File

@@ -99,6 +99,12 @@ elements</a>.</p>
disabled.</td>
<td align="center" valign="top">No, default is &quot;false&quot;.</td>
</tr>
<tr>
<td valign="top">includeantruntime</td>
<td valign="top">implicitly add the Ant classes required to run
the tests and JUnit to the classpath in forked mode.</td>
<td align="center" valign="top">No, default is &quot;true&quot;.</td>
</tr>
</table>

<h3><a name="nested">Nested Elements</a></h3>


+ 31
- 7
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

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


Loading…
Cancel
Save