Search in sources :

Example 1 with RepositoryManager

use of org.apache.maven.shared.repository.RepositoryManager 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)1 Map (java.util.Map)1 ArtifactMetadata (org.apache.maven.artifact.metadata.ArtifactMetadata)1 MavenSession (org.apache.maven.execution.MavenSession)1 AbstractInstallMojo (org.apache.maven.plugins.install.AbstractInstallMojo)1 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)1 MavenProject (org.apache.maven.project.MavenProject)1 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)1 RepositoryManager (org.apache.maven.shared.repository.RepositoryManager)1 EnhancedLocalRepositoryManager (org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager)1