Search in sources :

Example 1 with MavenModelDependencyManagement

use of org.springframework.boot.cli.compiler.dependencies.MavenModelDependencyManagement 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)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Model (org.apache.maven.model.Model)1 DefaultModelBuilder (org.apache.maven.model.building.DefaultModelBuilder)1 DefaultModelBuilderFactory (org.apache.maven.model.building.DefaultModelBuilderFactory)1 DefaultModelBuildingRequest (org.apache.maven.model.building.DefaultModelBuildingRequest)1 InvalidRepositoryException (org.apache.maven.model.resolution.InvalidRepositoryException)1 UnresolvableModelException (org.apache.maven.model.resolution.UnresolvableModelException)1 SyntaxException (org.codehaus.groovy.syntax.SyntaxException)1 MavenModelDependencyManagement (org.springframework.boot.cli.compiler.dependencies.MavenModelDependencyManagement)1