01: /* BatchTest.java */
02:
03: package org.quilt.frontend.ant;
04:
05: import java.util.Vector;
06: import java.io.File;
07:
08: import org.apache.tools.ant.DirectoryScanner;
09: import org.apache.tools.ant.Project;
10: import org.apache.tools.ant.types.FileSet;
11:
12: import org.quilt.framework.*;
13:
14: /**
15: * Stores Ant filesets and convert them to QuiltTests.
16: *
17: * @author <a href="jddixon@users.sourceforge.net">Jim Dixon</a>
18: */
19: public class BatchTest extends QuiltTest {
20:
21: /** The project this batch test was found in. */
22: private Project project;
23: /** Filesets named in the batchtest element in the build.xml. */
24: private Vector filesets = new Vector();
25:
26: /////////////////////////////////////////////////////////////////
27: /**
28: * One-arg constructor.
29: *
30: * @param p The project that the QuiltTask is in.
31: */
32: public BatchTest(Project p) {
33: project = p;
34: }
35:
36: /**
37: * Method used by Ant to add filesets. Ant first calls
38: * createBatchTest, then in a second pass calls this method
39: * to add filesets.
40: *
41: * @param fs One of possibly many filesets within the batch test
42: */
43: public void addFileSet(FileSet fs) {
44: filesets.addElement(fs);
45: }
46:
47: /////////////////////////////////////////////////////////////////
48: /**
49: * Converts the fileset names into QuiltTests and adds them to the
50: * list of tests maintained by the scheduler. This can only be
51: * done once; after the tests are unbatched, the vector of batch
52: * tests is deleted.
53: *
54: * @param sch Scheduler responsible for maintaining list of tests
55: * and scheduling the actual running of tests.
56: */
57: public void unbatch(Scheduler sch) {
58: // don't schedule tests that won't get run
59: if (runMe(project)) {
60: Vector v = new Vector();
61: int size = filesets.size();
62: for (int i = 0; i < size; i++) {
63: FileSet fs = (FileSet) filesets.elementAt(i);
64: DirectoryScanner ds = fs.getDirectoryScanner(project);
65: ds.scan();
66: String[] files = ds.getIncludedFiles();
67: for (int j = 0; j < files.length; j++) {
68: boolean gottaMatch = false;
69: String name = files[j];
70: String className = "";
71: if (name.endsWith(".class")) {
72: gottaMatch = true;
73: className = name.substring(0, name.length()
74: - ".class".length());
75: } else if (name.endsWith(".java")) {
76: gottaMatch = true;
77: className = name.substring(0, name.length()
78: - ".java".length());
79: }
80: if (gottaMatch) {
81: // replace forward or reverse slashes with dots
82: className = className.replace(
83: File.separatorChar, '.');
84: // make a QuiltTest with default attributes
85: QuiltTest qt = (QuiltTest) clone();
86: qt.setName(className);
87: // add the cloned QuiltTest to the list of tests
88: sch.addTest(qt);
89: }
90: }
91: }
92: }
93: }
94: }
|