Search in sources :

Example 6 with CollectRequest

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

Example 7 with CollectRequest

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

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

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

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

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