Skip to content

Commit

Permalink
[MRESOLVER-491] Resolver should not have any "predefined" scope
Browse files Browse the repository at this point in the history
It is duty of consumer application to define those. Also,
no need for SPI either, as essentialy ONLY the dependency
managers were using the "system" scope definition so far.

Now, client code, that instantianates these anyway are
able to pass in predicate.

---

https://issues.apache.org/jira/browse/MRESOLVER-491
  • Loading branch information
cstamas committed Feb 6, 2024
1 parent 81c1d62 commit 178bec2
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,7 @@
package org.eclipse.aether.internal.impl.collect;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.aether.DefaultRepositorySystemSession;
Expand Down Expand Up @@ -387,7 +379,7 @@ void testManagedVersionScope() throws DependencyCollectionException {
Dependency dependency = newDep("managed:aid:ext:ver");
CollectRequest request = new CollectRequest(dependency, singletonList(repository));

session.setDependencyManager(new ClassicDependencyManager());
session.setDependencyManager(new ClassicDependencyManager(s -> Objects.equals(s, "system")));

CollectResult result = collector.collectDependencies(session, request);

Expand Down Expand Up @@ -462,7 +454,7 @@ void testDependencyManagement_VerboseMode() throws Exception {
void testDependencyManagement_TransitiveDependencyManager() throws DependencyCollectionException, IOException {
collector = setupCollector(newReader("managed/"));
parser = new DependencyGraphParser("artifact-descriptions/managed/");
session.setDependencyManager(new TransitiveDependencyManager());
session.setDependencyManager(new TransitiveDependencyManager(s -> Objects.equals(s, "system")));
final Dependency root = newDep("gid:root:ext:ver", "compile");
CollectRequest request = new CollectRequest(root, singletonList(repository));
request.addManagedDependency(newDep("gid:root:ext:must-retain-core-management"));
Expand All @@ -479,7 +471,7 @@ void testDependencyManagement_TransitiveDependencyManager() throws DependencyCol
rootArtifactRequest.addManagedDependency(newDep("gid:root:ext:must-retain-core-management"));
rootArtifactRequest.addManagedDependency(newDep("gid:direct:ext:must-retain-core-management"));
rootArtifactRequest.addManagedDependency(newDep("gid:transitive-1:ext:managed-by-root"));
session.setDependencyManager(new TransitiveDependencyManager());
session.setDependencyManager(new TransitiveDependencyManager(s -> Objects.equals(s, "system")));
result = collector.collectDependencies(session, rootArtifactRequest);
assertEqualSubtree(expectedTree, toDependencyResult(result.getRoot(), "compile", null));
}
Expand All @@ -488,7 +480,7 @@ void testDependencyManagement_TransitiveDependencyManager() throws DependencyCol
void testDependencyManagement_DefaultDependencyManager() throws DependencyCollectionException, IOException {
collector = setupCollector(newReader("managed/"));
parser = new DependencyGraphParser("artifact-descriptions/managed/");
session.setDependencyManager(new DefaultDependencyManager());
session.setDependencyManager(new DefaultDependencyManager(s -> Objects.equals(s, "system")));
final Dependency root = newDep("gid:root:ext:ver", "compile");
CollectRequest request = new CollectRequest(root, singletonList(repository));
request.addManagedDependency(newDep("gid:root:ext:must-not-manage-root"));
Expand All @@ -506,7 +498,7 @@ void testDependencyManagement_DefaultDependencyManager() throws DependencyCollec
rootArtifactRequest.addManagedDependency(newDep("gid:root:ext:must-not-manage-root"));
rootArtifactRequest.addManagedDependency(newDep("gid:direct:ext:managed-by-dominant-request"));
rootArtifactRequest.addManagedDependency(newDep("gid:transitive-1:ext:managed-by-root"));
session.setDependencyManager(new DefaultDependencyManager());
session.setDependencyManager(new DefaultDependencyManager(s -> Objects.equals(s, "system")));
result = collector.collectDependencies(session, rootArtifactRequest);
assertEqualSubtree(expectedTree, toDependencyResult(result.getRoot(), "compile", null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
*/
package org.eclipse.aether.internal.impl.collect.bf;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.*;

import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.collection.CollectRequest;
Expand Down Expand Up @@ -72,7 +69,7 @@ private Dependency newDep(String coords, String scope, Collection<Exclusion> exc
void testSkipperWithDifferentExclusion() throws DependencyCollectionException {
collector = setupCollector(newReader("managed/"));
parser = new DependencyGraphParser("artifact-descriptions/managed/");
session.setDependencyManager(new TransitiveDependencyManager());
session.setDependencyManager(new TransitiveDependencyManager(s -> Objects.equals(s, "system")));

ExclusionDependencySelector exclSel1 = new ExclusionDependencySelector();
session.setDependencySelector(exclSel1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
*
* @see org.eclipse.aether.graph.Dependency#getScope()
* @since 2.0.0
* @deprecated Consumer project is defining scopes.
*/
@Deprecated
public final class DependencyScopes {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@
*/
package org.eclipse.aether.util.graph.manager;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.function.Predicate;

import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.ArtifactProperties;
Expand All @@ -32,7 +28,6 @@
import org.eclipse.aether.collection.DependencyManager;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.graph.Exclusion;
import org.eclipse.aether.util.artifact.DependencyScopes;

import static java.util.Objects.requireNonNull;

Expand All @@ -59,12 +54,11 @@ public abstract class AbstractDependencyManager implements DependencyManager {

protected final Map<Object, Collection<Exclusion>> managedExclusions;

protected final Predicate<String> systemScopePredicate;

private final int hashCode;

/**
* Creates a new dependency manager without any management information.
*/
protected AbstractDependencyManager(int deriveUntil, int applyFrom) {
protected AbstractDependencyManager(int deriveUntil, int applyFrom, Predicate<String> systemScopePredicate) {
this(
0,
deriveUntil,
Expand All @@ -73,7 +67,8 @@ protected AbstractDependencyManager(int deriveUntil, int applyFrom) {
Collections.emptyMap(),
Collections.emptyMap(),
Collections.emptyMap(),
Collections.emptyMap());
Collections.emptyMap(),
systemScopePredicate);
}

@SuppressWarnings("checkstyle:ParameterNumber")
Expand All @@ -85,15 +80,17 @@ protected AbstractDependencyManager(
Map<Object, String> managedScopes,
Map<Object, Boolean> managedOptionals,
Map<Object, String> managedLocalPaths,
Map<Object, Collection<Exclusion>> managedExclusions) {
Map<Object, Collection<Exclusion>> managedExclusions,
Predicate<String> systemScopePredicate) {
this.depth = depth;
this.deriveUntil = deriveUntil;
this.applyFrom = applyFrom;
this.managedVersions = managedVersions;
this.managedScopes = managedScopes;
this.managedOptionals = managedOptionals;
this.managedLocalPaths = managedLocalPaths;
this.managedExclusions = managedExclusions;
this.managedVersions = requireNonNull(managedVersions);
this.managedScopes = requireNonNull(managedScopes);
this.managedOptionals = requireNonNull(managedOptionals);
this.managedLocalPaths = requireNonNull(managedLocalPaths);
this.managedExclusions = requireNonNull(managedExclusions);
this.systemScopePredicate = requireNonNull(systemScopePredicate);

this.hashCode = Objects.hash(
depth,
Expand Down Expand Up @@ -195,7 +192,7 @@ public DependencyManagement manageDependency(Dependency dependency) {
}
management.setScope(scope);

if (!DependencyScopes.SYSTEM.equals(scope)
if (!systemScopePredicate.test(scope)
&& dependency.getArtifact().getProperty(ArtifactProperties.LOCAL_PATH, null) != null) {
Map<String, String> properties =
new HashMap<>(dependency.getArtifact().getProperties());
Expand All @@ -204,8 +201,8 @@ public DependencyManagement manageDependency(Dependency dependency) {
}
}

if ((DependencyScopes.SYSTEM.equals(scope))
|| (scope == null && DependencyScopes.SYSTEM.equals(dependency.getScope()))) {
if ((systemScopePredicate.test(scope))
|| (scope == null && systemScopePredicate.test(dependency.getScope()))) {
String localPath = managedLocalPaths.get(key);
if (localPath != null) {
if (management == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;

import org.eclipse.aether.collection.DependencyCollectionContext;
import org.eclipse.aether.collection.DependencyManager;
Expand All @@ -33,9 +35,16 @@
public final class ClassicDependencyManager extends AbstractDependencyManager {
/**
* Creates a new dependency manager without any management information.
*
* @deprecated Use constructor that provides consumer application specific predicate.
*/
@Deprecated
public ClassicDependencyManager() {
this(false);
this(s -> Objects.equals(s, "system"));
}

public ClassicDependencyManager(Predicate<String> systemScopePredicate) {
this(false, systemScopePredicate);
}

/**
Expand All @@ -47,8 +56,8 @@ public ClassicDependencyManager() {
*
* @since 2.0.0
*/
public ClassicDependencyManager(boolean transitive) {
super(transitive ? Integer.MAX_VALUE : 2, 2);
public ClassicDependencyManager(boolean transitive, Predicate<String> systemScopePredicate) {
super(transitive ? Integer.MAX_VALUE : 2, 2, systemScopePredicate);
}

@SuppressWarnings("checkstyle:ParameterNumber")
Expand All @@ -60,7 +69,8 @@ private ClassicDependencyManager(
Map<Object, String> managedScopes,
Map<Object, Boolean> managedOptionals,
Map<Object, String> managedLocalPaths,
Map<Object, Collection<Exclusion>> managedExclusions) {
Map<Object, Collection<Exclusion>> managedExclusions,
Predicate<String> systemScopePredicate) {
super(
depth,
deriveUntil,
Expand All @@ -69,7 +79,8 @@ private ClassicDependencyManager(
managedScopes,
managedOptionals,
managedLocalPaths,
managedExclusions);
managedExclusions,
systemScopePredicate);
}

@Override
Expand Down Expand Up @@ -98,6 +109,7 @@ protected DependencyManager newInstance(
managedScopes,
managedOptionals,
managedLocalPaths,
managedExclusions);
managedExclusions,
systemScopePredicate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;

import org.eclipse.aether.collection.DependencyManager;
import org.eclipse.aether.graph.Exclusion;
Expand All @@ -39,9 +41,16 @@
public final class DefaultDependencyManager extends AbstractDependencyManager {
/**
* Creates a new dependency manager without any management information.
*
* @deprecated Use constructor that provides consumer application specific predicate.
*/
@Deprecated
public DefaultDependencyManager() {
super(Integer.MAX_VALUE, 0);
this(s -> Objects.equals(s, "system"));
}

public DefaultDependencyManager(Predicate<String> systemScopePredicate) {
super(Integer.MAX_VALUE, 0, systemScopePredicate);
}

@SuppressWarnings("checkstyle:ParameterNumber")
Expand All @@ -53,7 +62,8 @@ private DefaultDependencyManager(
Map<Object, String> managedScopes,
Map<Object, Boolean> managedOptionals,
Map<Object, String> managedLocalPaths,
Map<Object, Collection<Exclusion>> managedExclusions) {
Map<Object, Collection<Exclusion>> managedExclusions,
Predicate<String> systemScopePredicate) {
super(
depth,
deriveUntil,
Expand All @@ -62,7 +72,8 @@ private DefaultDependencyManager(
managedScopes,
managedOptionals,
managedLocalPaths,
managedExclusions);
managedExclusions,
systemScopePredicate);
}

@Override
Expand All @@ -80,6 +91,7 @@ protected DependencyManager newInstance(
managedScopes,
managedOptionals,
managedLocalPaths,
managedExclusions);
managedExclusions,
systemScopePredicate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;

import org.eclipse.aether.collection.DependencyManager;
import org.eclipse.aether.graph.Exclusion;
Expand All @@ -36,9 +38,16 @@
public final class TransitiveDependencyManager extends AbstractDependencyManager {
/**
* Creates a new dependency manager without any management information.
*
* @deprecated Use constructor that provides consumer application specific predicate.
*/
@Deprecated
public TransitiveDependencyManager() {
super(Integer.MAX_VALUE, 2);
this(s -> Objects.equals(s, "system"));
}

public TransitiveDependencyManager(Predicate<String> systemScopePredicate) {
super(Integer.MAX_VALUE, 2, systemScopePredicate);
}

@SuppressWarnings("checkstyle:ParameterNumber")
Expand All @@ -50,7 +59,8 @@ private TransitiveDependencyManager(
Map<Object, String> managedScopes,
Map<Object, Boolean> managedOptionals,
Map<Object, String> managedLocalPaths,
Map<Object, Collection<Exclusion>> managedExclusions) {
Map<Object, Collection<Exclusion>> managedExclusions,
Predicate<String> systemScopePredicate) {
super(
depth,
deriveUntil,
Expand All @@ -59,7 +69,8 @@ private TransitiveDependencyManager(
managedScopes,
managedOptionals,
managedLocalPaths,
managedExclusions);
managedExclusions,
systemScopePredicate);
}

@Override
Expand All @@ -77,6 +88,7 @@ protected DependencyManager newInstance(
managedScopes,
managedOptionals,
managedLocalPaths,
managedExclusions);
managedExclusions,
systemScopePredicate);
}
}
Loading

0 comments on commit 178bec2

Please sign in to comment.