Search in sources :

Example 1 with MetadataDownload

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

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

the class DefaultMetadataResolverTest method testRemoveMetadataIfMissing.

@Test
public void testRemoveMetadataIfMissing() throws IOException {
    connector = new RecordingRepositoryConnector() {

        @Override
        public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
            super.get(artifactDownloads, metadataDownloads);
            for (MetadataDownload d : metadataDownloads) {
                d.setException(new MetadataNotFoundException(metadata, repository));
            }
        }
    };
    manager.setConnector(connector);
    File file = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, repository, ""));
    TestFileUtils.write(file.getAbsolutePath(), file);
    metadata.setFile(file);
    MetadataRequest request = new MetadataRequest(metadata, repository, "");
    request.setDeleteLocalCopyIfMissing(true);
    List<MetadataResult> results = resolver.resolveMetadata(session, Arrays.asList(request));
    assertEquals(1, results.size());
    MetadataResult result = results.get(0);
    assertNotNull(result.getException());
    assertEquals(false, file.exists());
}
Also used : MetadataNotFoundException(org.sonatype.aether.transfer.MetadataNotFoundException) MetadataRequest(org.sonatype.aether.resolution.MetadataRequest) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) File(java.io.File) MetadataResult(org.sonatype.aether.resolution.MetadataResult) Test(org.junit.Test)

Example 3 with MetadataDownload

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

the class DefaultDeployerTest method testStaleLocalMetadataCopyGetsDeletedBeforeMergeWhenMetadataIsNotCurrentlyPresentInRemoteRepo.

@Test
public void testStaleLocalMetadataCopyGetsDeletedBeforeMergeWhenMetadataIsNotCurrentlyPresentInRemoteRepo() throws Exception {
    MergeableMetadata metadata = new MergeableMetadata() {

        public Metadata setFile(File file) {
            return this;
        }

        public String getVersion() {
            return "";
        }

        public String getType() {
            return "test.properties";
        }

        public Nature getNature() {
            return Nature.RELEASE;
        }

        public String getGroupId() {
            return "org";
        }

        public File getFile() {
            return null;
        }

        public String getArtifactId() {
            return "aether";
        }

        public void merge(File current, File result) throws RepositoryException {
            Properties props = new Properties();
            try {
                if (current.isFile()) {
                    TestFileUtils.read(props, current);
                }
                props.setProperty("new", "value");
                TestFileUtils.write(props, result);
            } catch (IOException e) {
                throw new RepositoryException(e.getMessage(), e);
            }
        }

        public boolean isMerged() {
            return false;
        }
    };
    manager.setConnector(new RepositoryConnector() {

        public void put(Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads) {
        }

        public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
            if (metadataDownloads != null) {
                for (MetadataDownload download : metadataDownloads) {
                    download.setException(new MetadataNotFoundException(download.getMetadata(), null, null));
                }
            }
        }

        public void close() {
        }
    });
    request.addMetadata(metadata);
    File metadataFile = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, request.getRepository(), ""));
    Properties props = new Properties();
    props.setProperty("old", "value");
    TestFileUtils.write(props, metadataFile);
    deployer.deploy(session, request);
    props = new Properties();
    TestFileUtils.read(props, metadataFile);
    assertNull(props.toString(), props.get("old"));
}
Also used : MetadataNotFoundException(org.sonatype.aether.transfer.MetadataNotFoundException) MergeableMetadata(org.sonatype.aether.metadata.MergeableMetadata) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) RepositoryException(org.sonatype.aether.RepositoryException) IOException(java.io.IOException) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 4 with MetadataDownload

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

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

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