Search in sources :

Example 6 with MetadataUpload

use of org.sonatype.aether.spi.connector.MetadataUpload in project sonatype-aether by sonatype.

the class ConnectorTestSuite method testMkdirConcurrencyBug.

@Test
public void testMkdirConcurrencyBug() throws IOException, NoRepositoryConnectorException {
    RepositoryConnector connector = factory().newInstance(session, repository);
    File artifactFile = TestFileUtils.createTempFile("mkdirsBug0");
    File metadataFile = TestFileUtils.createTempFile("mkdirsBug1");
    int numTransfers = 2;
    ArtifactUpload[] artUps = new ArtifactUpload[numTransfers];
    MetadataUpload[] metaUps = new MetadataUpload[numTransfers];
    for (int i = 0; i < numTransfers; i++) {
        StubArtifact art = new StubArtifact("testGroup", "testArtifact", "", "jar", i + "-test");
        StubMetadata meta = new StubMetadata("testGroup", "testArtifact", i + "-test", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
        ArtifactUpload artUp = new ArtifactUpload(art, artifactFile);
        MetadataUpload metaUp = new MetadataUpload(meta, metadataFile);
        artUps[i] = artUp;
        metaUps[i] = metaUp;
    }
    connector.put(Arrays.asList(artUps), null);
    connector.put(null, Arrays.asList(metaUps));
    File localRepo = session.getLocalRepository().getBasedir();
    StringBuilder localPath = new StringBuilder(localRepo.getAbsolutePath());
    for (int i = 0; i < 50; i++) {
        localPath.append("/d");
    }
    ArtifactDownload[] artDowns = new ArtifactDownload[numTransfers];
    MetadataDownload[] metaDowns = new MetadataDownload[numTransfers];
    for (int m = 0; m < 20; m++) {
        for (int i = 0; i < numTransfers; i++) {
            File artFile = new File(localPath.toString() + "/a" + i);
            File metaFile = new File(localPath.toString() + "/m" + i);
            StubArtifact art = new StubArtifact("testGroup", "testArtifact", "", "jar", i + "-test");
            StubMetadata meta = new StubMetadata("testGroup", "testArtifact", i + "-test", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
            ArtifactDownload artDown = new ArtifactDownload(art, null, artFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
            MetadataDownload metaDown = new MetadataDownload(meta, null, metaFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
            artDowns[i] = artDown;
            metaDowns[i] = metaDown;
        }
        connector.get(Arrays.asList(artDowns), Arrays.asList(metaDowns));
        for (int j = 0; j < numTransfers; j++) {
            ArtifactDownload artDown = artDowns[j];
            MetadataDownload metaDown = metaDowns[j];
            assertNull("artifact download had exception: " + artDown.getException(), artDown.getException());
            assertNull("metadata download had exception: " + metaDown.getException(), metaDown.getException());
            assertEquals(State.DONE, artDown.getState());
            assertEquals(State.DONE, metaDown.getState());
        }
        TestFileUtils.delete(localRepo);
    }
    connector.close();
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) File(java.io.File) Test(org.junit.Test)

Example 7 with MetadataUpload

use of org.sonatype.aether.spi.connector.MetadataUpload in project sonatype-aether by sonatype.

the class ConnectorTestUtils method createTransfers.

/**
     * Creates transfer objects according to the given class. If the file parameter is {@code null}, a new temporary
     * file will be created for downloads. Uploads will just use the parameter as it is.
     */
public static <T extends Transfer> List<T> createTransfers(Class<T> cls, int count, File file) {
    ArrayList<T> ret = new ArrayList<T>();
    Object item;
    if (ArtifactTransfer.class.isAssignableFrom(cls)) {
        item = new StubArtifact("testGroup", "testArtifact", "sources", "jar", "will be replaced");
    } else {
        item = new StubMetadata("testGroup", "testArtifact", "will be replaced", "jar", Metadata.Nature.RELEASE_OR_SNAPSHOT, file);
    }
    for (int i = 0; i < count; i++) {
        String context = null;
        String checksumPolicy = RepositoryPolicy.CHECKSUM_POLICY_IGNORE;
        Object obj = null;
        if (cls.isAssignableFrom(ArtifactUpload.class)) {
            Artifact artifact = ((Artifact) item).setVersion((i + 1) + "-test");
            obj = new ArtifactUpload(artifact, file);
        } else if (cls.isAssignableFrom(ArtifactDownload.class)) {
            try {
                Artifact artifact = ((Artifact) item).setVersion((i + 1) + "-test");
                obj = new ArtifactDownload(artifact, context, safeFile(file), checksumPolicy);
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        } else if (cls.isAssignableFrom(MetadataUpload.class)) {
            Metadata metadata = ((StubMetadata) item).setVersion((i + 1) + "-test");
            obj = new MetadataUpload(metadata, file);
        } else if (cls.isAssignableFrom(MetadataDownload.class)) {
            try {
                Metadata metadata = ((StubMetadata) item).setVersion((i + 1) + "-test");
                obj = new MetadataDownload(metadata, context, safeFile(file), checksumPolicy);
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
        ret.add(cls.cast(obj));
    }
    return ret;
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) ArrayList(java.util.ArrayList) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) Metadata(org.sonatype.aether.metadata.Metadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) IOException(java.io.IOException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload)

Example 8 with MetadataUpload

use of org.sonatype.aether.spi.connector.MetadataUpload 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 9 with MetadataUpload

use of org.sonatype.aether.spi.connector.MetadataUpload in project sonatype-aether by sonatype.

the class PutTest method testMetadataUpload.

@Test
public void testMetadataUpload() throws Exception {
    String content = "metadata";
    addExpectation("gid/aid/version/maven-metadata.xml", content);
    addExpectation("gid/aid/version/maven-metadata.xml.sha1", sha1(content));
    addExpectation("gid/aid/version/maven-metadata.xml.md5", md5(content));
    Metadata metadata = metadata(content);
    List<MetadataUpload> uploads = Arrays.asList(new MetadataUpload(metadata, metadata.getFile()));
    connector().put(null, uploads);
    assertExpectations();
}
Also used : Metadata(org.sonatype.aether.metadata.Metadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) Test(org.junit.Test)

Example 10 with MetadataUpload

use of org.sonatype.aether.spi.connector.MetadataUpload in project sonatype-aether by sonatype.

the class PutTest method testCloseAfterMetadataUpload.

@Test
public void testCloseAfterMetadataUpload() throws Exception {
    Metadata metadata = metadata("metadata");
    List<MetadataUpload> uploads = Arrays.asList(new MetadataUpload(metadata, metadata.getFile()));
    connector().put(null, uploads);
    connector().close();
}
Also used : Metadata(org.sonatype.aether.metadata.Metadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) Test(org.junit.Test)

Aggregations

MetadataUpload (org.sonatype.aether.spi.connector.MetadataUpload)18 ArtifactUpload (org.sonatype.aether.spi.connector.ArtifactUpload)13 Test (org.junit.Test)10 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)9 File (java.io.File)8 Metadata (org.sonatype.aether.metadata.Metadata)8 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)8 RepositoryConnector (org.sonatype.aether.spi.connector.RepositoryConnector)8 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)5 StubMetadata (org.sonatype.aether.test.util.impl.StubMetadata)5 Artifact (org.sonatype.aether.artifact.Artifact)4 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)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 CountDownLatch (java.util.concurrent.CountDownLatch)1 Ignore (org.junit.Ignore)1