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();
}
}
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();
}
}
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();
}
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);
}
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());
}
Aggregations