Merge branch '2.7.x'

This commit is contained in:
Andy Wilkinson
2022-01-25 12:19:51 +00:00
6 changed files with 206 additions and 105 deletions

View File

@@ -26,8 +26,6 @@ dependencies {
compileOnly("org.apache.maven.plugin-tools:maven-plugin-annotations")
compileOnly("org.sonatype.plexus:plexus-build-api")
dependenciesBom(project(path: ":spring-boot-project:spring-boot-dependencies", configuration: "effectiveBom"))
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-buildpack-platform"))
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-loader-tools"))
implementation("org.apache.maven.shared:maven-common-artifact-filters") {
@@ -62,11 +60,8 @@ dependencies {
testImplementation("org.mockito:mockito-core")
testImplementation("org.mockito:mockito-junit-jupiter")
testImplementation("org.springframework:spring-core")
}
task syncSpringBootDependenciesBom(type: Sync) {
destinationDir = file("${buildDir}/generated-resources/org/springframework/boot/maven")
from configurations.dependenciesBom
versionProperties(project(path: ":spring-boot-project:spring-boot-dependencies", configuration: "effectiveBom"))
}
syncDocumentationSourceForAsciidoctor {
@@ -77,7 +72,7 @@ syncDocumentationSourceForAsciidoctor {
sourceSets {
intTest {
output.dir("${buildDir}/generated-resources", builtBy: "syncSpringBootDependenciesBom")
output.dir("${buildDir}/generated-resources", builtBy: "extractVersionProperties")
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,8 +36,7 @@ class EclipseM2eIntegrationTests {
@Test // gh-21992
void pluginPomIncludesOptionalShadeDependency() throws Exception {
SpringBootDependenciesBom bom = new SpringBootDependenciesBom();
String version = bom.get("version");
String version = new Versions().get("project.version");
File repository = new File("build/int-test-maven-repository");
File pluginDirectory = new File(repository, "org/springframework/boot/spring-boot-maven-plugin/" + version);
File[] pomFiles = pluginDirectory.listFiles(this::isPomFile);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -87,25 +87,13 @@ class MavenBuild {
private Map<String, String> getPomReplacements() {
Map<String, String> replacements = new HashMap<>();
SpringBootDependenciesBom bom = new SpringBootDependenciesBom();
replacements.put("java.version", "1.8");
replacements.put("project.groupId", "org.springframework.boot");
replacements.put("project.artifactId", "spring-boot-maven-plugin");
replacements.put("project.version", bom.get("version"));
putReplacement(replacements, bom, "log4j2.version");
putReplacement(replacements, bom, "maven-jar-plugin.version");
putReplacement(replacements, bom, "maven-war-plugin.version");
putReplacement(replacements, bom, "build-helper-maven-plugin.version");
putReplacement(replacements, bom, "spring-framework.version");
putReplacement(replacements, bom, "jakarta-servlet.version");
putReplacement(replacements, bom, "kotlin.version");
replacements.putAll(new Versions().asMap());
return Collections.unmodifiableMap(replacements);
}
private void putReplacement(Map<String, String> replacements, SpringBootDependenciesBom bom, String property) {
replacements.put(property, bom.get("properties/" + property));
}
MavenBuild project(String project) {
this.projectDir = new File("src/intTest/projects/" + project);
return this;

View File

@@ -1,80 +0,0 @@
/*
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.maven;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import org.springframework.util.Assert;
/**
* Provides access to values in the spring-boot-dependencies effective BOM.
*
* @author Phillip Webb
*/
class SpringBootDependenciesBom {
private static final String XML = "spring-boot-dependencies-effective-bom.xml";
private final Document document;
private final XPath xpath;
SpringBootDependenciesBom() {
this.document = loadDocument();
this.xpath = XPathFactory.newInstance().newXPath();
}
private Document loadDocument() {
try {
try (InputStream inputStream = getClass().getResourceAsStream(XML)) {
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
return builder.parse(inputStream);
}
}
catch (ParserConfigurationException | SAXException | IOException ex) {
throw new IllegalStateException(ex);
}
}
String get(String expression) {
try {
Node node = (Node) this.xpath.compile("/project/" + expression).evaluate(this.document,
XPathConstants.NODE);
String text = (node != null) ? node.getTextContent() : null;
Assert.hasLength(text, () -> "No result for expression " + expression);
return text;
}
catch (XPathExpressionException ex) {
throw new IllegalStateException(ex);
}
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.maven;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
* Provides access to various versions.
*
* @author Andy Wilkinson
*/
class Versions {
private final Map<String, String> versions;
Versions() {
this.versions = loadVersions();
}
private static Map<String, String> loadVersions() {
try (InputStream input = Versions.class.getClassLoader().getResourceAsStream("extracted-versions.properties")) {
Properties properties = new Properties();
properties.load(input);
Map<String, String> versions = new HashMap<>();
properties.forEach((key, value) -> versions.put((String) key, (String) value));
return versions;
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
}
String get(String name) {
return this.versions.get(name);
}
Map<String, String> asMap() {
return Collections.unmodifiableMap(this.versions);
}
}