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