001/* 002 * Copyright 2012-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.cli.compiler.dependencies; 018 019import java.io.IOException; 020 021import org.apache.maven.model.Model; 022import org.apache.maven.model.building.DefaultModelProcessor; 023import org.apache.maven.model.io.DefaultModelReader; 024import org.apache.maven.model.locator.DefaultModelLocator; 025 026/** 027 * {@link DependencyManagement} derived from the effective pom of 028 * {@code spring-boot-dependencies}. 029 * 030 * @author Andy Wilkinson 031 * @since 1.3.0 032 */ 033public class SpringBootDependenciesDependencyManagement 034 extends MavenModelDependencyManagement { 035 036 public SpringBootDependenciesDependencyManagement() { 037 super(readModel()); 038 } 039 040 private static Model readModel() { 041 DefaultModelProcessor modelProcessor = new DefaultModelProcessor(); 042 modelProcessor.setModelLocator(new DefaultModelLocator()); 043 modelProcessor.setModelReader(new DefaultModelReader()); 044 045 try { 046 return modelProcessor.read(SpringBootDependenciesDependencyManagement.class 047 .getResourceAsStream("effective-pom.xml"), null); 048 } 049 catch (IOException ex) { 050 throw new IllegalStateException("Failed to build model from effective pom", 051 ex); 052 } 053 } 054 055}