in src/main/java/org/apache/sling/maven/enforcer/RequireProvidedDependenciesInRuntimeClasspath.java [112:158]
public void execute() throws EnforcerRuleException {
// get a new session to be able to tweak the dependency selector
DefaultRepositorySystemSession newRepoSession = new DefaultRepositorySystemSession(session.getRepositorySession());
Collection<DependencySelector> depSelectors = new ArrayList<>();
depSelectors.add(new ScopeDependencySelector("test")); // exclude transitive and direct "test" dependencies of the rootDependency (i.e. the current project)
// add also the exclude patterns
if (excludes != null && !excludes.isEmpty()) {
Collection<Exclusion> exclusions = excludes.stream().map(RequireProvidedDependenciesInRuntimeClasspath::convertPatternToExclusion).collect(Collectors.toCollection(LinkedList::new));
exclusions.add(new Exclusion("*", "*", "*", "pom"));
depSelectors.add(new ExclusionDependencySelector(exclusions));
}
if (!includeOptionals) {
depSelectors.add(new OptionalDependencySelector());
}
if (!includeDirects) {
depSelectors.add(new LevelAndScopeExclusionSelector(1, "provided"));
}
newRepoSession.setDependencySelector(new AndDependencySelector(depSelectors));
// use the ones for https://maven.apache.org/guides/mini/guide-maven-classloading.html#3-plugin-classloaders
@SuppressWarnings("deprecation")
List<org.eclipse.aether.artifact.Artifact> runtimeArtifacts = project.getRuntimeArtifacts().stream().map(RepositoryUtils::toArtifact).collect(Collectors.toList());
// no guard supported here due to https://issues.apache.org/jira/browse/MENFORCER-488
getLog().debug("Collected " + runtimeArtifacts.size()+ " runtime dependencies ");
for (Artifact runtimeArtifact : runtimeArtifacts) {
getLog().debug(runtimeArtifact.toString());
}
Dependency rootDependency = RepositoryUtils.toDependency(project.getArtifact(), null);
try {
DependencyNode rootDependencyNode = collectTransitiveDependencies(
rootDependency, repoSystem, newRepoSession, project.getRemoteProjectRepositories());
int numViolations = checkForMissingArtifacts(rootDependencyNode, runtimeArtifacts);
if (numViolations > 0) {
ChoiceFormat dependenciesFormat = new ChoiceFormat("1#dependency|1<dependencies");
throw new EnforcerRuleException("Found " + numViolations + " missing runtime " + dependenciesFormat.format(numViolations) + ". Look at the warnings emitted above for the details.");
}
} catch (DependencyCollectionException e) {
// draw graph
StringWriter writer = new StringWriter();
DependencyVisitor depVisitor = new TreeDependencyVisitor(
new DependencyVisitorPrinter(new PrintWriter(writer)));
e.getResult().getRoot().accept(depVisitor);
throw new EnforcerRuleException("Could not retrieve dependency metadata for project : "
+ e.getMessage() + ". Partial dependency tree: " + writer.toString(), e);
}
}