Search in sources :

Example 1 with TransactionException

use of org.apache.archiva.transaction.TransactionException 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);
        }
    }
}
Also used : Versioning(org.apache.maven.artifact.repository.metadata.Versioning) Snapshot(org.apache.maven.artifact.repository.metadata.Snapshot) TransactionException(org.apache.archiva.transaction.TransactionException) Matcher(java.util.regex.Matcher) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata) RepositoryMetadata(org.apache.maven.artifact.repository.metadata.RepositoryMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) FileTransaction(org.apache.archiva.transaction.FileTransaction) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata)

Aggregations

Matcher (java.util.regex.Matcher)1 FileTransaction (org.apache.archiva.transaction.FileTransaction)1 TransactionException (org.apache.archiva.transaction.TransactionException)1 ArtifactRepositoryMetadata (org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata)1 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)1 RepositoryMetadata (org.apache.maven.artifact.repository.metadata.RepositoryMetadata)1 Snapshot (org.apache.maven.artifact.repository.metadata.Snapshot)1 SnapshotArtifactRepositoryMetadata (org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata)1 Versioning (org.apache.maven.artifact.repository.metadata.Versioning)1