Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: plugin fails with maven 3.8.x #9

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</scm>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mavenVersion>3.8.1</mavenVersion>
<!-- plugin versions -->
Expand All @@ -50,6 +50,7 @@
<maven-site-plugin.version>3.20.0</maven-site-plugin.version>
<maven-source-plugin.version>2.4</maven-source-plugin.version>
<maven-surefire-plugin.version>3.2.2</maven-surefire-plugin.version>
<sisu-maven-plugin.version>0.9.0.M3</sisu-maven-plugin.version>
<central-publishing-maven-plugin.version>0.6.0</central-publishing-maven-plugin.version>

<!-- Dependency versions -->
Expand Down Expand Up @@ -194,6 +195,19 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
<version>${sisu-maven-plugin.version}</version>
<executions>
<execution>
<id>generate-index</id>
<goals>
<goal>main-index</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand All @@ -210,6 +224,7 @@
<artifactId>maven-invoker-plugin</artifactId>
<version>${maven-invoker-plugin.version}</version>
<configuration>
<debug>true</debug>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<showErrors>true</showErrors>
<settingsFile>src/it/settings.xml</settingsFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
};
}
}
}

Expand All @@ -61,8 +63,16 @@ public void execute() throws EnforcerRuleException {
MavenProject project = session.getCurrentProject();
int threads = session.getRequest().getDegreeOfConcurrency();
LOGGER.info("threads: {}", threads);
List<Path> compileSourceRoots = project.getCompileSourceRoots().stream().map(Paths::get).toList();
List<Path> testCompileSourceRoots = project.getTestCompileSourceRoots().stream().map(Paths::get).toList();
List<Path> compileSourceRoots = new ArrayList<>();
List<Path> 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);
}
Expand Down Expand Up @@ -119,8 +129,41 @@ private void analyzeSourceRoots(List<Path> 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 + ']';
}
}
}
Loading