Exemplo n.º 1
0
 /**
  * Returns test classes annotated with @Category(IntegrationTests.class), according to the filter
  * specific on the command line (if any).
  */
 private Class<?>[] findIntegrationTestClasses()
     throws ClassNotFoundException, LinkageError, IOException {
   ClassTestFinder.TestFileNameFilter nameFilter = new ClassTestFinder.TestFileNameFilter();
   ClassFinder classFinder = new ClassFinder(nameFilter, nameFilter, intTestFilter);
   Set<Class<?>> classes = classFinder.findClasses(true);
   return classes.toArray(new Class<?>[classes.size()]);
 }
Exemplo n.º 2
0
  public ModuleSymbol findSingleModule() {
    try {
      JavaFileObject src_fo = getModuleInfoFromLocation(StandardLocation.SOURCE_PATH, Kind.SOURCE);
      JavaFileObject class_fo =
          getModuleInfoFromLocation(StandardLocation.CLASS_OUTPUT, Kind.CLASS);
      JavaFileObject fo =
          (src_fo == null)
              ? class_fo
              : (class_fo == null) ? src_fo : classFinder.preferredFileObject(src_fo, class_fo);

      ModuleSymbol msym;
      if (fo == null) {
        msym = syms.unnamedModule;
      } else {
        switch (fo.getKind()) {
          case SOURCE:
            if (!inFindSingleModule) {
              try {
                inFindSingleModule = true;
                // Note: the following will trigger a re-entrant call to Modules.enter
                msym = sourceFileCompleter.complete(fo);
                msym.module_info.classfile = fo;
              } finally {
                inFindSingleModule = false;
              }
            } else {
              // the module-info.java does not contain a module declaration,
              // avoid infinite recursion:
              msym = syms.unnamedModule;
            }
            break;
          case CLASS:
            Name name;
            try {
              name = names.fromString(readModuleName(fo));
            } catch (BadClassFile | IOException ex) {
              // fillIn will report proper errors:
              name = names.error;
            }
            msym = syms.enterModule(name);
            msym.module_info.classfile = fo;
            msym.completer = Completer.NULL_COMPLETER;
            classFinder.fillIn(msym.module_info);
            break;
          default:
            Assert.error();
            msym = syms.unnamedModule;
            break;
        }
      }

      msym.classLocation = StandardLocation.CLASS_OUTPUT;
      return msym;

    } catch (IOException e) {
      throw new Error(e); // FIXME
    }
  }
  @Test
  public void testFindClassNamesWithJustIncludedGlobs() throws Exception {
    List<String> expected = Arrays.asList(new String[] {"One"});
    List<String> actual = ClassFinder.findClassNames(ROOT_PATH, JUST_INCLUDED_GLOBS);

    Assert.assertEquals(expected, actual);
  }
  @Test
  public void testFindClassNamesWithBothIncludedAndExcludedGlobs() throws Exception {
    List<String> expected = Arrays.asList(new String[] {"One", "Three"});
    List<String> actual = ClassFinder.findClassNames(ROOT_PATH, BOTH_INCLUDED_AND_EXCLUDED_GLOBS);
    Collections.sort(actual);

    Assert.assertEquals(expected, actual);
  }
  @Test
  public void testFindClassNamesWithEmptyGlobs() throws Exception {
    List<String> expected = Arrays.asList(new String[] {"One", "Three", "Two"});
    List<String> actual = ClassFinder.findClassNames(ROOT_PATH, EMPTY_GLOBS);
    Collections.sort(actual);

    Assert.assertEquals(expected, actual);
  }
Exemplo n.º 6
0
  /** Construct a new module finder. */
  protected ModuleFinder(Context context) {
    context.put(moduleFinderKey, this);
    names = Names.instance(context);
    syms = Symtab.instance(context);
    fileManager = context.get(JavaFileManager.class);
    log = Log.instance(context);
    classFinder = ClassFinder.instance(context);

    diags = JCDiagnostic.Factory.instance(context);
  }
  @Test
  public void testFindClassNamesByUsingTheFormatGlobProcess() throws Exception {
    Path rootPath = Paths.get(ClassFinder.class.getResource(".").getPath());
    List<String> expected = Arrays.asList(new String[] {"samples.One"});
    List<String> actual =
        ClassFinder.findClassNames(
            rootPath, new Globs(Arrays.asList(new String[] {"One.class"}), null));
    Collections.sort(actual);

    Assert.assertEquals(expected, actual);
  }
Exemplo n.º 8
0
  public static void fillTestCases(
      TestCaseLoader testCaseLoader, String packageRoot, String... classRoots) throws IOException {
    for (String classRoot : classRoots) {
      int oldCount = testCaseLoader.getClasses().size();
      ClassFinder classFinder =
          new ClassFinder(new File(FileUtil.toSystemDependentName(classRoot)), packageRoot);
      testCaseLoader.loadTestCases(classFinder.getClasses());
      int newCount = testCaseLoader.getClasses().size();
      if (newCount != oldCount) {
        System.out.println(
            "Loaded " + (newCount - oldCount) + " tests from class root " + classRoot);
      }
    }

    if (testCaseLoader.getClasses().size() == 1) {
      testCaseLoader.clearClasses();
    }

    log("Number of test classes found: " + testCaseLoader.getClasses().size());
    testCaseLoader.checkClassesExist();
  }
Exemplo n.º 9
0
 private static List<Class<? extends Card>> get10RandomKingdomCards(
     List<Class<? extends Card>> cardsToInclude) {
   List<Class<? extends Card>> allCards = ClassFinder.findAllKingdomCards();
   Collections.shuffle(allCards);
   List<Class<? extends Card>> tenCards = new ArrayList<Class<? extends Card>>(cardsToInclude);
   for (int i = 0; tenCards.size() < 10; i++) {
     if (!tenCards.contains(allCards.get(i))) {
       tenCards.add(allCards.get(i));
     }
   }
   return tenCards;
 }
Exemplo n.º 10
0
  private void findModuleInfo(ModuleSymbol msym) {
    try {
      JavaFileObject src_fo =
          (msym.sourceLocation == null)
              ? null
              : fileManager.getJavaFileForInput(
                  msym.sourceLocation, names.module_info.toString(), Kind.SOURCE);

      JavaFileObject class_fo =
          (msym.classLocation == null)
              ? null
              : fileManager.getJavaFileForInput(
                  msym.classLocation, names.module_info.toString(), Kind.CLASS);

      JavaFileObject fo =
          (src_fo == null)
              ? class_fo
              : (class_fo == null) ? src_fo : classFinder.preferredFileObject(src_fo, class_fo);

      if (fo == null) {
        String moduleName =
            msym.sourceLocation == null && msym.classLocation != null
                ? fileManager.inferModuleName(msym.classLocation)
                : null;
        if (moduleName != null) {
          msym.module_info.classfile = null;
          msym.flags_field |= Flags.AUTOMATIC_MODULE;
        } else {
          msym.kind = ERR;
        }
      } else {
        msym.module_info.classfile = fo;
        msym.module_info.completer =
            new Symbol.Completer() {
              @Override
              public void complete(Symbol sym) throws CompletionFailure {
                classFinder.fillIn(msym.module_info);
              }

              @Override
              public String toString() {
                return "ModuleInfoCompleter";
              }
            };
      }
    } catch (IOException e) {
      msym.kind = ERR;
    }
  }
 @Test(expected = NullPointerException.class)
 public void testFindClassNamesWithNullGlobs() throws Exception {
   ClassFinder.findClassNames(ROOT_PATH, null);
 }
 @Test(expected = IllegalArgumentException.class)
 public void testFindClassNamesWithNonExistingRootPath() throws Exception {
   ClassFinder.findClassNames(Paths.get("wrong"), EMPTY_GLOBS);
 }
 @Test(expected = NullPointerException.class)
 public void testFindClassNamesWithNullRootPath() throws Exception {
   ClassFinder.findClassNames(null, EMPTY_GLOBS);
 }
 /* (non-Javadoc)
  * @see strategiclibrary.service.classfinder.ClassFinderService#findClassesThatExtend(java.lang.Class[])
  */
 public List findClassesThatExtend(Class[] superClasses) throws Exception {
   return cf.findClassesThatExtend(superClasses, paths, false);
 }
 /* (non-Javadoc)
  * @see strategiclibrary.service.classfinder.ClassFinderService#findClassesThatExtend(java.lang.Class[], boolean)
  */
 public List findClassesThatExtend(Class[] superClasses, boolean innerClasses) throws Exception {
   return cf.findClassesThatExtend(superClasses, paths, innerClasses);
 }