Search in sources :

Example 6 with AbstractInstallMojo

use of org.apache.maven.plugins.install.AbstractInstallMojo in project maven-plugins by apache.

the class InstallMojoTest method testInstallIfPackagingIsPom.

public void testInstallIfPackagingIsPom() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test-packaging-pom/" + "plugin-config.xml");
    AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo("install", testPom);
    assertNotNull(mojo);
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    updateMavenProject(project);
    setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
    setVariableValueToObject(mojo, "session", createMavenSession());
    String packaging = project.getPackaging();
    assertEquals("pom", packaging);
    artifact = (InstallArtifactStub) project.getArtifact();
    mojo.execute();
    String groupId = dotToSlashReplacer(artifact.getGroupId());
    File installedArtifact = new File(getBasedir(), LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + "pom");
    assertTrue(installedArtifact.exists());
    assertEquals(4, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) AbstractInstallMojo(org.apache.maven.plugins.install.AbstractInstallMojo) File(java.io.File)

Example 7 with AbstractInstallMojo

use of org.apache.maven.plugins.install.AbstractInstallMojo 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)

Aggregations

File (java.io.File)7 AbstractInstallMojo (org.apache.maven.plugins.install.AbstractInstallMojo)7 MavenProject (org.apache.maven.project.MavenProject)6 Map (java.util.Map)1 Artifact (org.apache.maven.artifact.Artifact)1 ArtifactMetadata (org.apache.maven.artifact.metadata.ArtifactMetadata)1 MavenSession (org.apache.maven.execution.MavenSession)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 AttachedArtifactStub0 (org.apache.maven.plugins.install.stubs.AttachedArtifactStub0)1 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)1 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)1 RepositoryManager (org.apache.maven.shared.repository.RepositoryManager)1 EnhancedLocalRepositoryManager (org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager)1