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
}
use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testRollbackArtifactCreated.
@Test
public void testRollbackArtifactCreated() throws Exception {
// test rollback can remove a created artifact, including checksums
Artifact artifact = createArtifact("test", "rollback-created-artifact", "1.0.0");
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata(artifact);
Path artifactMetadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata));
org.apache.archiva.common.utils.FileUtils.deleteDirectory(artifactMetadataFile.getParent());
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata(artifact);
Path versionMetadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(versionMetadata));
Path artifactFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
artifactConverter.convert(artifact, targetRepository);
checkWarnings(artifactConverter, 2);
boolean found = false;
String pattern = "^" + Messages.getString("invalid.source.pom").replaceFirst("\\{0\\}", ".*") + "$";
for (List<String> messages : artifactConverter.getWarnings().values()) {
for (String message : messages) {
if (message.matches(pattern)) {
found = true;
break;
}
}
if (found) {
break;
}
}
assertTrue("Check failure message.", found);
assertFalse("check artifact rolled back", Files.exists(artifactFile));
assertFalse("check metadata rolled back", Files.exists(artifactMetadataFile));
assertFalse("check metadata rolled back", Files.exists(versionMetadataFile));
}
use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testV3PomConvert.
@Test
public void testV3PomConvert() throws Exception {
// test that the pom is coverted
Artifact artifact = createArtifact("test", "v3artifact", "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);
checkSuccess(artifactConverter);
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.pom");
assertTrue("Check POM created", Files.exists(pomFile));
compareFiles(expectedPomFile, pomFile);
assertTrue("Check artifact metadata created", Files.exists(artifactMetadataFile));
Path expectedMetadataFile = getTestFile("src/test/expected-files/v3-artifact-metadata.xml");
compareFiles(expectedMetadataFile, artifactMetadataFile);
assertTrue("Check snapshot metadata created", Files.exists(versionMetadataFile));
expectedMetadataFile = getTestFile("src/test/expected-files/v3-version-metadata.xml");
compareFiles(expectedMetadataFile, versionMetadataFile);
}
use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testV3TimestampedSnapshotPomConvert.
@Test
public void testV3TimestampedSnapshotPomConvert() throws Exception {
// test that the pom is coverted
Artifact artifact = createArtifact("test", "v3artifact", "1.0.0-20060105.130101-3");
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata(artifact);
Path artifactMetadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata));
Files.deleteIfExists(artifactMetadataFile);
ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata(artifact);
Path snapshotMetadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(snapshotMetadata));
Files.deleteIfExists(snapshotMetadataFile);
artifactConverter.convert(artifact, targetRepository);
checkSuccess(artifactConverter);
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-timestamped-snapshot.pom");
assertTrue("Check POM created", Files.exists(pomFile));
compareFiles(expectedPomFile, pomFile);
assertTrue("Check artifact snapshotMetadata created", Files.exists(artifactMetadataFile));
Path expectedMetadataFile = getTestFile("src/test/expected-files/v3-snapshot-artifact-metadata.xml");
compareFiles(expectedMetadataFile, artifactMetadataFile);
assertTrue("Check snapshot snapshotMetadata created", Files.exists(snapshotMetadataFile));
expectedMetadataFile = getTestFile("src/test/expected-files/v3-timestamped-snapshot-metadata.xml");
compareFiles(expectedMetadataFile, snapshotMetadataFile);
}
Aggregations