in src/main/java/org/apache/maven/plugins/dependency/exclusion/AnalyzeExclusionsMojo.java [96:167]
public void execute() throws MojoExecutionException {
if (skip) {
getLog().debug("Skipping execution");
return;
}
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");
return;
}
ExclusionChecker checker = new ExclusionChecker();
ArtifactTypeRegistry artifactTypeRegistry =
session.getRepositorySession().getArtifactTypeRegistry();
for (Map.Entry<Coordinates, Collection<Exclusion>> entry : dependenciesWithExclusions.entrySet()) {
Coordinates currentCoordinates = entry.getKey();
Collection<org.eclipse.aether.graph.Dependency> actualDependencies;
try {
actualDependencies = resolverUtil.collectDependencies(
RepositoryUtils.toDependency(currentCoordinates.getDependency(), artifactTypeRegistry)
.setExclusions(null));
} catch (DependencyCollectionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
Set<Coordinates> actualCoordinates = actualDependencies.stream()
.map(org.eclipse.aether.graph.Dependency::getArtifact)
.map(a -> coordinates(a.getGroupId(), a.getArtifactId()))
.collect(toSet());
Set<Coordinates> exclusions =
entry.getValue().stream().map(Coordinates::coordinates).collect(toSet());
checker.check(currentCoordinates, exclusions, actualCoordinates);
}
if (!checker.getViolations().isEmpty()) {
if (exclusionFail) {
logViolations(project.getName(), checker.getViolations(), value -> getLog().error(value));
throw new MojoExecutionException("Invalid exclusions found");
} else {
logViolations(project.getName(), checker.getViolations(), value -> getLog().warn(value));
}
} else {
getLog().info("No problems with dependencies exclusions");
}
}