Search in sources :

Example 1 with StringModelSource

use of org.apache.maven.model.building.StringModelSource in project maven-plugins by apache.

the class InstallFileMojo method createMavenProject.

/**
     * Creates a Maven project in-memory from the user-supplied groupId, artifactId and version. When a classifier is
     * supplied, the packaging must be POM because the project with only have attachments. This project serves as basis
     * to attach the artifacts to install to.
     * 
     * @return The created Maven project, never <code>null</code>.
     * @throws MojoExecutionException When the model of the project could not be built.
     * @throws MojoFailureException When building the project failed.
     */
private MavenProject createMavenProject() throws MojoExecutionException, MojoFailureException {
    if (groupId == null || artifactId == null || version == null || packaging == null) {
        throw new MojoExecutionException("The artifact information is incomplete: 'groupId', 'artifactId', " + "'version' and 'packaging' are required.");
    }
    ModelSource modelSource = new StringModelSource("<project><modelVersion>4.0.0</modelVersion><groupId>" + groupId + "</groupId><artifactId>" + artifactId + "</artifactId><version>" + version + "</version><packaging>" + (classifier == null ? packaging : "pom") + "</packaging></project>");
    ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
    pbr.setProcessPlugins(false);
    try {
        return projectBuilder.build(modelSource, pbr).getProject();
    } catch (ProjectBuildingException e) {
        if (e.getCause() instanceof ModelBuildingException) {
            throw new MojoExecutionException("The artifact information is not valid:" + Os.LINE_SEP + e.getCause().getMessage());
        }
        throw new MojoFailureException("Unable to create the project.", e);
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException) StringModelSource(org.apache.maven.model.building.StringModelSource) StringModelSource(org.apache.maven.model.building.StringModelSource) ModelSource(org.apache.maven.model.building.ModelSource) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Example 2 with StringModelSource

use of org.apache.maven.model.building.StringModelSource in project maven-plugins by apache.

the class DeployFileMojo method createMavenProject.

/**
     * Creates a Maven project in-memory from the user-supplied groupId, artifactId and version. When a classifier is
     * supplied, the packaging must be POM because the project with only have attachments. This project serves as basis
     * to attach the artifacts to deploy to.
     * 
     * @return The created Maven project, never <code>null</code>.
     * @throws MojoExecutionException When the model of the project could not be built.
     * @throws MojoFailureException When building the project failed.
     */
private MavenProject createMavenProject() throws MojoExecutionException, MojoFailureException {
    if (groupId == null || artifactId == null || version == null || packaging == null) {
        throw new MojoExecutionException("The artifact information is incomplete: 'groupId', 'artifactId', " + "'version' and 'packaging' are required.");
    }
    ModelSource modelSource = new StringModelSource("<project>" + "<modelVersion>4.0.0</modelVersion>" + "<groupId>" + groupId + "</groupId>" + "<artifactId>" + artifactId + "</artifactId>" + "<version>" + version + "</version>" + "<packaging>" + (classifier == null ? packaging : "pom") + "</packaging>" + "</project>");
    DefaultProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(getSession().getProjectBuildingRequest());
    buildingRequest.setProcessPlugins(false);
    try {
        return projectBuilder.build(modelSource, buildingRequest).getProject();
    } catch (ProjectBuildingException e) {
        if (e.getCause() instanceof ModelBuildingException) {
            throw new MojoExecutionException("The artifact information is not valid:" + Os.LINE_SEP + e.getCause().getMessage());
        }
        throw new MojoFailureException("Unable to create the project.", e);
    }
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException) StringModelSource(org.apache.maven.model.building.StringModelSource) StringModelSource(org.apache.maven.model.building.StringModelSource) ModelSource(org.apache.maven.model.building.ModelSource) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Aggregations

ModelBuildingException (org.apache.maven.model.building.ModelBuildingException)2 ModelSource (org.apache.maven.model.building.ModelSource)2 StringModelSource (org.apache.maven.model.building.StringModelSource)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)2 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)2 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)1