Search in sources :

Example 16 with ArtifactRepositoryMetadata

use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.

the class LegacyToDefaultConverterTest method testV3PomConvertWithRelocation.

@Test
public void testV3PomConvertWithRelocation() throws Exception {
    Artifact artifact = createArtifact("test", "relocated-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();  --> commented until MNG-2100 is fixed
    Path artifactFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
    assertTrue("Check if relocated artifact created", Files.exists(artifactFile));
    assertTrue("Check if relocated artifact matches", FileUtils.contentEquals(artifactFile.toFile(), artifact.getFile()));
    Artifact pomArtifact = createArtifact("relocated-test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom");
    Path pomFile = getTestFile("src/test/expected-files/" + targetRepository.pathOf(pomArtifact));
    Path testFile = getTestFile("target/test-target-repository/" + targetRepository.pathOf(pomArtifact));
    compareFiles(pomFile, testFile);
    Artifact orig = createArtifact("test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom");
    artifactFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(orig));
    assertTrue("Check if relocation artifact pom is created", Files.exists(artifactFile));
    testFile = getTestFile("src/test/expected-files/" + targetRepository.pathOf(orig));
    compareFiles(artifactFile, testFile);
}
Also used : Path(java.nio.file.Path) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) ArtifactMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) Artifact(org.apache.maven.artifact.Artifact) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) Test(org.junit.Test)

Example 17 with ArtifactRepositoryMetadata

use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.

the class LegacyToDefaultConverterTest method testIncorrectSourceChecksumMd5.

@Test
public void testIncorrectSourceChecksumMd5() throws Exception {
    // test that it fails when the source md5 is wrong
    Artifact artifact = createArtifact("test", "incorrectMd5Artifact", "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.md5"));
    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));
}
Also used : Path(java.nio.file.Path) Artifact(org.apache.maven.artifact.Artifact) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) Test(org.junit.Test)

Example 18 with ArtifactRepositoryMetadata

use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.

the class LegacyToDefaultConverterTest method testInvalidSourceSnapshotMetadata.

@Test
public void testInvalidSourceSnapshotMetadata() throws Exception {
    // test artifact is not converted when source snapshot metadata is invalid and returns failure
    createModernSourceRepository();
    Artifact artifact = createArtifact("test", "incorrectSnapshotMetadata", "1.0.0-20060102.030405-6");
    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.snapshotMetadata.snapshot"));
    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));
}
Also used : Path(java.nio.file.Path) Artifact(org.apache.maven.artifact.Artifact) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) Test(org.junit.Test)

Example 19 with ArtifactRepositoryMetadata

use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.

the class LegacyToDefaultConverterTest method testDryRunSuccess.

@Test
public void testDryRunSuccess() throws Exception {
    // test dry run does nothing on a run that will be successful, and returns success
    artifactConverter = applicationContext.getBean("artifactConverter#dryrun-repository-converter", ArtifactConverter.class);
    Artifact artifact = createArtifact("test", "dryrun-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));
    // clear warning before test related to MRM-1638
    artifactConverter.clearWarnings();
    artifactConverter.convert(artifact, targetRepository);
    checkSuccess(artifactConverter);
    assertTrue("Check source file exists", Files.exists(sourceFile));
    assertTrue("Check source POM exists", Files.exists(sourcePomFile));
    assertFalse("Check target file doesn't exist", Files.exists(targetFile));
    assertFalse("Check target POM doesn't exist", Files.exists(targetPomFile));
    ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact);
    Path metadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(metadata));
    assertFalse("Check metadata not created", Files.exists(metadataFile));
}
Also used : Path(java.nio.file.Path) Artifact(org.apache.maven.artifact.Artifact) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) Test(org.junit.Test)

Example 20 with ArtifactRepositoryMetadata

use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.

the class LegacyToDefaultConverterTest method testModifedArtifactFails.

@Test
public void testModifedArtifactFails() throws Exception {
    // test that it fails when the source artifact has changed and is different to the existing artifact in the
    // target repository
    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);
    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));
}
Also used : Path(java.nio.file.Path) Artifact(org.apache.maven.artifact.Artifact) ArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) Test(org.junit.Test)

Aggregations

ArtifactRepositoryMetadata (org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata)28 SnapshotArtifactRepositoryMetadata (org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata)22 Artifact (org.apache.maven.artifact.Artifact)20 Path (java.nio.file.Path)18 Test (org.junit.Test)16 ArtifactMetadata (org.apache.maven.artifact.metadata.ArtifactMetadata)11 RepositoryMetadata (org.apache.maven.artifact.repository.metadata.RepositoryMetadata)8 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)4 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)3 RepositoryMetadataResolutionException (org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException)3 Versioning (org.apache.maven.artifact.repository.metadata.Versioning)3 File (java.io.File)2 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)2 MetadataBridge (org.apache.maven.artifact.repository.metadata.MetadataBridge)2 Snapshot (org.apache.maven.artifact.repository.metadata.Snapshot)2 ProjectArtifactMetadata (org.apache.maven.project.artifact.ProjectArtifactMetadata)2 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)2 SubArtifact (org.eclipse.aether.util.artifact.SubArtifact)2 Test (org.junit.jupiter.api.Test)2 IOException (java.io.IOException)1