From 4d402cce79451553a323aa999676782e425000a0 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 28 Sep 2005 18:32:08 +0000 Subject: [PATCH] ResourceCollection support for batchtest git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@292242 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/OptionalTasks/junit.html | 10 +++-- .../taskdefs/optional/junit/BatchTest.java | 37 +++++++++++++------ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/docs/manual/OptionalTasks/junit.html b/docs/manual/OptionalTasks/junit.html index 8ae73b01d..b00ef6ba6 100644 --- a/docs/manual/OptionalTasks/junit.html +++ b/docs/manual/OptionalTasks/junit.html @@ -448,12 +448,16 @@ time.

Define a number of tests based on pattern matching.

-

batchtest collects the included files from any number +

batchtest collects the included resources from any number of nested <fileset>s. It then -generates a test class name for each file that ends in +href="../CoreTypes/resources.html#collection">Resource Collections. It then +generates a test class name for each resource that ends in .java or .class.

+

Any type of Resource Collection is supported as a nested element, +prior to Ant 1.7 only <fileset> has been +supported.

+ diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java index 6184c4ce4..31b1f1a0e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java @@ -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; /** *

Create then run JUnitTest'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 + * .java or .class 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()];

Attribute