예제 #1
0
파일: Weld.java 프로젝트: amannm/weld-core
 private void handleDir(
     File packDir, boolean scanRecursively, String packName, Set<String> foundClasses) {
   if (packDir != null && packDir.exists() && packDir.canRead()) {
     for (File file : packDir.listFiles()) {
       if (file.isFile()) {
         if (Files.isUsable(file) && Files.isClass(file.getName())) {
           foundClasses.add(Files.filenameToClassname(packName + "." + file.getName()));
         }
       }
       if (file.isDirectory() && scanRecursively) {
         handleDir(file, scanRecursively, packName + "." + file.getName(), foundClasses);
       }
     }
   }
 }
예제 #2
0
파일: Weld.java 프로젝트: amannm/weld-core
  private Set<String> scanPackages() {

    if (packages.isEmpty()) {
      return Collections.emptySet();
    }

    Set<String> foundClasses = new HashSet<String>();

    for (PackInfo packInfo : packages) {

      ClassLoader cl = packInfo.getClassLoaderRef().get();
      if (cl == null) {
        continue;
      }
      String packName = packInfo.getPackName();
      URL resourceUrl =
          cl.getResource(
              packInfo.getPackClassName().replace('.', '/') + Files.CLASS_FILE_EXTENSION);

      if (resourceUrl != null) {

        WeldSELogger.LOG.scanningPackage(packName, resourceUrl);

        try {
          URI resourceUri = resourceUrl.toURI();

          if (PROCOTOL_FILE.equals(resourceUrl.getProtocol())) {
            // Get the package directory, e.g. "file:///home/weld/org/jboss
            handleDir(
                new File(resourceUri).getParentFile(),
                packInfo.isScanRecursively(),
                packName,
                foundClasses);
          } else if (PROCOTOL_JAR.equals(resourceUrl.getProtocol())) {
            handleJar(resourceUri, packInfo.isScanRecursively(), packName, foundClasses);
          } else {
            WeldSELogger.LOG.resourceUrlProtocolNotSupported(resourceUrl);
          }

        } catch (URISyntaxException e) {
          CommonLogger.LOG.couldNotReadResource(resourceUrl, e);
        }
      } else {
        WeldSELogger.LOG.packageNotFound(packName);
      }
    }
    return foundClasses;
  }