Search in sources :

Example 1 with ArtifactDownload

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

the class AsyncRepositoryConnector method get.

/**
     * Use the async http client library to download artifacts and metadata.
     *
     * @param artifactDownloads The artifact downloads to perform, may be {@code null} or empty.
     * @param metadataDownloads The metadata downloads to perform, may be {@code null} or empty.
     */
public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
    if (closed.get()) {
        throw new IllegalStateException("connector closed");
    }
    artifactDownloads = safe(artifactDownloads);
    metadataDownloads = safe(metadataDownloads);
    CountDownLatch latch = new CountDownLatch(artifactDownloads.size() + metadataDownloads.size());
    Collection<GetTask<?>> tasks = new ArrayList<GetTask<?>>();
    for (MetadataDownload download : metadataDownloads) {
        String resource = layout.getPath(download.getMetadata()).getPath();
        GetTask<?> task = new GetTask<MetadataTransfer>(resource, download.getFile(), download.getChecksumPolicy(), latch, download, METADATA, false);
        tasks.add(task);
        task.run();
    }
    for (ArtifactDownload download : artifactDownloads) {
        String resource = layout.getPath(download.getArtifact()).getPath();
        GetTask<?> task = new GetTask<ArtifactTransfer>(resource, download.isExistenceCheck() ? null : download.getFile(), download.getChecksumPolicy(), latch, download, ARTIFACT, true);
        tasks.add(task);
        task.run();
    }
    await(latch);
    for (GetTask<?> task : tasks) {
        task.flush();
    }
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) ArrayList(java.util.ArrayList) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with ArtifactDownload

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

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

the class GetTest method testCloseAfterArtifactDownload.

@Test
public void testCloseAfterArtifactDownload() throws Exception {
    File f = TestFileUtils.createTempFile("");
    Artifact a = artifact("foo");
    ArtifactDownload down = new ArtifactDownload(a, null, f, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
    Collection<? extends ArtifactDownload> downs = Arrays.asList(down);
    connector().get(downs, null);
    connector().close();
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) File(java.io.File) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 4 with ArtifactDownload

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

the class GetTest method testDownloadArtifactWithWait.

@Test
public void testDownloadArtifactWithWait() throws Exception {
    addDelivery("gid/aid/version/aid-version-classifier.extension", "artifact");
    addDelivery("gid/aid/version/aid-version-classifier.extension.sha1", sha1("artifact"));
    addDelivery("gid/aid/version/aid-version-classifier.extension.md5", md5("artifact"));
    File f = TestFileUtils.createTempFile("");
    Artifact a = artifact("foo");
    ArtifactDownload down = new ArtifactDownload(a, null, f, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
    Collection<? extends ArtifactDownload> downs = Arrays.asList(down);
    connector().get(downs, null);
    assertNull(String.valueOf(down.getException()), down.getException());
    TestFileUtils.assertContent("foo", a.getFile());
    TestFileUtils.assertContent("artifact", f);
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) File(java.io.File) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 5 with ArtifactDownload

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

the class GetTest method testDownloadArtifactWhoseSizeExceedsMaxHeapSize.

@Test
public void testDownloadArtifactWhoseSizeExceedsMaxHeapSize() throws Exception {
    long bytes = Runtime.getRuntime().maxMemory() * 5 / 4;
    generate.addContent("gid/aid/version/aid-version-classifier.extension", bytes);
    File f = TestFileUtils.createTempFile("");
    Artifact a = artifact();
    ArtifactDownload down = new ArtifactDownload(a, null, f, RepositoryPolicy.CHECKSUM_POLICY_IGNORE);
    connector().get(Arrays.asList(down), null);
    connector().close();
    assertEquals(bytes, f.length());
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) File(java.io.File) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Aggregations

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