Search in sources :

Example 6 with ArtifactTransferException

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

the class DefaultUpdateCheckManagerTest method testCheckArtifactErrorFromRepoCachingDisabled.

@Test
public void testCheckArtifactErrorFromRepoCachingDisabled() throws Exception {
    artifact.getFile().delete();
    UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
    check.setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
    check.setException(new ArtifactTransferException(artifact, repository, "some error"));
    manager.touchArtifact(session, check);
    resetSessionData(session);
    // ! file.exists && ! updateRequired && previousError -> depends on transfer error caching
    check = newArtifactCheck();
    session.setTransferErrorCachingEnabled(false);
    manager.checkArtifact(session, check);
    assertEquals(true, check.isRequired());
    assertNull(check.getException());
}
Also used : ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 7 with ArtifactTransferException

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

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

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

the class RecordingRepositoryConnector method put.

public void put(Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads) {
    if (artifactUploads != null) {
        for (ArtifactUpload artifactUpload : artifactUploads) {
            // mimic "real" connector
            artifactUpload.setState(State.ACTIVE);
            if (artifactUpload.getFile() == null) {
                artifactUpload.setException(new ArtifactTransferException(artifactUpload.getArtifact(), null, "no file"));
            }
            this.actualPut.add(artifactUpload.getArtifact());
            artifactUpload.setState(State.DONE);
        }
    }
    if (metadataUploads != null) {
        for (MetadataUpload metadataUpload : metadataUploads) {
            // mimic "real" connector
            metadataUpload.setState(State.ACTIVE);
            if (metadataUpload.getFile() == null) {
                metadataUpload.setException(new MetadataTransferException(metadataUpload.getMetadata(), null, "no file"));
            }
            this.actualPutMD.add(metadataUpload.getMetadata());
            metadataUpload.setState(State.DONE);
        }
    }
}
Also used : ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) MetadataTransferException(org.sonatype.aether.transfer.MetadataTransferException)

Example 10 with ArtifactTransferException

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

the class PutTest method testArtifactWithZeroBytesFile.

@Test
@Ignore("https://issues.sonatype.org/browse/AHC-5")
public void testArtifactWithZeroBytesFile() throws Exception {
    String content = "";
    addExpectation("gid/aid/version/aid-version-classifier.extension", content);
    addExpectation("gid/aid/version/aid-version-classifier.extension.sha1", sha1(content));
    addExpectation("gid/aid/version/aid-version-classifier.extension.md5", md5(content));
    Artifact artifact = artifact(content);
    ArtifactUpload up = new ArtifactUpload(artifact, artifact.getFile());
    List<ArtifactUpload> uploads = Arrays.asList(up);
    connector().put(uploads, null);
    ArtifactTransferException ex = up.getException();
    assertNull(ex != null ? ex.getMessage() : "", ex);
    assertExpectations();
}
Also used : ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) Artifact(org.sonatype.aether.artifact.Artifact) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)16 Test (org.junit.Test)12 Artifact (org.sonatype.aether.artifact.Artifact)12 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)9 ArtifactNotFoundException (org.sonatype.aether.transfer.ArtifactNotFoundException)7 File (java.io.File)4 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)4 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)4 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)4 ArtifactResolutionException (org.sonatype.aether.resolution.ArtifactResolutionException)4 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)4 Collection (java.util.Collection)3 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)3 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)3 ArtifactUpload (org.sonatype.aether.spi.connector.ArtifactUpload)3 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)3 IOException (java.io.IOException)2 Calendar (java.util.Calendar)2 MetadataTransferException (org.sonatype.aether.transfer.MetadataTransferException)2 FileNotFoundException (java.io.FileNotFoundException)1