Search in sources :

Example 1 with DependencyVisitor

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

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

the class DefaultRepositorySystem method resolveDependencies.

public List<ArtifactResult> resolveDependencies(RepositorySystemSession session, DependencyNode node, DependencyFilter filter) throws ArtifactResolutionException {
    validateSession(session);
    RequestTrace trace = DefaultRequestTrace.newChild(null, node);
    ArtifactRequestBuilder builder = new ArtifactRequestBuilder(trace);
    DependencyVisitor visitor = (filter != null) ? new FilteringDependencyVisitor(builder, filter) : builder;
    visitor = new TreeDependencyVisitor(visitor);
    node.accept(visitor);
    List<ArtifactRequest> requests = builder.getRequests();
    try {
        List<ArtifactResult> results = resolveArtifacts(session, requests);
        updateNodesWithResolvedArtifacts(results);
        return results;
    } catch (ArtifactResolutionException e) {
        updateNodesWithResolvedArtifacts(e.getResults());
        throw e;
    }
}
Also used : ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) FilteringDependencyVisitor(org.sonatype.aether.util.graph.FilteringDependencyVisitor) 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) RequestTrace(org.sonatype.aether.RequestTrace) DefaultRequestTrace(org.sonatype.aether.util.DefaultRequestTrace) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult)

Aggregations

RequestTrace (org.sonatype.aether.RequestTrace)2 DependencyVisitor (org.sonatype.aether.graph.DependencyVisitor)2 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)2 ArtifactResolutionException (org.sonatype.aether.resolution.ArtifactResolutionException)2 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)2 DefaultRequestTrace (org.sonatype.aether.util.DefaultRequestTrace)2 FilteringDependencyVisitor (org.sonatype.aether.util.graph.FilteringDependencyVisitor)2 TreeDependencyVisitor (org.sonatype.aether.util.graph.TreeDependencyVisitor)2 CollectResult (org.sonatype.aether.collection.CollectResult)1 DependencyCollectionException (org.sonatype.aether.collection.DependencyCollectionException)1 DependencyFilter (org.sonatype.aether.graph.DependencyFilter)1 DependencyResolutionException (org.sonatype.aether.resolution.DependencyResolutionException)1 DependencyResult (org.sonatype.aether.resolution.DependencyResult)1