Search in sources :

Example 1 with ArtifactMetadata

use of org.apache.maven.artifact.metadata.ArtifactMetadata 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
}
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 2 with ArtifactMetadata

use of org.apache.maven.artifact.metadata.ArtifactMetadata 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));
}
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 3 with ArtifactMetadata

use of org.apache.maven.artifact.metadata.ArtifactMetadata 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);
}
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 4 with ArtifactMetadata

use of org.apache.maven.artifact.metadata.ArtifactMetadata 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);
}
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 5 with ArtifactMetadata

use of org.apache.maven.artifact.metadata.ArtifactMetadata 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)

Aggregations

ArtifactMetadata (org.apache.maven.artifact.metadata.ArtifactMetadata)17 Artifact (org.apache.maven.artifact.Artifact)11 SnapshotArtifactRepositoryMetadata (org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata)10 Path (java.nio.file.Path)9 ArtifactRepositoryMetadata (org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata)9 Test (org.junit.Test)8 File (java.io.File)4 ProjectArtifactMetadata (org.apache.maven.project.artifact.ProjectArtifactMetadata)3 ArtifactDeploymentException (org.apache.maven.artifact.deployer.ArtifactDeploymentException)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 ArtifactRepositoryLayout (org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout)1 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)1 Versioning (org.apache.maven.artifact.repository.metadata.Versioning)1 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)1 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)1 MavenSession (org.apache.maven.execution.MavenSession)1