Search in sources :

Example 1 with ArtifactNotFoundException

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

the class DefaultArtifactResolverTest method testResolveLocalArtifactUnsuccessful.

@Test
public void testResolveLocalArtifactUnsuccessful() throws IOException, ArtifactResolutionException {
    File tmpFile = TestFileUtils.createTempFile("tmp");
    Map<String, String> properties = new HashMap<String, String>();
    properties.put(ArtifactProperties.LOCAL_PATH, tmpFile.getAbsolutePath());
    artifact = artifact.setProperties(properties);
    tmpFile.delete();
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    try {
        resolver.resolveArtifact(session, request);
        fail("expected exception");
    } catch (ArtifactResolutionException e) {
        assertNotNull(e.getResults());
        assertEquals(1, e.getResults().size());
        ArtifactResult result = e.getResults().get(0);
        assertSame(request, result.getRequest());
        assertFalse(result.getExceptions().isEmpty());
        assertTrue(result.getExceptions().get(0) instanceof ArtifactNotFoundException);
        Artifact resolved = result.getArtifact();
        assertNull(resolved);
    }
}
Also used : ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) HashMap(java.util.HashMap) File(java.io.File) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) Test(org.junit.Test)

Example 2 with ArtifactNotFoundException

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

the class DefaultUpdateCheckManagerTest method testCheckArtifactNotFoundInRepoCachingDisabled.

@Test
public void testCheckArtifactNotFoundInRepoCachingDisabled() throws Exception {
    artifact.getFile().delete();
    session.setNotFoundCachingEnabled(false);
    UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
    check.setException(new ArtifactNotFoundException(artifact, repository));
    manager.touchArtifact(session, check);
    resetSessionData(session);
    // ! file.exists && ! updateRequired -> artifact not found in remote repo
    check = newArtifactCheck().setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
    manager.checkArtifact(session, check);
    assertEquals(true, check.isRequired());
    assertNull(check.getException());
}
Also used : ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 3 with ArtifactNotFoundException

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

the class DefaultUpdateCheckManagerTest method testCheckArtifactNotFoundInRepoCachingEnabled.

@Test
public void testCheckArtifactNotFoundInRepoCachingEnabled() throws Exception {
    artifact.getFile().delete();
    session.setNotFoundCachingEnabled(true);
    UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
    check.setException(new ArtifactNotFoundException(artifact, repository));
    manager.touchArtifact(session, check);
    resetSessionData(session);
    // ! file.exists && ! updateRequired -> artifact not found in remote repo
    check = newArtifactCheck().setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
    manager.checkArtifact(session, check);
    assertEquals(false, check.isRequired());
    assertTrue(check.getException() instanceof ArtifactNotFoundException);
}
Also used : ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 4 with ArtifactNotFoundException

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

Example 5 with ArtifactNotFoundException

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

Aggregations

ArtifactNotFoundException (org.sonatype.aether.transfer.ArtifactNotFoundException)9 Test (org.junit.Test)7 ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)7 Artifact (org.sonatype.aether.artifact.Artifact)6 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)6 File (java.io.File)5 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)5 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)5 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)5 ArtifactResolutionException (org.sonatype.aether.resolution.ArtifactResolutionException)5 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)5 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)4 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)4 Collection (java.util.Collection)3 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)3 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1