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