Search in sources :

Example 11 with CollectRequest

use of org.sonatype.aether.collection.CollectRequest in project storm by apache.

the class DependencyResolver method resolve.

public List<ArtifactResult> resolve(List<Dependency> dependencies) throws MalformedURLException, DependencyResolutionException, ArtifactResolutionException {
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE, JavaScopes.RUNTIME);
    if (dependencies.size() == 0) {
        return Collections.EMPTY_LIST;
    }
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(dependencies.get(0));
    for (int idx = 1; idx < dependencies.size(); idx++) {
        collectRequest.addDependency(dependencies.get(idx));
    }
    for (RemoteRepository repository : remoteRepositories) {
        collectRequest.addRepository(repository);
    }
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter);
    return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
}
Also used : DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) CollectRequest(org.sonatype.aether.collection.CollectRequest)

Example 12 with CollectRequest

use of org.sonatype.aether.collection.CollectRequest in project zeppelin by apache.

the class SparkDependencyContext method fetchArtifactWithDep.

private List<ArtifactResult> fetchArtifactWithDep(Dependency dep) throws DependencyResolutionException, ArtifactResolutionException {
    Artifact artifact = new DefaultArtifact(SparkDependencyResolver.inferScalaVersion(dep.getGroupArtifactVersion()));
    DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(SparkDependencyResolver.inferScalaVersion(dep.getExclusions()));
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new org.sonatype.aether.graph.Dependency(artifact, JavaScopes.COMPILE));
    collectRequest.addRepository(mavenCentral);
    collectRequest.addRepository(mavenLocal);
    for (RemoteRepository repo : additionalRepos) {
        collectRequest.addRepository(repo);
    }
    for (Repository repo : repositories) {
        RemoteRepository rr = new RemoteRepository(repo.getId(), "default", repo.getUrl());
        rr.setPolicy(repo.isSnapshot(), null);
        Authentication auth = repo.getAuthentication();
        if (auth != null) {
            rr.setAuthentication(auth);
        }
        collectRequest.addRepository(rr);
    }
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(exclusionFilter, classpathFlter));
    return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
}
Also used : Repository(org.apache.zeppelin.dep.Repository) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) Authentication(org.sonatype.aether.repository.Authentication) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) 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 13 with CollectRequest

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

the class GetDependencyTree method main.

public static void main(String[] args) throws Exception {
    System.out.println("------------------------------------------------------------");
    System.out.println(GetDependencyTree.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 repo = Booter.newCentralRepository();
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, ""));
    collectRequest.addRepository(repo);
    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) 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 14 with CollectRequest

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

the class DefaultDependencyCollectorTest method testMissingDependencyDescription.

@Test
public void testMissingDependencyDescription() throws IOException {
    DependencyNode root = parser.parseLiteral("missing:description:ext:ver");
    CollectRequest request = new CollectRequest(root.getDependency(), Arrays.asList(repository));
    try {
        collector.collectDependencies(session, request);
        fail("expected exception");
    } catch (DependencyCollectionException e) {
        CollectResult result = e.getResult();
        assertSame(request, result.getRequest());
        assertNotNull(result.getExceptions());
        assertEquals(1, result.getExceptions().size());
        assertTrue(result.getExceptions().get(0) instanceof ArtifactDescriptorException);
        assertEquals(request.getRoot(), result.getRoot().getDependency());
    }
}
Also used : DependencyCollectionException(org.sonatype.aether.collection.DependencyCollectionException) CollectResult(org.sonatype.aether.collection.CollectResult) DependencyNode(org.sonatype.aether.graph.DependencyNode) CollectRequest(org.sonatype.aether.collection.CollectRequest) ArtifactDescriptorException(org.sonatype.aether.resolution.ArtifactDescriptorException) Test(org.junit.Test)

Example 15 with CollectRequest

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

the class DefaultDependencyCollectorTest method testPartialResultOnError.

@Test
public void testPartialResultOnError() throws IOException {
    DependencyNode root = parser.parse("expectedPartialSubtreeOnError.txt");
    Dependency dependency = root.getDependency();
    CollectRequest request = new CollectRequest(dependency, Arrays.asList(repository));
    CollectResult result;
    try {
        result = collector.collectDependencies(session, request);
        fail("expected exception ");
    } catch (DependencyCollectionException e) {
        result = e.getResult();
        assertSame(request, result.getRequest());
        assertNotNull(result.getExceptions());
        assertEquals(1, result.getExceptions().size());
        assertTrue(result.getExceptions().get(0) instanceof ArtifactDescriptorException);
        assertEqualSubtree(root, result.getRoot());
    }
}
Also used : DependencyCollectionException(org.sonatype.aether.collection.DependencyCollectionException) CollectResult(org.sonatype.aether.collection.CollectResult) DependencyNode(org.sonatype.aether.graph.DependencyNode) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) ArtifactDescriptorException(org.sonatype.aether.resolution.ArtifactDescriptorException) Test(org.junit.Test)

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