Search in sources :

Example 11 with ArtifactResolutionException

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

the class DefaultArtifactResolverTest method testResolveRemoteArtifactUnsuccessful.

@Test
public void testResolveRemoteArtifactUnsuccessful() 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);
        }
    };
    connector.setExpectGet(artifact);
    remoteRepositoryManager.setConnector(connector);
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    request.addRepository(new RemoteRepository("id", "default", "file:///"));
    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 ArtifactNotFoundException);
        Artifact resolved = result.getArtifact();
        assertNull(resolved);
    }
}
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) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException) 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)

Example 12 with ArtifactResolutionException

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

the class DefaultArtifactResolverTest method testRepositoryEventsOnVersionResolverFail.

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

        public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
            throw new VersionResolutionException(new VersionResult(request));
        }
    });
    RecordingRepositoryListener listener = new RecordingRepositoryListener();
    session.setRepositoryListener(listener);
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    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 : 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) RecordingRepositoryListener(org.sonatype.aether.test.impl.RecordingRepositoryListener) EventWrapper(org.sonatype.aether.test.impl.RecordingRepositoryListener.EventWrapper) Test(org.junit.Test)

Example 13 with ArtifactResolutionException

use of org.sonatype.aether.resolution.ArtifactResolutionException in project karaf by apache.

the class Dependency30Helper method resolveById.

@Override
public File resolveById(String id, Log log) throws MojoFailureException {
    if (id.startsWith("mvn:")) {
        if (id.contains("!")) {
            id = id.substring(0, "mvn:".length()) + id.substring(id.indexOf("!") + 1);
        }
        if (id.endsWith("/")) {
            id = id.substring(0, id.length() - 1);
        }
    }
    id = MavenUtil.mvnToAether(id);
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(new DefaultArtifact(id));
    request.setRepositories(projectRepositories);
    log.debug("Resolving artifact " + id + " from " + projectRepositories);
    ArtifactResult result;
    try {
        result = repositorySystem.resolveArtifact(repositorySystemSession, request);
    } catch (ArtifactResolutionException e) {
        log.warn("Could not resolve " + id, e);
        throw new MojoFailureException(format("Couldn't resolve artifact %s", id), e);
    }
    log.debug("Resolved artifact " + id + " to " + result.getArtifact().getFile() + " from " + result.getRepository());
    return result.getArtifact().getFile();
}
Also used : ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult)

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