// TODO AstUtils.getClassFilesForSource(f.toString()); - attempt to get only relevant classpaths for a given source file?
// TODO Naively we can multi-thread here (i.e. per file) but simple testing indicated that this slowed us down.
protected void runOperations(String directoryPath, UseCase useCase) throws IOException {
    log.info(System.lineSeparator() +
      "================================================" + System.lineSeparator() +
      "     ____     ____________________     ____" + System.lineSeparator() +
      "    /    \\   /  __|__    __|   _  \\   /    \\" + System.lineSeparator() +
      "   /  /\\  \\  \\  \\    |  |  |  |/  /  /  /\\  \\" + System.lineSeparator() +
      "  /  /__\\  \\__\\  \\   |  |  |  |\\  \\ /  /__\\  \\" + System.lineSeparator() +
      " /__/    \\__\\____/   |__|  |__| \\__\\__/    \\__\\" + System.lineSeparator() +
      "================================================");
    log.info("Starting Astra run for directory: " + directoryPath);
    AtomicLong currentFileIndex = new AtomicLong();
    AtomicLong currentPercentage = new AtomicLong();
    log.info("Counting files (this may take a few seconds)");
    Instant startTime = Instant.now();
    List<Path> javaFilesInDirectory;
    try (Stream<Path> walk = Files.walk(Paths.get(directoryPath))) {
      javaFilesInDirectory = walk
          .filter(f -> f.toFile().isFile())
          .filter(f -> f.getFileName().toString().endsWith("java"))
          .collect(Collectors.toList());
    }
    log.info(javaFilesInDirectory.size() + " .java files in directory to review");
    log.info("Applying prefilters to files in directory");
    Predicate<String> prefilteringPredicate = useCase.getPrefilteringPredicate();
    List<Path> filteredJavaFiles = javaFilesInDirectory.stream()
        .filter(f -> prefilteringPredicate.test(f.toString()))
        .collect(Collectors.toList());
    log.info(filteredJavaFiles.size() + " files remain after prefiltering");
    final Set<? extends ASTOperation> operations = useCase.getOperations();
    final String[] sources = useCase.getSources();
    final String[] classPath = useCase.getClassPath();
    for (Path f : filteredJavaFiles) {
      // TODO AstUtils.getClassFilesForSource(f.toString()); - attempt to get only relevant classpaths for a given source file?
      // TODO Naively we can multi-thread here (i.e. per file) but simple testing indicated that this slowed us down.
      applyOperationsAndSave(new File(f.toString()), operations, sources, classPath);
      long newPercentage = currentFileIndex.incrementAndGet() * 100 / filteredJavaFiles.size();
      if (newPercentage != currentPercentage.get()) {
        currentPercentage.set(newPercentage);
        logProgress(currentFileIndex.get(), currentPercentage.get(), startTime, filteredJavaFiles.size());
      }
    }
    log.info(getPrintableDuration(Duration.between(startTime, Instant.now())));
  }
final String[] classPath = useCase.getClassPath();
for (Path f : filteredJavaFiles) {
// TODO AstUtils.getClassFilesForSource(f.toString()); - attempt to get only relevant classpaths for a given source file?
// TODO Naively we can multi-thread here (i.e. per file) but simple testing indicated that this slowed us down.
applyOperationsAndSave(new File(f.toString()), operations, sources, classPath);
long newPercentage = currentFileIndex.incrementAndGet() * 100 / filteredJavaFiles.size();
log.info("Applying prefilters to files in directory");
Predicate<String> prefilteringPredicate = useCase.getPrefilteringPredicate();
List<Path> filteredJavaFiles = javaFilesInDirectory.stream()
.filter(f -> prefilteringPredicate.test(f.toString()))
.collect(Collectors.toList());
log.info(filteredJavaFiles.size() + " files remain after prefiltering");
final Set<? extends ASTOperation> operations = useCase.getOperations();
final String[] sources = useCase.getSources();
final String[] classPath = useCase.getClassPath();
for (Path f : filteredJavaFiles) {
// TODO AstUtils.getClassFilesForSource(f.toString()); - attempt to get only relevant classpaths for a given source file?
// TODO Naively we can multi-thread here (i.e. per file) but simple testing indicated that this slowed us down.
applyOperationsAndSave(new File(f.toString()), operations, sources, classPath);
long newPercentage = currentFileIndex.incrementAndGet() * 100 / filteredJavaFiles.size();
if (newPercentage != currentPercentage.get()) {
currentPercentage.set(newPercentage);
logProgress(currentFileIndex.get(), currentPercentage.get(), startTime, filteredJavaFiles.size());
}
}
log.info(getPrintableDuration(Duration.between(startTime, Instant.now())));
}
log.info("Counting files (this may take a few seconds)");
Instant startTime = Instant.now();
List<Path> javaFilesInDirectory;
try (Stream<Path> walk = Files.walk(Paths.get(directoryPath))) {
javaFilesInDirectory = walk
.filter(f -> f.toFile().isFile())
.filter(f -> f.getFileName().toString().endsWith("java"))
.collect(Collectors.toList());
}
log.info(javaFilesInDirectory.size() + " .java files in directory to review");
log.info("Applying prefilters to files in directory");
Predicate<String> prefilteringPredicate = useCase.getPrefilteringPredicate();
List<Path> filteredJavaFiles = javaFilesInDirectory.stream()
.filter(f -> prefilteringPredicate.test(f.toString()))
.collect(Collectors.toList());
log.info(filteredJavaFiles.size() + " files remain after prefiltering");
final Set<? extends ASTOperation> operations = useCase.getOperations();
final String[] sources = useCase.getSources();
final String[] classPath = useCase.getClassPath();
for (Path f : filteredJavaFiles) {
// TODO AstUtils.getClassFilesForSource(f.toString()); - attempt to get only relevant classpaths for a given source file?
// TODO Naively we can multi-thread here (i.e. per file) but simple testing indicated that this slowed us down.
applyOperationsAndSave(new File(f.toString()), operations, sources, classPath);
long newPercentage = currentFileIndex.incrementAndGet() * 100 / filteredJavaFiles.size();
if (newPercentage != currentPercentage.get()) {
currentPercentage.set(newPercentage);
logProgress(currentFileIndex.get(), currentPercentage.get(), startTime, filteredJavaFiles.size());
}
}
log.info(getPrintableDuration(Duration.between(startTime, Instant.now())));
}