示例#1
0
 private static void scanDirectory(
     File directory,
     ClassLoader classloader,
     String packagePrefix,
     Set<File> ancestors,
     Visitor visitor)
     throws IOException {
   File canonical = directory.getCanonicalFile();
   if (ancestors.contains(canonical)) {
     // A cycle in the filesystem, for example due to a symbolic link.
     return;
   }
   File[] files = directory.listFiles();
   if (files == null) {
     // logger.warning("Cannot read directory " + directory);
     // IO error, just skip the directory
     return;
   }
   Set<File> newAncestors = new HashSet<>();
   newAncestors.addAll(ancestors);
   newAncestors.add(canonical);
   for (File f : files) {
     String name = f.getName();
     if (f.isDirectory()) {
       scanDirectory(f, classloader, packagePrefix + name + "/", newAncestors, visitor);
     } else {
       String resourceName = packagePrefix + name;
       if (!resourceName.equals(JarFile.MANIFEST_NAME))
         visitor.visit(resourceName, f.toURI().toURL(), classloader);
     }
   }
 }
示例#2
0
  private static void scanFrom(
      File file, ClassLoader classloader, Set<URI> scannedUris, Visitor visitor)
      throws IOException {
    if (!file.exists()) return;

    if (file.isDirectory()) scanDirectory(file, classloader, visitor);
    else scanJar(file, classloader, scannedUris, visitor);
  }
示例#3
0
 private static void scanDirectory(File directory, ClassLoader classloader, Visitor visitor)
     throws IOException {
   scanDirectory(directory, classloader, "", new HashSet<File>(), visitor);
 }