Search in sources :

Example 16 with ArtifactDownload

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

the class ResumeGetTest method testResumeInterruptedDownloadUsingRangeRequests.

@Test
public void testResumeInterruptedDownloadUsingRangeRequests() throws Exception {
    FlakyHandler flakyHandler = new FlakyHandler(4);
    server.setHandler(flakyHandler);
    server.start();
    File file = TestFileUtils.createTempFile("");
    file.delete();
    ArtifactDownload download = new ArtifactDownload(artifact, "", file, RepositoryPolicy.CHECKSUM_POLICY_IGNORE);
    RemoteRepository repo = new RemoteRepository("test", "default", url());
    RepositoryConnector connector = factory.newInstance(session, repo);
    try {
        connector.get(Arrays.asList(download), null);
    } finally {
        connector.close();
    }
    assertNull(String.valueOf(download.getException()), download.getException());
    assertTrue("Missing " + file.getAbsolutePath(), file.isFile());
    assertEquals("Bad size of " + file.getAbsolutePath(), flakyHandler.totalSize, file.length());
    assertContentPattern(file);
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) File(java.io.File) Test(org.junit.Test)

Example 17 with ArtifactDownload

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

Example 18 with ArtifactDownload

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

the class ArtifactWorkerTest method downloadArtifact.

private File downloadArtifact(DefaultArtifact artifact) throws IOException, ArtifactTransferException {
    File file = TestFileUtils.createTempFile("");
    ArtifactDownload down = new ArtifactDownload(artifact, "", file, "");
    down.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_FAIL);
    FileRepositoryWorker worker = new FileRepositoryWorker(down, repository, session);
    worker.setFileProcessor(TestFileProcessor.INSTANCE);
    worker.run();
    if (down.getException() != null) {
        throw down.getException();
    }
    return file;
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) File(java.io.File)

Example 19 with ArtifactDownload

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

the class WagonRepositoryConnector method get.

public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
    if (closed) {
        throw new IllegalStateException("connector closed");
    }
    artifactDownloads = safe(artifactDownloads);
    metadataDownloads = safe(metadataDownloads);
    Collection<GetTask<?>> tasks = new ArrayList<GetTask<?>>();
    RunnableErrorForwarder errorForwarder = new RunnableErrorForwarder();
    for (MetadataDownload download : metadataDownloads) {
        String resource = layout.getPath(download.getMetadata()).getPath();
        GetTask<?> task = new GetTask<MetadataTransfer>(resource, download.getFile(), download.getChecksumPolicy(), download, METADATA);
        tasks.add(task);
        executor.execute(errorForwarder.wrap(task));
    }
    for (ArtifactDownload download : artifactDownloads) {
        String resource = layout.getPath(download.getArtifact()).getPath();
        GetTask<?> task = new GetTask<ArtifactTransfer>(resource, download.isExistenceCheck() ? null : download.getFile(), download.getChecksumPolicy(), download, ARTIFACT);
        tasks.add(task);
        executor.execute(errorForwarder.wrap(task));
    }
    errorForwarder.await();
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) ArrayList(java.util.ArrayList) RunnableErrorForwarder(org.sonatype.aether.util.concurrency.RunnableErrorForwarder) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload)

Example 20 with ArtifactDownload

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

the class TimeoutTest method testRequestTimeout.

@Test(timeout = 3000)
public void testRequestTimeout() throws Exception {
    Map<String, Object> configProps = new HashMap<String, Object>();
    configProps.put(ConfigurationProperties.CONNECT_TIMEOUT, "60000");
    configProps.put(ConfigurationProperties.REQUEST_TIMEOUT, "1000");
    session().setConfigProperties(configProps);
    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);
    assertNotNull(down.getException());
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) HashMap(java.util.HashMap) 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