From 9db07d075613ef04ae0793e50daf98f8dddd87a1 Mon Sep 17 00:00:00 2001 From: Shitikanth Kashyap Date: Thu, 26 Sep 2024 03:52:26 +0530 Subject: [PATCH] Add missing plugin dependency --- pom.xml | 19 +++++- .../enforcerrules/BanEmptyJavaFiles.java | 59 ++++++++++++++++--- 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index c7279a0..a0cb1cf 100644 --- a/pom.xml +++ b/pom.xml @@ -32,8 +32,8 @@ - 17 - 17 + 11 + 11 UTF-8 3.8.1 @@ -50,6 +50,7 @@ 3.20.0 2.4 3.2.2 + 0.9.0.M3 0.6.0 @@ -194,6 +195,19 @@ + + org.eclipse.sisu + sisu-maven-plugin + ${sisu-maven-plugin.version} + + + generate-index + + main-index + + + + @@ -210,6 +224,7 @@ maven-invoker-plugin ${maven-invoker-plugin.version} + true ${project.build.directory}/it true src/it/settings.xml diff --git a/src/main/java/io/github/shitikanth/enforcerrules/BanEmptyJavaFiles.java b/src/main/java/io/github/shitikanth/enforcerrules/BanEmptyJavaFiles.java index 50c0251..a5f8627 100644 --- a/src/main/java/io/github/shitikanth/enforcerrules/BanEmptyJavaFiles.java +++ b/src/main/java/io/github/shitikanth/enforcerrules/BanEmptyJavaFiles.java @@ -7,6 +7,7 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -49,10 +50,11 @@ public BanEmptyJavaFiles(MavenSession session) { void shutdownExecutor() { if (executor != null) { for (Runnable task : this.executor.shutdownNow()) { - if (task instanceof Future future) { + if (task instanceof Future) { + Future future = (Future) task; future.cancel(true); } - }; + } } } @@ -61,8 +63,16 @@ public void execute() throws EnforcerRuleException { MavenProject project = session.getCurrentProject(); int threads = session.getRequest().getDegreeOfConcurrency(); LOGGER.info("threads: {}", threads); - List compileSourceRoots = project.getCompileSourceRoots().stream().map(Paths::get).toList(); - List testCompileSourceRoots = project.getTestCompileSourceRoots().stream().map(Paths::get).toList(); + List compileSourceRoots = new ArrayList<>(); + List testCompileSourceRoots = new ArrayList<>(); + for (String s : project.getCompileSourceRoots()) { + Path path = Paths.get(s); + compileSourceRoots.add(path); + } + for (String s : project.getTestCompileSourceRoots()) { + Path path = Paths.get(s); + testCompileSourceRoots.add(path); + } analyzeSourceRoots(compileSourceRoots); analyzeSourceRoots(testCompileSourceRoots); } @@ -119,8 +129,41 @@ private void analyzeSourceRoots(List sourceRoots) throws EnforcerRuleExcep } } - record AnalysisResult( - Path path, - boolean isEmpty - ) {} + static final class AnalysisResult { + private final Path path; + private final boolean isEmpty; + + AnalysisResult( + Path path, + boolean isEmpty + ) { + this.path = path; + this.isEmpty = isEmpty; + } + + public Path path() {return path;} + + public boolean isEmpty() {return isEmpty;} + + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj == null || obj.getClass() != this.getClass()) return false; + var that = (AnalysisResult) obj; + return Objects.equals(this.path, that.path) && + this.isEmpty == that.isEmpty; + } + + @Override + public int hashCode() { + return Objects.hash(path, isEmpty); + } + + @Override + public String toString() { + return "AnalysisResult[" + + "path=" + path + ", " + + "isEmpty=" + isEmpty + ']'; + } + } }