use of org.sonatype.aether.transfer.MetadataNotFoundException in project sonatype-aether by sonatype.
the class DefaultDeployerTest method testStaleLocalMetadataCopyGetsDeletedBeforeMergeWhenMetadataIsNotCurrentlyPresentInRemoteRepo.
@Test
public void testStaleLocalMetadataCopyGetsDeletedBeforeMergeWhenMetadataIsNotCurrentlyPresentInRemoteRepo() throws Exception {
MergeableMetadata metadata = new MergeableMetadata() {
public Metadata setFile(File file) {
return this;
}
public String getVersion() {
return "";
}
public String getType() {
return "test.properties";
}
public Nature getNature() {
return Nature.RELEASE;
}
public String getGroupId() {
return "org";
}
public File getFile() {
return null;
}
public String getArtifactId() {
return "aether";
}
public void merge(File current, File result) throws RepositoryException {
Properties props = new Properties();
try {
if (current.isFile()) {
TestFileUtils.read(props, current);
}
props.setProperty("new", "value");
TestFileUtils.write(props, result);
} catch (IOException e) {
throw new RepositoryException(e.getMessage(), e);
}
}
public boolean isMerged() {
return false;
}
};
manager.setConnector(new RepositoryConnector() {
public void put(Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads) {
}
public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
if (metadataDownloads != null) {
for (MetadataDownload download : metadataDownloads) {
download.setException(new MetadataNotFoundException(download.getMetadata(), null, null));
}
}
}
public void close() {
}
});
request.addMetadata(metadata);
File metadataFile = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, request.getRepository(), ""));
Properties props = new Properties();
props.setProperty("old", "value");
TestFileUtils.write(props, metadataFile);
deployer.deploy(session, request);
props = new Properties();
TestFileUtils.read(props, metadataFile);
assertNull(props.toString(), props.get("old"));
}
use of org.sonatype.aether.transfer.MetadataNotFoundException in project sonatype-aether by sonatype.
the class DefaultMetadataResolverTest method testRemoveMetadataIfMissing.
@Test
public void testRemoveMetadataIfMissing() throws IOException {
connector = new RecordingRepositoryConnector() {
@Override
public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
super.get(artifactDownloads, metadataDownloads);
for (MetadataDownload d : metadataDownloads) {
d.setException(new MetadataNotFoundException(metadata, repository));
}
}
};
manager.setConnector(connector);
File file = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteMetadata(metadata, repository, ""));
TestFileUtils.write(file.getAbsolutePath(), file);
metadata.setFile(file);
MetadataRequest request = new MetadataRequest(metadata, repository, "");
request.setDeleteLocalCopyIfMissing(true);
List<MetadataResult> results = resolver.resolveMetadata(session, Arrays.asList(request));
assertEquals(1, results.size());
MetadataResult result = results.get(0);
assertNotNull(result.getException());
assertEquals(false, file.exists());
}
use of org.sonatype.aether.transfer.MetadataNotFoundException 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.MetadataNotFoundException 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.MetadataNotFoundException 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);
}
}
}
Aggregations