Search in sources :

Example 1 with Dependency

use of org.sonatype.aether.graph.Dependency in project zeppelin by apache.

the class SparkDependencyResolver method getArtifactsWithDep.

/**
   * @param dependency
   * @param excludes list of pattern can either be of the form groupId:artifactId
   * @return
   * @throws Exception
   */
@Override
public List<ArtifactResult> getArtifactsWithDep(String dependency, Collection<String> excludes) throws Exception {
    Artifact artifact = new DefaultArtifact(inferScalaVersion(dependency));
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(inferScalaVersion(excludes));
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
    synchronized (repos) {
        for (RemoteRepository repo : repos) {
            collectRequest.addRepository(repo);
        }
    }
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter));
    return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
}
Also used : DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) 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) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter)

Example 2 with Dependency

use of org.sonatype.aether.graph.Dependency 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 3 with Dependency

use of org.sonatype.aether.graph.Dependency 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 4 with Dependency

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

the class DefaultDependencyCollectorTest method testDuplicates.

@Test
public void testDuplicates() throws IOException, DependencyCollectionException {
    DependencyNode root = parser.parseLiteral("duplicate:transitive:ext:dependency");
    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(2, newRoot.getChildren().size());
    DependencyNode expect = parser.parseLiteral("gid:aid:ext:ver:compile");
    Dependency dep = expect.getDependency();
    assertEquals(dep, dep(newRoot, 0));
    expect = parser.parseLiteral("gid:aid2:ext:ver:compile");
    dep = expect.getDependency();
    assertEquals(dep, dep(newRoot, 1));
    assertEquals(dep, dep(newRoot, 0, 0));
    assertEquals(dep(newRoot, 1), dep(newRoot, 0, 0));
}
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 5 with Dependency

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

the class DefaultDependencyCollectorTest method testEqualSubtree.

@Test
public void testEqualSubtree() throws IOException, DependencyCollectionException {
    DependencyNode root = parser.parse("expectedSubtreeComparisonResult.txt");
    Dependency dependency = root.getDependency();
    CollectRequest request = new CollectRequest(dependency, 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) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) Test(org.junit.Test)

Aggregations

Dependency (org.sonatype.aether.graph.Dependency)45 Artifact (org.sonatype.aether.artifact.Artifact)21 CollectRequest (org.sonatype.aether.collection.CollectRequest)15 DependencyNode (org.sonatype.aether.graph.DependencyNode)14 Test (org.junit.Test)13 CollectResult (org.sonatype.aether.collection.CollectResult)12 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)12 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)10 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)8 Exclusion (org.sonatype.aether.graph.Exclusion)7 ArrayList (java.util.ArrayList)5 RepositorySystem (org.sonatype.aether.RepositorySystem)5 DependencyCollectionException (org.sonatype.aether.collection.DependencyCollectionException)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 IOException (java.io.IOException)3 RepositoryException (org.sonatype.aether.RepositoryException)3