Search in sources :

Example 1 with DependencyCollectionException

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

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

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

the class DefaultDependencyCollector method collectDependencies.

public CollectResult collectDependencies(RepositorySystemSession session, CollectRequest request) throws DependencyCollectionException {
    session = optimizeSession(session);
    RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
    CollectResult result = new CollectResult(request);
    DependencySelector depSelector = session.getDependencySelector();
    DependencyManager depManager = session.getDependencyManager();
    DependencyTraverser depTraverser = session.getDependencyTraverser();
    Dependency root = request.getRoot();
    List<RemoteRepository> repositories = request.getRepositories();
    List<Dependency> dependencies = request.getDependencies();
    List<Dependency> managedDependencies = request.getManagedDependencies();
    GraphEdge edge = null;
    if (root != null) {
        VersionRangeResult rangeResult;
        try {
            VersionRangeRequest rangeRequest = new VersionRangeRequest(root.getArtifact(), request.getRepositories(), request.getRequestContext());
            rangeRequest.setTrace(trace);
            rangeResult = versionRangeResolver.resolveVersionRange(session, rangeRequest);
            if (rangeResult.getVersions().isEmpty()) {
                throw new VersionRangeResolutionException(rangeResult, "No versions available for " + root.getArtifact() + " within specified range");
            }
        } catch (VersionRangeResolutionException e) {
            result.addException(e);
            throw new DependencyCollectionException(result);
        }
        Version version = rangeResult.getVersions().get(rangeResult.getVersions().size() - 1);
        root = root.setArtifact(root.getArtifact().setVersion(version.toString()));
        ArtifactDescriptorResult descriptorResult;
        try {
            ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
            descriptorRequest.setArtifact(root.getArtifact());
            descriptorRequest.setRepositories(request.getRepositories());
            descriptorRequest.setRequestContext(request.getRequestContext());
            descriptorRequest.setTrace(trace);
            if (isLackingDescriptor(root.getArtifact())) {
                descriptorResult = new ArtifactDescriptorResult(descriptorRequest);
            } else {
                descriptorResult = descriptorReader.readArtifactDescriptor(session, descriptorRequest);
            }
        } catch (ArtifactDescriptorException e) {
            result.addException(e);
            throw new DependencyCollectionException(result);
        }
        root = root.setArtifact(descriptorResult.getArtifact());
        repositories = remoteRepositoryManager.aggregateRepositories(session, repositories, descriptorResult.getRepositories(), true);
        dependencies = mergeDeps(dependencies, descriptorResult.getDependencies());
        managedDependencies = mergeDeps(managedDependencies, descriptorResult.getManagedDependencies());
        GraphNode node = new GraphNode();
        node.setAliases(descriptorResult.getAliases());
        node.setRepositories(request.getRepositories());
        edge = new GraphEdge(node);
        edge.setDependency(root);
        edge.setRequestContext(request.getRequestContext());
        edge.setRelocations(descriptorResult.getRelocations());
        edge.setVersionConstraint(rangeResult.getVersionConstraint());
        edge.setVersion(version);
    } else {
        edge = new GraphEdge(new GraphNode());
    }
    result.setRoot(edge);
    boolean traverse = (root == null) || depTraverser.traverseDependency(root);
    if (traverse && !dependencies.isEmpty()) {
        DataPool pool = new DataPool(session);
        EdgeStack edges = new EdgeStack();
        edges.push(edge);
        DefaultDependencyCollectionContext context = new DefaultDependencyCollectionContext(session, root, managedDependencies);
        Args args = new Args(result, session, trace, pool, edges, context);
        process(args, dependencies, repositories, depSelector.deriveChildSelector(context), depManager.deriveChildManager(context), depTraverser.deriveChildTraverser(context));
    }
    DependencyGraphTransformer transformer = session.getDependencyGraphTransformer();
    try {
        DefaultDependencyGraphTransformationContext context = new DefaultDependencyGraphTransformationContext(session);
        result.setRoot(transformer.transformGraph(edge, context));
    } catch (RepositoryException e) {
        result.addException(e);
    }
    if (!result.getExceptions().isEmpty()) {
        throw new DependencyCollectionException(result);
    }
    return result;
}
Also used : DependencyManager(org.sonatype.aether.collection.DependencyManager) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) RequestTrace(org.sonatype.aether.RequestTrace) DefaultRequestTrace(org.sonatype.aether.util.DefaultRequestTrace) DependencyTraverser(org.sonatype.aether.collection.DependencyTraverser) Version(org.sonatype.aether.version.Version) DependencyGraphTransformer(org.sonatype.aether.collection.DependencyGraphTransformer) VersionRangeRequest(org.sonatype.aether.resolution.VersionRangeRequest) ArtifactDescriptorRequest(org.sonatype.aether.resolution.ArtifactDescriptorRequest) VersionRangeResolutionException(org.sonatype.aether.resolution.VersionRangeResolutionException) DependencyCollectionException(org.sonatype.aether.collection.DependencyCollectionException) VersionRangeResult(org.sonatype.aether.resolution.VersionRangeResult) CollectResult(org.sonatype.aether.collection.CollectResult) RepositoryException(org.sonatype.aether.RepositoryException) Dependency(org.sonatype.aether.graph.Dependency) DependencySelector(org.sonatype.aether.collection.DependencySelector) ArtifactDescriptorResult(org.sonatype.aether.resolution.ArtifactDescriptorResult) ArtifactDescriptorException(org.sonatype.aether.resolution.ArtifactDescriptorException)

Example 4 with DependencyCollectionException

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

the class DefaultRepositorySystem method resolveDependencies.

public DependencyResult resolveDependencies(RepositorySystemSession session, DependencyRequest request) throws DependencyResolutionException {
    validateSession(session);
    RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
    DependencyResult result = new DependencyResult(request);
    DependencyCollectionException dce = null;
    ArtifactResolutionException are = null;
    if (request.getRoot() != null) {
        result.setRoot(request.getRoot());
    } else if (request.getCollectRequest() != null) {
        CollectResult collectResult;
        try {
            request.getCollectRequest().setTrace(trace);
            collectResult = dependencyCollector.collectDependencies(session, request.getCollectRequest());
        } catch (DependencyCollectionException e) {
            dce = e;
            collectResult = e.getResult();
        }
        result.setRoot(collectResult.getRoot());
        result.setCollectExceptions(collectResult.getExceptions());
    } else {
        throw new IllegalArgumentException("dependency node or collect request missing");
    }
    ArtifactRequestBuilder builder = new ArtifactRequestBuilder(trace);
    DependencyFilter filter = request.getFilter();
    DependencyVisitor visitor = (filter != null) ? new FilteringDependencyVisitor(builder, filter) : builder;
    visitor = new TreeDependencyVisitor(visitor);
    result.getRoot().accept(visitor);
    List<ArtifactRequest> requests = builder.getRequests();
    List<ArtifactResult> results;
    try {
        results = artifactResolver.resolveArtifacts(session, requests);
    } catch (ArtifactResolutionException e) {
        are = e;
        results = e.getResults();
    }
    result.setArtifactResults(results);
    updateNodesWithResolvedArtifacts(results);
    if (dce != null) {
        throw new DependencyResolutionException(result, dce);
    } else if (are != null) {
        throw new DependencyResolutionException(result, are);
    }
    return result;
}
Also used : DependencyCollectionException(org.sonatype.aether.collection.DependencyCollectionException) FilteringDependencyVisitor(org.sonatype.aether.util.graph.FilteringDependencyVisitor) CollectResult(org.sonatype.aether.collection.CollectResult) DependencyResult(org.sonatype.aether.resolution.DependencyResult) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) RequestTrace(org.sonatype.aether.RequestTrace) DefaultRequestTrace(org.sonatype.aether.util.DefaultRequestTrace) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) DependencyVisitor(org.sonatype.aether.graph.DependencyVisitor) FilteringDependencyVisitor(org.sonatype.aether.util.graph.FilteringDependencyVisitor) TreeDependencyVisitor(org.sonatype.aether.util.graph.TreeDependencyVisitor) TreeDependencyVisitor(org.sonatype.aether.util.graph.TreeDependencyVisitor) DependencyResolutionException(org.sonatype.aether.resolution.DependencyResolutionException)

Example 5 with DependencyCollectionException

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

Aggregations

CollectResult (org.sonatype.aether.collection.CollectResult)6 DependencyCollectionException (org.sonatype.aether.collection.DependencyCollectionException)6 CollectRequest (org.sonatype.aether.collection.CollectRequest)4 Dependency (org.sonatype.aether.graph.Dependency)4 ArtifactDescriptorException (org.sonatype.aether.resolution.ArtifactDescriptorException)3 Test (org.junit.Test)2 RequestTrace (org.sonatype.aether.RequestTrace)2 DependencyGraphTransformer (org.sonatype.aether.collection.DependencyGraphTransformer)2 DependencyNode (org.sonatype.aether.graph.DependencyNode)2 DefaultRequestTrace (org.sonatype.aether.util.DefaultRequestTrace)2 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)1 RepositoryException (org.sonatype.aether.RepositoryException)1 RepositorySystem (org.sonatype.aether.RepositorySystem)1 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)1 DependencyManager (org.sonatype.aether.collection.DependencyManager)1 DependencySelector (org.sonatype.aether.collection.DependencySelector)1 DependencyTraverser (org.sonatype.aether.collection.DependencyTraverser)1 DependencyFilter (org.sonatype.aether.graph.DependencyFilter)1