use of org.sonatype.aether.spi.connector.MetadataDownload in project sonatype-aether by sonatype.
the class WagonRepositoryConnector method get.
public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
if (closed) {
throw new IllegalStateException("connector closed");
}
artifactDownloads = safe(artifactDownloads);
metadataDownloads = safe(metadataDownloads);
Collection<GetTask<?>> tasks = new ArrayList<GetTask<?>>();
RunnableErrorForwarder errorForwarder = new RunnableErrorForwarder();
for (MetadataDownload download : metadataDownloads) {
String resource = layout.getPath(download.getMetadata()).getPath();
GetTask<?> task = new GetTask<MetadataTransfer>(resource, download.getFile(), download.getChecksumPolicy(), download, METADATA);
tasks.add(task);
executor.execute(errorForwarder.wrap(task));
}
for (ArtifactDownload download : artifactDownloads) {
String resource = layout.getPath(download.getArtifact()).getPath();
GetTask<?> task = new GetTask<ArtifactTransfer>(resource, download.isExistenceCheck() ? null : download.getFile(), download.getChecksumPolicy(), download, ARTIFACT);
tasks.add(task);
executor.execute(errorForwarder.wrap(task));
}
errorForwarder.await();
}
use of org.sonatype.aether.spi.connector.MetadataDownload in project sonatype-aether by sonatype.
the class ConnectorTestSuite method testBlocking.
@Test
public void testBlocking() throws NoRepositoryConnectorException, IOException {
RepositoryConnector connector = factory().newInstance(session, repository);
int count = 10;
byte[] pattern = "tmpFile".getBytes("UTF-8");
File tmpFile = TestFileUtils.createTempFile(pattern, 100000);
List<ArtifactUpload> artUps = ConnectorTestUtils.createTransfers(ArtifactUpload.class, count, tmpFile);
List<MetadataUpload> metaUps = ConnectorTestUtils.createTransfers(MetadataUpload.class, count, tmpFile);
List<ArtifactDownload> artDowns = ConnectorTestUtils.createTransfers(ArtifactDownload.class, count, null);
List<MetadataDownload> metaDowns = ConnectorTestUtils.createTransfers(MetadataDownload.class, count, null);
// this should block until all transfers are done - racing condition, better way to test this?
connector.put(artUps, metaUps);
connector.get(artDowns, metaDowns);
for (int i = 0; i < count; i++) {
ArtifactUpload artUp = artUps.get(i);
MetadataUpload metaUp = metaUps.get(i);
ArtifactDownload artDown = artDowns.get(i);
MetadataDownload metaDown = metaDowns.get(i);
assertTrue(Transfer.State.DONE.equals(artUp.getState()));
assertTrue(Transfer.State.DONE.equals(artDown.getState()));
assertTrue(Transfer.State.DONE.equals(metaUp.getState()));
assertTrue(Transfer.State.DONE.equals(metaDown.getState()));
}
connector.close();
}
use of org.sonatype.aether.spi.connector.MetadataDownload in project sonatype-aether by sonatype.
the class ConnectorTestSuite method testProgressEventsDataBuffer.
@Test
public void testProgressEventsDataBuffer() throws UnsupportedEncodingException, IOException, NoSuchAlgorithmException, NoRepositoryConnectorException {
byte[] bytes = "These are the test contents.\n".getBytes("UTF-8");
int count = 120000;
MessageDigest digest = MessageDigest.getInstance("SHA-1");
for (int i = 0; i < count; i++) {
digest.update(bytes);
}
byte[] hash = digest.digest();
File file = TestFileUtils.createTempFile(bytes, count);
Artifact artifact = new StubArtifact("gid:aid:ext:ver");
ArtifactUpload upA = new ArtifactUpload(artifact, file);
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, file);
File downMFile = new File(dir, "downM.file");
downMFile.deleteOnExit();
MetadataDownload downM = new MetadataDownload(metadata, "", downMFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
DigestingTransferListener listener = new DigestingTransferListener();
session.setTransferListener(listener);
RepositoryConnector connector = factory().newInstance(session, repository);
connector.put(Arrays.asList(upA), null);
assertArrayEquals(hash, listener.getHash());
listener.rewind();
connector.put(null, Arrays.asList(upM));
assertArrayEquals(hash, listener.getHash());
listener.rewind();
connector.get(Arrays.asList(downA), null);
assertArrayEquals(hash, listener.getHash());
listener.rewind();
connector.get(null, Arrays.asList(downM));
assertArrayEquals(hash, listener.getHash());
listener.rewind();
connector.close();
}
use of org.sonatype.aether.spi.connector.MetadataDownload in project sonatype-aether by sonatype.
the class TransferEventTester method testSuccessfulTransferEvents.
/**
* Test the order of events and their properties for the successful up- and download of artifact and metadata.
*/
public static void testSuccessfulTransferEvents(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();
File tmpFile = TestFileUtils.createTempFile(pattern, 10000);
long expectedBytes = tmpFile.length();
Collection<ArtifactUpload> artUps = ConnectorTestUtils.createTransfers(ArtifactUpload.class, 1, tmpFile);
Collection<ArtifactDownload> artDowns = ConnectorTestUtils.createTransfers(ArtifactDownload.class, 1, tmpFile);
Collection<MetadataUpload> metaUps = ConnectorTestUtils.createTransfers(MetadataUpload.class, 1, tmpFile);
Collection<MetadataDownload> metaDowns = ConnectorTestUtils.createTransfers(MetadataDownload.class, 1, tmpFile);
connector.put(artUps, null);
LinkedList<TransferEvent> events = new LinkedList<TransferEvent>(listener.getEvents());
checkEvents(events, expectedBytes);
listener.clear();
connector.get(artDowns, null);
events = new LinkedList<TransferEvent>(listener.getEvents());
checkEvents(events, expectedBytes);
listener.clear();
connector.put(null, metaUps);
events = new LinkedList<TransferEvent>(listener.getEvents());
checkEvents(events, expectedBytes);
listener.clear();
connector.get(null, metaDowns);
events = new LinkedList<TransferEvent>(listener.getEvents());
checkEvents(events, expectedBytes);
connector.close();
session.setTransferListener(null);
}
use of org.sonatype.aether.spi.connector.MetadataDownload in project sonatype-aether by sonatype.
the class ArtifactWorkerTest method testMetadataTransfer.
@Test
public void testMetadataTransfer() throws IOException, MetadataTransferException {
String expectedContent = "Dies ist ein Test.";
File srcFile = TestFileUtils.createTempFile(expectedContent);
DefaultMetadata metadata = new DefaultMetadata("test", "artId1", "1", "jar", Nature.RELEASE_OR_SNAPSHOT);
MetadataUpload up = new MetadataUpload(metadata, srcFile);
FileRepositoryWorker worker = new FileRepositoryWorker(up, repository, session);
worker.setFileProcessor(TestFileProcessor.INSTANCE);
worker.run();
if (up.getException() != null) {
throw up.getException();
}
File targetFile = TestFileUtils.createTempFile("");
TestFileUtils.delete(targetFile);
MetadataDownload down = new MetadataDownload();
down.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_FAIL);
down.setMetadata(metadata).setFile(targetFile);
worker = new FileRepositoryWorker(down, repository, session);
worker.setFileProcessor(TestFileProcessor.INSTANCE);
worker.run();
if (down.getException() != null) {
throw down.getException();
}
assertTrue("download did not happen.", targetFile.exists());
assertContentEquals(targetFile, expectedContent);
}
Aggregations