use of org.apache.maven.model.building.ModelBuildingException in project buck by facebook.
the class Resolver method loadPomModel.
private Model loadPomModel(Path pomFile) {
DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
request.setPomFile(pomFile.toFile());
try {
ModelBuildingResult result = modelBuilder.build(request);
return result.getRawModel();
} catch (ModelBuildingException | IllegalArgumentException e) {
// IllegalArg can be thrown if the parent POM cannot be resolved.
throw new RuntimeException(e);
}
}
use of org.apache.maven.model.building.ModelBuildingException in project bazel by bazelbuild.
the class DefaultModelResolver method getEffectiveModel.
public Model getEffectiveModel(ModelSource modelSource, EventHandler handler) {
DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
request.setModelResolver(this);
request.setModelSource(modelSource);
Model model;
try {
ModelBuildingResult result = modelBuilder.build(request);
model = result.getEffectiveModel();
} catch (ModelBuildingException | IllegalArgumentException e) {
// IllegalArg can be thrown if the parent POM cannot be resolved.
handler.handle(Event.error("Unable to resolve Maven model from " + modelSource.getLocation() + ": " + e.getMessage()));
return null;
}
return model;
}
use of org.apache.maven.model.building.ModelBuildingException 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.ModelBuildingException in project bazel by bazelbuild.
the class DefaultModelResolver method getRawModel.
public Model getRawModel(FileModelSource fileModelSource, EventHandler handler) {
DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
request.setModelResolver(this);
request.setModelSource(fileModelSource);
Model model;
try {
ModelBuildingResult result = modelBuilder.build(request);
model = result.getRawModel();
} catch (ModelBuildingException | IllegalArgumentException e) {
// IllegalArg can be thrown if the parent POM cannot be resolved.
handler.handle(Event.error("Unable to resolve raw Maven model from " + fileModelSource.getLocation() + ": " + e.getMessage()));
return null;
}
return model;
}
use of org.apache.maven.model.building.ModelBuildingException in project buck by facebook.
the class Pom method constructModel.
private Model constructModel(File file, Model model) {
ModelBuilder modelBuilder = MODEL_BUILDER_FACTORY.newInstance();
try {
ModelBuildingRequest req = new DefaultModelBuildingRequest().setPomFile(file);
ModelBuildingResult modelBuildingResult = modelBuilder.build(req);
Model constructed = Preconditions.checkNotNull(modelBuildingResult.getRawModel());
return merge(model, constructed);
} catch (ModelBuildingException e) {
throw new RuntimeException(e);
}
}
Aggregations