use of org.sonatype.aether.impl.VersionResolver in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method testFindInLocalRepositoryWhenVersionRangeWasResolvedFromLocalRepository.
@Test
public void testFindInLocalRepositoryWhenVersionRangeWasResolvedFromLocalRepository() 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, "");
resolver.setVersionResolver(new VersionResolver() {
public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
return new VersionResult(request).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.impl.VersionResolver 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.impl.VersionResolver 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);
}
}
use of org.sonatype.aether.impl.VersionResolver in project sonatype-aether by sonatype.
the class DefaultArtifactResolverTest method setup.
@Before
public void setup() throws IOException {
UpdateCheckManager updateCheckManager = new StaticUpdateCheckManager(true);
remoteRepositoryManager = new StubRemoteRepositoryManager();
VersionResolver versionResolver = new StubVersionResolver();
session = new TestRepositorySystemSession();
lrm = (TestLocalRepositoryManager) session.getLocalRepositoryManager();
resolver = new DefaultArtifactResolver(NullLogger.INSTANCE, TestFileProcessor.INSTANCE, new StubRepositoryEventDispatcher(), versionResolver, updateCheckManager, remoteRepositoryManager, new StubSyncContextFactory());
artifact = new StubArtifact("gid", "aid", "", "ext", "ver");
connector = new RecordingRepositoryConnector();
remoteRepositoryManager.setConnector(connector);
}
use of org.sonatype.aether.impl.VersionResolver 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());
}
Aggregations