use of org.sonatype.aether.resolution.MetadataRequest in project sonatype-aether by sonatype.
the class DefaultMetadataResolverTest method testOfflineSessionResolveMetadata.
@Test
public void testOfflineSessionResolveMetadata() throws IOException {
session.setOffline(true);
String path = session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, repository, "");
File file = new File(session.getLocalRepository().getBasedir(), path);
TestFileUtils.write(file.getAbsolutePath(), file);
// set file to use in TestLRM find()
metadata = metadata.setFile(file);
MetadataRequest request = new MetadataRequest(metadata, repository, "");
List<MetadataResult> results = resolver.resolveMetadata(session, Arrays.asList(request));
assertEquals(1, results.size());
MetadataResult result = results.get(0);
assertSame(request, result.getRequest());
assertNull(String.valueOf(result.getException()), result.getException());
assertNotNull(result.getMetadata());
assertNotNull(result.getMetadata().getFile());
assertEquals(file, result.getMetadata().getFile());
assertEquals(metadata.setFile(null), result.getMetadata().setFile(null));
connector.assertSeenExpected();
}
use of org.sonatype.aether.resolution.MetadataRequest in project sonatype-aether by sonatype.
the class DefaultMetadataResolverTest method testResolve.
@Test
public void testResolve() throws IOException {
connector.setExpectGet(metadata);
// prepare "download"
File file = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, repository, ""));
TestFileUtils.write(file.getAbsolutePath(), file);
MetadataRequest request = new MetadataRequest(metadata, repository, "");
List<MetadataResult> results = resolver.resolveMetadata(session, Arrays.asList(request));
assertEquals(1, results.size());
MetadataResult result = results.get(0);
assertSame(request, result.getRequest());
assertNull(result.getException());
assertNotNull(result.getMetadata());
assertNotNull(result.getMetadata().getFile());
assertEquals(file, result.getMetadata().getFile());
assertEquals(metadata, result.getMetadata().setFile(null));
connector.assertSeenExpected();
Set<Metadata> metadataRegistration = ((TestLocalRepositoryManager) session.getLocalRepositoryManager()).getMetadataRegistration();
assertTrue(metadataRegistration.contains(metadata));
assertEquals(1, metadataRegistration.size());
}
use of org.sonatype.aether.resolution.MetadataRequest in project sonatype-aether by sonatype.
the class DefaultMetadataResolverTest method testRemoveMetadataIfMissing.
@Test
public void testRemoveMetadataIfMissing() throws IOException {
connector = new RecordingRepositoryConnector() {
@Override
public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
super.get(artifactDownloads, metadataDownloads);
for (MetadataDownload d : metadataDownloads) {
d.setException(new MetadataNotFoundException(metadata, repository));
}
}
};
manager.setConnector(connector);
File file = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, repository, ""));
TestFileUtils.write(file.getAbsolutePath(), file);
metadata.setFile(file);
MetadataRequest request = new MetadataRequest(metadata, repository, "");
request.setDeleteLocalCopyIfMissing(true);
List<MetadataResult> results = resolver.resolveMetadata(session, Arrays.asList(request));
assertEquals(1, results.size());
MetadataResult result = results.get(0);
assertNotNull(result.getException());
assertEquals(false, file.exists());
}
use of org.sonatype.aether.resolution.MetadataRequest in project sonatype-aether by sonatype.
the class DefaultMetadataResolverTest method testNoRepositoryFailing.
@Test
public void testNoRepositoryFailing() {
MetadataRequest request = new MetadataRequest(metadata, null, "");
List<MetadataResult> results = resolver.resolveMetadata(session, Arrays.asList(request));
assertEquals(1, results.size());
MetadataResult result = results.get(0);
assertSame(request, result.getRequest());
assertNotNull("" + (result.getMetadata() != null ? result.getMetadata().getFile() : result.getMetadata()), result.getException());
assertEquals(MetadataNotFoundException.class, result.getException().getClass());
assertNull(result.getMetadata());
}
use of org.sonatype.aether.resolution.MetadataRequest in project sonatype-aether by sonatype.
the class DefaultMetadataResolver method resolveMetadata.
public List<MetadataResult> resolveMetadata(RepositorySystemSession session, Collection<? extends MetadataRequest> requests) {
SyncContext syncContext = syncContextFactory.newInstance(session, false);
try {
Collection<Metadata> metadata = new ArrayList<Metadata>(requests.size());
for (MetadataRequest request : requests) {
metadata.add(request.getMetadata());
}
syncContext.acquire(null, metadata);
return resolve(session, requests);
} finally {
syncContext.release();
}
}
Aggregations