Skip to content

Commit

Permalink
Fix Java 11 compatibility errors
Browse files Browse the repository at this point in the history
  • Loading branch information
shitikanth committed Sep 25, 2024
1 parent 7500b72 commit f77e1fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;

import javax.annotation.PreDestroy;
import javax.inject.Inject;
Expand Down Expand Up @@ -87,29 +88,29 @@ private void analyzeSourceRoots(List<Path> sourceRoots) throws EnforcerRuleExcep
}
try {
var sourceFiles = Files.find(sourceRoot, Integer.MAX_VALUE, (path, attr) -> attr.isRegularFile() && path.toFile().getName().endsWith(".java"))
.toList();
.collect(Collectors.toList());
long startTime = System.currentTimeMillis();
LOGGER.info("Analyzing {} files", sourceFiles.size());
executor = Executors.newFixedThreadPool(4);
List<Future<AnalysisResult>> futureList = executor.invokeAll(sourceFiles.stream().map(
executor.invokeAll(sourceFiles.stream().map(
path -> (Callable<AnalysisResult>) () -> {
boolean isEmpty = analyzer.isEmptyJavaFile(path);
return new AnalysisResult(path, isEmpty);
}).toList());
futureList.forEach(result -> {
if (result.isDone()) {
try {
var analysisResult = result.get();
if (analysisResult.isEmpty()) {
emptyJavaSourceFiles.add(analysisResult.path());
}).collect(Collectors.toList()))
.forEach(result -> {
if (result.isDone()) {
try {
var analysisResult = result.get();
if (analysisResult.isEmpty()) {
emptyJavaSourceFiles.add(analysisResult.path());
}
} catch (ExecutionException e) {
LOGGER.error("Task encountered exception: ", e.getCause());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
} catch (ExecutionException e) {
LOGGER.error("Task encountered exception: ", e.getCause());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
});
});
long endTime = System.currentTimeMillis();
LOGGER.info("Finished in {}ms", endTime - startTime);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;

import io.github.shitikanth.enforcerrules.AbstractTLDParser;
import io.github.shitikanth.enforcerrules.JavaTLDLexer;
Expand Down Expand Up @@ -38,6 +39,6 @@ public List<String> parse(BufferedReader bufferedReader) throws IOException {
var compilationUnit = parser.compilationUnit();
return compilationUnit.typeDeclaration().stream()
.map(typeDeclaration -> typeDeclaration.ID().toString())
.toList();
.collect(Collectors.toList());
}
}

0 comments on commit f77e1fa

Please sign in to comment.