use of org.sonatype.aether.resolution.ArtifactResult in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testResolveLocalArtifactUnsuccessful.
@Test
public void testResolveLocalArtifactUnsuccessful() throws IOException, ArtifactResolutionException {
File tmpFile = TestFileUtils.createTempFile("tmp");
Map<String, String> properties = new HashMap<String, String>();
properties.put(ArtifactProperties.LOCAL_PATH, tmpFile.getAbsolutePath());
artifact = artifact.setProperties(properties);
tmpFile.delete();
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
try {
resolver.resolveArtifact(session, request);
fail("expected exception");
} catch (ArtifactResolutionException e) {
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.ArtifactResult in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testFindInLocalRepositoryWhenVersionWasFoundInLocalRepository.
@Test
public void testFindInLocalRepositoryWhenVersionWasFoundInLocalRepository() throws ArtifactResolutionException {
session.setLocalRepositoryManager(new LocalRepositoryManager() {
public LocalRepository getRepository() {
return null;
}
public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
return null;
}
public String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
return null;
}
public String getPathForLocalMetadata(Metadata metadata) {
return null;
}
public String getPathForLocalArtifact(Artifact artifact) {
return null;
}
public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
LocalArtifactResult result = new LocalArtifactResult(request);
result.setAvailable(false);
try {
result.setFile(TestFileUtils.createTempFile(""));
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public void add(RepositorySystemSession session, LocalArtifactRegistration request) {
}
public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
LocalMetadataResult result = new LocalMetadataResult(request);
return result;
}
public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
}
});
ArtifactRequest request = new ArtifactRequest(artifact, null, "");
request.addRepository(new RemoteRepository("id", "default", "file:///"));
resolver.setVersionResolver(new VersionResolver() {
public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
return new VersionResult(request).setRepository(new LocalRepository("id")).setVersion(request.getArtifact().getVersion());
}
});
ArtifactResult result = resolver.resolveArtifact(session, request);
assertTrue(result.getExceptions().isEmpty());
Artifact resolved = result.getArtifact();
assertNotNull(resolved.getFile());
resolved = resolved.setFile(null);
assertEquals(artifact, resolved);
}
use of org.sonatype.aether.resolution.ArtifactResult 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.ArtifactResult 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.ArtifactResult 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