Search in sources :

Example 1 with AbstractInstallMojo

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

the class InstallMojoTest method testInstallTestEnvironment.

public void testInstallTestEnvironment() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml");
    AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo("install", testPom);
    assertNotNull(mojo);
}
Also used : AbstractInstallMojo(org.apache.maven.plugins.install.AbstractInstallMojo) File(java.io.File)

Example 2 with AbstractInstallMojo

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

the class InstallMojoTest method testBasicInstallWithAttachedArtifacts.

public void testBasicInstallWithAttachedArtifacts() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test-with-attached-artifacts/" + "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());
    List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
    mojo.execute();
    String packaging = project.getPackaging();
    String groupId;
    for (Object attachedArtifact1 : attachedArtifacts) {
        AttachedArtifactStub0 attachedArtifact = (AttachedArtifactStub0) attachedArtifact1;
        groupId = dotToSlashReplacer(attachedArtifact.getGroupId());
        File installedArtifact = new File(getBasedir(), LOCAL_REPO + groupId + "/" + attachedArtifact.getArtifactId() + "/" + attachedArtifact.getVersion() + "/" + attachedArtifact.getArtifactId() + "-" + attachedArtifact.getVersion() + "." + packaging);
        assertTrue(installedArtifact.getPath() + " does not exist", installedArtifact.exists());
    }
    assertEquals(13, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) AbstractInstallMojo(org.apache.maven.plugins.install.AbstractInstallMojo) AttachedArtifactStub0(org.apache.maven.plugins.install.stubs.AttachedArtifactStub0) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 3 with AbstractInstallMojo

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

the class InstallMojoTest method testUpdateReleaseParamSetToTrue.

public void testUpdateReleaseParamSetToTrue() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/configured-install-test/plugin-config.xml");
    AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo("install", testPom);
    assertNotNull(mojo);
    File file = new File(getBasedir(), "target/test-classes/unit/configured-install-test/target/" + "maven-install-test-1.0-SNAPSHOT.jar");
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    updateMavenProject(project);
    setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
    setVariableValueToObject(mojo, "session", createMavenSession());
    artifact = (InstallArtifactStub) project.getArtifact();
    artifact.setFile(file);
    mojo.execute();
    assertTrue(artifact.isRelease());
    assertEquals(5, 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 4 with AbstractInstallMojo

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

the class InstallMojoTest method testBasicInstall.

public void testBasicInstall() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml");
    AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo("install", testPom);
    assertNotNull(mojo);
    File file = new File(getBasedir(), "target/test-classes/unit/basic-install-test/target/" + "maven-install-test-1.0-SNAPSHOT.jar");
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    updateMavenProject(project);
    setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
    setVariableValueToObject(mojo, "session", createMavenSession());
    artifact = (InstallArtifactStub) project.getArtifact();
    artifact.setFile(file);
    mojo.execute();
    String groupId = dotToSlashReplacer(artifact.getGroupId());
    File installedArtifact = new File(getBasedir(), LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + artifact.getArtifactHandler().getExtension());
    assertTrue(installedArtifact.exists());
    assertEquals(5, 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 5 with AbstractInstallMojo

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

the class InstallMojoTest method testInstallIfArtifactFileIsNull.

public void testInstallIfArtifactFileIsNull() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test/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());
    artifact = (InstallArtifactStub) project.getArtifact();
    artifact.setFile(null);
    assertNull(artifact.getFile());
    try {
        mojo.execute();
        fail("Did not throw mojo execution exception");
    } catch (MojoExecutionException e) {
    //expected
    }
    assertFalse(new File(LOCAL_REPO).exists());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AbstractInstallMojo(org.apache.maven.plugins.install.AbstractInstallMojo) File(java.io.File)

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