use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testDryRunFailure.
@Test
public void testDryRunFailure() throws Exception {
// test dry run does nothing on a run that will fail, and returns failure
artifactConverter = applicationContext.getBean("artifactConverter#dryrun-repository-converter", ArtifactConverter.class);
Artifact artifact = createArtifact("test", "modified-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));
assertTrue("Check target file exists", Files.exists(targetFile));
assertTrue("Check target POM exists", Files.exists(targetPomFile));
Files.setLastModifiedTime(sourceFile, FileTime.from(System.currentTimeMillis(), TimeUnit.MILLISECONDS));
Files.setLastModifiedTime(sourcePomFile, FileTime.from(System.currentTimeMillis(), TimeUnit.MILLISECONDS));
long origTime = Files.getLastModifiedTime(targetFile).toMillis();
long origPomTime = Files.getLastModifiedTime(targetPomFile).toMillis();
// Need to guarantee last modified is not equal
Thread.sleep(SLEEP_MILLIS);
// clear warning before test related to MRM-1638
artifactConverter.clearWarnings();
artifactConverter.convert(artifact, targetRepository);
checkWarnings(artifactConverter, 2);
assertHasWarningReason(artifactConverter, Messages.getString("failure.target.already.exists"));
assertEquals("Check unmodified", origTime, Files.getLastModifiedTime(targetFile).toMillis());
assertEquals("Check unmodified", origPomTime, Files.getLastModifiedTime(targetPomFile).toMillis());
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 doTestV4SnapshotPomConvert.
private void doTestV4SnapshotPomConvert(String version, String expectedMetadataFileName) throws Exception {
// test that it is copied as is
Artifact artifact = createArtifact("test", "v4artifact", version);
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 sourcePomFile = Paths.get(sourceRepository.getBasedir(), sourceRepository.pathOf(artifact));
assertTrue("Check POM created", Files.exists(pomFile));
compareFiles(sourcePomFile, pomFile);
assertTrue("Check artifact metadata created", Files.exists(artifactMetadataFile));
Path expectedMetadataFile = getTestFile("src/test/expected-files/v4-snapshot-artifact-metadata.xml");
compareFiles(expectedMetadataFile, artifactMetadataFile);
assertTrue("Check snapshot metadata created", Files.exists(snapshotMetadataFile));
expectedMetadataFile = getTestFile(expectedMetadataFileName);
compareFiles(expectedMetadataFile, snapshotMetadataFile);
}
use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testV3SnapshotPomConvert.
@Test
public void testV3SnapshotPomConvert() throws Exception {
// test that the pom is coverted
Artifact artifact = createArtifact("test", "v3artifact", "1.0.0-SNAPSHOT");
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-snapshot.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-snapshot-artifact-metadata.xml");
compareFiles(expectedMetadataFile, artifactMetadataFile);
assertTrue("Check snapshot metadata created", Files.exists(snapshotMetadataFile));
expectedMetadataFile = getTestFile("src/test/expected-files/v3-snapshot-metadata.xml");
compareFiles(expectedMetadataFile, snapshotMetadataFile);
}
use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testMergeArtifactMetadata.
@Test
public void testMergeArtifactMetadata() throws Exception {
// test artifact level metadata is merged when it already exists on successful conversion
Artifact artifact = createArtifact("test", "newversion-artifact", "1.0.1");
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 sourcePomFile = Paths.get(sourceRepository.getBasedir(), sourceRepository.pathOf(artifact));
assertTrue("Check POM created", Files.exists(pomFile));
compareFiles(sourcePomFile, pomFile);
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata(artifact);
Path artifactMetadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata));
assertTrue("Check artifact metadata created", Files.exists(artifactMetadataFile));
Path expectedMetadataFile = getTestFile("src/test/expected-files/newversion-artifact-metadata.xml");
compareFiles(expectedMetadataFile, artifactMetadataFile);
}
use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testIncorrectSourceChecksumSha1.
@Test
public void testIncorrectSourceChecksumSha1() throws Exception {
// test that it fails when the source sha1 is wrong
Artifact artifact = createArtifact("test", "incorrectSha1Artifact", "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.sha1"));
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));
}
Aggregations