Search in sources :

Example 6 with MetadataDownload

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

the class ConnectorTestSuite method testFileHandleLeakage.

@Test
public void testFileHandleLeakage() throws IOException, NoRepositoryConnectorException {
    StubArtifact artifact = new StubArtifact("testGroup", "testArtifact", "", "jar", "1-test");
    StubMetadata metadata = new StubMetadata("testGroup", "testArtifact", "1-test", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
    RepositoryConnector connector = factory().newInstance(session, repository);
    File tmpFile = TestFileUtils.createTempFile("testFileHandleLeakage");
    ArtifactUpload artUp = new ArtifactUpload(artifact, tmpFile);
    connector.put(Arrays.asList(artUp), null);
    assertTrue("Leaking file handle in artifact upload", tmpFile.delete());
    tmpFile = TestFileUtils.createTempFile("testFileHandleLeakage");
    MetadataUpload metaUp = new MetadataUpload(metadata, tmpFile);
    connector.put(null, Arrays.asList(metaUp));
    assertTrue("Leaking file handle in metadata upload", tmpFile.delete());
    tmpFile = TestFileUtils.createTempFile("testFileHandleLeakage");
    ArtifactDownload artDown = new ArtifactDownload(artifact, null, tmpFile, null);
    connector.get(Arrays.asList(artDown), null);
    new File(tmpFile.getAbsolutePath() + ".sha1").deleteOnExit();
    assertTrue("Leaking file handle in artifact download", tmpFile.delete());
    tmpFile = TestFileUtils.createTempFile("testFileHandleLeakage");
    MetadataDownload metaDown = new MetadataDownload(metadata, null, tmpFile, null);
    connector.get(null, Arrays.asList(metaDown));
    new File(tmpFile.getAbsolutePath() + ".sha1").deleteOnExit();
    assertTrue("Leaking file handle in metadata download", tmpFile.delete());
    connector.close();
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) File(java.io.File) Test(org.junit.Test)

Example 7 with MetadataDownload

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

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

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

the class RecordingRepositoryConnector method get.

public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
    try {
        if (artifactDownloads != null) {
            for (ArtifactDownload artifactDownload : artifactDownloads) {
                artifactDownload.setState(State.ACTIVE);
                Artifact artifact = artifactDownload.getArtifact();
                this.actualGet.add(artifact);
                TestFileUtils.write(artifact.toString(), artifactDownload.getFile());
                artifactDownload.setState(State.DONE);
            }
        }
        if (metadataDownloads != null) {
            for (MetadataDownload metadataDownload : metadataDownloads) {
                metadataDownload.setState(State.ACTIVE);
                Metadata metadata = metadataDownload.getMetadata();
                this.actualGetMD.add(metadata);
                TestFileUtils.write(metadata.toString(), metadataDownload.getFile());
                metadataDownload.setState(State.DONE);
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException("Cannot create temporary file", e);
    }
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) Metadata(org.sonatype.aether.metadata.Metadata) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) IOException(java.io.IOException) Artifact(org.sonatype.aether.artifact.Artifact)

Example 10 with MetadataDownload

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

the class FileRepositoryConnector method get.

public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
    checkClosed();
    artifactDownloads = notNull(artifactDownloads);
    metadataDownloads = notNull(metadataDownloads);
    RunnableErrorForwarder errorForwarder = new RunnableErrorForwarder();
    for (ArtifactDownload artifactDownload : artifactDownloads) {
        FileRepositoryWorker worker = new FileRepositoryWorker(artifactDownload, repository, session);
        worker.setLogger(logger);
        worker.setFileProcessor(fileProcessor);
        executor.execute(errorForwarder.wrap(worker));
    }
    for (MetadataDownload metadataDownload : metadataDownloads) {
        FileRepositoryWorker worker = new FileRepositoryWorker(metadataDownload, repository, session);
        worker.setLogger(logger);
        worker.setFileProcessor(fileProcessor);
        executor.execute(errorForwarder.wrap(worker));
    }
    errorForwarder.await();
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) RunnableErrorForwarder(org.sonatype.aether.util.concurrency.RunnableErrorForwarder) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload)

Aggregations

MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)19 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)15 File (java.io.File)12 Test (org.junit.Test)11 MetadataUpload (org.sonatype.aether.spi.connector.MetadataUpload)9 ArtifactUpload (org.sonatype.aether.spi.connector.ArtifactUpload)8 RepositoryConnector (org.sonatype.aether.spi.connector.RepositoryConnector)8 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)7 Artifact (org.sonatype.aether.artifact.Artifact)6 Metadata (org.sonatype.aether.metadata.Metadata)5 StubMetadata (org.sonatype.aether.test.util.impl.StubMetadata)5 IOException (java.io.IOException)4 ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)3 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)3 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)3 ArtifactResolutionException (org.sonatype.aether.resolution.ArtifactResolutionException)3 ArtifactNotFoundException (org.sonatype.aether.transfer.ArtifactNotFoundException)3