Search in sources :

Example 1 with ProjectInstallerRequest

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

the class InstallFileMojo method execute.

/**
 * @see org.apache.maven.plugin.Mojo#execute()
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    if (!file.exists()) {
        String message = "The specified file '" + file.getPath() + "' not exists";
        getLog().error(message);
        throw new MojoFailureException(message);
    }
    ProjectBuildingRequest buildingRequest = session.getProjectBuildingRequest();
    // ----------------------------------------------------------------------
    if (localRepositoryPath != null) {
        buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, localRepositoryPath);
        getLog().debug("localRepoPath: " + repositoryManager.getLocalRepositoryBasedir(buildingRequest));
    }
    File temporaryPom = null;
    if (pomFile != null) {
        processModel(readModel(pomFile));
    } else {
        temporaryPom = readingPomFromJarFile();
        pomFile = temporaryPom;
    }
    MavenProject project = createMavenProject();
    // We need to set a new ArtifactHandler otherwise
    // the extension will be set to the packaging type
    // which is sometimes wrong.
    DefaultArtifactHandler ah = new DefaultArtifactHandler(packaging);
    ah.setExtension(FileUtils.getExtension(file.getName()));
    project.getArtifact().setArtifactHandler(ah);
    Artifact artifact = project.getArtifact();
    if (file.equals(getLocalRepoFile(buildingRequest, artifact))) {
        throw new MojoFailureException("Cannot install artifact. " + "Artifact is already in the local repository.\n\nFile in question is: " + file + "\n");
    }
    if (classifier == null) {
        artifact.setFile(file);
        if ("pom".equals(packaging)) {
            project.setFile(file);
        }
    } else {
        projectHelper.attachArtifact(project, packaging, classifier, file);
    }
    if (!"pom".equals(packaging)) {
        if (pomFile != null) {
            if (classifier == null) {
                artifact.addMetadata(new ProjectArtifactMetadata(artifact, pomFile));
            } else {
                project.setFile(pomFile);
            }
        } else {
            temporaryPom = generatePomFile();
            ProjectArtifactMetadata pomMetadata = new ProjectArtifactMetadata(artifact, temporaryPom);
            if (Boolean.TRUE.equals(generatePom) || (generatePom == null && !getLocalRepoFile(buildingRequest, pomMetadata).exists())) {
                getLog().debug("Installing generated POM");
                if (classifier == null) {
                    artifact.addMetadata(pomMetadata);
                } else {
                    project.setFile(temporaryPom);
                }
            } else if (generatePom == null) {
                getLog().debug("Skipping installation of generated POM, already present in local repository");
            }
        }
    }
    if (sources != null) {
        projectHelper.attachArtifact(project, "jar", "sources", sources);
    }
    if (javadoc != null) {
        projectHelper.attachArtifact(project, "jar", "javadoc", javadoc);
    }
    try {
        // CHECKSTYLE_OFF: LineLength
        ProjectInstallerRequest projectInstallerRequest = new ProjectInstallerRequest().setProject(project).setCreateChecksum(createChecksum).setUpdateReleaseInfo(updateReleaseInfo);
        // CHECKSTYLE_ON: LineLength
        installer.install(buildingRequest, projectInstallerRequest);
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } finally {
        if (temporaryPom != null) {
            // noinspection ResultOfMethodCallIgnored
            temporaryPom.delete();
        }
    }
}
Also used : ProjectArtifactMetadata(org.apache.maven.project.artifact.ProjectArtifactMetadata) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ProjectInstallerRequest(org.apache.maven.shared.project.install.ProjectInstallerRequest) MavenProject(org.apache.maven.project.MavenProject) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) JarFile(java.util.jar.JarFile) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileNotFoundException(java.io.FileNotFoundException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 2 with ProjectInstallerRequest

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

the class InstallMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    boolean addedInstallRequest = false;
    if (skip) {
        getLog().info("Skipping artifact installation");
    } else {
        // CHECKSTYLE_OFF: LineLength
        ProjectInstallerRequest projectInstallerRequest = new ProjectInstallerRequest().setProject(project).setCreateChecksum(createChecksum).setUpdateReleaseInfo(updateReleaseInfo);
        if (!installAtEnd) {
            installProject(session.getProjectBuildingRequest(), projectInstallerRequest);
        } else {
            INSTALLREQUESTS.add(projectInstallerRequest);
            addedInstallRequest = true;
        }
    }
    boolean projectsReady = READYPROJECTSCOUTNER.incrementAndGet() == reactorProjects.size();
    if (projectsReady) {
        synchronized (INSTALLREQUESTS) {
            while (!INSTALLREQUESTS.isEmpty()) {
                installProject(session.getProjectBuildingRequest(), INSTALLREQUESTS.remove(0));
            }
        }
    } else if (addedInstallRequest) {
        getLog().info("Installing " + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion() + " at end");
    }
}
Also used : ProjectInstallerRequest(org.apache.maven.shared.project.install.ProjectInstallerRequest)

Aggregations

ProjectInstallerRequest (org.apache.maven.shared.project.install.ProjectInstallerRequest)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 JarFile (java.util.jar.JarFile)1 Artifact (org.apache.maven.artifact.Artifact)1 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)1 ModelBuildingException (org.apache.maven.model.building.ModelBuildingException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)1 MavenProject (org.apache.maven.project.MavenProject)1 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)1 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)1 ProjectArtifactMetadata (org.apache.maven.project.artifact.ProjectArtifactMetadata)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1