Search in sources :

Example 1 with ArtifactUpload

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;
}
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)

Example 2 with ArtifactUpload

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();
    }
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload)

Example 3 with ArtifactUpload

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();
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) RunnableErrorForwarder(org.sonatype.aether.util.concurrency.RunnableErrorForwarder)

Example 4 with ArtifactUpload

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();
    }
}
Also used : RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) SysoutLogger(org.sonatype.aether.test.impl.SysoutLogger) ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) TestFileProcessor(org.sonatype.aether.test.impl.TestFileProcessor) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) File(java.io.File) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException) Test(org.junit.Test)

Example 5 with ArtifactUpload

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();
    }
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) File(java.io.File)

Aggregations

ArtifactUpload (org.sonatype.aether.spi.connector.ArtifactUpload)18 MetadataUpload (org.sonatype.aether.spi.connector.MetadataUpload)13 File (java.io.File)9 Test (org.junit.Test)9 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)9 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)8 RepositoryConnector (org.sonatype.aether.spi.connector.RepositoryConnector)8 Artifact (org.sonatype.aether.artifact.Artifact)7 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)6 StubMetadata (org.sonatype.aether.test.util.impl.StubMetadata)5 Metadata (org.sonatype.aether.metadata.Metadata)4 ArrayList (java.util.ArrayList)3 ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)3 LinkedList (java.util.LinkedList)2 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)2 RecordingTransferListener (org.sonatype.aether.test.impl.RecordingTransferListener)2 TransferEvent (org.sonatype.aether.transfer.TransferEvent)2 IOException (java.io.IOException)1 MessageDigest (java.security.MessageDigest)1 IdentityHashMap (java.util.IdentityHashMap)1