use of org.sonatype.aether.metadata.MergeableMetadata 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.metadata.MergeableMetadata 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));
}
use of org.sonatype.aether.metadata.MergeableMetadata in project sonatype-aether by sonatype.
the class DefaultInstaller method install.
private void install(RepositorySystemSession session, RequestTrace trace, Metadata metadata) throws InstallationException {
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
File dstFile = new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalMetadata(metadata));
metadataInstalling(session, trace, metadata, dstFile);
Exception exception = null;
try {
if (metadata instanceof MergeableMetadata) {
((MergeableMetadata) metadata).merge(dstFile, dstFile);
} else {
fileProcessor.copy(metadata.getFile(), dstFile, null);
}
lrm.add(session, new LocalMetadataRegistration(metadata));
} catch (Exception e) {
exception = e;
throw new InstallationException("Failed to install metadata " + metadata + ": " + e.getMessage(), e);
} finally {
metadataInstalled(session, trace, metadata, dstFile, exception);
}
}
Aggregations