[MDEP-922] dependency:analyze-exclusions - should report issue only in current project
- filter exclusion by dependency location
diff --git a/src/it/mrm/repository/a-with-dep.pom b/src/it/mrm/repository/a-with-dep.pom
new file mode 100644
index 0000000..d3d163a
--- /dev/null
+++ b/src/it/mrm/repository/a-with-dep.pom
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>a-with-dep</artifactId>
+ <version>1.0.0</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>b-with-dep</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/src/it/mrm/repository/b-with-dep.pom b/src/it/mrm/repository/b-with-dep.pom
new file mode 100644
index 0000000..60c213f
--- /dev/null
+++ b/src/it/mrm/repository/b-with-dep.pom
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>b-with-dep</artifactId>
+ <version>1.0.0</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>c-without-dep</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/src/it/mrm/repository/c-without-dep.pom b/src/it/mrm/repository/c-without-dep.pom
new file mode 100644
index 0000000..36721d2
--- /dev/null
+++ b/src/it/mrm/repository/c-without-dep.pom
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>c-without-dep</artifactId>
+ <version>1.0.0</version>
+
+</project>
diff --git a/src/it/projects/analyze-invalid-exclude-multumodule-project/module1/pom.xml b/src/it/projects/analyze-invalid-exclude-multumodule-project/module1/pom.xml
index 2b329db..fb26626 100644
--- a/src/it/projects/analyze-invalid-exclude-multumodule-project/module1/pom.xml
+++ b/src/it/projects/analyze-invalid-exclude-multumodule-project/module1/pom.xml
@@ -33,8 +33,23 @@
<dependencies>
<dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-core</artifactId>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>a-with-dep</artifactId>
+ <version>1.0.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>invalid-exclusion2</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>c-without-dep</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>invalid-exclusion3</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
</dependencies>
</project>
diff --git a/src/it/projects/analyze-invalid-exclude-multumodule-project/module2/pom.xml b/src/it/projects/analyze-invalid-exclude-multumodule-project/module2/pom.xml
index 17d63f1..59f3a92 100644
--- a/src/it/projects/analyze-invalid-exclude-multumodule-project/module2/pom.xml
+++ b/src/it/projects/analyze-invalid-exclude-multumodule-project/module2/pom.xml
@@ -38,8 +38,8 @@
<version>${project.version}</version>
<exclusions>
<exclusion>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-core</artifactId>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>a-with-dep</artifactId>
</exclusion>
</exclusions>
</dependency>
diff --git a/src/it/projects/analyze-invalid-exclude-multumodule-project/pom.xml b/src/it/projects/analyze-invalid-exclude-multumodule-project/pom.xml
index 56e37b4..8e9c27a 100644
--- a/src/it/projects/analyze-invalid-exclude-multumodule-project/pom.xml
+++ b/src/it/projects/analyze-invalid-exclude-multumodule-project/pom.xml
@@ -45,13 +45,13 @@
<dependencyManagement>
<dependencies>
<dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-core</artifactId>
- <version>3.9.6</version>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>a-with-dep</artifactId>
+ <version>1.0.0</version>
<exclusions>
<exclusion>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>invalid-exclusion1</artifactId>
</exclusion>
</exclusions>
</dependency>
diff --git a/src/it/projects/analyze-invalid-exclude-multumodule-project/verify.groovy b/src/it/projects/analyze-invalid-exclude-multumodule-project/verify.groovy
index 7505142..8b798d2 100644
--- a/src/it/projects/analyze-invalid-exclude-multumodule-project/verify.groovy
+++ b/src/it/projects/analyze-invalid-exclude-multumodule-project/verify.groovy
@@ -1,3 +1,5 @@
+import java.lang.reflect.Array
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -17,14 +19,34 @@
* under the License.
*/
-File file = new File( basedir, "build.log" );
+
+static void checkMessagedInLogs(logLines, messages) {
+ def index = logLines.indexOf(messages[0])
+ assert index > 0: "no messages: '" + messages[0] + "' in log"
+
+ def logMessages = logLines[index..index + messages.size() - 1]
+
+ assert logMessages == messages
+
+}
+
+def file = new File(basedir, "build.log");
assert file.exists();
-String buildLog = file.getText( "UTF-8" );
-assert buildLog.contains( '[WARNING] test-module1 defines following unnecessary excludes');
-assert buildLog.contains( '[WARNING] org.apache.maven:maven-core:');
-assert buildLog.contains( '[WARNING] - javax.servlet:javax.servlet-api');
+def logLines = buildLog = file.readLines()
-assert !buildLog.contains( '[WARNING] test-module2 defines following unnecessary excludes');
+checkMessagedInLogs(logLines, [
+ '[WARNING] Test defines following unnecessary excludes',
+ '[WARNING] org.apache.maven.its.dependency:a-with-dep:1.0.0',
+ '[WARNING] - org.apache.maven.its.dependency:invalid-exclusion1 @ line: 52'
+])
-return true;
+checkMessagedInLogs(logLines, [
+ '[WARNING] test-module1 defines following unnecessary excludes',
+ '[WARNING] org.apache.maven.its.dependency:a-with-dep:1.0.0',
+ '[WARNING] - org.apache.maven.its.dependency:invalid-exclusion2 @ line: 40',
+ '[WARNING] - org.apache.maven.its.dependency:invalid-exclusion3 @ line: 48'
+
+])
+
+assert logLines.count('[INFO] No problems with dependencies exclusions') == 1
diff --git a/src/it/projects/analyze-invalid-exclude/pom.xml b/src/it/projects/analyze-invalid-exclude/pom.xml
index 17587fe..5c65025 100644
--- a/src/it/projects/analyze-invalid-exclude/pom.xml
+++ b/src/it/projects/analyze-invalid-exclude/pom.xml
@@ -36,53 +36,59 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-artifact</artifactId>
- <version>3.9.6</version>
- <exclusions>
- <exclusion>
- <groupId>javax.annotation</groupId>
- <artifactId>javax.annotation-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>javax.activation</groupId>
- <artifactId>javax.activation-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-model</artifactId>
- <version>3.9.6</version>
- </dependency>
- </dependencies>
-
<dependencyManagement>
<dependencies>
<dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-core</artifactId>
- <version>3.9.6</version>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>a-with-dep</artifactId>
+ <version>1.0.0</version>
<exclusions>
<exclusion>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>*</artifactId>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>invalid-exclusion1</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>b-with-dep</artifactId>
+ <version>1.0.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>c-without-dep</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>invalid-exclusion3</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>a-with-dep</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>invalid-exclusion2</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>c-without-dep</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>c-without-dep</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ </dependencies>
+
<build>
<pluginManagement>
<plugins>
diff --git a/src/it/projects/analyze-invalid-exclude/verify.groovy b/src/it/projects/analyze-invalid-exclude/verify.groovy
index 513517d..fb3c8c7 100644
--- a/src/it/projects/analyze-invalid-exclude/verify.groovy
+++ b/src/it/projects/analyze-invalid-exclude/verify.groovy
@@ -17,15 +17,23 @@
* under the License.
*/
-File file = new File( basedir, "build.log" );
+def file = new File(basedir, "build.log");
assert file.exists();
-String buildLog = file.getText( "UTF-8" );
-assert buildLog.contains( '[WARNING] test-module defines following unnecessary excludes');
-assert buildLog.contains( '[WARNING] org.apache.maven:maven-artifact:');
-assert buildLog.contains( '[WARNING] - javax.annotation:javax.annotation-api');
-assert buildLog.contains( '[WARNING] - javax.activation:javax.activation-api');
-assert buildLog.contains( '[WARNING] org.apache.maven:maven-core:');
-assert buildLog.contains( '[WARNING] - javax.servlet:javax.servlet-api');
+def logLines = buildLog = file.readLines()
-return true;
+def index = logLines.indexOf('[WARNING] test-module defines following unnecessary excludes')
+assert index > 0: "no messages in log"
+
+def messages = logLines[index..index + 5];
+
+assert messages == [
+ '[WARNING] test-module defines following unnecessary excludes',
+ '[WARNING] org.apache.maven.its.dependency:a-with-dep:1.0.0',
+ '[WARNING] - org.apache.maven.its.dependency:invalid-exclusion1 @ line: 46',
+ '[WARNING] - org.apache.maven.its.dependency:invalid-exclusion2 @ line: 75',
+ '[WARNING] org.apache.maven.its.dependency:b-with-dep:1.0.0',
+ '[WARNING] - org.apache.maven.its.dependency:invalid-exclusion3 @ line: 65'
+]
+
+
diff --git a/src/main/java/org/apache/maven/plugins/dependency/exclusion/AnalyzeExclusionsMojo.java b/src/main/java/org/apache/maven/plugins/dependency/exclusion/AnalyzeExclusionsMojo.java
index 871296f..3ad8d3b 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/exclusion/AnalyzeExclusionsMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/exclusion/AnalyzeExclusionsMojo.java
@@ -18,7 +18,9 @@
*/
package org.apache.maven.plugins.dependency.exclusion;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -27,6 +29,7 @@
import org.apache.maven.RepositoryUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Exclusion;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
@@ -79,15 +82,39 @@
@Parameter(property = "mdep.skip", defaultValue = "false")
private boolean skip;
+ /**
+ * Current project modelId.
+ */
+ private String projectModelId;
+
@Override
public void execute() throws MojoExecutionException {
if (skip) {
getLog().debug("Skipping execution");
return;
}
- Collection<Dependency> dependenciesWithExclusions = project.getDependencies().stream()
- .filter(dep -> !dep.getExclusions().isEmpty())
- .collect(toList());
+
+ projectModelId = project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion();
+
+ Map<Coordinates, Collection<Exclusion>> dependenciesWithExclusions = new HashMap<>();
+
+ project.getDependencyManagement().getDependencies().forEach(dependency -> {
+ Collection<Exclusion> exclusions = getExclusionsForDependency(dependency);
+ if (!exclusions.isEmpty()) {
+ dependenciesWithExclusions
+ .computeIfAbsent(coordinates(dependency), d -> new ArrayList<>())
+ .addAll(exclusions);
+ }
+ });
+
+ project.getDependencies().forEach(dependency -> {
+ Collection<Exclusion> exclusions = getExclusionsForDependency(dependency);
+ if (!exclusions.isEmpty()) {
+ dependenciesWithExclusions
+ .computeIfAbsent(coordinates(dependency), d -> new ArrayList<>())
+ .addAll(exclusions);
+ }
+ });
if (dependenciesWithExclusions.isEmpty()) {
getLog().debug("No dependencies defined with exclusions - exiting");
@@ -98,14 +125,14 @@
ArtifactTypeRegistry artifactTypeRegistry =
session.getRepositorySession().getArtifactTypeRegistry();
- for (final Dependency dependency : dependenciesWithExclusions) {
+ for (Map.Entry<Coordinates, Collection<Exclusion>> entry : dependenciesWithExclusions.entrySet()) {
- Coordinates currentCoordinates = coordinates(dependency.getGroupId(), dependency.getArtifactId());
+ Coordinates currentCoordinates = entry.getKey();
Collection<org.eclipse.aether.graph.Dependency> actualDependencies = null;
try {
- actualDependencies =
- resolverUtil.collectDependencies(RepositoryUtils.toDependency(dependency, artifactTypeRegistry)
+ actualDependencies = resolverUtil.collectDependencies(
+ RepositoryUtils.toDependency(currentCoordinates.getDependency(), artifactTypeRegistry)
.setExclusions(null));
} catch (DependencyCollectionException e) {
throw new MojoExecutionException(e.getMessage(), e);
@@ -116,9 +143,8 @@
.map(a -> coordinates(a.getGroupId(), a.getArtifactId()))
.collect(toSet());
- Set<Coordinates> exclusions = dependency.getExclusions().stream()
- .map(e -> coordinates(e.getGroupId(), e.getArtifactId()))
- .collect(toSet());
+ Set<Coordinates> exclusions =
+ entry.getValue().stream().map(Coordinates::coordinates).collect(toSet());
checker.check(currentCoordinates, exclusions, actualCoordinates);
}
@@ -130,13 +156,26 @@
} else {
logViolations(project.getName(), checker.getViolations(), value -> getLog().warn(value));
}
+ } else {
+ getLog().info("No problems with dependencies exclusions");
}
}
+ private Collection<Exclusion> getExclusionsForDependency(Dependency dependency) {
+ return dependency.getExclusions().stream()
+ .filter(this::isExclusionInProject)
+ .collect(toList());
+ }
+
+ private boolean isExclusionInProject(Exclusion exclusion) {
+ String modelId = exclusion.getLocation("").getSource().getModelId();
+ return projectModelId.equals(modelId);
+ }
+
private void logViolations(String name, Map<Coordinates, List<Coordinates>> violations, Consumer<String> logger) {
logger.accept(name + " defines following unnecessary excludes");
violations.forEach((dependency, invalidExclusions) -> {
- logger.accept(" " + dependency + ":");
+ logger.accept(" " + dependency);
invalidExclusions.forEach(invalidExclusion -> logger.accept(" - " + invalidExclusion));
});
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/exclusion/Coordinates.java b/src/main/java/org/apache/maven/plugins/dependency/exclusion/Coordinates.java
index cb4a042..d81f7b3 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/exclusion/Coordinates.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/exclusion/Coordinates.java
@@ -25,23 +25,43 @@
import java.util.Objects;
import java.util.function.Predicate;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Exclusion;
+import org.apache.maven.model.InputLocation;
+
/**
* Simple "record" to hold the coordinates of the dependency which is excluded.
* <p>
* When dealing with exclusions the version is not important. Only groupId and artifactId is used.
* </p>
*/
-class Coordinates {
+class Coordinates implements Comparable<Coordinates> {
+
private final String groupId;
+
private final String artifactId;
- private Coordinates(String groupId, String artifactId) {
+ private final Dependency dependency;
+
+ private final InputLocation location;
+
+ private Coordinates(String groupId, String artifactId, Dependency dependency, InputLocation location) {
this.groupId = groupId;
this.artifactId = artifactId;
+ this.dependency = dependency;
+ this.location = location;
}
public static Coordinates coordinates(String groupId, String artifactId) {
- return new Coordinates(groupId, artifactId);
+ return new Coordinates(groupId, artifactId, null, null);
+ }
+
+ public static Coordinates coordinates(Dependency dependency) {
+ return new Coordinates(dependency.getGroupId(), dependency.getArtifactId(), dependency, null);
+ }
+
+ public static Coordinates coordinates(Exclusion exclusion) {
+ return new Coordinates(exclusion.getGroupId(), exclusion.getArtifactId(), null, exclusion.getLocation(""));
}
public String getGroupId() {
@@ -52,6 +72,10 @@
return artifactId;
}
+ public Dependency getDependency() {
+ return dependency;
+ }
+
Predicate<Coordinates> getExclusionPattern() {
PathMatcher groupId = FileSystems.getDefault().getPathMatcher("glob:" + getGroupId());
PathMatcher artifactId = FileSystems.getDefault().getPathMatcher("glob:" + getArtifactId());
@@ -86,16 +110,36 @@
return false;
}
Coordinates that = (Coordinates) o;
- return Objects.equals(groupId, that.groupId) && Objects.equals(artifactId, that.artifactId);
+ return Objects.equals(groupId, that.groupId)
+ && Objects.equals(artifactId, that.artifactId)
+ && Objects.equals(location, that.location);
}
@Override
public int hashCode() {
- return Objects.hash(groupId, artifactId);
+ return Objects.hash(groupId, artifactId, location);
+ }
+
+ @Override
+ public int compareTo(Coordinates that) {
+
+ if (location != null && that.location != null) {
+ return location.getLineNumber() - that.location.getLineNumber();
+ }
+
+ return toString().compareTo(that.toString());
}
@Override
public String toString() {
- return groupId + ":" + artifactId;
+ String version = "";
+ if (dependency != null) {
+ version = ":" + dependency.getVersion();
+ }
+ String line = "";
+ if (location != null) {
+ line = " @ line: " + location.getLineNumber();
+ }
+ return groupId + ":" + artifactId + version + line;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/exclusion/ExclusionChecker.java b/src/main/java/org/apache/maven/plugins/dependency/exclusion/ExclusionChecker.java
index 7219cde..1340461 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/exclusion/ExclusionChecker.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/exclusion/ExclusionChecker.java
@@ -18,16 +18,16 @@
*/
package org.apache.maven.plugins.dependency.exclusion;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
import static java.util.stream.Collectors.toList;
class ExclusionChecker {
- private final Map<Coordinates, List<Coordinates>> violations = new HashMap<>();
+ private final Map<Coordinates, List<Coordinates>> violations = new TreeMap<>();
Map<Coordinates, List<Coordinates>> getViolations() {
return violations;
@@ -36,6 +36,7 @@
void check(Coordinates artifact, Set<Coordinates> excludes, Set<Coordinates> actualDependencies) {
List<Coordinates> invalidExclusions = excludes.stream()
.filter(exclude -> actualDependencies.stream().noneMatch(exclude.getExclusionPattern()))
+ .sorted()
.collect(toList());
if (!invalidExclusions.isEmpty()) {
diff --git a/src/test/java/org/apache/maven/plugins/dependency/exclusion/AnalyzeExclusionsMojoTest.java b/src/test/java/org/apache/maven/plugins/dependency/exclusion/AnalyzeExclusionsMojoTest.java
index 10ce184..231871c 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/exclusion/AnalyzeExclusionsMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/exclusion/AnalyzeExclusionsMojoTest.java
@@ -32,6 +32,8 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
+import org.apache.maven.model.InputLocation;
+import org.apache.maven.model.InputSource;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
@@ -63,6 +65,10 @@
project = new DependencyProjectStub();
project.setName("projectName");
+ project.setGroupId("testGroupId");
+ project.setArtifactId("testArtifactId");
+ project.setVersion("1.0.0");
+
getContainer().addComponent(project, MavenProject.class.getName());
MavenSession session = newMavenSession(project);
@@ -192,6 +198,7 @@
dependency.setScope("compile");
dependency.setType("jar");
dependency.setClassifier("");
+ dependency.setLocation("", new InputLocation(1, 1));
return dependency;
}
@@ -203,6 +210,7 @@
dependency.setScope(scope);
dependency.setType("jar");
dependency.setClassifier(classifier);
+ dependency.setLocation("", new InputLocation(1, 1));
return dependency;
}
@@ -210,6 +218,9 @@
Exclusion exclusion = new Exclusion();
exclusion.setGroupId(groupId);
exclusion.setArtifactId(artifactId);
+ InputSource inputSource = new InputSource();
+ inputSource.setModelId("testGroupId:testArtifactId:1.0.0");
+ exclusion.setLocation("", new InputLocation(1, 1, inputSource));
return exclusion;
}
diff --git a/src/test/java/org/apache/maven/plugins/dependency/exclusion/ExclusionCheckerTest.java b/src/test/java/org/apache/maven/plugins/dependency/exclusion/ExclusionCheckerTest.java
index 857fd6f..70a4241 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/exclusion/ExclusionCheckerTest.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/exclusion/ExclusionCheckerTest.java
@@ -54,7 +54,7 @@
assertThat(checker.getViolations())
.containsEntry(
artifact,
- Arrays.asList(coordinates("com.example", "two"), coordinates("com.example", "three")));
+ Arrays.asList(coordinates("com.example", "three"), coordinates("com.example", "two")));
}
@Test