use of org.apache.archiva.transaction.FileTransaction in project archiva by apache.
the class LegacyToDefaultConverter method convert.
@Override
public void convert(Artifact artifact, ArtifactRepository targetRepository) throws ArtifactConversionException {
if (artifact.getRepository().getUrl().equals(targetRepository.getUrl())) {
// $NON-NLS-1$
throw new ArtifactConversionException(Messages.getString("exception.repositories.match"));
}
if (!validateMetadata(artifact)) {
// $NON-NLS-1$
addWarning(artifact, Messages.getString("unable.to.validate.metadata"));
return;
}
FileTransaction transaction = new FileTransaction();
if (!copyPom(artifact, targetRepository, transaction)) {
// $NON-NLS-1$
addWarning(artifact, Messages.getString("unable.to.copy.pom"));
return;
}
if (!copyArtifact(artifact, targetRepository, transaction)) {
// $NON-NLS-1$
addWarning(artifact, Messages.getString("unable.to.copy.artifact"));
return;
}
Metadata metadata = createBaseMetadata(artifact);
Versioning versioning = new Versioning();
versioning.addVersion(artifact.getBaseVersion());
metadata.setVersioning(versioning);
updateMetadata(new ArtifactRepositoryMetadata(artifact), targetRepository, metadata, transaction);
metadata = createBaseMetadata(artifact);
metadata.setVersion(artifact.getBaseVersion());
versioning = new Versioning();
Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion());
if (matcher.matches()) {
Snapshot snapshot = new Snapshot();
snapshot.setBuildNumber(Integer.parseInt(matcher.group(3)));
snapshot.setTimestamp(matcher.group(2));
versioning.setSnapshot(snapshot);
}
// TODO: merge latest/release/snapshot from source instead
metadata.setVersioning(versioning);
updateMetadata(new SnapshotArtifactRepositoryMetadata(artifact), targetRepository, metadata, transaction);
if (!dryrun) {
try {
transaction.commit();
} catch (TransactionException e) {
throw new ArtifactConversionException(Messages.getString("transaction.failure", e.getMessage()), // $NON-NLS-1$
e);
}
}
}
Aggregations