use of org.sonatype.aether.transfer.MetadataTransferException 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);
}
use of org.sonatype.aether.transfer.MetadataTransferException 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());
}
use of org.sonatype.aether.transfer.MetadataTransferException in project sonatype-aether by sonatype.
the class DefaultUpdateCheckManagerTest method testCheckMetadataUpdatePolicyRequired.
@Test
public void testCheckMetadataUpdatePolicyRequired() throws Exception {
UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
check.setLocalLastUpdated(cal.getTimeInMillis());
check.setPolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
manager.checkMetadata(session, check);
assertNull(check.getException());
assertTrue(check.isRequired());
check.setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
manager.checkMetadata(session, check);
assertNull(check.getException());
assertTrue(check.isRequired());
check.setPolicy(RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":60");
manager.checkMetadata(session, check);
assertNull(check.getException());
assertTrue(check.isRequired());
}
use of org.sonatype.aether.transfer.MetadataTransferException 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.MetadataTransferException in project sonatype-aether by sonatype.
the class DefaultDeployer method upload.
private void upload(Collection<MetadataUpload> metadataUploads, RepositorySystemSession session, Metadata metadata, RemoteRepository repository, RepositoryConnector connector, EventCatapult catapult) throws DeploymentException {
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
File basedir = lrm.getRepository().getBasedir();
File dstFile = new File(basedir, lrm.getPathForRemoteMetadata(metadata, repository, ""));
if (metadata instanceof MergeableMetadata) {
if (!((MergeableMetadata) metadata).isMerged()) {
{
DefaultRepositoryEvent event = new DefaultRepositoryEvent(EventType.METADATA_RESOLVING, session, catapult.getTrace());
event.setMetadata(metadata);
event.setRepository(repository);
repositoryEventDispatcher.dispatch(event);
event = new DefaultRepositoryEvent(EventType.METADATA_DOWNLOADING, session, catapult.getTrace());
event.setMetadata(metadata);
event.setRepository(repository);
repositoryEventDispatcher.dispatch(event);
}
RepositoryPolicy policy = getPolicy(session, repository, metadata.getNature());
MetadataDownload download = new MetadataDownload();
download.setMetadata(metadata);
download.setFile(dstFile);
download.setChecksumPolicy(policy.getChecksumPolicy());
connector.get(null, Arrays.asList(download));
Exception error = download.getException();
if (error instanceof MetadataNotFoundException) {
dstFile.delete();
}
{
DefaultRepositoryEvent event = new DefaultRepositoryEvent(EventType.METADATA_DOWNLOADED, session, catapult.getTrace());
event.setMetadata(metadata);
event.setRepository(repository);
event.setException(error);
event.setFile(dstFile);
repositoryEventDispatcher.dispatch(event);
event = new DefaultRepositoryEvent(EventType.METADATA_RESOLVED, session, catapult.getTrace());
event.setMetadata(metadata);
event.setRepository(repository);
event.setException(error);
event.setFile(dstFile);
repositoryEventDispatcher.dispatch(event);
}
if (error != null && !(error instanceof MetadataNotFoundException)) {
throw new DeploymentException("Failed to retrieve remote metadata " + metadata + ": " + error.getMessage(), error);
}
}
try {
((MergeableMetadata) metadata).merge(dstFile, dstFile);
} catch (RepositoryException e) {
throw new DeploymentException("Failed to update metadata " + metadata + ": " + e.getMessage(), e);
}
} else {
if (metadata.getFile() == null) {
throw new DeploymentException("Failed to update metadata " + metadata + ": No file attached.");
}
try {
fileProcessor.copy(metadata.getFile(), dstFile, null);
} catch (IOException e) {
throw new DeploymentException("Failed to update metadata " + metadata + ": " + e.getMessage(), e);
}
}
UpdateCheck<Metadata, MetadataTransferException> check = new UpdateCheck<Metadata, MetadataTransferException>();
check.setItem(metadata);
check.setFile(dstFile);
check.setRepository(repository);
check.setAuthoritativeRepository(repository);
updateCheckManager.touchMetadata(session, check);
metadataUploads.add(new MetadataUploadEx(metadata, dstFile, catapult));
}
Aggregations