Search in sources :

Example 11 with ArtifactRepositoryMetadata

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));
}
Also used : Path(java.nio.file.Path) SimpleDateFormat(java.text.SimpleDateFormat) 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 12 with ArtifactRepositoryMetadata

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
}
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 13 with ArtifactRepositoryMetadata

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));
}
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 14 with ArtifactRepositoryMetadata

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);
}
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 15 with ArtifactRepositoryMetadata

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);
}
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

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