Search in sources :

Example 31 with Dependency

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

the class ScopeDependencyFilter method accept.

public boolean accept(DependencyNode node, List<DependencyNode> parents) {
    Dependency dependency = node.getDependency();
    if (dependency == null) {
        return true;
    }
    String scope = node.getDependency().getScope();
    return (included.isEmpty() || included.contains(scope)) && (excluded.isEmpty() || !excluded.contains(scope));
}
Also used : Dependency(org.sonatype.aether.graph.Dependency)

Example 32 with Dependency

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

the class ClassicDependencyManager method deriveChildManager.

public DependencyManager deriveChildManager(DependencyCollectionContext context) {
    if (depth >= 2) {
        return this;
    } else if (depth == 1) {
        return new ClassicDependencyManager(depth + 1, managedVersions, managedScopes, managedLocalPaths, managedExclusions);
    }
    Map<Object, String> managedVersions = this.managedVersions;
    Map<Object, String> managedScopes = this.managedScopes;
    Map<Object, String> managedLocalPaths = this.managedLocalPaths;
    Map<Object, Collection<Exclusion>> managedExclusions = this.managedExclusions;
    for (Dependency managedDependency : context.getManagedDependencies()) {
        Artifact artifact = managedDependency.getArtifact();
        Object key = getKey(artifact);
        String version = artifact.getVersion();
        if (version.length() > 0 && !managedVersions.containsKey(key)) {
            if (managedVersions == this.managedVersions) {
                managedVersions = new HashMap<Object, String>(this.managedVersions);
            }
            managedVersions.put(key, version);
        }
        String scope = managedDependency.getScope();
        if (scope.length() > 0 && !managedScopes.containsKey(key)) {
            if (managedScopes == this.managedScopes) {
                managedScopes = new HashMap<Object, String>(this.managedScopes);
            }
            managedScopes.put(key, scope);
        }
        String localPath = managedDependency.getArtifact().getProperty(ArtifactProperties.LOCAL_PATH, null);
        if (localPath != null && !managedLocalPaths.containsKey(key)) {
            if (managedLocalPaths == this.managedLocalPaths) {
                managedLocalPaths = new HashMap<Object, String>(this.managedLocalPaths);
            }
            managedLocalPaths.put(key, localPath);
        }
        Collection<Exclusion> exclusions = managedDependency.getExclusions();
        if (!exclusions.isEmpty()) {
            if (managedExclusions == this.managedExclusions) {
                managedExclusions = new HashMap<Object, Collection<Exclusion>>(this.managedExclusions);
            }
            Collection<Exclusion> managed = managedExclusions.get(key);
            if (managed == null) {
                managed = new LinkedHashSet<Exclusion>();
                managedExclusions.put(key, managed);
            }
            managed.addAll(exclusions);
        }
    }
    return new ClassicDependencyManager(depth + 1, managedVersions, managedScopes, managedLocalPaths, managedExclusions);
}
Also used : Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact) Exclusion(org.sonatype.aether.graph.Exclusion) Collection(java.util.Collection)

Example 33 with Dependency

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

the class ExclusionDependencySelector method deriveChildSelector.

public DependencySelector deriveChildSelector(DependencyCollectionContext context) {
    Dependency dependency = context.getDependency();
    Collection<Exclusion> exclusions = (dependency != null) ? dependency.getExclusions() : null;
    if (exclusions == null || exclusions.isEmpty()) {
        return this;
    }
    Set<Exclusion> merged = new LinkedHashSet<Exclusion>();
    merged.addAll(this.exclusions);
    merged.addAll(exclusions);
    return new ExclusionDependencySelector(merged);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Exclusion(org.sonatype.aether.graph.Exclusion) Dependency(org.sonatype.aether.graph.Dependency)

Example 34 with Dependency

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

the class DependencyGraphDumper method dump.

private static void dump(Context context, DependencyNode node, int depth, boolean last) {
    Line line = context.nodes.get(node);
    if (line != null) {
        if (line.id <= 0) {
            line.id = ++context.ids;
        }
        context.lines.add(new Line(null, line.id, depth, last));
        return;
    }
    Dependency dependency = node.getDependency();
    if (dependency == null) {
        line = new Line(null, 0, depth, last);
    } else {
        line = new Line(dependency, 0, depth, last);
    }
    context.lines.add(line);
    context.nodes.put(node, line);
    depth++;
    for (Iterator<DependencyNode> it = node.getChildren().iterator(); it.hasNext(); ) {
        DependencyNode child = it.next();
        dump(context, child, depth, !it.hasNext());
    }
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Dependency(org.sonatype.aether.graph.Dependency)

Example 35 with Dependency

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

the class DependencyGraphParserTest method testOptionalScope.

@Test
public void testOptionalScope() throws IOException {
    String def = "gid:aid:jar:1";
    DependencyNode node = parser.parseLiteral(def);
    assertNotNull(node);
    assertEquals(0, node.getChildren().size());
    Dependency dependency = node.getDependency();
    assertNotNull(dependency);
    assertEquals("", dependency.getScope());
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Dependency(org.sonatype.aether.graph.Dependency) Test(org.junit.Test)

Aggregations

Dependency (org.sonatype.aether.graph.Dependency)45 Artifact (org.sonatype.aether.artifact.Artifact)22 Test (org.junit.Test)14 CollectRequest (org.sonatype.aether.collection.CollectRequest)14 DependencyNode (org.sonatype.aether.graph.DependencyNode)14 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)12 CollectResult (org.sonatype.aether.collection.CollectResult)11 Exclusion (org.sonatype.aether.graph.Exclusion)9 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)9 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)7 ArrayList (java.util.ArrayList)5 RepositorySystem (org.sonatype.aether.RepositorySystem)4 ArtifactDescriptorException (org.sonatype.aether.resolution.ArtifactDescriptorException)4 ArtifactDescriptorRequest (org.sonatype.aether.resolution.ArtifactDescriptorRequest)4 ArtifactDescriptorResult (org.sonatype.aether.resolution.ArtifactDescriptorResult)4 DependencyRequest (org.sonatype.aether.resolution.DependencyRequest)4 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)4 DependencyCollectionException (org.sonatype.aether.collection.DependencyCollectionException)3 ConsoleDependencyGraphDumper (demo.util.ConsoleDependencyGraphDumper)2 HashMap (java.util.HashMap)2