コード例 #1
0
  /**
   * Execute the search for source directories.
   *
   * @throws edu.umd.cs.findbugs.classfile.CheckedAnalysisException
   * @throws java.io.IOException
   * @throws java.lang.InterruptedException
   */
  public void execute() throws CheckedAnalysisException, IOException, InterruptedException {
    File dir = new File(rootSourceDirectory);
    if (!dir.isDirectory()) {
      throw new IOException("Path " + rootSourceDirectory + " is not a directory");
    }

    // Find all directories underneath the root source directory
    progress.startRecursiveDirectorySearch();
    RecursiveFileSearch rfs =
        new RecursiveFileSearch(
            rootSourceDirectory,
            new FileFilter() {
              @Override
              public boolean accept(File pathname) {
                return pathname.isDirectory();
              }
            });
    rfs.search();
    progress.doneRecursiveDirectorySearch();
    List<String> candidateSourceDirList = rfs.getDirectoriesScanned();

    // Build the classpath
    IClassPath classPath = null;
    try {
      IClassFactory factory = ClassFactory.instance();
      IClassPathBuilder builder = factory.createClassPathBuilder(errorLogger);

      classPath = buildClassPath(builder, factory);

      // From the application classes, find the full list of
      // fully-qualified source file names.
      List<String> fullyQualifiedSourceFileNameList =
          findFullyQualifiedSourceFileNames(builder, classPath);

      // Attempt to find source directories for all source files,
      // and add them to the discoveredSourceDirectoryList
      if (DEBUG) {
        System.out.println("looking for " + fullyQualifiedSourceFileNameList.size() + " files");
      }
      findSourceDirectoriesForAllSourceFiles(
          fullyQualifiedSourceFileNameList, candidateSourceDirList);
    } finally {
      if (classPath != null) {
        classPath.close();
      }
    }
  }
コード例 #2
0
  private IClassPath buildClassPath(IClassPathBuilder builder, IClassFactory factory)
      throws InterruptedException, IOException, CheckedAnalysisException {

    progress.startScanningArchives(project.getFileCount());

    for (String path : project.getFileList()) {
      builder.addCodeBase(factory.createFilesystemCodeBaseLocator(path), true);
    }

    for (String path : project.getAuxClasspathEntryList()) {
      builder.addCodeBase(factory.createFilesystemCodeBaseLocator(path), false);
    }

    IClassPath classPath = factory.createClassPath();

    builder.build(classPath, progress);

    progress.doneScanningArchives();

    return classPath;
  }