View Javadoc
1 /* Scheduler.java */ 2 3 package org.quilt.frontend.ant; 4 5 import java.util.Vector; 6 7 import org.apache.tools.ant.Project; 8 import org.apache.tools.ant.Task; 9 import org.quilt.framework.QuiltTest; 10 11 /*** 12 * Collects individual and batch tests during initial processing of the 13 * Ant build.xml file, then schedules tests for running. Before running 14 * any tests, batch tests are unpacked and attributes assigned. 15 */ 16 public class Scheduler { 17 18 private QuiltTask task = null; 19 private TaskControl tc = null; 20 private boolean batched = true; 21 22 /*** Vector of QuiltTests */ 23 private Vector tests = new Vector(); 24 /*** Index into that Vector. */ 25 private int testIndex = 0; 26 27 /*** Vector of BatchTests */ 28 private Vector batchTests = new Vector(); 29 /*** Index into Vector of BatchTests. */ 30 private int batchIndex = 0; 31 32 /*** All tests are clones of this one. */ 33 private QuiltTest modelTest = new QuiltTest(); 34 35 /*** One-arg constructor called at beginning of run */ 36 public Scheduler ( QuiltTask t) { 37 task = t; 38 tc = new TaskControl (task); 39 } 40 41 // SCHEDULING METHODS ///////////////////////////////// 42 /*** 43 * Ant-compatible method for adding a batch test. When Ant 44 * encounters a <batchtest ... it calls QuiltTask.createBatchTest 45 * to get an instance, then uses the set* methods to set test 46 * parameters for the batch. QuiltTask uses this method to pass 47 * the batch test to the Scheduler. 48 * 49 * @param bt BatchTest instance created by QuiltTask 50 */ 51 public void addBatchTest (BatchTest bt) { 52 task.log("--> Scheduler.addBatchTest", Project.MSG_VERBOSE); 53 batchTests.addElement(bt); 54 } 55 /*** 56 * Ant-compatible method for adding test to queue. When Ant 57 * counters a <test name=... it uses this method to create 58 * the QuiltTest object and then calls set* methods to set 59 * test parameters. 60 * 61 * @param test QuiltTest structure containing test parameters. 62 */ 63 public void addTest (QuiltTest test) { 64 task.log("--> Scheduler.addTest", Project.MSG_VERBOSE); 65 tests.addElement (test); 66 } 67 /*** 68 * Zero out indexes into lists of tests and batch tests. This 69 * will be called whenever the user wants to rescan the lists of 70 * tests and batch tests. 71 */ 72 public void schedule () { 73 testIndex = 0; 74 batchIndex = 0; 75 76 task.log ( 77 "\n===========================================================\n" 78 + "--> Scheduler.schedule: there are " 79 + tests.size() + " tests and " 80 + batchTests.size() + " batch tests" 81 + "\n===========================================================\n", 82 Project.MSG_DEBUG 83 ); 84 } 85 /*** 86 * Returns the next test or batch test available. 87 * 88 * @return QuiltTest-compatible structure 89 */ 90 public QuiltTest nextTest() { 91 if (testIndex < tests.size()) { 92 return (QuiltTest) tests.elementAt( testIndex++ ); 93 } else if (batchIndex < batchTests.size()) { 94 return (BatchTest) batchTests.elementAt( batchIndex++ ); 95 } else { 96 return null; 97 } 98 } 99 /*** 100 * Pass through the list of batch tests, creating individual tests 101 * and passing these to the scheduler. 102 */ 103 public void unbatch() { 104 task.log("--> Scheduler.unbatch", Project.MSG_VERBOSE); 105 for (int i = 0; i < batchTests.size(); i++) { 106 ((BatchTest)batchTests.elementAt(i)).unbatch(this); 107 } 108 batched = false; 109 batchTests = new Vector(); 110 } 111 112 // GET/SET METHODS ////////////////////////////////////////////// 113 /*** 114 * Get a reference to the TaskControl object created by the 115 * constructor. 116 * */ 117 public TaskControl getTaskControl() { 118 return tc; 119 } 120 }

This page was automatically generated by Maven