Search in sources :

Example 16 with DependencyNode

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

the class DefaultDependencyCollectorTest method testCyclicDependenciesBig.

@Test
public void testCyclicDependenciesBig() throws Exception {
    DependencyNode root = parser.parse("cycle-big.txt");
    CollectRequest request = new CollectRequest(root.getDependency(), Arrays.asList(repository));
    collector.setArtifactDescriptorReader(new IniArtifactDescriptorReader("artifact-descriptions/cycle-big/"));
    CollectResult result = collector.collectDependencies(session, request);
    assertNotNull(result.getRoot());
// we only care about the performance here, this test must not hang or run out of mem
}
Also used : CollectResult(org.sonatype.aether.collection.CollectResult) DependencyNode(org.sonatype.aether.graph.DependencyNode) CollectRequest(org.sonatype.aether.collection.CollectRequest) Test(org.junit.Test)

Example 17 with DependencyNode

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

the class PathRecordingDependencyVisitor method visitEnter.

public boolean visitEnter(DependencyNode node) {
    boolean accept = filter == null || filter.accept(node, parents);
    parents.push(node);
    if (accept) {
        DependencyNode[] path = new DependencyNode[parents.size()];
        int i = parents.size() - 1;
        for (DependencyNode n : parents) {
            path[i] = n;
            i--;
        }
        paths.add(Arrays.asList(path));
    }
    return !(excludeChildrenOfMatches && accept);
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode)

Example 18 with DependencyNode

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

the class ConflictIdSorter method buildConflitIdDAG.

private void buildConflitIdDAG(Map<Object, ConflictId> ids, DependencyNode node, ConflictId id, int depth, Map<DependencyNode, Object> visited, Map<?, ?> conflictIds) {
    if (visited.put(node, Boolean.TRUE) != null) {
        return;
    }
    depth++;
    for (DependencyNode child : node.getChildren()) {
        Object key = conflictIds.get(child);
        ConflictId childId = ids.get(key);
        if (childId == null) {
            childId = new ConflictId(key, depth);
            ids.put(key, childId);
        } else {
            childId.pullup(depth);
        }
        if (id != null) {
            id.add(childId);
        }
        buildConflitIdDAG(ids, child, childId, depth, visited, conflictIds);
    }
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode)

Example 19 with DependencyNode

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

the class ConflictMarker method analyze.

private void analyze(DependencyNode node, Map<DependencyNode, Object> nodes, Map<Object, ConflictGroup> groups) {
    if (nodes.put(node, SEEN) != null) {
        return;
    }
    Set<Object> keys = getKeys(node);
    if (!keys.isEmpty()) {
        ConflictGroup group = null;
        boolean fixMappings = false;
        for (Object key : keys) {
            ConflictGroup g = groups.get(key);
            if (group != g) {
                if (group == null) {
                    Set<Object> newKeys = merge(g.keys, keys);
                    if (newKeys == g.keys) {
                        group = g;
                        break;
                    } else {
                        group = new ConflictGroup(newKeys);
                        fixMappings = true;
                    }
                } else if (g == null) {
                    fixMappings = true;
                } else {
                    Set<Object> newKeys = merge(g.keys, group.keys);
                    if (newKeys == g.keys) {
                        group = g;
                        fixMappings = false;
                        break;
                    } else if (newKeys != group.keys) {
                        group = new ConflictGroup(newKeys);
                        fixMappings = true;
                    }
                }
            }
        }
        if (group == null) {
            group = new ConflictGroup(keys);
            fixMappings = true;
        }
        if (fixMappings) {
            for (Object key : group.keys) {
                groups.put(key, group);
            }
        }
    }
    for (DependencyNode child : node.getChildren()) {
        analyze(child, nodes, groups);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) DependencyNode(org.sonatype.aether.graph.DependencyNode)

Example 20 with DependencyNode

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

the class JavaEffectiveScopeCalculator method transformGraph.

public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context) throws RepositoryException {
    List<?> sortedConflictIds = (List<?>) context.get(TransformationContextKeys.SORTED_CONFLICT_IDS);
    if (sortedConflictIds == null) {
        ConflictIdSorter sorter = new ConflictIdSorter();
        sorter.transformGraph(node, context);
        sortedConflictIds = (List<?>) context.get(TransformationContextKeys.SORTED_CONFLICT_IDS);
    }
    Map<?, ?> conflictIds = (Map<?, ?>) context.get(TransformationContextKeys.CONFLICT_IDS);
    if (conflictIds == null) {
        throw new RepositoryException("conflict groups have not been identified");
    }
    Boolean cyclicConflictIds = (Boolean) context.get(TransformationContextKeys.CYCLIC_CONFLICT_IDS);
    Map<Object, ConflictGroup> groups = new HashMap<Object, ConflictGroup>(256);
    buildConflictGroups(groups, node, null, conflictIds);
    String rootScope = "";
    if (node.getDependency() != null) {
        Object key = conflictIds.get(node);
        groups.get(key).scope = rootScope = node.getDependency().getScope();
    }
    for (DependencyNode child : node.getChildren()) {
        Object key = conflictIds.get(child);
        groups.get(key).scope = getInheritedScope(rootScope, child.getDependency().getScope());
    }
    Set<Object> prequisites = null;
    if (Boolean.TRUE.equals(cyclicConflictIds)) {
        prequisites = new HashSet<Object>(sortedConflictIds.size() * 2);
    }
    for (Object key : sortedConflictIds) {
        if (prequisites != null) {
            prequisites.add(key);
        }
        ConflictGroup group = groups.get(key);
        resolve(group, conflictIds, prequisites);
    }
    return node;
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) RepositoryException(org.sonatype.aether.RepositoryException) 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)

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