use of org.apache.maven.model.building.ModelBuildingResult 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.ModelBuildingResult 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.ModelBuildingResult in project meghanada-server by mopemope.
the class POMParser method parsePom.
POMInfo parsePom(File pom) throws ProjectParseException {
try {
if (!pom.isAbsolute()) {
pom = pom.getCanonicalFile();
}
ModelBuildingRequest req = new DefaultModelBuildingRequest();
req.setPomFile(pom);
req.setSystemProperties(System.getProperties());
req.setModelResolver(new LocalModelResolver(this.projectRoot));
req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
req.setProcessPlugins(true);
DefaultModelBuilderFactory factory = new DefaultModelBuilderFactory();
DefaultModelBuilder builder = factory.newInstance();
ModelBuildingResult result = builder.build(req);
Model mavenModel = result.getEffectiveModel();
POMInfo pomInfo = new POMInfo(pom.getParent());
String groupId = mavenModel.getGroupId();
if (nonNull(groupId)) {
pomInfo.groupId = groupId;
}
String artifactId = mavenModel.getArtifactId();
if (nonNull(artifactId)) {
pomInfo.artifactId = artifactId;
}
String version = mavenModel.getVersion();
if (nonNull(version)) {
pomInfo.version = version;
}
Properties modelProperties = mavenModel.getProperties();
if (nonNull(modelProperties)) {
if (nonNull(groupId)) {
modelProperties.put("project.groupId", groupId);
}
if (nonNull(artifactId)) {
modelProperties.put("project.artifactId", artifactId);
}
if (nonNull(version)) {
modelProperties.put("project.version", version);
}
for (String key : modelProperties.stringPropertyNames()) {
String value = modelProperties.getProperty(key);
if (nonNull(value)) {
pomInfo.properties.setProperty(key, value);
}
}
POMParser.replacePOMProperties(pomInfo);
}
Build build = mavenModel.getBuild();
this.parseBuild(pomInfo, build);
return pomInfo;
} catch (IOException | ModelBuildingException e) {
throw new ProjectParseException(e);
}
}
use of org.apache.maven.model.building.ModelBuildingResult 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.ModelBuildingResult 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