Search in sources :

Example 1 with DeployResult

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;
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) MergeableMetadata(org.sonatype.aether.metadata.MergeableMetadata) Metadata(org.sonatype.aether.metadata.Metadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) RequestTrace(org.sonatype.aether.RequestTrace) DefaultRequestTrace(org.sonatype.aether.util.DefaultRequestTrace) Artifact(org.sonatype.aether.artifact.Artifact) DeployResult(org.sonatype.aether.deployment.DeployResult) NoRepositoryConnectorException(org.sonatype.aether.transfer.NoRepositoryConnectorException) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) DeploymentException(org.sonatype.aether.deployment.DeploymentException) MetadataGenerator(org.sonatype.aether.impl.MetadataGenerator)

Aggregations

ArrayList (java.util.ArrayList)1 IdentityHashMap (java.util.IdentityHashMap)1 RequestTrace (org.sonatype.aether.RequestTrace)1 Artifact (org.sonatype.aether.artifact.Artifact)1 DeployResult (org.sonatype.aether.deployment.DeployResult)1 DeploymentException (org.sonatype.aether.deployment.DeploymentException)1 MetadataGenerator (org.sonatype.aether.impl.MetadataGenerator)1 MergeableMetadata (org.sonatype.aether.metadata.MergeableMetadata)1 Metadata (org.sonatype.aether.metadata.Metadata)1 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)1 ArtifactUpload (org.sonatype.aether.spi.connector.ArtifactUpload)1 MetadataUpload (org.sonatype.aether.spi.connector.MetadataUpload)1 RepositoryConnector (org.sonatype.aether.spi.connector.RepositoryConnector)1 NoRepositoryConnectorException (org.sonatype.aether.transfer.NoRepositoryConnectorException)1 DefaultRequestTrace (org.sonatype.aether.util.DefaultRequestTrace)1