KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quilt > frontend > ant > BatchTest


1 /* BatchTest.java */
2
3 package org.quilt.frontend.ant;
4
5 import java.util.Vector JavaDoc;
6 import java.io.File JavaDoc;
7
8 import org.apache.tools.ant.DirectoryScanner;
9 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 JavaDoc filesets = new Vector JavaDoc();
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 JavaDoc v = new Vector JavaDoc();
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 JavaDoc[] files = ds.getIncludedFiles();
67                 for (int j = 0; j < files.length; j++) {
68                     boolean gottaMatch = false;
69                     String JavaDoc name = files[j];
70                     String JavaDoc className = "";
71                     if (name.endsWith(".class")) {
72                         gottaMatch = true;
73                         className = name.substring(0,
74                                 name.length() - ".class".length());
75                     } else if (name.endsWith(".java")) {
76                         gottaMatch = true;
77                         className = name.substring(0,
78                                 name.length() - ".java".length());
79                     }
80                     if (gottaMatch) {
81                         // replace forward or reverse slashes with dots
82
className =
83                             className.replace(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 }
95
Popular Tags