use of org.sonatype.aether.spi.connector.ArtifactUpload in project sonatype-aether by sonatype.
the class DefaultDeployer method deploy.
private DeployResult deploy(SyncContext syncContext, RepositorySystemSession session, DeployRequest request) throws DeploymentException {
DeployResult result = new DeployResult(request);
RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
RemoteRepository repository = request.getRepository();
RepositoryConnector connector;
try {
connector = remoteRepositoryManager.getRepositoryConnector(session, repository);
} catch (NoRepositoryConnectorException e) {
throw new DeploymentException("Failed to deploy artifacts/metadata: " + e.getMessage(), e);
}
List<MetadataGenerator> generators = getMetadataGenerators(session, request);
try {
List<ArtifactUpload> artifactUploads = new ArrayList<ArtifactUpload>();
List<MetadataUpload> metadataUploads = new ArrayList<MetadataUpload>();
IdentityHashMap<Metadata, Object> processedMetadata = new IdentityHashMap<Metadata, Object>();
EventCatapult catapult = new EventCatapult(session, trace, repository, repositoryEventDispatcher);
List<Artifact> artifacts = new ArrayList<Artifact>(request.getArtifacts());
List<Metadata> metadatas = Utils.prepareMetadata(generators, artifacts);
syncContext.acquire(artifacts, Utils.combine(request.getMetadata(), metadatas));
for (Metadata metadata : metadatas) {
upload(metadataUploads, session, metadata, repository, connector, catapult);
processedMetadata.put(metadata, null);
}
for (int i = 0; i < artifacts.size(); i++) {
Artifact artifact = artifacts.get(i);
for (MetadataGenerator generator : generators) {
artifact = generator.transformArtifact(artifact);
}
artifacts.set(i, artifact);
artifactUploads.add(new ArtifactUploadEx(artifact, artifact.getFile(), catapult));
}
connector.put(artifactUploads, null);
for (ArtifactUpload upload : artifactUploads) {
if (upload.getException() != null) {
throw new DeploymentException("Failed to deploy artifacts: " + upload.getException().getMessage(), upload.getException());
}
result.addArtifact(upload.getArtifact());
}
metadatas = Utils.finishMetadata(generators, artifacts);
syncContext.acquire(null, metadatas);
for (Metadata metadata : metadatas) {
upload(metadataUploads, session, metadata, repository, connector, catapult);
processedMetadata.put(metadata, null);
}
for (Metadata metadata : request.getMetadata()) {
if (!processedMetadata.containsKey(metadata)) {
upload(metadataUploads, session, metadata, repository, connector, catapult);
processedMetadata.put(metadata, null);
}
}
connector.put(null, metadataUploads);
for (MetadataUpload upload : metadataUploads) {
if (upload.getException() != null) {
throw new DeploymentException("Failed to deploy metadata: " + upload.getException().getMessage(), upload.getException());
}
result.addMetadata(upload.getMetadata());
}
} finally {
connector.close();
}
return result;
}
use of org.sonatype.aether.spi.connector.ArtifactUpload 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.ArtifactUpload 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.ArtifactUpload in project sonatype-aether by sonatype.
the class AsyncHandlerExceptionTest method testIt.
@Test
public void testIt() throws Exception {
HttpServer server = new HttpServer();
server.addResources("/", baseDir.getAbsolutePath());
server.start();
try {
RemoteRepository repo = new RemoteRepository("id", "default", server.getHttpUrl() + "/repo");
RepositorySystemSession session = new DefaultRepositorySystemSession();
AsyncRepositoryConnector connector = new AsyncRepositoryConnector(repo, session, new TestFileProcessor(), new SysoutLogger());
try {
StubArtifact artifact = new StubArtifact("gid:aid:1.0");
for (int i = 0; i < 16; i++) {
System.out.println("RUN #" + i);
TestFileUtils.delete(baseDir);
ArtifactDownload download = new ArtifactDownload(artifact, "project", new File(baseDir, "a.jar"), "ignore");
System.out.println("GET");
connector.get(Arrays.asList(download), null);
assertTrue(String.valueOf(download.getException()), download.getException() instanceof ArtifactNotFoundException);
ArtifactUpload upload = new ArtifactUpload(artifact, new File("pom.xml"));
System.out.println("PUT");
connector.put(Arrays.asList(upload), null);
if (upload.getException() != null) {
upload.getException().printStackTrace();
}
assertNull(String.valueOf(upload.getException()), upload.getException());
}
} finally {
connector.close();
}
} finally {
server.stop();
}
}
use of org.sonatype.aether.spi.connector.ArtifactUpload in project sonatype-aether by sonatype.
the class ArtifactWorkerTest method uploadArtifact.
private void uploadArtifact(Artifact artifact, String content) throws IOException, ArtifactTransferException {
File file = TestFileUtils.createTempFile(content);
ArtifactUpload transfer = new ArtifactUpload(artifact, file);
FileRepositoryWorker worker = new FileRepositoryWorker(transfer, repository, session);
worker.setFileProcessor(TestFileProcessor.INSTANCE);
worker.run();
TestFileUtils.delete(file);
if (transfer.getException() != null) {
throw transfer.getException();
}
}
Aggregations