Search in sources :

Example 1 with MetadataNotFoundException

use of org.sonatype.aether.transfer.MetadataNotFoundException 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 2 with MetadataNotFoundException

use of org.sonatype.aether.transfer.MetadataNotFoundException 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 MetadataNotFoundException

use of org.sonatype.aether.transfer.MetadataNotFoundException in project sonatype-aether by sonatype.

the class DefaultUpdateCheckManagerTest method testCheckMetadataNotFoundInRepoCachingDisabled.

@Test
public void testCheckMetadataNotFoundInRepoCachingDisabled() throws Exception {
    metadata.getFile().delete();
    session.setNotFoundCachingEnabled(false);
    UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
    check.setException(new MetadataNotFoundException(metadata, repository, ""));
    manager.touchMetadata(session, check);
    resetSessionData(session);
    // ! file.exists && ! updateRequired -> artifact not found in remote repo
    // ignore NotFoundCaching-setting, don't check if update policy does not say so for metadata
    check.setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
    manager.checkMetadata(session, check);
    assertEquals(false, check.isRequired());
    assertTrue(check.getException() instanceof MetadataNotFoundException);
}
Also used : MetadataNotFoundException(org.sonatype.aether.transfer.MetadataNotFoundException) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) Metadata(org.sonatype.aether.metadata.Metadata) MetadataTransferException(org.sonatype.aether.transfer.MetadataTransferException) Test(org.junit.Test)

Example 4 with MetadataNotFoundException

use of org.sonatype.aether.transfer.MetadataNotFoundException in project sonatype-aether by sonatype.

the class DefaultUpdateCheckManagerTest method testCheckMetadataNotFoundInRepoCachingEnabled.

@Test
public void testCheckMetadataNotFoundInRepoCachingEnabled() throws Exception {
    metadata.getFile().delete();
    session.setNotFoundCachingEnabled(true);
    UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
    check.setException(new MetadataNotFoundException(metadata, repository, ""));
    manager.touchMetadata(session, check);
    resetSessionData(session);
    // ! file.exists && ! updateRequired -> artifact not found in remote repo
    check = newMetadataCheck().setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
    manager.checkMetadata(session, check);
    assertEquals(false, check.isRequired());
    assertNotNull(check.getException());
}
Also used : MetadataNotFoundException(org.sonatype.aether.transfer.MetadataNotFoundException) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) Metadata(org.sonatype.aether.metadata.Metadata) MetadataTransferException(org.sonatype.aether.transfer.MetadataTransferException) Test(org.junit.Test)

Example 5 with MetadataNotFoundException

use of org.sonatype.aether.transfer.MetadataNotFoundException in project sonatype-aether by sonatype.

the class FileRepositoryWorker method run.

/**
 * Do transfer according to {@link RepositoryConnector} specifications.
 *
 * @see FileRepositoryConnector
 */
public void run() {
    File target = null;
    long totalTransferred = -1;
    try {
        transfer.setState(State.ACTIVE);
        resource = newResource(transfer, repository);
        DefaultTransferEvent event = newEvent(transfer);
        catapult.fireInitiated(event);
        File baseDir = new File(PathUtils.basedir(repository.getUrl()));
        File localFile = transfer.getFile();
        File repoFile = new File(baseDir, transfer.getRelativePath());
        File src = null;
        switch(direction) {
            case UPLOAD:
                src = localFile;
                target = repoFile;
                break;
            case DOWNLOAD:
                src = repoFile;
                target = localFile;
                break;
        }
        if (transfer.isExistenceCheck()) {
            if (!src.exists()) {
                throw new FileNotFoundException(src.getAbsolutePath());
            }
        } else {
            File tmp = tmpfile(target);
            totalTransferred = copy(src, tmp);
            fileProcessor.move(tmp, target);
            switch(direction) {
                case UPLOAD:
                    writeChecksum(src, target.getPath());
                    break;
                case DOWNLOAD:
                    verifyChecksum(src);
                    break;
            }
        }
    } catch (FileNotFoundException e) {
        switch(transfer.getType()) {
            case ARTIFACT:
                ArtifactTransferException artEx;
                if (Direction.DOWNLOAD.equals(direction)) {
                    artEx = new ArtifactNotFoundException(transfer.getArtifact(), repository);
                } else {
                    artEx = new ArtifactTransferException(transfer.getArtifact(), repository, e);
                }
                transfer.setException(artEx);
                break;
            case METADATA:
                MetadataTransferException mdEx;
                if (Direction.DOWNLOAD.equals(direction)) {
                    mdEx = new MetadataNotFoundException(transfer.getMetadata(), repository);
                } else {
                    mdEx = new MetadataTransferException(transfer.getMetadata(), repository, e);
                }
                transfer.setException(mdEx);
                break;
        }
    } catch (Throwable t) {
        logger.debug(t.getMessage(), t);
        switch(transfer.getType()) {
            case ARTIFACT:
                transfer.setException(new ArtifactTransferException(transfer.getArtifact(), repository, t));
                break;
            case METADATA:
                transfer.setException(new MetadataTransferException(transfer.getMetadata(), repository, t));
                break;
        }
    } finally {
        transfer.setState(State.DONE);
        if (transfer.getException() == null) {
            DefaultTransferEvent event = newEvent(transfer);
            event.setTransferredBytes((int) totalTransferred);
            catapult.fireSucceeded(event);
        } else {
            // cleanup
            if (direction.equals(Direction.UPLOAD)) {
                for (String ext : checksumAlgos.values()) {
                    new File(target.getPath() + ext).delete();
                }
            }
            if (target != null) {
                target.delete();
            }
            DefaultTransferEvent event = newEvent(transfer);
            catapult.fireFailed(event);
        }
    }
}
Also used : MetadataNotFoundException(org.sonatype.aether.transfer.MetadataNotFoundException) ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) FileNotFoundException(java.io.FileNotFoundException) MetadataTransferException(org.sonatype.aether.transfer.MetadataTransferException) DefaultTransferEvent(org.sonatype.aether.util.listener.DefaultTransferEvent) File(java.io.File) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException)

Aggregations

MetadataNotFoundException (org.sonatype.aether.transfer.MetadataNotFoundException)7 File (java.io.File)5 MetadataTransferException (org.sonatype.aether.transfer.MetadataTransferException)5 Test (org.junit.Test)4 Metadata (org.sonatype.aether.metadata.Metadata)4 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)3 IOException (java.io.IOException)2 RepositoryException (org.sonatype.aether.RepositoryException)2 UpdateCheck (org.sonatype.aether.impl.UpdateCheck)2 MergeableMetadata (org.sonatype.aether.metadata.MergeableMetadata)2 LocalRepositoryManager (org.sonatype.aether.repository.LocalRepositoryManager)2 RepositoryPolicy (org.sonatype.aether.repository.RepositoryPolicy)2 MetadataRequest (org.sonatype.aether.resolution.MetadataRequest)2 MetadataResult (org.sonatype.aether.resolution.MetadataResult)2 StubMetadata (org.sonatype.aether.test.util.impl.StubMetadata)2 ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)2 NoRepositoryConnectorException (org.sonatype.aether.transfer.NoRepositoryConnectorException)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1