Search in sources :

Example 6 with ArtifactResolutionException

use of org.sonatype.aether.resolution.ArtifactResolutionException 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 7 with ArtifactResolutionException

use of org.sonatype.aether.resolution.ArtifactResolutionException 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)

Example 8 with ArtifactResolutionException

use of org.sonatype.aether.resolution.ArtifactResolutionException in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testRepositoryEventsUnsuccessfulRemote.

@Test
public void testRepositoryEventsUnsuccessfulRemote() throws IOException, ArtifactResolutionException {
    RecordingRepositoryConnector connector = new RecordingRepositoryConnector() {

        @Override
        public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
            super.get(artifactDownloads, metadataDownloads);
            ArtifactDownload download = artifactDownloads.iterator().next();
            ArtifactTransferException exception = new ArtifactNotFoundException(download.getArtifact(), null, "not found");
            download.setException(exception);
        }
    };
    remoteRepositoryManager.setConnector(connector);
    RecordingRepositoryListener listener = new RecordingRepositoryListener();
    session.setRepositoryListener(listener);
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    request.addRepository(new RemoteRepository("id", "default", "file:///"));
    try {
        resolver.resolveArtifact(session, request);
        fail("expected exception");
    } catch (ArtifactResolutionException e) {
    }
    List<EventWrapper> events = listener.getEvents();
    assertEquals(2, events.size());
    EventWrapper event = events.get(0);
    assertEquals(artifact, event.getEvent().getArtifact());
    assertEquals(Type.ARTIFACT_RESOLVING, event.getType());
    event = events.get(1);
    assertEquals(artifact, event.getEvent().getArtifact());
    assertEquals(Type.ARTIFACT_RESOLVED, event.getType());
    assertNotNull(event.getEvent().getException());
    assertEquals(1, event.getEvent().getExceptions().size());
}
Also used : ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) Collection(java.util.Collection) RecordingRepositoryListener(org.sonatype.aether.test.impl.RecordingRepositoryListener) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException) EventWrapper(org.sonatype.aether.test.impl.RecordingRepositoryListener.EventWrapper) Test(org.junit.Test)

Example 9 with ArtifactResolutionException

use of org.sonatype.aether.resolution.ArtifactResolutionException in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testArtifactNotFoundCache.

@Test
public void testArtifactNotFoundCache() throws Exception {
    RecordingRepositoryConnector connector = new RecordingRepositoryConnector() {

        @Override
        public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
            super.get(artifactDownloads, metadataDownloads);
            for (ArtifactDownload download : artifactDownloads) {
                download.getFile().delete();
                ArtifactTransferException exception = new ArtifactNotFoundException(download.getArtifact(), null, "not found");
                download.setException(exception);
            }
        }
    };
    remoteRepositoryManager.setConnector(connector);
    resolver.setUpdateCheckManager(new DefaultUpdateCheckManager());
    session.setNotFoundCachingEnabled(true);
    session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER);
    RemoteRepository remoteRepo = new RemoteRepository("id", "default", "file:///");
    Artifact artifact1 = artifact;
    Artifact artifact2 = artifact.setVersion("ver2");
    ArtifactRequest request1 = new ArtifactRequest(artifact1, Arrays.asList(remoteRepo), "");
    ArtifactRequest request2 = new ArtifactRequest(artifact2, Arrays.asList(remoteRepo), "");
    connector.setExpectGet(new Artifact[] { artifact1, artifact2 });
    try {
        resolver.resolveArtifacts(session, Arrays.asList(request1, request2));
        fail("expected exception");
    } catch (ArtifactResolutionException e) {
        connector.assertSeenExpected();
    }
    TestFileUtils.write("artifact", new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifact2)));
    lrm.setArtifactAvailability(artifact2, false);
    DefaultUpdateCheckManagerTest.resetSessionData(session);
    connector.resetActual();
    connector.setExpectGet(new Artifact[0]);
    try {
        resolver.resolveArtifacts(session, Arrays.asList(request1, request2));
        fail("expected exception");
    } catch (ArtifactResolutionException e) {
        connector.assertSeenExpected();
        for (ArtifactResult result : e.getResults()) {
            Throwable t = result.getExceptions().get(0);
            assertEquals(t.toString(), true, t instanceof ArtifactNotFoundException);
            assertEquals(t.toString(), true, t.getMessage().contains("cached"));
        }
    }
}
Also used : RemoteRepository(org.sonatype.aether.repository.RemoteRepository) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) Collection(java.util.Collection) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException) File(java.io.File) Test(org.junit.Test)

Example 10 with ArtifactResolutionException

use of org.sonatype.aether.resolution.ArtifactResolutionException in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testVersionResolverFails.

@Test
public void testVersionResolverFails() {
    resolver.setVersionResolver(new VersionResolver() {

        public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
            throw new VersionResolutionException(new VersionResult(request));
        }
    });
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    try {
        resolver.resolveArtifact(session, request);
        fail("expected exception");
    } catch (ArtifactResolutionException e) {
        connector.assertSeenExpected();
        assertNotNull(e.getResults());
        assertEquals(1, e.getResults().size());
        ArtifactResult result = e.getResults().get(0);
        assertSame(request, result.getRequest());
        assertFalse(result.getExceptions().isEmpty());
        assertTrue(result.getExceptions().get(0) instanceof VersionResolutionException);
        Artifact resolved = result.getArtifact();
        assertNull(resolved);
    }
}
Also used : RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) VersionResolver(org.sonatype.aether.impl.VersionResolver) VersionResult(org.sonatype.aether.resolution.VersionResult) VersionRequest(org.sonatype.aether.resolution.VersionRequest) VersionResolutionException(org.sonatype.aether.resolution.VersionResolutionException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) Test(org.junit.Test)

Aggregations

ArtifactResolutionException (org.sonatype.aether.resolution.ArtifactResolutionException)13 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)12 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)9 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)8 Test (org.junit.Test)7 Artifact (org.sonatype.aether.artifact.Artifact)5 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)5 ArtifactNotFoundException (org.sonatype.aether.transfer.ArtifactNotFoundException)5 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)4 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)4 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)4 ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)4 File (java.io.File)3 Collection (java.util.Collection)3 RequestTrace (org.sonatype.aether.RequestTrace)3 VersionRequest (org.sonatype.aether.resolution.VersionRequest)3 VersionResolutionException (org.sonatype.aether.resolution.VersionResolutionException)3 VersionResult (org.sonatype.aether.resolution.VersionResult)3 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)3 RecordingRepositoryListener (org.sonatype.aether.test.impl.RecordingRepositoryListener)3