use of org.sonatype.aether.spi.connector.MetadataDownload in project sonatype-aether by sonatype.
the class AsyncRepositoryConnector method get.
/**
* Use the async http client library to download artifacts and metadata.
*
* @param artifactDownloads The artifact downloads to perform, may be {@code null} or empty.
* @param metadataDownloads The metadata downloads to perform, may be {@code null} or empty.
*/
public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
if (closed.get()) {
throw new IllegalStateException("connector closed");
}
artifactDownloads = safe(artifactDownloads);
metadataDownloads = safe(metadataDownloads);
CountDownLatch latch = new CountDownLatch(artifactDownloads.size() + metadataDownloads.size());
Collection<GetTask<?>> tasks = new ArrayList<GetTask<?>>();
for (MetadataDownload download : metadataDownloads) {
String resource = layout.getPath(download.getMetadata()).getPath();
GetTask<?> task = new GetTask<MetadataTransfer>(resource, download.getFile(), download.getChecksumPolicy(), latch, download, METADATA, false);
tasks.add(task);
task.run();
}
for (ArtifactDownload download : artifactDownloads) {
String resource = layout.getPath(download.getArtifact()).getPath();
GetTask<?> task = new GetTask<ArtifactTransfer>(resource, download.isExistenceCheck() ? null : download.getFile(), download.getChecksumPolicy(), latch, download, ARTIFACT, true);
tasks.add(task);
task.run();
}
await(latch);
for (GetTask<?> task : tasks) {
task.flush();
}
}
use of org.sonatype.aether.spi.connector.MetadataDownload 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.spi.connector.MetadataDownload in project sonatype-aether by sonatype.
the class DefaultDeployerTest method testStaleLocalMetadataCopyGetsDeletedBeforeMergeWhenMetadataIsNotCurrentlyPresentInRemoteRepo.
@Test
public void testStaleLocalMetadataCopyGetsDeletedBeforeMergeWhenMetadataIsNotCurrentlyPresentInRemoteRepo() throws Exception {
MergeableMetadata metadata = new MergeableMetadata() {
public Metadata setFile(File file) {
return this;
}
public String getVersion() {
return "";
}
public String getType() {
return "test.properties";
}
public Nature getNature() {
return Nature.RELEASE;
}
public String getGroupId() {
return "org";
}
public File getFile() {
return null;
}
public String getArtifactId() {
return "aether";
}
public void merge(File current, File result) throws RepositoryException {
Properties props = new Properties();
try {
if (current.isFile()) {
TestFileUtils.read(props, current);
}
props.setProperty("new", "value");
TestFileUtils.write(props, result);
} catch (IOException e) {
throw new RepositoryException(e.getMessage(), e);
}
}
public boolean isMerged() {
return false;
}
};
manager.setConnector(new RepositoryConnector() {
public void put(Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads) {
}
public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
if (metadataDownloads != null) {
for (MetadataDownload download : metadataDownloads) {
download.setException(new MetadataNotFoundException(download.getMetadata(), null, null));
}
}
}
public void close() {
}
});
request.addMetadata(metadata);
File metadataFile = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, request.getRepository(), ""));
Properties props = new Properties();
props.setProperty("old", "value");
TestFileUtils.write(props, metadataFile);
deployer.deploy(session, request);
props = new Properties();
TestFileUtils.read(props, metadataFile);
assertNull(props.toString(), props.get("old"));
}
use of org.sonatype.aether.spi.connector.MetadataDownload in project sonatype-aether by sonatype.
the class TransferEventTester method testFailedTransferEvents.
/**
* Test the order of events and their properties for the unsuccessful up- and download of artifact and metadata.
* Failure is triggered by setting the file to transfer to {@code null} for uploads, and asking for a non-existent
* item for downloads.
*/
public static void testFailedTransferEvents(RepositoryConnectorFactory factory, TestRepositorySystemSession session, RemoteRepository repository) throws NoRepositoryConnectorException, IOException {
RecordingTransferListener listener = new RecordingTransferListener(session.getTransferListener());
session.setTransferListener(listener);
RepositoryConnector connector = factory.newInstance(session, repository);
byte[] pattern = "tmpFile".getBytes("us-ascii");
File tmpFile = TestFileUtils.createTempFile(pattern, 10000);
Collection<ArtifactUpload> artUps = ConnectorTestUtils.createTransfers(ArtifactUpload.class, 1, null);
Collection<ArtifactDownload> artDowns = ConnectorTestUtils.createTransfers(ArtifactDownload.class, 1, tmpFile);
Collection<MetadataUpload> metaUps = ConnectorTestUtils.createTransfers(MetadataUpload.class, 1, null);
Collection<MetadataDownload> metaDowns = ConnectorTestUtils.createTransfers(MetadataDownload.class, 1, tmpFile);
connector.put(artUps, null);
LinkedList<TransferEvent> events = new LinkedList<TransferEvent>(listener.getEvents());
checkFailedEvents(events, null);
listener.clear();
connector.get(artDowns, null);
events = new LinkedList<TransferEvent>(listener.getEvents());
checkFailedEvents(events, null);
listener.clear();
connector.put(null, metaUps);
events = new LinkedList<TransferEvent>(listener.getEvents());
checkFailedEvents(events, null);
listener.clear();
connector.get(null, metaDowns);
events = new LinkedList<TransferEvent>(listener.getEvents());
checkFailedEvents(events, null);
connector.close();
session.setTransferListener(null);
}
use of org.sonatype.aether.spi.connector.MetadataDownload in project sonatype-aether by sonatype.
the class ConnectorTestSuite method testTransferZeroBytesFile.
/**
* See https://issues.sonatype.org/browse/AETHER-8
*/
@Test
public void testTransferZeroBytesFile() throws IOException, NoRepositoryConnectorException {
File emptyFile = TestFileUtils.createTempFile("");
Artifact artifact = new StubArtifact("gid:aid:ext:ver");
ArtifactUpload upA = new ArtifactUpload(artifact, emptyFile);
File dir = TestFileUtils.createTempDir("con-test");
File downAFile = new File(dir, "downA.file");
downAFile.deleteOnExit();
ArtifactDownload downA = new ArtifactDownload(artifact, "", downAFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
Metadata metadata = new StubMetadata("gid", "aid", "ver", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
MetadataUpload upM = new MetadataUpload(metadata, emptyFile);
File downMFile = new File(dir, "downM.file");
downMFile.deleteOnExit();
MetadataDownload downM = new MetadataDownload(metadata, "", downMFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
RepositoryConnector connector = factory().newInstance(session, repository);
connector.put(Arrays.asList(upA), Arrays.asList(upM));
connector.get(Arrays.asList(downA), Arrays.asList(downM));
assertNull(String.valueOf(upA.getException()), upA.getException());
assertNull(String.valueOf(upM.getException()), upM.getException());
assertNull(String.valueOf(downA.getException()), downA.getException());
assertNull(String.valueOf(downM.getException()), downM.getException());
assertEquals(0, downAFile.length());
assertEquals(0, downMFile.length());
connector.close();
}
Aggregations