use of org.sonatype.aether.spi.connector.MetadataUpload in project sonatype-aether by sonatype.
the class FileRepositoryConnector method put.
public void put(Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads) {
checkClosed();
artifactUploads = notNull(artifactUploads);
metadataUploads = notNull(metadataUploads);
RunnableErrorForwarder errorForwarder = new RunnableErrorForwarder();
for (ArtifactUpload artifactUpload : artifactUploads) {
FileRepositoryWorker worker = new FileRepositoryWorker(artifactUpload, repository, session);
worker.setLogger(logger);
worker.setFileProcessor(fileProcessor);
executor.execute(errorForwarder.wrap(worker));
}
for (MetadataUpload metadataUpload : metadataUploads) {
FileRepositoryWorker worker = new FileRepositoryWorker(metadataUpload, repository, session);
worker.setLogger(logger);
worker.setFileProcessor(fileProcessor);
executor.execute(errorForwarder.wrap(worker));
}
errorForwarder.await();
}
use of org.sonatype.aether.spi.connector.MetadataUpload in project sonatype-aether by sonatype.
the class WagonRepositoryConnector method put.
public void put(Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads) {
if (closed) {
throw new IllegalStateException("connector closed");
}
artifactUploads = safe(artifactUploads);
metadataUploads = safe(metadataUploads);
for (ArtifactUpload upload : artifactUploads) {
String path = layout.getPath(upload.getArtifact()).getPath();
PutTask<?> task = new PutTask<ArtifactTransfer>(path, upload.getFile(), upload, ARTIFACT);
task.run();
}
for (MetadataUpload upload : metadataUploads) {
String path = layout.getPath(upload.getMetadata()).getPath();
PutTask<?> task = new PutTask<MetadataTransfer>(path, upload.getFile(), upload, METADATA);
task.run();
}
}
use of org.sonatype.aether.spi.connector.MetadataUpload in project sonatype-aether by sonatype.
the class RecordingRepositoryConnector method put.
public void put(Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads) {
if (artifactUploads != null) {
for (ArtifactUpload artifactUpload : artifactUploads) {
// mimic "real" connector
artifactUpload.setState(State.ACTIVE);
if (artifactUpload.getFile() == null) {
artifactUpload.setException(new ArtifactTransferException(artifactUpload.getArtifact(), null, "no file"));
}
this.actualPut.add(artifactUpload.getArtifact());
artifactUpload.setState(State.DONE);
}
}
if (metadataUploads != null) {
for (MetadataUpload metadataUpload : metadataUploads) {
// mimic "real" connector
metadataUpload.setState(State.ACTIVE);
if (metadataUpload.getFile() == null) {
metadataUpload.setException(new MetadataTransferException(metadataUpload.getMetadata(), null, "no file"));
}
this.actualPutMD.add(metadataUpload.getMetadata());
metadataUpload.setState(State.DONE);
}
}
}
use of org.sonatype.aether.spi.connector.MetadataUpload 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.MetadataUpload 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();
}
Aggregations