use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverter method validateMetadata.
private boolean validateMetadata(Artifact artifact) throws ArtifactConversionException {
ArtifactRepository repository = artifact.getRepository();
boolean result = true;
RepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata(artifact);
Path file = Paths.get(repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata(repositoryMetadata));
if (Files.exists(file)) {
Metadata metadata = readMetadata(file);
result = validateMetadata(metadata, repositoryMetadata, artifact);
}
repositoryMetadata = new SnapshotArtifactRepositoryMetadata(artifact);
file = Paths.get(repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata(repositoryMetadata));
if (Files.exists(file)) {
Metadata metadata = readMetadata(file);
result = result && validateMetadata(metadata, repositoryMetadata, artifact);
}
return result;
}
use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata 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);
}
}
}
use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testInvalidSourceArtifactMetadata.
@Test
public void testInvalidSourceArtifactMetadata() throws Exception {
// test artifact is not converted when source metadata is invalid, and returns failure
createModernSourceRepository();
Artifact artifact = createArtifact("test", "incorrectArtifactMetadata", "1.0.0");
Path file = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
Files.deleteIfExists(file);
artifactConverter.convert(artifact, targetRepository);
checkWarnings(artifactConverter, 2);
assertHasWarningReason(artifactConverter, Messages.getString("failure.incorrect.artifactMetadata.versions"));
assertFalse("Check artifact not created", Files.exists(file));
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact);
Path metadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(metadata));
assertFalse("Check metadata not created", Files.exists(metadataFile));
}
use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testForcedUnmodifiedArtifact.
@Test
public void testForcedUnmodifiedArtifact() throws Exception {
// test unmodified artifact is still converted when set to force
artifactConverter = applicationContext.getBean("artifactConverter#force-repository-converter", ArtifactConverter.class);
Artifact artifact = createArtifact("test", "unmodified-artifact", "1.0.0");
Artifact pomArtifact = createPomArtifact(artifact);
Path sourceFile = Paths.get(sourceRepository.getBasedir(), sourceRepository.pathOf(artifact));
Path sourcePomFile = Paths.get(sourceRepository.getBasedir(), sourceRepository.pathOf(pomArtifact));
Path targetFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
Path targetPomFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(pomArtifact));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
long origTime = dateFormat.parse("2006-03-03").getTime();
Files.setLastModifiedTime(targetFile, FileTime.from(origTime, TimeUnit.MILLISECONDS));
Files.setLastModifiedTime(targetPomFile, FileTime.from(origTime, TimeUnit.MILLISECONDS));
Files.setLastModifiedTime(sourceFile, FileTime.from(dateFormat.parse("2006-01-01").getTime(), TimeUnit.MILLISECONDS));
Files.setLastModifiedTime(sourcePomFile, FileTime.from(dateFormat.parse("2006-02-02").getTime(), TimeUnit.MILLISECONDS));
artifactConverter.convert(artifact, targetRepository);
checkSuccess(artifactConverter);
compareFiles(sourceFile, targetFile);
compareFiles(sourcePomFile, targetPomFile);
assertFalse("Check modified", origTime == Files.getLastModifiedTime(targetFile).toMillis());
assertFalse("Check modified", origTime == Files.getLastModifiedTime(targetPomFile).toMillis());
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact);
Path metadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(metadata));
assertTrue("Check metadata created", Files.exists(metadataFile));
}
use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testV3PomWarningsOnConvert.
@Test
public void testV3PomWarningsOnConvert() throws Exception {
// test that the pom is converted but that warnings are reported
Artifact artifact = createArtifact("test", "v3-warnings-artifact", "1.0.0");
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata(artifact);
Path artifactMetadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata));
Files.deleteIfExists(artifactMetadataFile);
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata(artifact);
Path versionMetadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(versionMetadata));
Files.deleteIfExists(versionMetadataFile);
artifactConverter.convert(artifact, targetRepository);
checkWarnings(artifactConverter, 2);
Path artifactFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
assertTrue("Check artifact created", Files.exists(artifactFile));
assertTrue("Check artifact matches", FileUtils.contentEquals(artifactFile.toFile(), artifact.getFile()));
artifact = createPomArtifact(artifact);
Path pomFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
Path expectedPomFile = getTestFile("src/test/expected-files/converted-v3-warnings.pom");
assertTrue("Check POM created", Files.exists(pomFile));
compareFiles(expectedPomFile, pomFile);
// TODO: check 2 warnings (extend and versions) matched on i18n key
}
Aggregations