Search in sources :

Example 6 with DefaultModelBuildingRequest

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();
}
Also used : DefaultModelBuilderFactory(org.apache.maven.model.building.DefaultModelBuilderFactory) ModelBuildingRequest(org.apache.maven.model.building.ModelBuildingRequest) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest)

Example 7 with DefaultModelBuildingRequest

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);
        }
    }
}
Also used : DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) URI(java.net.URI) DefaultModelBuilder(org.apache.maven.model.building.DefaultModelBuilder) InvalidRepositoryException(org.apache.maven.model.resolution.InvalidRepositoryException) UnresolvableModelException(org.apache.maven.model.resolution.UnresolvableModelException) MalformedURLException(java.net.MalformedURLException) SyntaxException(org.codehaus.groovy.syntax.SyntaxException) DefaultModelBuilderFactory(org.apache.maven.model.building.DefaultModelBuilderFactory) MavenModelDependencyManagement(org.springframework.boot.cli.compiler.dependencies.MavenModelDependencyManagement) Model(org.apache.maven.model.Model) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with DefaultModelBuildingRequest

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);
}
Also used : ModelBuildingRequest(org.apache.maven.model.building.ModelBuildingRequest) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) ModelInterpolator(org.apache.maven.model.interpolation.ModelInterpolator) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) ModelProblemCollector(org.apache.maven.model.building.ModelProblemCollector) ModelProblemCollectorRequest(org.apache.maven.model.building.ModelProblemCollectorRequest)

Example 9 with DefaultModelBuildingRequest

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;
}
Also used : ModelBuildingResult(org.apache.maven.model.building.ModelBuildingResult) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) Model(org.apache.maven.model.Model) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException)

Example 10 with DefaultModelBuildingRequest

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);
    }
}
Also used : ModelBuilder(org.apache.maven.model.building.ModelBuilder) ModelBuildingRequest(org.apache.maven.model.building.ModelBuildingRequest) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) ModelBuildingResult(org.apache.maven.model.building.ModelBuildingResult) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) Model(org.apache.maven.model.Model) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException)

Aggregations

DefaultModelBuildingRequest (org.apache.maven.model.building.DefaultModelBuildingRequest)10 Model (org.apache.maven.model.Model)7 ModelBuildingException (org.apache.maven.model.building.ModelBuildingException)6 ModelBuildingRequest (org.apache.maven.model.building.ModelBuildingRequest)6 ModelBuildingResult (org.apache.maven.model.building.ModelBuildingResult)5 DefaultModelBuilderFactory (org.apache.maven.model.building.DefaultModelBuilderFactory)4 HashMap (java.util.HashMap)2 DefaultModelBuilder (org.apache.maven.model.building.DefaultModelBuilder)2 ModelBuilder (org.apache.maven.model.building.ModelBuilder)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1