use of org.sonatype.aether.deployment.DeploymentException 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.deployment.DeploymentException in project sonatype-aether by sonatype.
the class DefaultDeployer method upload.
private void upload(Collection<MetadataUpload> metadataUploads, RepositorySystemSession session, Metadata metadata, RemoteRepository repository, RepositoryConnector connector, EventCatapult catapult) throws DeploymentException {
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
File basedir = lrm.getRepository().getBasedir();
File dstFile = new File(basedir, lrm.getPathForRemoteMetadata(metadata, repository, ""));
if (metadata instanceof MergeableMetadata) {
if (!((MergeableMetadata) metadata).isMerged()) {
{
DefaultRepositoryEvent event = new DefaultRepositoryEvent(EventType.METADATA_RESOLVING, session, catapult.getTrace());
event.setMetadata(metadata);
event.setRepository(repository);
repositoryEventDispatcher.dispatch(event);
event = new DefaultRepositoryEvent(EventType.METADATA_DOWNLOADING, session, catapult.getTrace());
event.setMetadata(metadata);
event.setRepository(repository);
repositoryEventDispatcher.dispatch(event);
}
RepositoryPolicy policy = getPolicy(session, repository, metadata.getNature());
MetadataDownload download = new MetadataDownload();
download.setMetadata(metadata);
download.setFile(dstFile);
download.setChecksumPolicy(policy.getChecksumPolicy());
connector.get(null, Arrays.asList(download));
Exception error = download.getException();
if (error instanceof MetadataNotFoundException) {
dstFile.delete();
}
{
DefaultRepositoryEvent event = new DefaultRepositoryEvent(EventType.METADATA_DOWNLOADED, session, catapult.getTrace());
event.setMetadata(metadata);
event.setRepository(repository);
event.setException(error);
event.setFile(dstFile);
repositoryEventDispatcher.dispatch(event);
event = new DefaultRepositoryEvent(EventType.METADATA_RESOLVED, session, catapult.getTrace());
event.setMetadata(metadata);
event.setRepository(repository);
event.setException(error);
event.setFile(dstFile);
repositoryEventDispatcher.dispatch(event);
}
if (error != null && !(error instanceof MetadataNotFoundException)) {
throw new DeploymentException("Failed to retrieve remote metadata " + metadata + ": " + error.getMessage(), error);
}
}
try {
((MergeableMetadata) metadata).merge(dstFile, dstFile);
} catch (RepositoryException e) {
throw new DeploymentException("Failed to update metadata " + metadata + ": " + e.getMessage(), e);
}
} else {
if (metadata.getFile() == null) {
throw new DeploymentException("Failed to update metadata " + metadata + ": No file attached.");
}
try {
fileProcessor.copy(metadata.getFile(), dstFile, null);
} catch (IOException e) {
throw new DeploymentException("Failed to update metadata " + metadata + ": " + e.getMessage(), e);
}
}
UpdateCheck<Metadata, MetadataTransferException> check = new UpdateCheck<Metadata, MetadataTransferException>();
check.setItem(metadata);
check.setFile(dstFile);
check.setRepository(repository);
check.setAuthoritativeRepository(repository);
updateCheckManager.touchMetadata(session, check);
metadataUploads.add(new MetadataUploadEx(metadata, dstFile, catapult));
}
Aggregations