use of org.apache.maven.model.building.DefaultModelBuildingRequest in project repairnator by Spirals-Team.
the class MavenHelper method readPomXml.
public static Model readPomXml(File pomXml, String localMavenRepository) throws ModelBuildingException {
ModelBuildingRequest req = new DefaultModelBuildingRequest();
req.setProcessPlugins(false);
req.setPomFile(pomXml);
req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
req.setModelResolver(new RepositoryModelResolver(localMavenRepository));
return new DefaultModelBuilderFactory().newInstance().build(req).getEffectiveModel();
}
use of org.apache.maven.model.building.DefaultModelBuildingRequest in project spring-boot by spring-projects.
the class DependencyManagementBomTransformation method updateDependencyResolutionContext.
private void updateDependencyResolutionContext(List<Map<String, String>> bomDependencies) {
URI[] uris = Grape.getInstance().resolve(null, bomDependencies.toArray(new Map<?, ?>[0]));
DefaultModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance();
for (URI uri : uris) {
try {
DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
request.setModelResolver(new GrapeModelResolver());
request.setModelSource(new org.apache.maven.model.building.UrlModelSource(uri.toURL()));
request.setSystemProperties(System.getProperties());
Model model = modelBuilder.build(request).getEffectiveModel();
this.resolutionContext.addDependencyManagement(new MavenModelDependencyManagement(model));
} catch (Exception ex) {
throw new IllegalStateException("Failed to build model for '" + uri + "'. Is it a valid Maven bom?", ex);
}
}
}
use of org.apache.maven.model.building.DefaultModelBuildingRequest in project sts4 by spring-projects.
the class MavenBridge method interpolateModel.
public void interpolateModel(MavenProject project, Model model) throws MavenException {
ModelBuildingRequest request = new DefaultModelBuildingRequest();
request.setUserProperties(project.getProperties());
ModelProblemCollector problems = new ModelProblemCollector() {
@Override
public void add(ModelProblemCollectorRequest req) {
}
};
lookup(ModelInterpolator.class).interpolateModel(model, project.getBasedir(), request, problems);
}
use of org.apache.maven.model.building.DefaultModelBuildingRequest 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.DefaultModelBuildingRequest 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