Skip to content

[MNG-8578]add exclusion scope to repo, allow exclude dependencies from build(including parent, dependencies, etc) #654

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -26,6 +26,7 @@
import org.eclipse.aether.RequestTrace;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.graph.Exclusion;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.scope.ResolutionScope;

Expand Down Expand Up @@ -55,6 +56,8 @@ public final class CollectRequest {

private RequestTrace trace;

private List<Exclusion> exclusions = Collections.emptyList();

/**
* Creates an uninitialized request.
*/
Expand Down Expand Up @@ -331,6 +334,46 @@ public CollectRequest setTrace(RequestTrace trace) {
return this;
}

/**
* Gets the direct exclusions.
*
* @return The direct exclusions, never {@code null}.
*/
public List<Exclusion> getExclusions() {
return exclusions;
}

/**
* Sets the direct exclusions.
*
* @param exclusions The direct exclusions, may be {@code null}.
* @return This request for chaining, never {@code null}.
*/
public CollectRequest setExclusions(List<Exclusion> exclusions) {
if (exclusions == null) {
this.exclusions = Collections.emptyList();
} else {
this.exclusions = exclusions;
}
return this;
}

/**
* Adds the specified exclusion.
*
* @param exclusion The exclusion to add, may be {@code null}.
* @return This request for chaining, never {@code null}.
*/
public CollectRequest addExclusion(Exclusion exclusion) {
if (exclusion != null) {
if (this.exclusions.isEmpty()) {
this.exclusions = new ArrayList<>();
}
this.exclusions.add(exclusion);
}
return this;
}

@Override
public String toString() {
return getRoot() + " -> " + getDependencies() + " < " + getRepositories();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.aether.graph.DefaultDependencyNode;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.graph.DependencyNode;
import org.eclipse.aether.graph.Exclusion;
import org.eclipse.aether.impl.ArtifactDescriptorReader;
import org.eclipse.aether.impl.DependencyCollector;
import org.eclipse.aether.impl.RemoteRepositoryManager;
Expand Down Expand Up @@ -140,6 +141,7 @@ public final CollectResult collectDependencies(RepositorySystemSession session,
List<RemoteRepository> repositories = request.getRepositories();
List<Dependency> dependencies = request.getDependencies();
List<Dependency> managedDependencies = request.getManagedDependencies();
List<Exclusion> exclusions = request.getExclusions();

Map<String, Object> stats = new LinkedHashMap<>();
long time1 = System.nanoTime();
Expand Down Expand Up @@ -230,6 +232,7 @@ public final CollectResult collectDependencies(RepositorySystemSession session,
repositories,
dependencies,
managedDependencies,
exclusions,
results);

errorPath = results.getErrorPath();
Expand Down Expand Up @@ -301,6 +304,7 @@ protected abstract void doCollectDependencies(
List<RemoteRepository> repositories,
List<Dependency> dependencies,
List<Dependency> managedDependencies,
List<Exclusion> exclusions,
Results results)
throws DependencyCollectionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.eclipse.aether.graph.DefaultDependencyNode;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.graph.DependencyNode;
import org.eclipse.aether.graph.Exclusion;
import org.eclipse.aether.impl.ArtifactDescriptorReader;
import org.eclipse.aether.impl.RemoteRepositoryManager;
import org.eclipse.aether.impl.VersionRangeResolver;
Expand All @@ -74,6 +75,7 @@
import org.eclipse.aether.util.artifact.ArtifactIdUtils;
import org.eclipse.aether.util.concurrency.ExecutorUtils;
import org.eclipse.aether.util.graph.manager.DependencyManagerUtils;
import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
import org.eclipse.aether.version.Version;

import static org.eclipse.aether.internal.impl.collect.DefaultDependencyCycle.find;
Expand Down Expand Up @@ -147,6 +149,7 @@ protected void doCollectDependencies(
List<RemoteRepository> repositories,
List<Dependency> dependencies,
List<Dependency> managedDependencies,
List<Exclusion> exclusions,
Results results)
throws DependencyCollectionException {
boolean useSkip = ConfigUtils.getBoolean(session, DEFAULT_SKIPPER, CONFIG_PROP_SKIPPER);
Expand All @@ -162,6 +165,8 @@ protected void doCollectDependencies(
: DependencyResolutionSkipper.neverSkipper();
ParallelDescriptorResolver parallelDescriptorResolver = new ParallelDescriptorResolver(nThreads)) {
Args args = new Args(session, pool, context, versionContext, request, skipper, parallelDescriptorResolver);
ExclusionDependencySelector exclusionDependencySelector =
exclusions == null || exclusions.isEmpty() ? null : new ExclusionDependencySelector(exclusions);

DependencySelector rootDepSelector = session.getDependencySelector() != null
? session.getDependencySelector().deriveChildSelector(context)
Expand Down Expand Up @@ -200,7 +205,12 @@ protected void doCollectDependencies(

while (!args.dependencyProcessingQueue.isEmpty()) {
processDependency(
args, results, args.dependencyProcessingQueue.remove(), Collections.emptyList(), false);
args,
results,
args.dependencyProcessingQueue.remove(),
Collections.emptyList(),
false,
exclusionDependencySelector);
}

if (args.interruptedException.get() != null) {
Expand All @@ -216,14 +226,20 @@ private void processDependency(
Results results,
DependencyProcessingContext context,
List<Artifact> relocations,
boolean disableVersionManagement) {
boolean disableVersionManagement,
ExclusionDependencySelector exclusionDependencySelector) {
if (Thread.interrupted()) {
args.interruptedException.set(new InterruptedException());
}
if (args.interruptedException.get() != null) {
return;
}
Dependency dependency = context.dependency;
if (exclusionDependencySelector != null) {
if (!exclusionDependencySelector.selectDependency(dependency)) {
return;
}
}
PremanagedDependency preManaged = context.premanagedDependency;

boolean noDescriptor = isLackingDescriptor(args.session, dependency.getArtifact());
Expand Down Expand Up @@ -291,7 +307,8 @@ private void processDependency(
results,
relocatedContext,
descriptorResult.getRelocations(),
disableVersionManagementSubsequently);
disableVersionManagementSubsequently,
exclusionDependencySelector);
}

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.eclipse.aether.graph.DefaultDependencyNode;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.graph.DependencyNode;
import org.eclipse.aether.graph.Exclusion;
import org.eclipse.aether.impl.ArtifactDescriptorReader;
import org.eclipse.aether.impl.RemoteRepositoryManager;
import org.eclipse.aether.impl.VersionRangeResolver;
Expand All @@ -57,6 +58,7 @@
import org.eclipse.aether.spi.artifact.decorator.ArtifactDecoratorFactory;
import org.eclipse.aether.util.ConfigUtils;
import org.eclipse.aether.util.graph.manager.DependencyManagerUtils;
import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
import org.eclipse.aether.version.Version;

/**
Expand Down Expand Up @@ -92,12 +94,16 @@ protected void doCollectDependencies(
List<RemoteRepository> repositories,
List<Dependency> dependencies,
List<Dependency> managedDependencies,
List<Exclusion> exclusions,
Results results)
throws DependencyCollectionException {
// TODO
NodeStack nodes = new NodeStack();
nodes.push(node);

Args args = new Args(session, pool, nodes, context, versionContext, request);
ExclusionDependencySelector exclusionDependencySelector =
exclusions == null || exclusions.isEmpty() ? null : new ExclusionDependencySelector(exclusions);

process(
args,
Expand All @@ -114,7 +120,8 @@ protected void doCollectDependencies(
session.getDependencyTraverser() != null
? session.getDependencyTraverser().deriveChildTraverser(context)
: null,
session.getVersionFilter() != null ? session.getVersionFilter().deriveChildFilter(context) : null);
session.getVersionFilter() != null ? session.getVersionFilter().deriveChildFilter(context) : null,
exclusionDependencySelector);

if (args.interruptedException.get() != null) {
throw new DependencyCollectionException(
Expand All @@ -132,7 +139,8 @@ private void process(
DependencySelector depSelector,
DependencyManager depManager,
DependencyTraverser depTraverser,
VersionFilter verFilter) {
VersionFilter verFilter,
ExclusionDependencySelector exclusionDependencySelector) {
if (Thread.interrupted()) {
args.interruptedException.set(new InterruptedException());
}
Expand All @@ -141,7 +149,16 @@ private void process(
}
for (Dependency dependency : dependencies) {
processDependency(
args, trace, results, repositories, depSelector, depManager, depTraverser, verFilter, dependency);
args,
trace,
results,
repositories,
depSelector,
depManager,
depTraverser,
verFilter,
dependency,
exclusionDependencySelector);
}
}

Expand All @@ -155,7 +172,8 @@ private void processDependency(
DependencyManager depManager,
DependencyTraverser depTraverser,
VersionFilter verFilter,
Dependency dependency) {
Dependency dependency,
ExclusionDependencySelector exclusionDependencySelector) {

List<Artifact> relocations = Collections.emptyList();
processDependency(
Expand All @@ -169,7 +187,8 @@ private void processDependency(
verFilter,
dependency,
relocations,
false);
false,
exclusionDependencySelector);
}

@SuppressWarnings("checkstyle:parameternumber")
Expand All @@ -184,7 +203,13 @@ private void processDependency(
VersionFilter verFilter,
Dependency dependency,
List<Artifact> relocations,
boolean disableVersionManagement) {
boolean disableVersionManagement,
ExclusionDependencySelector exclusionDependencySelector) {
if (exclusionDependencySelector != null) {
if (!exclusionDependencySelector.selectDependency(dependency)) {
return;
}
}
if (depSelector != null && !depSelector.selectDependency(dependency)) {
return;
}
Expand Down Expand Up @@ -256,7 +281,8 @@ private void processDependency(
verFilter,
d,
descriptorResult.getRelocations(),
disableVersionManagementSubsequently);
disableVersionManagementSubsequently,
exclusionDependencySelector);
return;
} else {
d = args.pool.intern(d.setArtifact(args.pool.intern(d.getArtifact())));
Expand Down Expand Up @@ -290,7 +316,8 @@ private void processDependency(
verFilter,
d,
descriptorResult,
child);
child,
exclusionDependencySelector);
}
}
} else {
Expand Down Expand Up @@ -322,7 +349,8 @@ private void doRecurse(
VersionFilter verFilter,
Dependency d,
ArtifactDescriptorResult descriptorResult,
DefaultDependencyNode child) {
DefaultDependencyNode child,
ExclusionDependencySelector exclusionDependencySelector) {
DefaultDependencyCollectionContext context = args.collectionContext.get();
args.collectionContext.compareAndSet(context, context.set(d, descriptorResult.getManagedDependencies()));
context = args.collectionContext.get();
Expand Down Expand Up @@ -355,7 +383,8 @@ private void doRecurse(
childSelector,
childManager,
childTraverser,
childFilter);
childFilter,
exclusionDependencySelector);

args.nodes.pop();
} else {
Expand Down