Search in sources :

Example 16 with CollectRequest

use of org.sonatype.aether.collection.CollectRequest in project sonatype-aether by sonatype.

the class DefaultDependencyCollectorTest method testManagedVersionScope.

@Test
public void testManagedVersionScope() throws IOException, DependencyCollectionException {
    DependencyNode root = parser.parseLiteral("managed:aid:ext:ver");
    Dependency dependency = root.getDependency();
    CollectRequest request = new CollectRequest(dependency, Arrays.asList(repository));
    session.setDependencyManager(new ClassicDependencyManager());
    CollectResult result = collector.collectDependencies(session, request);
    assertEquals(0, result.getExceptions().size());
    DependencyNode newRoot = result.getRoot();
    assertEquals(dependency, dep(newRoot));
    assertEquals(dependency.getArtifact(), dep(newRoot).getArtifact());
    assertEquals(1, newRoot.getChildren().size());
    DependencyNode expect = parser.parseLiteral("gid:aid:ext:ver:compile");
    assertEquals(dep(expect), dep(newRoot, 0));
    assertEquals(1, path(newRoot, 0).getChildren().size());
    expect = parser.parseLiteral("gid:aid2:ext:managedVersion:managedScope");
    assertEquals(dep(expect), dep(newRoot, 0, 0));
}
Also used : ClassicDependencyManager(org.sonatype.aether.util.graph.manager.ClassicDependencyManager) 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 17 with CollectRequest

use of org.sonatype.aether.collection.CollectRequest in project sonatype-aether by sonatype.

the class DefaultDependencyCollectorTest method testArtifactDescriptorResolutionNotRestrictedToRepoHostingSelectedVersion.

@Test
public void testArtifactDescriptorResolutionNotRestrictedToRepoHostingSelectedVersion() throws Exception {
    RemoteRepository repo2 = new RemoteRepository("test", "default", "file:///");
    final List<RemoteRepository> repos = new ArrayList<RemoteRepository>();
    collector.setArtifactDescriptorReader(new ArtifactDescriptorReader() {

        public ArtifactDescriptorResult readArtifactDescriptor(RepositorySystemSession session, ArtifactDescriptorRequest request) throws ArtifactDescriptorException {
            repos.addAll(request.getRepositories());
            return new ArtifactDescriptorResult(request);
        }
    });
    DependencyNode root = parser.parseLiteral("verrange:parent:jar:[1,):compile");
    List<Dependency> dependencies = Arrays.asList(root.getDependency());
    CollectRequest request = new CollectRequest(dependencies, null, Arrays.asList(repository, repo2));
    CollectResult result = collector.collectDependencies(session, request);
    assertEquals(0, result.getExceptions().size());
    assertEquals(2, repos.size());
    assertEquals("id", repos.get(0).getId());
    assertEquals("test", repos.get(1).getId());
}
Also used : RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) CollectResult(org.sonatype.aether.collection.CollectResult) ArrayList(java.util.ArrayList) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) DependencyNode(org.sonatype.aether.graph.DependencyNode) ArtifactDescriptorException(org.sonatype.aether.resolution.ArtifactDescriptorException) ArtifactDescriptorResult(org.sonatype.aether.resolution.ArtifactDescriptorResult) ArtifactDescriptorRequest(org.sonatype.aether.resolution.ArtifactDescriptorRequest) ArtifactDescriptorReader(org.sonatype.aether.impl.ArtifactDescriptorReader) Test(org.junit.Test)

Example 18 with CollectRequest

use of org.sonatype.aether.collection.CollectRequest 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 19 with CollectRequest

use of org.sonatype.aether.collection.CollectRequest 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 20 with CollectRequest

use of org.sonatype.aether.collection.CollectRequest 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)

Aggregations

CollectRequest (org.sonatype.aether.collection.CollectRequest)21 CollectResult (org.sonatype.aether.collection.CollectResult)14 Dependency (org.sonatype.aether.graph.Dependency)14 DependencyNode (org.sonatype.aether.graph.DependencyNode)12 Test (org.junit.Test)11 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)10 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)8 Artifact (org.sonatype.aether.artifact.Artifact)7 DependencyRequest (org.sonatype.aether.resolution.DependencyRequest)7 DependencyFilter (org.sonatype.aether.graph.DependencyFilter)6 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)5 PatternExclusionsDependencyFilter (org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter)4 RepositorySystem (org.sonatype.aether.RepositorySystem)3 DependencyCollectionException (org.sonatype.aether.collection.DependencyCollectionException)3 ArtifactDescriptorException (org.sonatype.aether.resolution.ArtifactDescriptorException)3 ConsoleDependencyGraphDumper (demo.util.ConsoleDependencyGraphDumper)2 ArrayList (java.util.ArrayList)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)1 Repository (org.apache.zeppelin.dep.Repository)1