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);
}
}
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);
}
}
Aggregations