Search in sources :

Example 26 with Dependency

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

the class DefaultDependencyCollectorTest method testSimpleCollection.

@Test
public void testSimpleCollection() throws IOException, DependencyCollectionException {
    DependencyNode root = parser.parseLiteral("gid:aid:ext:ver");
    Dependency dependency = root.getDependency();
    CollectRequest request = new CollectRequest(dependency, Arrays.asList(repository));
    CollectResult result = collector.collectDependencies(session, request);
    assertEquals(0, result.getExceptions().size());
    DependencyNode newRoot = result.getRoot();
    Dependency newDependency = newRoot.getDependency();
    assertEquals(dependency, newDependency);
    assertEquals(dependency.getArtifact(), newDependency.getArtifact());
    assertEquals(1, newRoot.getChildren().size());
    DependencyNode expect = parser.parseLiteral("gid:aid2:ext:ver:compile");
    assertEquals(expect.getDependency(), newRoot.getChildren().get(0).getDependency());
}
Also used : CollectResult(org.sonatype.aether.collection.CollectResult) DependencyNode(org.sonatype.aether.graph.DependencyNode) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) Test(org.junit.Test)

Example 27 with Dependency

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

the class DefaultDependencyCollectorTest method testCollectMultipleDependencies.

@Test
public void testCollectMultipleDependencies() throws IOException, DependencyCollectionException {
    DependencyNode root1 = parser.parseLiteral("gid:aid:ext:ver:compile");
    DependencyNode root2 = parser.parseLiteral("gid:aid2:ext:ver:compile");
    List<Dependency> dependencies = Arrays.asList(root1.getDependency(), root2.getDependency());
    CollectRequest request = new CollectRequest(dependencies, null, Arrays.asList(repository));
    CollectResult result = collector.collectDependencies(session, request);
    assertEquals(0, result.getExceptions().size());
    assertEquals(2, result.getRoot().getChildren().size());
    assertEquals(root1.getDependency(), dep(result.getRoot(), 0));
    assertEquals(1, path(result.getRoot(), 0).getChildren().size());
    assertEquals(root2.getDependency(), dep(result.getRoot(), 0, 0));
    assertEquals(0, path(result.getRoot(), 1).getChildren().size());
    assertEquals(root2.getDependency(), dep(result.getRoot(), 1));
}
Also used : CollectResult(org.sonatype.aether.collection.CollectResult) DependencyNode(org.sonatype.aether.graph.DependencyNode) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) Test(org.junit.Test)

Example 28 with Dependency

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

the class ResolveTransitiveDependencies method main.

public static void main(String[] args) throws Exception {
    System.out.println("------------------------------------------------------------");
    System.out.println(ResolveTransitiveDependencies.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();
    DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
    collectRequest.addRepository(repo);
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);
    List<ArtifactResult> artifactResults = system.resolveDependencies(session, dependencyRequest).getArtifactResults();
    for (ArtifactResult artifactResult : artifactResults) {
        System.out.println(artifactResult.getArtifact() + " resolved to " + artifactResult.getArtifact().getFile());
    }
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult)

Example 29 with Dependency

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

the class Aether method resolve.

public AetherResult resolve(String groupId, String artifactId, String version) throws DependencyResolutionException {
    RepositorySystemSession session = newSession();
    Dependency dependency = new Dependency(new DefaultArtifact(groupId, artifactId, "", "jar", version), "runtime");
    RemoteRepository central = new RemoteRepository("central", "default", remoteRepository);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(dependency);
    collectRequest.addRepository(central);
    DependencyRequest dependencyRequest = new DependencyRequest();
    dependencyRequest.setCollectRequest(collectRequest);
    DependencyNode rootNode = repositorySystem.resolveDependencies(session, dependencyRequest).getRoot();
    StringBuilder dump = new StringBuilder();
    displayTree(rootNode, dump);
    PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
    rootNode.accept(nlg);
    return new AetherResult(rootNode, nlg.getFiles(), nlg.getClassPath());
}
Also used : MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) DependencyNode(org.sonatype.aether.graph.DependencyNode) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) PreorderNodeListGenerator(org.sonatype.aether.util.graph.PreorderNodeListGenerator) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 30 with Dependency

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

the class ExclusionsDependencyFilter method accept.

public boolean accept(DependencyNode node, List<DependencyNode> parents) {
    Dependency dependency = node.getDependency();
    if (dependency == null) {
        return true;
    }
    String id = dependency.getArtifact().getArtifactId();
    if (excludes.contains(id)) {
        return false;
    }
    id = dependency.getArtifact().getGroupId() + ':' + id;
    if (excludes.contains(id)) {
        return false;
    }
    return true;
}
Also used : Dependency(org.sonatype.aether.graph.Dependency)

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