public static PackageScanner create() {
    for (int i = 0; i < PACKAGE_SCANNERS.size(); i++) {
      Class<? extends PackageScanner> scannerClass = PACKAGE_SCANNERS.get(i);
      PackageScanner scanner = ReflectionUtils.invokeConstructor(scannerClass);
      String packageName = PackageScannerFactory.class.getPackage().getName();
      Sequence<String> test = scanner.getPackageClasses(packageName, ClassesListerOptions.DEFAULT);
      if (!test.isEmpty()) {
        if (i > 0) {
          logger.debug(
              "Using "
                  + scannerClass.getSimpleName()
                  + "(previously did not work: "
                  + classList(PACKAGE_SCANNERS.subList(0, i))
                  + ")");
        }
        return scanner;
      }
    }

    logger.error(
        "No working scanner "
            + PackageScanner.class.getSimpleName()
            + " found, "
            + "returning dummy (did not work: "
            + classList(PACKAGE_SCANNERS)
            + ")");
    return new NullPackageScanner();
  }
Example #2
0
  /** Test of fromPackageToFile method, of class PackageScanner. */
  @Test
  public void testFromPackageToFile() {
    System.out.println("fromPackageToFile");

    File expResult = null;
    try {
      PackageScanner.fromPackageToFile(wrongPackage);
      fail("Result is supposed to null");
    } catch (NullPointerException ex) {
    }

    URL url = fromPackageToUrl(correctPackage);
    expResult = new File(url.getPath());
    File result = PackageScanner.fromPackageToFile(correctPackage);
    assertEquals(expResult.getAbsolutePath(), result.getAbsolutePath());
  }
Example #3
0
  /** Test of listFiles method, of class PackageScanner. */
  @Test
  public void testListFiles_String_FilenameFilter() {
    System.out.println("listFiles");

    FilenameFilter filter =
        new FilenameFilter() {

          public boolean accept(File dir, String name) {
            return name.endsWith(".yawl");
          }
        };

    File[] result = PackageScanner.listFiles(correctPackage + ".specs", filter);

    assertNotNull(result);

    for (File file : result) {
      assertTrue(file.getName().endsWith(".yawl"));
    }
  }