Example usage for org.apache.maven.model.building DefaultModelBuilder buildRawModel

List of usage examples for org.apache.maven.model.building DefaultModelBuilder buildRawModel

Introduction

In this page you can find the example usage for org.apache.maven.model.building DefaultModelBuilder buildRawModel.

Prototype

@Override
    public Result<? extends Model> buildRawModel(File pomFile, int validationLevel, boolean locationTracking) 

Source Link

Usage

From source file:fr.inria.spirals.repairnator.process.maven.MavenHelper.java

public static Model readPomXml(File pomXml, String localMavenRepository) {
    ModelBuildingRequest req = new DefaultModelBuildingRequest();
    req.setProcessPlugins(true);/*from w ww. j a  va 2s . c om*/
    req.setPomFile(pomXml);
    req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
    req.setModelResolver(new RepositoryModelResolver(localMavenRepository));

    DefaultModelBuilder defaultModelBuilder = new DefaultModelBuilderFactory().newInstance();

    // we try to build the model, and if we fail, we try to get the raw model
    try {
        ModelBuildingResult modelBuildingResult = defaultModelBuilder.build(req);
        return modelBuildingResult.getEffectiveModel();
    } catch (ModelBuildingException e) {
        LOGGER.error("Error while building complete model. The raw model will be used. Error message: "
                + e.getMessage());
        return defaultModelBuilder.buildRawModel(pomXml, ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL, true)
                .get();
    }

}