Search in sources :

Example 11 with ArtifactMetadata

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

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

the class LegacyToDefaultConverterTest method testV4PomConvert.

@Test
public void testV4PomConvert() throws Exception {
    // test that it is copied as is
    Artifact artifact = createArtifact("test", "v4artifact", "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);
    Path artifactFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
    Files.deleteIfExists(artifactFile);
    artifactConverter.convert(artifact, targetRepository);
    checkSuccess(artifactConverter);
    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-artifact-metadata.xml");
    compareFiles(expectedMetadataFile, artifactMetadataFile);
    assertTrue("Check snapshot metadata created", Files.exists(versionMetadataFile));
    expectedMetadataFile = getTestFile("src/test/expected-files/v4-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 13 with ArtifactMetadata

use of org.apache.maven.artifact.metadata.ArtifactMetadata in project build-info by JFrogDev.

the class BuildInfoRecorder method addPomArtifact.

private void addPomArtifact(Artifact nonPomArtifact, ModuleBuilder module, IncludeExcludePatterns patterns, String deploymentPath, String pomFileName, boolean excludeArtifactsFromBuild) {
    for (ArtifactMetadata metadata : nonPomArtifact.getMetadataList()) {
        if (metadata instanceof ProjectArtifactMetadata) {
            // The pom metadata
            ArtifactBuilder artifactBuilder = new ArtifactBuilder(pomFileName).type("pom");
            File pomFile = ((ProjectArtifactMetadata) metadata).getFile();
            org.jfrog.build.api.Artifact pomArtifact = artifactBuilder.build();
            if (pomFile != null && pomFile.isFile()) {
                if (excludeArtifactsFromBuild && PatternMatcher.pathConflicts(deploymentPath, patterns)) {
                    module.addExcludedArtifact(pomArtifact);
                } else {
                    module.addArtifact(pomArtifact);
                }
                addDeployableArtifact(pomArtifact, pomFile, nonPomArtifact.getGroupId(), nonPomArtifact.getArtifactId(), nonPomArtifact.getVersion(), nonPomArtifact.getClassifier(), "pom");
            }
            break;
        }
    }
}
Also used : ProjectArtifactMetadata(org.apache.maven.project.artifact.ProjectArtifactMetadata) ArtifactMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) ProjectArtifactMetadata(org.apache.maven.project.artifact.ProjectArtifactMetadata) ArtifactBuilder(org.jfrog.build.api.builder.ArtifactBuilder)

Example 14 with ArtifactMetadata

use of org.apache.maven.artifact.metadata.ArtifactMetadata in project maven-plugins by apache.

the class InstallMojoTest method testBasicInstallAndCreateChecksumIsTrue.

public void testBasicInstallAndCreateChecksumIsTrue() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-checksum/plugin-config.xml");
    AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo("install", testPom);
    assertNotNull(mojo);
    File file = new File(getBasedir(), "target/test-classes/unit/basic-install-checksum/" + "maven-test-jar.jar");
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    MavenSession mavenSession = createMavenSession();
    updateMavenProject(project);
    setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
    setVariableValueToObject(mojo, "session", mavenSession);
    artifact = (InstallArtifactStub) project.getArtifact();
    boolean createChecksum = (Boolean) getVariableValueFromObject(mojo, "createChecksum");
    assertTrue(createChecksum);
    artifact.setFile(file);
    mojo.execute();
    ArtifactMetadata metadata = null;
    for (Object o : artifact.getMetadataList()) {
        metadata = (ArtifactMetadata) o;
        if (metadata.getRemoteFilename().endsWith("pom")) {
            break;
        }
    }
    RepositoryManager repoManager = (RepositoryManager) getVariableValueFromObject(mojo, "repositoryManager");
    ProjectBuildingRequest pbr = mavenSession.getProjectBuildingRequest();
    File pom = new File(repoManager.getLocalRepositoryBasedir(pbr), repoManager.getPathForLocalMetadata(pbr, metadata));
    assertTrue(pom.exists());
    String groupId = dotToSlashReplacer(artifact.getGroupId());
    String packaging = project.getPackaging();
    String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion();
    // get the actual checksum of the pom
    Map<String, Object> csums = ChecksumUtils.calc(pom, Utils.CHECKSUM_ALGORITHMS);
    for (Map.Entry<String, Object> csum : csums.entrySet()) {
        Object actualPomSum = csum.getValue();
        File pomSum = new File(localPath + ".pom." + csum.getKey().toLowerCase().replace("-", ""));
        assertTrue(pomSum.exists());
        String generatedPomSum = FileUtils.fileRead(pomSum, "UTF-8");
        assertEquals(actualPomSum, generatedPomSum);
    }
    // get the actual checksum of the artifact
    csums = ChecksumUtils.calc(file, Utils.CHECKSUM_ALGORITHMS);
    for (Map.Entry<String, Object> csum : csums.entrySet()) {
        Object actualSum = csum.getValue();
        File sum = new File(localPath + "." + packaging + "." + csum.getKey().toLowerCase().replace("-", ""));
        assertTrue(sum.exists());
        String generatedSum = FileUtils.fileRead(sum, "UTF-8");
        assertEquals(actualSum, generatedSum);
    }
    File installedArtifact = new File(localPath + "." + packaging);
    assertTrue(installedArtifact.exists());
    assertEquals(9, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) MavenProject(org.apache.maven.project.MavenProject) AbstractInstallMojo(org.apache.maven.plugins.install.AbstractInstallMojo) EnhancedLocalRepositoryManager(org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager) RepositoryManager(org.apache.maven.shared.repository.RepositoryManager) File(java.io.File) ArtifactMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) Map(java.util.Map)

Example 15 with ArtifactMetadata

use of org.apache.maven.artifact.metadata.ArtifactMetadata in project maven-plugins by apache.

the class SignAndDeployFileMojo method deploy.

/**
 * Deploy an artifact from a particular file.
 *
 * @param source the file to deploy
 * @param artifact the artifact definition
 * @param deploymentRepository the repository to deploy to
 * @param localRepository the local repository to install into
 * @throws ArtifactDeploymentException if an error occurred deploying the artifact
 */
protected void deploy(File source, Artifact artifact, ArtifactRepository deploymentRepository, ArtifactRepository localRepository) throws ArtifactDeploymentException {
    int retryFailedDeploymentCount = Math.max(1, Math.min(10, this.retryFailedDeploymentCount));
    ArtifactDeploymentException exception = null;
    for (int count = 0; count < retryFailedDeploymentCount; count++) {
        try {
            if (count > 0) {
                // CHECKSTYLE_OFF: LineLength
                getLog().info("Retrying deployment attempt " + (count + 1) + " of " + retryFailedDeploymentCount);
            // CHECKSTYLE_ON: LineLength
            }
            deployer.deploy(source, artifact, deploymentRepository, localRepository);
            for (Object o : artifact.getMetadataList()) {
                ArtifactMetadata metadata = (ArtifactMetadata) o;
                getLog().info("Metadata[" + metadata.getKey() + "].filename = " + metadata.getRemoteFilename());
            }
            exception = null;
            break;
        } catch (ArtifactDeploymentException e) {
            if (count + 1 < retryFailedDeploymentCount) {
                getLog().warn("Encountered issue during deployment: " + e.getLocalizedMessage());
                getLog().debug(e);
            }
            if (exception == null) {
                exception = e;
            }
        }
    }
    if (exception != null) {
        throw exception;
    }
}
Also used : ArtifactDeploymentException(org.apache.maven.artifact.deployer.ArtifactDeploymentException) ArtifactMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) ProjectArtifactMetadata(org.apache.maven.project.artifact.ProjectArtifactMetadata)

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