예제 #1
0
 public static void runFindBugs(File file, File dir) {
   if (FINDBUGS_JAR.getValue() != null) {
     TaskProgressLogger task = TaskProgressLogger.get();
     task.start("Running FindBugs");
     File output = new File(dir, FINDBUGS_FILE_NAME.getValue());
     try {
       ProcessBuilder builder =
           new ProcessBuilder(
               "java",
               "-jar",
               FINDBUGS_JAR.getValue().getPath(),
               "-textui",
               "-xml",
               "-output",
               output.getPath(),
               file.getPath());
       builder.inheritIO();
       builder.directory(dir);
       Process process = builder.start();
       process.waitFor();
       task.finish();
     } catch (IOException | InterruptedException e) {
       task.exception(e);
     }
   }
 }
예제 #2
0
  public static void cleanNonJavaFiles() {
    ModifiableJavaRepository repo =
        JavaRepositoryFactory.INSTANCE.loadModifiableJavaRepository(
            JavaRepositoryFactory.INPUT_REPO);

    class CustomFilter implements DeletionFilter {
      long deleted = 0l;

      @Override
      public boolean shouldDelete(RepoFile file) {
        boolean delete =
            !(file.isDirectory()
                || file.getName().endsWith(".java")
                || file.getName().endsWith(".jar"));
        if (delete) {
          deleted += file.toFile().length();
        }
        return delete;
      }
    };

    CustomFilter filter = new CustomFilter();

    TaskProgressLogger task = TaskProgressLogger.get();
    task.start(
        "Cleaning Java repository at " + JavaRepositoryFactory.INPUT_REPO.getValue(),
        "projects cleaned",
        500);
    for (ModifiableJavaProject project : repo.getProjects()) {
      project.delete(filter);
      task.progress(
          "%d projects cleaned (" + MemoryStatsReporter.formatSize(filter.deleted) + ") in %s");
    }
    task.report("Cleaned a total of " + MemoryStatsReporter.formatSize(filter.deleted));
    task.finish();
  }