All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.tesla.maven.plugins.Install Maven / Gradle / Ivy

The newest version!
package io.tesla.maven.plugins;

import io.tesla.maven.plugins.util.AetherUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.installation.InstallRequest;
import org.eclipse.aether.installation.InstallationException;
import org.eclipse.aether.util.artifact.SubArtifact;

/**
 * @goal install
 * @phase install
 * @author Jason van Zyl
 */
public class Install extends TeslaLifecycleMojo {

  @Override
  public void executeMojo() throws MojoExecutionException, MojoFailureException {

    MavenProject lastProject = reactorProjects.get(reactorProjects.size() - 1);
    if (lastProject.equals(project)) {
      for (MavenProject reactorProject : reactorProjects) {
        installProject(reactorProject);
      }
    } else {
      getLog().info("Installing " + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion() + " at end");
    }
  }

  private void installProject(MavenProject project) throws MojoExecutionException {
    
    Artifact artifact = AetherUtils.toArtifact(project.getArtifact());
    String packaging = project.getPackaging();
    File pomFile = project.getFile();
    List attachedArtifacts = new ArrayList();
    
    for (org.apache.maven.artifact.Artifact attachedArtifact : project.getAttachedArtifacts()) {
      attachedArtifacts.add(AetherUtils.toArtifact(attachedArtifact));
    }

    // POM
    Artifact pomArtifact = new SubArtifact( artifact, "", "pom" );
    pomArtifact = pomArtifact.setFile( pomFile );
    
    InstallRequest installRequest = new InstallRequest();
    installRequest.addArtifact( artifact )
      .addArtifact( pomArtifact );

    try {
      repositorySystem.install( repositorySystemSession, installRequest );
    } catch (InstallationException e) {
      throw new MojoExecutionException(e.getMessage(), e);
    }    
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy