Search in sources :

Example 16 with Dependency

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

the class ConflictMarker method getKeys.

private Set<Object> getKeys(DependencyNode node) {
    Set<Object> keys;
    Dependency dependency = node.getDependency();
    if (dependency == null) {
        keys = Collections.emptySet();
    } else {
        Object key = toKey(dependency.getArtifact());
        if (node.getRelocations().isEmpty() && node.getAliases().isEmpty()) {
            keys = Collections.singleton(key);
        } else {
            keys = new HashSet<Object>();
            keys.add(key);
            for (Artifact relocation : node.getRelocations()) {
                key = toKey(relocation);
                keys.add(key);
            }
            for (Artifact alias : node.getAliases()) {
                key = toKey(alias);
                keys.add(key);
            }
        }
    }
    return keys;
}
Also used : Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact)

Example 17 with Dependency

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

the class SimpleConflictMarker method mark.

private void mark(DependencyNode node, Map<DependencyNode, Object> conflictIds) {
    Dependency dependency = node.getDependency();
    if (dependency != null) {
        Artifact artifact = dependency.getArtifact();
        String key = String.format("%s:%s:%s:%s", artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension());
        if (conflictIds.put(node, key) != null) {
            return;
        }
    }
    for (DependencyNode child : node.getChildren()) {
        mark(child, conflictIds);
    }
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact)

Example 18 with Dependency

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

the class EdgeStack method find.

public GraphEdge find(Artifact artifact) {
    for (int i = size - 1; i >= 0; i--) {
        GraphEdge edge = edges[i];
        Dependency dependency = edge.getDependency();
        if (dependency == null) {
            break;
        }
        Artifact a = dependency.getArtifact();
        if (!a.getArtifactId().equals(artifact.getArtifactId())) {
            continue;
        }
        if (!a.getGroupId().equals(artifact.getGroupId())) {
            continue;
        }
        if (!a.getBaseVersion().equals(artifact.getBaseVersion())) {
            continue;
        }
        if (!a.getExtension().equals(artifact.getExtension())) {
            continue;
        }
        if (!a.getClassifier().equals(artifact.getClassifier())) {
            continue;
        }
        return edge;
    }
    return null;
}
Also used : Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact)

Example 19 with Dependency

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

the class GetDependencyTreeWithMirror method main.

public static void main(String[] args) throws Exception {
    System.out.println("------------------------------------------------------------");
    System.out.println(GetDependencyTreeWithMirror.class.getSimpleName());
    RepositorySystem system = Booter.newRepositorySystem();
    RepositorySystemSession session = Booter.newRepositorySystemSession(system);
    Artifact artifact = new DefaultArtifact("org.apache.maven:maven-aether-provider:3.0.2");
    RemoteRepository central = new RemoteRepository("central", "default", "http://repo1.maven.org/maven2/");
    DefaultMirrorSelector dms = (DefaultMirrorSelector) session.getMirrorSelector();
    dms.add("mirror", "http://repo1.maven.org/maven2/", "default", true, "central", "*");
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, ""));
    collectRequest.addRepository(central);
    CollectResult collectResult = system.collectDependencies(session, collectRequest);
    collectResult.getRoot().accept(new ConsoleDependencyGraphDumper());
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) CollectResult(org.sonatype.aether.collection.CollectResult) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) DefaultMirrorSelector(org.sonatype.aether.util.repository.DefaultMirrorSelector) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) ConsoleDependencyGraphDumper(demo.util.ConsoleDependencyGraphDumper) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 20 with Dependency

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

the class GetDirectDependencies method main.

public static void main(String[] args) throws Exception {
    System.out.println("------------------------------------------------------------");
    System.out.println(GetDirectDependencies.class.getSimpleName());
    RepositorySystem system = Booter.newRepositorySystem();
    RepositorySystemSession session = Booter.newRepositorySystemSession(system);
    Artifact artifact = new DefaultArtifact("org.sonatype.aether:aether-impl:1.9");
    RemoteRepository repo = Booter.newCentralRepository();
    ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
    descriptorRequest.setArtifact(artifact);
    descriptorRequest.addRepository(repo);
    ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor(session, descriptorRequest);
    for (Dependency dependency : descriptorResult.getDependencies()) {
        System.out.println(dependency);
    }
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) ArtifactDescriptorResult(org.sonatype.aether.resolution.ArtifactDescriptorResult) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) ArtifactDescriptorRequest(org.sonatype.aether.resolution.ArtifactDescriptorRequest)

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