use of org.sonatype.aether.resolution.ArtifactRequest in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testResolveFromWorkspace.
@Test
public void testResolveFromWorkspace() throws IOException, ArtifactResolutionException {
session = new TestRepositorySystemSession() {
@Override
public WorkspaceReader getWorkspaceReader() {
return new WorkspaceReader() {
public WorkspaceRepository getRepository() {
return new WorkspaceRepository("default");
}
public List<String> findVersions(Artifact artifact) {
return Arrays.asList(artifact.getVersion());
}
public File findArtifact(Artifact artifact) {
try {
return TestFileUtils.createTempFile(artifact.toString());
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
};
}
};
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
request.addRepository(new RemoteRepository("id", "default", "file:///"));
ArtifactResult result = resolver.resolveArtifact(session, request);
assertTrue(result.getExceptions().isEmpty());
Artifact resolved = result.getArtifact();
assertNotNull(resolved.getFile());
byte[] expected = resolved.toString().getBytes("UTF-8");
TestFileUtils.assertContent(expected, resolved.getFile());
resolved = resolved.setFile(null);
assertEquals(artifact, resolved);
connector.assertSeenExpected();
}
use of org.sonatype.aether.resolution.ArtifactRequest in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testRepositoryEventsUnsuccessfulLocal.
@Test
public void testRepositoryEventsUnsuccessfulLocal() throws IOException {
RecordingRepositoryListener listener = new RecordingRepositoryListener();
session.setRepositoryListener(listener);
Map<String, String> properties = new HashMap<String, String>();
properties.put(ArtifactProperties.LOCAL_PATH, "doesnotexist");
artifact = artifact.setProperties(properties);
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.ArtifactRequest in project sonatype-aether by sonatype.
the class ArtifactRequestBuilder method visitEnter.
public boolean visitEnter(DependencyNode node) {
if (node.getDependency() != null) {
ArtifactRequest request = new ArtifactRequest(node);
request.setTrace(trace);
requests.add(request);
}
return true;
}
use of org.sonatype.aether.resolution.ArtifactRequest in project sonatype-aether by sonatype.
the class ResolveArtifact method main.
public static void main(String[] args) throws Exception {
System.out.println("------------------------------------------------------------");
System.out.println(ResolveArtifact.class.getSimpleName());
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession(system);
Artifact artifact = new DefaultArtifact("org.sonatype.aether:aether-util:1.9");
RemoteRepository repo = Booter.newCentralRepository();
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifact);
artifactRequest.addRepository(repo);
ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
artifact = artifactResult.getArtifact();
System.out.println(artifact + " resolved to " + artifact.getFile());
}
use of org.sonatype.aether.resolution.ArtifactRequest in project karaf by apache.
the class Dependency30Helper method resolve.
@Override
public File resolve(Object artifact, Log log) {
ArtifactRequest request = new ArtifactRequest();
request.setArtifact((Artifact) artifact);
request.setRepositories(projectRepositories);
log.debug("Resolving artifact " + artifact + " from " + projectRepositories);
ArtifactResult result;
try {
result = repositorySystem.resolveArtifact(repositorySystemSession, request);
} catch (ArtifactResolutionException e) {
log.warn("Could not resolve " + artifact, e);
return null;
}
log.debug("Resolved artifact " + artifact + " to " + result.getArtifact().getFile() + " from " + result.getRepository());
return result.getArtifact().getFile();
}
Aggregations