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

[MNG-8041] A quick draft about problem #1398

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,11 @@ private Set<Artifact> getDependencies(
scopesToCollect = new HashSet<>(scopesToCollect);
scopesToCollect.addAll(scopesToResolve);

DependencyFilter collectionFilter = new ScopeDependencyFilter(null, negate(scopesToCollect));
DependencyFilter resolutionFilter = new ScopeDependencyFilter(null, negate(scopesToResolve));
Collection<String> collectScopesToExclude = negate(scopesToCollect);
Collection<String> resolveScopesToExclude = negate(scopesToResolve);

DependencyFilter collectionFilter = new ScopeDependencyFilter(null, collectScopesToExclude);
DependencyFilter resolutionFilter = new ScopeDependencyFilter(null, resolveScopesToExclude);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just use the scopes to collect / resolve instead of the ones to exclude and give them as a negative test in the filter ?
i.e.:

DependencyFilter collectionFilter = new ScopeDependencyFilter(scopesToCollect);
DependencyFilter resolutionFilter = new ScopeDependencyFilter(scopesToResolve);

resolutionFilter = AndDependencyFilter.newInstance(collectionFilter, resolutionFilter);
resolutionFilter =
AndDependencyFilter.newInstance(resolutionFilter, new ReactorDependencyFilter(projectArtifacts));
Expand All @@ -254,6 +257,8 @@ private Set<Artifact> getDependencies(
DefaultDependencyResolutionRequest request =
new DefaultDependencyResolutionRequest(project, session.getRepositorySession());
request.setResolutionFilter(resolutionFilter);
request.setCollectScopesToExclude(collectScopesToExclude);
request.setResolveScopesToExclude(resolveScopesToExclude);

eventSpyDispatcher.onEvent(request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.project;

import java.util.Collection;

import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.graph.DependencyFilter;

Expand All @@ -31,6 +33,10 @@ public class DefaultDependencyResolutionRequest implements DependencyResolutionR

private RepositorySystemSession session;

private Collection<String> collectScopesToExclude;

private Collection<String> resolveScopesToExclude;

public DefaultDependencyResolutionRequest() {
// enables default constructor
}
Expand Down Expand Up @@ -66,4 +72,20 @@ public DependencyResolutionRequest setRepositorySession(RepositorySystemSession
this.session = repositorySession;
return this;
}

public void setCollectScopesToExclude(Collection<String> collectScopesToExclude) {
this.collectScopesToExclude = collectScopesToExclude;
}

public void setResolveScopesToExclude(Collection<String> resolveScopesToExclude) {
this.resolveScopesToExclude = resolveScopesToExclude;
}

public Collection<String> getCollectScopesToExclude() {
return collectScopesToExclude;
}

public Collection<String> getResolveScopesToExclude() {
return resolveScopesToExclude;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public DependencyResolutionResult resolve(DependencyResolutionRequest request)
// guard against case where best-effort resolution for invalid models is requested
continue;
}
collect.addDependency(RepositoryUtils.toDependency(dependency, stereotypes));
mayAddCollectDirectDependency(collect, request, RepositoryUtils.toDependency(dependency, stereotypes));
}
} else {
Map<String, Dependency> dependencies = new HashMap<>();
Expand Down Expand Up @@ -136,7 +136,7 @@ public DependencyResolutionResult resolve(DependencyResolutionRequest request)
art = art.setFile(null).setVersion(art.getBaseVersion());
dep = dep.setArtifact(art);
}
collect.addDependency(dep);
mayAddCollectDirectDependency(collect, request, dep);
}
}

Expand Down Expand Up @@ -196,6 +196,16 @@ public DependencyResolutionResult resolve(DependencyResolutionRequest request)
return result;
}

private void mayAddCollectDirectDependency(
CollectRequest collectRequest,
DependencyResolutionRequest request,
org.eclipse.aether.graph.Dependency dependency) {
if (request.getCollectScopesToExclude() == null
|| !request.getCollectScopesToExclude().contains(dependency.getScope())) {
collectRequest.addDependency(dependency);
}
}

private void process(DefaultDependencyResolutionResult result, Collection<ArtifactResult> results) {
for (ArtifactResult ar : results) {
DependencyNode node = ar.getRequest().getDependencyNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.project;

import java.util.Collection;

import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.graph.DependencyFilter;

Expand Down Expand Up @@ -74,4 +76,8 @@ public interface DependencyResolutionRequest {
* @return This request for chaining, never {@code null}.
*/
DependencyResolutionRequest setRepositorySession(RepositorySystemSession repositorySession);

Collection<String> getCollectScopesToExclude();

Collection<String> getResolveScopesToExclude();
}