Search in sources :

Example 1 with MetadataUpload

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

the class AsyncRepositoryConnector method put.

/**
     * Use the async http client library to upload artifacts and metadata.
     *
     * @param artifactUploads The artifact uploads to perform, may be {@code null} or empty.
     * @param metadataUploads The metadata uploads to perform, may be {@code null} or empty.
     */
public void put(Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads) {
    if (closed.get()) {
        throw new IllegalStateException("connector closed");
    }
    artifactUploads = safe(artifactUploads);
    metadataUploads = safe(metadataUploads);
    CountDownLatch latch = new CountDownLatch(artifactUploads.size() + metadataUploads.size());
    Collection<PutTask<?>> tasks = new ArrayList<PutTask<?>>();
    for (ArtifactUpload upload : artifactUploads) {
        String path = layout.getPath(upload.getArtifact()).getPath();
        PutTask<?> task = new PutTask<ArtifactTransfer>(path, upload.getFile(), latch, upload, ARTIFACT);
        tasks.add(task);
        task.run();
    }
    for (MetadataUpload upload : metadataUploads) {
        String path = layout.getPath(upload.getMetadata()).getPath();
        PutTask<?> task = new PutTask<MetadataTransfer>(path, upload.getFile(), latch, upload, METADATA);
        tasks.add(task);
        task.run();
    }
    await(latch);
    for (PutTask<?> task : tasks) {
        task.flush();
    }
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) ArrayList(java.util.ArrayList) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with MetadataUpload

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

the class PutTest method testMetadataWithZeroBytesFile.

@Test
@Ignore("https://issues.sonatype.org/browse/AHC-5")
public void testMetadataWithZeroBytesFile() throws Exception {
    String content = "";
    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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with MetadataUpload

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

the class TransferEventTester method testFailedTransferEvents.

/**
     * Test the order of events and their properties for the unsuccessful up- and download of artifact and metadata.
     * Failure is triggered by setting the file to transfer to {@code null} for uploads, and asking for a non-existent
     * item for downloads.
     */
public static void testFailedTransferEvents(RepositoryConnectorFactory factory, TestRepositorySystemSession session, RemoteRepository repository) throws NoRepositoryConnectorException, IOException {
    RecordingTransferListener listener = new RecordingTransferListener(session.getTransferListener());
    session.setTransferListener(listener);
    RepositoryConnector connector = factory.newInstance(session, repository);
    byte[] pattern = "tmpFile".getBytes("us-ascii");
    File tmpFile = TestFileUtils.createTempFile(pattern, 10000);
    Collection<ArtifactUpload> artUps = ConnectorTestUtils.createTransfers(ArtifactUpload.class, 1, null);
    Collection<ArtifactDownload> artDowns = ConnectorTestUtils.createTransfers(ArtifactDownload.class, 1, tmpFile);
    Collection<MetadataUpload> metaUps = ConnectorTestUtils.createTransfers(MetadataUpload.class, 1, null);
    Collection<MetadataDownload> metaDowns = ConnectorTestUtils.createTransfers(MetadataDownload.class, 1, tmpFile);
    connector.put(artUps, null);
    LinkedList<TransferEvent> events = new LinkedList<TransferEvent>(listener.getEvents());
    checkFailedEvents(events, null);
    listener.clear();
    connector.get(artDowns, null);
    events = new LinkedList<TransferEvent>(listener.getEvents());
    checkFailedEvents(events, null);
    listener.clear();
    connector.put(null, metaUps);
    events = new LinkedList<TransferEvent>(listener.getEvents());
    checkFailedEvents(events, null);
    listener.clear();
    connector.get(null, metaDowns);
    events = new LinkedList<TransferEvent>(listener.getEvents());
    checkFailedEvents(events, null);
    connector.close();
    session.setTransferListener(null);
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) TransferEvent(org.sonatype.aether.transfer.TransferEvent) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) RecordingTransferListener(org.sonatype.aether.test.impl.RecordingTransferListener) LinkedList(java.util.LinkedList) ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) File(java.io.File)

Example 4 with MetadataUpload

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

the class ConnectorTestSuite method testTransferZeroBytesFile.

/**
     * See https://issues.sonatype.org/browse/AETHER-8
     */
@Test
public void testTransferZeroBytesFile() throws IOException, NoRepositoryConnectorException {
    File emptyFile = TestFileUtils.createTempFile("");
    Artifact artifact = new StubArtifact("gid:aid:ext:ver");
    ArtifactUpload upA = new ArtifactUpload(artifact, emptyFile);
    File dir = TestFileUtils.createTempDir("con-test");
    File downAFile = new File(dir, "downA.file");
    downAFile.deleteOnExit();
    ArtifactDownload downA = new ArtifactDownload(artifact, "", downAFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
    Metadata metadata = new StubMetadata("gid", "aid", "ver", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
    MetadataUpload upM = new MetadataUpload(metadata, emptyFile);
    File downMFile = new File(dir, "downM.file");
    downMFile.deleteOnExit();
    MetadataDownload downM = new MetadataDownload(metadata, "", downMFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
    RepositoryConnector connector = factory().newInstance(session, repository);
    connector.put(Arrays.asList(upA), Arrays.asList(upM));
    connector.get(Arrays.asList(downA), Arrays.asList(downM));
    assertNull(String.valueOf(upA.getException()), upA.getException());
    assertNull(String.valueOf(upM.getException()), upM.getException());
    assertNull(String.valueOf(downA.getException()), downA.getException());
    assertNull(String.valueOf(downM.getException()), downM.getException());
    assertEquals(0, downAFile.length());
    assertEquals(0, downMFile.length());
    connector.close();
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) Metadata(org.sonatype.aether.metadata.Metadata) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) File(java.io.File) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 5 with MetadataUpload

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

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