Search in sources :

Example 1 with CollectResult

use of org.sonatype.aether.collection.CollectResult in project karaf by apache.

the class Dependency30Helper method getDependencyTree.

private DependencyNode getDependencyTree(Artifact artifact) throws MojoExecutionException {
    try {
        CollectRequest collectRequest = new CollectRequest(new Dependency(artifact, "compile"), null, projectRepositories);
        DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);
        session.setDependencySelector(new AndDependencySelector(new OptionalDependencySelector(), new ScopeDependencySelector1(), new ExclusionDependencySelector()));
        DependencyGraphTransformer transformer = new ChainedDependencyGraphTransformer(new ConflictMarker(), new JavaEffectiveScopeCalculator(), new JavaDependencyContextRefiner());
        session.setDependencyGraphTransformer(transformer);
        CollectResult result = repositorySystem.collectDependencies(session, collectRequest);
        return result.getRoot();
    } catch (DependencyCollectionException e) {
        throw new MojoExecutionException("Cannot build project dependency tree", e);
    }
}
Also used : JavaDependencyContextRefiner(org.sonatype.aether.util.graph.transformer.JavaDependencyContextRefiner) DependencyCollectionException(org.sonatype.aether.collection.DependencyCollectionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) CollectResult(org.sonatype.aether.collection.CollectResult) AndDependencySelector(org.sonatype.aether.util.graph.selector.AndDependencySelector) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) ChainedDependencyGraphTransformer(org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer) OptionalDependencySelector(org.sonatype.aether.util.graph.selector.OptionalDependencySelector) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) JavaEffectiveScopeCalculator(org.sonatype.aether.util.graph.transformer.JavaEffectiveScopeCalculator) DependencyGraphTransformer(org.sonatype.aether.collection.DependencyGraphTransformer) ChainedDependencyGraphTransformer(org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer) ConflictMarker(org.sonatype.aether.util.graph.transformer.ConflictMarker) ExclusionDependencySelector(org.sonatype.aether.util.graph.selector.ExclusionDependencySelector)

Example 2 with CollectResult

use of org.sonatype.aether.collection.CollectResult in project archiva by apache.

the class Maven3DependencyTreeBuilder method resolve.

private void resolve(ResolveRequest resolveRequest) {
    RepositorySystem system = newRepositorySystem();
    RepositorySystemSession session = newRepositorySystemSession(system, resolveRequest.localRepoDir);
    org.sonatype.aether.artifact.Artifact artifact = new DefaultArtifact(resolveRequest.groupId + ":" + resolveRequest.artifactId + ":" + resolveRequest.version);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, ""));
    // add remote repositories
    for (RemoteRepository remoteRepository : resolveRequest.remoteRepositories) {
        collectRequest.addRepository(new org.sonatype.aether.repository.RemoteRepository(remoteRepository.getId(), "default", remoteRepository.getUrl()));
    }
    collectRequest.setRequestContext("project");
    try {
        CollectResult collectResult = system.collectDependencies(session, collectRequest);
        collectResult.getRoot().accept(resolveRequest.dependencyVisitor);
        log.debug("test");
    } catch (DependencyCollectionException e) {
        log.error(e.getMessage(), e);
    }
}
Also used : MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) DependencyCollectionException(org.sonatype.aether.collection.DependencyCollectionException) CollectResult(org.sonatype.aether.collection.CollectResult) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) RepositorySystem(org.sonatype.aether.RepositorySystem) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 3 with CollectResult

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

the class DefaultDependencyCollectorTest method testCyclicDependencies.

@Test
public void testCyclicDependencies() throws Exception {
    DependencyNode root = parser.parse("cycle.txt");
    CollectRequest request = new CollectRequest(root.getDependency(), Arrays.asList(repository));
    CollectResult result = collector.collectDependencies(session, request);
    assertEqualSubtree(root, result.getRoot());
}
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 4 with CollectResult

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

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

the class DefaultDependencyCollectorTest method testDependencyManagement.

@Test
public void testDependencyManagement() throws IOException, DependencyCollectionException {
    collector.setArtifactDescriptorReader(new IniArtifactDescriptorReader("artifact-descriptions/managed/"));
    DependencyNode root = parser.parse("expectedSubtreeComparisonResult.txt");
    TestDependencyManager depMgmt = new TestDependencyManager();
    depMgmt.addManagedDependency(dep(root, 0), "managed", null, null);
    depMgmt.addManagedDependency(dep(root, 0, 1), "managed", "managed", null);
    depMgmt.addManagedDependency(dep(root, 1), null, null, "managed");
    session.setDependencyManager(depMgmt);
    // collect result will differ from expectedSubtreeComparisonResult.txt
    // set localPath -> no dependency traversal
    CollectRequest request = new CollectRequest(dep(root), Arrays.asList(repository));
    CollectResult result = collector.collectDependencies(session, request);
    DependencyNode node = result.getRoot();
    assertEquals("managed", dep(node, 0, 1).getArtifact().getVersion());
    assertEquals("managed", dep(node, 0, 1).getScope());
    assertEquals("managed", dep(node, 1).getArtifact().getProperty(ArtifactProperties.LOCAL_PATH, null));
    assertEquals("managed", dep(node, 0, 0).getArtifact().getProperty(ArtifactProperties.LOCAL_PATH, null));
}
Also used : CollectResult(org.sonatype.aether.collection.CollectResult) DependencyNode(org.sonatype.aether.graph.DependencyNode) CollectRequest(org.sonatype.aether.collection.CollectRequest) Test(org.junit.Test)

Aggregations

CollectResult (org.sonatype.aether.collection.CollectResult)18 CollectRequest (org.sonatype.aether.collection.CollectRequest)15 Dependency (org.sonatype.aether.graph.Dependency)12 Test (org.junit.Test)11 DependencyNode (org.sonatype.aether.graph.DependencyNode)11 DependencyCollectionException (org.sonatype.aether.collection.DependencyCollectionException)6 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)4 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)4 ArtifactDescriptorException (org.sonatype.aether.resolution.ArtifactDescriptorException)4 RepositorySystem (org.sonatype.aether.RepositorySystem)3 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)3 ConsoleDependencyGraphDumper (demo.util.ConsoleDependencyGraphDumper)2 RequestTrace (org.sonatype.aether.RequestTrace)2 Artifact (org.sonatype.aether.artifact.Artifact)2 DependencyGraphTransformer (org.sonatype.aether.collection.DependencyGraphTransformer)2 ArtifactDescriptorRequest (org.sonatype.aether.resolution.ArtifactDescriptorRequest)2 ArtifactDescriptorResult (org.sonatype.aether.resolution.ArtifactDescriptorResult)2 DefaultRequestTrace (org.sonatype.aether.util.DefaultRequestTrace)2 ArrayList (java.util.ArrayList)1 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)1