Browse Source

ResourceCollection support for batchtest

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@292242 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 19 years ago
parent
commit
4d402cce79
2 changed files with 33 additions and 14 deletions
  1. +7
    -3
      docs/manual/OptionalTasks/junit.html
  2. +26
    -11
      src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java

+ 7
- 3
docs/manual/OptionalTasks/junit.html View File

@@ -448,12 +448,16 @@ time.</p>

<p>Define a number of tests based on pattern matching.</p>

<p><code>batchtest</code> collects the included files from any number
<p><code>batchtest</code> collects the included <a href="../CoreTypes/resources.html">resources</a> from any number
of nested <a
href="../CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a>s. It then
generates a test class name for each file that ends in
href="../CoreTypes/resources.html#collection">Resource Collection</a>s. It then
generates a test class name for each resource that ends in
<code>.java</code> or <code>.class</code>.</p>

<p>Any type of Resource Collection is supported as a nested element,
prior to Ant 1.7 only <code>&lt;fileset&gt;</code> has been
supported.</p>

<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td width="12%" valign="top"><b>Attribute</b></td>


+ 26
- 11
src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java View File

@@ -20,10 +20,14 @@ package org.apache.tools.ant.taskdefs.optional.junit;

import java.io.File;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.resources.Resources;

/**
* <p> Create then run <code>JUnitTest</code>'s based on the list of files
@@ -42,7 +46,7 @@ public final class BatchTest extends BaseTest {
private Project project;

/** the list of filesets containing the testcase filename rules */
private Vector filesets = new Vector();
private Resources resources = new Resources();

/**
* create a new batchtest instance
@@ -59,7 +63,21 @@ public final class BatchTest extends BaseTest {
* @param fs the new fileset containing the rules to get the testcases.
*/
public void addFileSet(FileSet fs) {
filesets.addElement(fs);
add(fs);
}


/**
* Add a new ResourceCollection instance to this
* batchtest. Whatever the collection is, only names that are
* <tt>.java</tt> or <tt>.class</tt> will be considered as
* 'candidates'.
* @param rc the new ResourceCollection containing the rules to
* get the testcases.
* @since Ant 1.7
*/
public void add(ResourceCollection rc) {
resources.add(rc);
}

/**
@@ -113,20 +131,17 @@ public final class BatchTest extends BaseTest {
*/
private String[] getFilenames() {
Vector v = new Vector();
final int size = this.filesets.size();
for (int j = 0; j < size; j++) {
FileSet fs = (FileSet) filesets.elementAt(j);
DirectoryScanner ds = fs.getDirectoryScanner(project);
ds.scan();
String[] f = ds.getIncludedFiles();
for (int k = 0; k < f.length; k++) {
String pathname = f[k];
Iterator iter = resources.iterator();
while (iter.hasNext()) {
Resource r = (Resource) iter.next();
if (r.isExists()) {
String pathname = r.getName();
if (pathname.endsWith(".java")) {
v.addElement(pathname.substring(0, pathname.length() - ".java".length()));
} else if (pathname.endsWith(".class")) {
v.addElement(pathname.substring(0, pathname.length() - ".class".length()));
}
}
}
}

String[] files = new String[v.size()];


Loading…
Cancel
Save