< prev index next >

src/com/sun/javatest/TestFinderQueue.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


 169         File testSuiteRoot = testFinder.getRoot();
 170 
 171         // make canonical copy of tests
 172         // really ought not to be using File, since the tests may contain a trailing #xxx
 173         File[] files;
 174         if (initTests == null)
 175             // ensure not null
 176             files = new File[] {testSuiteRoot};
 177         else {
 178             files = new File[initTests.length];
 179             for (int i = 0; i < initTests.length; i++) {
 180                 files[i] = new File(initTests[i]);
 181             }
 182         }
 183 
 184         rootDir = (testSuiteRoot.isDirectory() ?
 185                    testSuiteRoot : new File(testSuiteRoot.getParent()));
 186 
 187         // build up the fifo of tests to be used by readNextFile
 188 
 189         tests = new Fifo();
 190         currInitialFile = null;
 191 
 192         for (int pass = 0; pass < 2; pass++) {
 193             for (int i = 0; i < files.length; i++) {
 194                 File f = files[i];
 195                 String n = f.getName();
 196                 // in pass 0, only select initial files without #
 197                 // in pass 1, only select initial files with #
 198                 if ((n.indexOf("#") != -1) == (pass == 0))
 199                     continue;
 200 
 201                 // ensure all absolute, or if relative, make them relative
 202                 // to rootDir
 203                 if (!f.isAbsolute())
 204                     f = new File(rootDir, f.getPath());
 205                 // ensure no trailing file separator
 206                 String p = f.getPath();
 207                 if (p.endsWith(File.separator))
 208                     f = new File(p.substring(0, p.length() - 1));
 209                 tests.insert(f);


 216     /**
 217      * Set a flag indicating whether it is OK to find no tests in the
 218      * specified set of files. If set to false, and if no tests have
 219      * been found by the time the last file has been read, an error
 220      * will be notified to any observers.
 221      * @param zeroTestsOK set to true to suppress an error being generated
 222      * if no tests are found by the time that all files have been read
 223      */
 224     public void setZeroTestsOK(boolean zeroTestsOK) {
 225         this.zeroTestsOK = zeroTestsOK;
 226     }
 227 
 228     /**
 229      * Set the queue to "repeat" a set of test descriptions by putting
 230      * them in the test found queue again.
 231      * @param tds the test descriptions to be "found again".
 232      * @deprecated retained for historical purposes
 233      */
 234     public void repeat(TestDescription[] tds) {
 235         if (tests == null)
 236             tests = new Fifo(); // for now
 237         for (int i = 0; i < tds.length; i++) {
 238             TestDescription td = tds[i];
 239             testDescsFound.insert(td);
 240             testsFoundCount++;
 241             notifier.found(td);
 242         }
 243     }
 244 
 245 
 246 
 247     /**
 248      * Get the next test description if one is available, or null when all have
 249      * been returned.
 250      *
 251      * @return     A test description or null.
 252      */
 253     public TestDescription next() {
 254         TestDescription td;
 255 
 256         synchronized (this) {
 257             while (needReadAhead() && readNextFile()) /*NO-OP*/;
 258 
 259             // read files until there is a test description available or there
 260             // are no more files.
 261             while ((td = (TestDescription)(testDescsFound.remove())) == null) {
 262                 boolean ok = readNextFile();
 263                 if (!ok)
 264                     return null;
 265             }
 266 
 267             // note testsDone, for readAhead
 268             testsDoneCount++;
 269         }
 270 
 271         notifier.done(td);
 272         return td;
 273     }
 274 
 275 
 276     //--------------------------------------------------------------------------
 277 
 278     /**
 279      * Get the root directory for the test finder.
 280      * @return the root directory, as set in the test finder
 281      */


 490             return false;
 491         }
 492     }
 493 
 494     //---------------------------------------------------------------
 495 
 496     private synchronized boolean readNextFile() {
 497         if (filesToRead.isEmpty()) {
 498             // have we finished reading an initial file and found no test descriptions in it?
 499             // if so, inform the caller
 500             if (currInitialFile != null
 501                 && testsFoundCountBeforeCurrInitialFile == testsFoundCount
 502                 && !zeroTestsOK) {
 503                 errorCount++;
 504                 notifier.error(i18n.getString("finder.noTests", currInitialFile));
 505             }
 506 
 507             // are there any more tests that have not been read?
 508             // check until we find one (just one).
 509             while (filesToRead.isEmpty() && !tests.isEmpty()) {
 510                 currInitialFile = (File)tests.remove();
 511                 foundFile(currInitialFile);
 512             }
 513 
 514             // if we didn't find any more initial files, there is nothing more to do
 515             if (filesToRead.isEmpty()) {
 516                 currInitialFile = null;
 517                 return false;
 518             }
 519             else
 520                 testsFoundCountBeforeCurrInitialFile = testsFoundCount;
 521         }
 522 
 523 
 524         File f = filesToRead.lastElement();
 525         filesToRead.setSize(filesToRead.size() - 1);
 526         filesRemainingCount = filesToRead.size() + tests.size();
 527 
 528         String path = f.getPath();
 529         int index = path.indexOf('#');
 530         if (index != -1) {


 670                 observers[i].flushed();
 671         }
 672 
 673         public synchronized void error(String msg) {
 674             for (int i = 0; i < observers.length; i++)
 675                 observers[i].error(msg);
 676         }
 677 
 678         public synchronized void error(TestDescription td, String msg) {
 679             for (int i = 0; i < observers.length; i++)
 680                 observers[i].error(td, msg);
 681         }
 682 
 683         private Observer[] observers = new Observer[0];
 684     }
 685 
 686     //----------member variables------------------------------------------------
 687 
 688 
 689     private TestFinder testFinder;
 690     private Fifo tests;
 691     private TestFilter[] filters;
 692     private String selectedId;
 693     private File rootDir;
 694     private File currInitialFile;
 695     private int testsFoundCountBeforeCurrInitialFile;
 696     private boolean zeroTestsOK;
 697 
 698     private Vector<File> filesToRead  = new Vector<>(32, 8);
 699     private int fileInsertPosn;
 700     private Fifo testDescsFound = new Fifo();
 701     private int filesRemainingCount;
 702     private int filesDoneCount;
 703     private int testsDoneCount;
 704     private int testsFoundCount;
 705     private int errorCount;
 706 
 707     private Map<String, File> filesFound  = new Hashtable<>();
 708 
 709     private byte readAheadMode;
 710     private Thread readAheadWorker;
 711     private static int workerIndex;
 712 
 713     private Notifier notifier = new Notifier();
 714     private static I18NResourceBundle i18n = I18NResourceBundle.getBundleForClass(TestFinder.class);
 715 }


 169         File testSuiteRoot = testFinder.getRoot();
 170 
 171         // make canonical copy of tests
 172         // really ought not to be using File, since the tests may contain a trailing #xxx
 173         File[] files;
 174         if (initTests == null)
 175             // ensure not null
 176             files = new File[] {testSuiteRoot};
 177         else {
 178             files = new File[initTests.length];
 179             for (int i = 0; i < initTests.length; i++) {
 180                 files[i] = new File(initTests[i]);
 181             }
 182         }
 183 
 184         rootDir = (testSuiteRoot.isDirectory() ?
 185                    testSuiteRoot : new File(testSuiteRoot.getParent()));
 186 
 187         // build up the fifo of tests to be used by readNextFile
 188 
 189         tests = new Fifo<>();
 190         currInitialFile = null;
 191 
 192         for (int pass = 0; pass < 2; pass++) {
 193             for (int i = 0; i < files.length; i++) {
 194                 File f = files[i];
 195                 String n = f.getName();
 196                 // in pass 0, only select initial files without #
 197                 // in pass 1, only select initial files with #
 198                 if ((n.indexOf("#") != -1) == (pass == 0))
 199                     continue;
 200 
 201                 // ensure all absolute, or if relative, make them relative
 202                 // to rootDir
 203                 if (!f.isAbsolute())
 204                     f = new File(rootDir, f.getPath());
 205                 // ensure no trailing file separator
 206                 String p = f.getPath();
 207                 if (p.endsWith(File.separator))
 208                     f = new File(p.substring(0, p.length() - 1));
 209                 tests.insert(f);


 216     /**
 217      * Set a flag indicating whether it is OK to find no tests in the
 218      * specified set of files. If set to false, and if no tests have
 219      * been found by the time the last file has been read, an error
 220      * will be notified to any observers.
 221      * @param zeroTestsOK set to true to suppress an error being generated
 222      * if no tests are found by the time that all files have been read
 223      */
 224     public void setZeroTestsOK(boolean zeroTestsOK) {
 225         this.zeroTestsOK = zeroTestsOK;
 226     }
 227 
 228     /**
 229      * Set the queue to "repeat" a set of test descriptions by putting
 230      * them in the test found queue again.
 231      * @param tds the test descriptions to be "found again".
 232      * @deprecated retained for historical purposes
 233      */
 234     public void repeat(TestDescription[] tds) {
 235         if (tests == null)
 236             tests = new Fifo<>(); // for now
 237         for (int i = 0; i < tds.length; i++) {
 238             TestDescription td = tds[i];
 239             testDescsFound.insert(td);
 240             testsFoundCount++;
 241             notifier.found(td);
 242         }
 243     }
 244 
 245 
 246 
 247     /**
 248      * Get the next test description if one is available, or null when all have
 249      * been returned.
 250      *
 251      * @return     A test description or null.
 252      */
 253     public TestDescription next() {
 254         TestDescription td;
 255 
 256         synchronized (this) {
 257             while (needReadAhead() && readNextFile()) /*NO-OP*/;
 258 
 259             // read files until there is a test description available or there
 260             // are no more files.
 261             while ((td = testDescsFound.remove()) == null) {
 262                 boolean ok = readNextFile();
 263                 if (!ok)
 264                     return null;
 265             }
 266 
 267             // note testsDone, for readAhead
 268             testsDoneCount++;
 269         }
 270 
 271         notifier.done(td);
 272         return td;
 273     }
 274 
 275 
 276     //--------------------------------------------------------------------------
 277 
 278     /**
 279      * Get the root directory for the test finder.
 280      * @return the root directory, as set in the test finder
 281      */


 490             return false;
 491         }
 492     }
 493 
 494     //---------------------------------------------------------------
 495 
 496     private synchronized boolean readNextFile() {
 497         if (filesToRead.isEmpty()) {
 498             // have we finished reading an initial file and found no test descriptions in it?
 499             // if so, inform the caller
 500             if (currInitialFile != null
 501                 && testsFoundCountBeforeCurrInitialFile == testsFoundCount
 502                 && !zeroTestsOK) {
 503                 errorCount++;
 504                 notifier.error(i18n.getString("finder.noTests", currInitialFile));
 505             }
 506 
 507             // are there any more tests that have not been read?
 508             // check until we find one (just one).
 509             while (filesToRead.isEmpty() && !tests.isEmpty()) {
 510                 currInitialFile = tests.remove();
 511                 foundFile(currInitialFile);
 512             }
 513 
 514             // if we didn't find any more initial files, there is nothing more to do
 515             if (filesToRead.isEmpty()) {
 516                 currInitialFile = null;
 517                 return false;
 518             }
 519             else
 520                 testsFoundCountBeforeCurrInitialFile = testsFoundCount;
 521         }
 522 
 523 
 524         File f = filesToRead.lastElement();
 525         filesToRead.setSize(filesToRead.size() - 1);
 526         filesRemainingCount = filesToRead.size() + tests.size();
 527 
 528         String path = f.getPath();
 529         int index = path.indexOf('#');
 530         if (index != -1) {


 670                 observers[i].flushed();
 671         }
 672 
 673         public synchronized void error(String msg) {
 674             for (int i = 0; i < observers.length; i++)
 675                 observers[i].error(msg);
 676         }
 677 
 678         public synchronized void error(TestDescription td, String msg) {
 679             for (int i = 0; i < observers.length; i++)
 680                 observers[i].error(td, msg);
 681         }
 682 
 683         private Observer[] observers = new Observer[0];
 684     }
 685 
 686     //----------member variables------------------------------------------------
 687 
 688 
 689     private TestFinder testFinder;
 690     private Fifo<File> tests;
 691     private TestFilter[] filters;
 692     private String selectedId;
 693     private File rootDir;
 694     private File currInitialFile;
 695     private int testsFoundCountBeforeCurrInitialFile;
 696     private boolean zeroTestsOK;
 697 
 698     private Vector<File> filesToRead  = new Vector<>(32, 8);
 699     private int fileInsertPosn;
 700     private Fifo<TestDescription> testDescsFound = new Fifo<>();
 701     private int filesRemainingCount;
 702     private int filesDoneCount;
 703     private int testsDoneCount;
 704     private int testsFoundCount;
 705     private int errorCount;
 706 
 707     private Map<String, File> filesFound  = new Hashtable<>();
 708 
 709     private byte readAheadMode;
 710     private Thread readAheadWorker;
 711     private static int workerIndex;
 712 
 713     private Notifier notifier = new Notifier();
 714     private static I18NResourceBundle i18n = I18NResourceBundle.getBundleForClass(TestFinder.class);
 715 }
< prev index next >