Browse Source

Added <classpathref> element to <junit>.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267926 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
bbcbfb186a
2 changed files with 27 additions and 2 deletions
  1. +4
    -2
      docs/junit.html
  2. +23
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java

+ 4
- 2
docs/junit.html View File

@@ -70,8 +70,10 @@ elements</a>.</p>


<p><code>junit</code> supports a nested <code>&lt;classpath&gt;</code> <p><code>junit</code> supports a nested <code>&lt;classpath&gt;</code>
element, that represents a <a href="index.html#path">PATH like element, that represents a <a href="index.html#path">PATH like
structure</a>. The value is ignore if <code>fork</code> is
disabled.</p>
structure</a>. PATHs defined elsewhere can be <a
href="index.html#references">referred</a> to via nested
<code>&lt;classpathref&gt;</code> elements. The value is ignored if
<code>fork</code> is disabled.</p>


<h4>jvmarg</h4> <h4>jvmarg</h4>




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

@@ -61,6 +61,7 @@ import org.apache.tools.ant.taskdefs.*;
import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.CommandlineJava;
import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;


import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -87,6 +88,7 @@ import java.util.Vector;
public class JUnitTask extends Task { public class JUnitTask extends Task {


private CommandlineJava commandline = new CommandlineJava(); private CommandlineJava commandline = new CommandlineJava();
private Vector classpathReferences = new Vector();
private Vector tests = new Vector(); private Vector tests = new Vector();
private Vector batchTests = new Vector(); private Vector batchTests = new Vector();
private Vector formatters = new Vector(); private Vector formatters = new Vector();
@@ -132,6 +134,14 @@ public class JUnitTask extends Task {
return commandline.createVmArgument(); return commandline.createVmArgument();
} }


/**
* Adds a reference to a CLASSPATH defined elsewhere - nested
* <classpathref> element.
*/
public void addClasspathRef(Reference r) {
classpathReferences.addElement(r);
}

public Path createClasspath() { public Path createClasspath() {
return commandline.createClasspath(project); return commandline.createClasspath(project);
} }
@@ -170,6 +180,19 @@ public class JUnitTask extends Task {
boolean errorOccurred = false; boolean errorOccurred = false;
boolean failureOccurred = false; boolean failureOccurred = false;


Path classpath = commandline.createClasspath(project);
for (int i=0; i<classpathReferences.size(); i++) {
Reference r = (Reference) classpathReferences.elementAt(i);
Object o = r.getReferencedObject(project);
if (o instanceof Path) {
classpath.append((Path) o);
} else {
String msg = r.getRefId()+" doesn\'t denote a classpath";
throw new BuildException(msg, location);
}
}

Enumeration list = batchTests.elements(); Enumeration list = batchTests.elements();
while (list.hasMoreElements()) { while (list.hasMoreElements()) {
BatchTest test = (BatchTest)list.nextElement(); BatchTest test = (BatchTest)list.nextElement();


Loading…
Cancel
Save