use of org.sonatype.aether.deployment.DeployResult 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;
}
Aggregations