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);
}
}
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());
}
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();
}
Aggregations