Skip to content

Commit 236e2c2

Browse files
Plugins transitive dependencies should be filtered
1 parent fa91320 commit 236e2c2

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/main/java/org/simplify4u/plugins/ArtifactResolver.java

+19-8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
import org.eclipse.aether.artifact.DefaultArtifact;
5252
import org.eclipse.aether.collection.CollectRequest;
5353
import org.eclipse.aether.graph.Dependency;
54+
import org.eclipse.aether.graph.DependencyNode;
55+
import org.eclipse.aether.graph.DependencyVisitor;
5456
import org.eclipse.aether.repository.RemoteRepository;
5557
import org.eclipse.aether.repository.RepositoryPolicy;
5658
import org.eclipse.aether.resolution.ArtifactRequest;
@@ -223,7 +225,7 @@ private List<Artifact> resolvePlugin(Plugin plugin, Configuration config) {
223225

224226
if (config.verifyPluginDependencies) {
225227
// we need resolve all transitive dependencies
226-
result = resolvePluginArtifactsTransitive(pArtifact, pluginDependencies, config.verifyPomFiles);
228+
result = resolvePluginArtifactsTransitive(pArtifact, pluginDependencies, config.dependencyFilter, config.verifyPomFiles);
227229
} else {
228230
// only resolve plugin artifact
229231
List<org.eclipse.aether.artifact.Artifact> aeArtifacts = new ArrayList<>();
@@ -240,7 +242,7 @@ private List<Artifact> resolvePlugin(Plugin plugin, Configuration config) {
240242

241243
private List<org.eclipse.aether.artifact.Artifact> resolvePluginArtifactsTransitive(
242244
org.eclipse.aether.artifact.Artifact artifact,
243-
List<Dependency> dependencies, boolean verifyPomFiles) {
245+
List<Dependency> dependencies, SkipFilter dependencyFilter, boolean verifyPomFiles) {
244246

245247
CollectRequest collectRequest = new CollectRequest(new Dependency(artifact, "runtime"),
246248
remotePluginRepositories);
@@ -252,12 +254,21 @@ private List<org.eclipse.aether.artifact.Artifact> resolvePluginArtifactsTransit
252254
.recover(DependencyResolutionException.class, DependencyResolutionException::getResult)
253255
.get();
254256

255-
List<org.eclipse.aether.artifact.Artifact> result = new ArrayList<>(
256-
dependencyResult.getArtifactResults().stream()
257-
.map(aResult -> aResult.isResolved() ?
258-
aResult.getArtifact() :
259-
aResult.getRequest().getArtifact())
260-
.collect(Collectors.toList()));
257+
List<org.eclipse.aether.artifact.Artifact> result = new ArrayList<>();
258+
dependencyResult.getRoot().accept(new DependencyVisitor() {
259+
@Override
260+
public boolean visitEnter(DependencyNode node) {
261+
if (node.getArtifact() != null && !dependencyFilter.shouldSkipDependency(node.getDependency())) {
262+
result.add(node.getArtifact());
263+
}
264+
return true;
265+
}
266+
267+
@Override
268+
public boolean visitLeave(DependencyNode node) {
269+
return true;
270+
}
271+
});
261272

262273
if (verifyPomFiles) {
263274
resolvePoms(result, remotePluginRepositories);

src/main/java/org/simplify4u/plugins/skipfilters/SkipFilter.java

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.simplify4u.plugins.skipfilters;
1818

19+
import org.apache.maven.RepositoryUtils;
1920
import org.apache.maven.artifact.Artifact;
2021
import org.apache.maven.artifact.DefaultArtifact;
2122
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
@@ -53,4 +54,12 @@ default boolean shouldSkipDependency(Dependency dependency, ArtifactHandlerManag
5354
artifactHandlerManager.getArtifactHandler(dependency.getType()));
5455
return shouldSkipArtifact(artifact);
5556
}
57+
58+
default boolean shouldSkipDependency(org.eclipse.aether.graph.Dependency dependency) {
59+
60+
Artifact artifact = RepositoryUtils.toArtifact(dependency.getArtifact());
61+
artifact.setScope(dependency.getScope());
62+
artifact.setOptional(dependency.getOptional());
63+
return shouldSkipArtifact(artifact);
64+
}
5665
}

0 commit comments

Comments
 (0)