Search in sources :

Example 21 with ArtifactRepositoryMetadata

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

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

Example 23 with ArtifactRepositoryMetadata

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

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

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