Search in sources :

Example 21 with DependencyNode

use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.

the class JavaEffectiveScopeCalculator method getInheritedScopes.

private Set<String> getInheritedScopes(ConflictGroup group, Map<?, ?> conflictIds, Set<?> prerequisites) {
    Set<String> inheritedScopes = new HashSet<String>();
    for (Map.Entry<DependencyNode, List<DependencyNode>> entry : group.parents.entrySet()) {
        String childScope = entry.getKey().getDependency().getScope();
        if (entry.getValue().isEmpty()) {
            inheritedScopes.add(childScope);
        } else {
            for (DependencyNode parent : entry.getValue()) {
                if (prerequisites != null && !prerequisites.contains(conflictIds.get(parent))) {
                    /*
                         * There's a cycle and the parent node belongs to a later group, i.e. its scope is not yet
                         * calculated so ignore it.
                         */
                    continue;
                }
                String parentScope = parent.getDependency().getScope();
                String inheritedScope = getInheritedScope(parentScope, childScope);
                inheritedScopes.add(inheritedScope);
            }
        }
    }
    return inheritedScopes;
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) List(java.util.List) ArrayList(java.util.ArrayList) IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 22 with DependencyNode

use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.

the class NearestVersionConflictResolver method backtrack.

private void backtrack(ConflictGroup group, Map<?, ?> conflictIds, DependencyNode root) throws UnsolvableVersionConflictException {
    group.version = null;
    for (Iterator<Map.Entry<DependencyNode, Position>> it = group.candidates.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry<DependencyNode, Position> entry = it.next();
        Version version = entry.getKey().getVersion();
        Position pos = entry.getValue();
        if (!isAcceptable(group, version)) {
            it.remove();
        } else if (group.version == null || isNearer(pos, version, group.position, group.version)) {
            group.version = version;
            group.position = pos;
        }
    }
    if (group.version == null) {
        throw newFailure(group, conflictIds, root);
    }
}
Also used : Version(org.sonatype.aether.version.Version) DependencyNode(org.sonatype.aether.graph.DependencyNode) IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map)

Example 23 with DependencyNode

use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.

the class NearestVersionConflictResolver method pruneNonSelectedVersions.

private void pruneNonSelectedVersions(ConflictGroup group, Map<?, ?> conflictIds) {
    for (Position pos : group.positions) {
        for (Iterator<DependencyNode> it = pos.parent.getChildren().iterator(); it.hasNext(); ) {
            DependencyNode child = it.next();
            Object key = conflictIds.get(child);
            if (group.key.equals(key)) {
                if (!group.pruned && group.position.depth == pos.depth && group.version.equals(child.getVersion())) {
                    group.pruned = true;
                } else {
                    it.remove();
                }
            }
        }
    }
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode)

Example 24 with DependencyNode

use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.

the class NearestVersionConflictResolver method newFailure.

private UnsolvableVersionConflictException newFailure(final ConflictGroup group, final Map<?, ?> conflictIds, DependencyNode root) {
    DependencyFilter filter = new DependencyFilter() {

        public boolean accept(DependencyNode node, List<DependencyNode> parents) {
            return group.key.equals(conflictIds.get(node));
        }
    };
    PathRecordingDependencyVisitor visitor = new PathRecordingDependencyVisitor(filter);
    root.accept(visitor);
    return new UnsolvableVersionConflictException(visitor.getPaths(), group.key);
}
Also used : PathRecordingDependencyVisitor(org.sonatype.aether.util.graph.PathRecordingDependencyVisitor) DependencyNode(org.sonatype.aether.graph.DependencyNode) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) List(java.util.List) UnsolvableVersionConflictException(org.sonatype.aether.collection.UnsolvableVersionConflictException)

Example 25 with DependencyNode

use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.

the class NearestVersionConflictResolverTest method testViolationOfHardConstraintFallsBackToNearestSeenNotFirstSeen.

@Test
public void testViolationOfHardConstraintFallsBackToNearestSeenNotFirstSeen() throws Exception {
    // root
    // +- x:1
    // +- a:1
    // |  \- b:1
    // |     \- x:3
    // +- c:1
    // |  \- x:2
    // \- d:1
    //    \- e:1
    //       \- x:[2,)   # forces rejection of x:1, should fallback to nearest and not first-seen, i.e. x:2 and not x:3
    DependencyNode x1 = builder.artifactId("x").version("1").build();
    DependencyNode x2 = builder.artifactId("x").version("2").build();
    DependencyNode x3 = builder.artifactId("x").version("3").build();
    DependencyNode x2r = builder.artifactId("x").version("2").range("[2,)").build();
    DependencyNode b = builder.artifactId("b").version("1").build();
    b.getChildren().add(x3);
    DependencyNode a = builder.artifactId("a").build();
    a.getChildren().add(b);
    DependencyNode c = builder.artifactId("c").build();
    c.getChildren().add(x2);
    DependencyNode e = builder.artifactId("e").build();
    e.getChildren().add(x2r);
    DependencyNode d = builder.artifactId("d").build();
    d.getChildren().add(e);
    DependencyNode root = builder.artifactId(null).build();
    root.getChildren().add(x1);
    root.getChildren().add(a);
    root.getChildren().add(c);
    root.getChildren().add(d);
    Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>();
    conflictIds.put(x1, "x");
    conflictIds.put(x2, "x");
    conflictIds.put(x3, "x");
    conflictIds.put(x2r, "x");
    conflictIds.put(a, "a");
    conflictIds.put(b, "b");
    conflictIds.put(c, "c");
    conflictIds.put(d, "d");
    conflictIds.put(e, "e");
    context.put(TransformationContextKeys.CONFLICT_IDS, conflictIds);
    NearestVersionConflictResolver transformer = new NearestVersionConflictResolver();
    root = transformer.transformGraph(root, context);
    List<DependencyNode> trail = find(root, "x");
    assertEquals(3, trail.size());
    assertSame(x2, trail.get(0));
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) IdentityHashMap(java.util.IdentityHashMap) Test(org.junit.Test)

Aggregations

DependencyNode (org.sonatype.aether.graph.DependencyNode)114 Test (org.junit.Test)82 NodeBuilder (org.sonatype.aether.test.util.NodeBuilder)20 Dependency (org.sonatype.aether.graph.Dependency)14 IdentityHashMap (java.util.IdentityHashMap)13 CollectRequest (org.sonatype.aether.collection.CollectRequest)12 CollectResult (org.sonatype.aether.collection.CollectResult)11 List (java.util.List)8 Map (java.util.Map)8 LinkedList (java.util.LinkedList)7 Artifact (org.sonatype.aether.artifact.Artifact)6 DependencyFilter (org.sonatype.aether.graph.DependencyFilter)5 ArrayList (java.util.ArrayList)4 DependencyGraphTransformationContext (org.sonatype.aether.collection.DependencyGraphTransformationContext)4 ConflictMarker (org.sonatype.aether.util.graph.transformer.ConflictMarker)4 HashMap (java.util.HashMap)3 ArtifactDescriptorException (org.sonatype.aether.resolution.ArtifactDescriptorException)3 BufferedReader (java.io.BufferedReader)2 HashSet (java.util.HashSet)2 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)2