Port the build to Gradle

Closes gh-19609
Closes gh-19608
This commit is contained in:
Andy Wilkinson
2020-01-10 13:48:43 +00:00
parent abe95fa8a7
commit ce99db1902
974 changed files with 17108 additions and 26596 deletions

View File

@@ -0,0 +1,51 @@
plugins {
id 'java'
id 'org.springframework.boot.conventions'
}
description = "Spring Boot Server Tests"
configurations {
testRepository
}
dependencies {
testImplementation project(':spring-boot-project:spring-boot-starters:spring-boot-starter-test')
testImplementation project(':spring-boot-project:spring-boot-tools:spring-boot-test-support')
testImplementation 'com.samskivert:jmustache'
testImplementation 'jakarta.servlet:jakarta.servlet-api'
testImplementation 'org.apache.httpcomponents:httpasyncclient'
testImplementation 'org.apache.maven.shared:maven-invoker:3.0.0'
testImplementation 'org.awaitility:awaitility'
testImplementation('org.eclipse.jetty:jetty-webapp') {
exclude group: 'javax.servlet', module: 'javax-servlet-api'
}
testImplementation 'org.springframework:spring-web'
testRepository project(path: ':spring-boot-project:spring-boot-dependencies', configuration: 'mavenRepository')
testRepository project(path: ':spring-boot-project:spring-boot-tools:spring-boot-maven-plugin', configuration: 'mavenRepository')
testRepository project(path: ':spring-boot-project:spring-boot-starters:spring-boot-starter', configuration: 'mavenRepository')
testRepository project(path: ':spring-boot-project:spring-boot-starters:spring-boot-starter-jetty', configuration: 'mavenRepository')
testRepository project(path: ':spring-boot-project:spring-boot-starters:spring-boot-starter-parent', configuration: 'mavenRepository')
testRepository project(path: ':spring-boot-project:spring-boot-starters:spring-boot-starter-tomcat', configuration: 'mavenRepository')
testRepository project(path: ':spring-boot-project:spring-boot-starters:spring-boot-starter-undertow', configuration: 'mavenRepository')
testRuntimeOnly project(':spring-boot-project:spring-boot-starters:spring-boot-starter-logging')
}
task prepareMavenBinaries(type: org.springframework.boot.build.mavenplugin.PrepareMavenBinaries) {
outputDir = file("$buildDir/maven-binaries")
versions '3.6.2'
}
task syncTestRepository(type: Sync) {
destinationDir = file("${buildDir}/test-repository")
from {
configurations.testRepository
}
}
test {
dependsOn prepareMavenBinaries, syncTestRepository
}

View File

@@ -1,84 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-integration-tests</artifactId>
<version>${revision}</version>
</parent>
<artifactId>spring-boot-server-tests</artifactId>
<packaging>jar</packaging>
<name>Spring Boot Server Tests</name>
<properties>
<main.basedir>${basedir}/../../..</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test-support</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.samskivert</groupId>
<artifactId>jmustache</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<maven.home>${maven.home}</maven.home>
<repository>${repository}</repository>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -95,7 +95,7 @@ abstract class AbstractApplicationLauncher implements BeforeEachCallback, AfterE
}
private int awaitServerPort(Process process, File serverPortFile) throws Exception {
Awaitility.waitAtMost(Duration.ofSeconds(30)).until(serverPortFile::length, (length) -> {
Awaitility.waitAtMost(Duration.ofSeconds(180)).until(serverPortFile::length, (length) -> {
if (!process.isAlive()) {
throw new IllegalStateException("Application failed to start");
}

View File

@@ -36,13 +36,11 @@ import org.apache.maven.shared.invoker.InvocationResult;
import org.apache.maven.shared.invoker.MavenInvocationException;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Builds a Spring Boot application using Maven. To use this class, the {@code maven.home}
* system property must be set.
* Builds a Spring Boot application using Maven.
*
* @author Andy Wilkinson
*/
@@ -121,12 +119,9 @@ class ApplicationBuilder {
}
private File writeSettingsXml(File appFolder) throws IOException {
String repository = System.getProperty("repository");
if (!StringUtils.hasText(repository)) {
return null;
}
Map<String, Object> context = new HashMap<>();
context.put("repository", repository);
context.put("repository", new File("build/test-repository").toURI().toURL());
context.put("localRepository", new File("build/local-m2-repository").getAbsolutePath());
File settingsXml = new File(appFolder, "settings.xml");
try (FileWriter out = new FileWriter(settingsXml);
FileReader templateReader = new FileReader("src/test/resources/settings-template.xml")) {
@@ -160,7 +155,9 @@ class ApplicationBuilder {
if (settingsXml != null) {
invocation.setUserSettingsFile(settingsXml);
}
InvocationResult execute = new DefaultInvoker().execute(invocation);
DefaultInvoker invoker = new DefaultInvoker();
invoker.setMavenHome(new File("build/maven-binaries/apache-maven-3.6.2"));
InvocationResult execute = invoker.execute(invocation);
assertThat(execute.getExitCode()).isEqualTo(0);
}

View File

@@ -27,6 +27,8 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.client.StandardHttpRequestRetryHandler;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.Extension;
import org.junit.jupiter.api.extension.ExtensionContext;
@@ -39,6 +41,7 @@ import org.junit.platform.commons.util.ReflectionUtils;
import org.springframework.boot.testsupport.BuildOutput;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.client.ResponseErrorHandler;
@@ -154,7 +157,8 @@ class EmbeddedServerContainerInvocationContextProvider
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
throws ParameterResolutionException {
RestTemplate rest = new RestTemplate();
RestTemplate rest = new RestTemplate(new HttpComponentsClientHttpRequestFactory(
HttpClients.custom().setRetryHandler(new StandardHttpRequestRetryHandler(10, false)).build()));
rest.setErrorHandler(new ResponseErrorHandler() {
@Override

View File

@@ -80,6 +80,7 @@ class ExplodedApplicationLauncher extends AbstractApplicationLauncher {
extracted.mkdirs();
}
else {
extracted.getParentFile().mkdirs();
FileOutputStream extractedOutputStream = new FileOutputStream(extracted);
StreamUtils.copy(jarFile.getInputStream(jarEntry), extractedOutputStream);
extractedOutputStream.close();

View File

@@ -16,43 +16,28 @@
package org.springframework.boot.context.embedded;
import java.io.File;
import java.io.FileReader;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import org.xml.sax.InputSource;
import org.springframework.util.StringUtils;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
/**
* Provides access to dependency versions by querying the project's pom.
* Provides access to the current Boot version by referring to {@code gradle.properties}.
*
* @author Andy Wilkinson
*/
final class Versions {
private static final String PROPERTIES = "/*[local-name()='project']/*[local-name()='properties']";
private Versions() {
}
static String getBootVersion() {
String baseDir = StringUtils.cleanPath(new File(".").getAbsolutePath());
String mainBaseDir = evaluateExpression("pom.xml", PROPERTIES + "/*[local-name()='main.basedir']/text()");
mainBaseDir = mainBaseDir.replace("${basedir}", baseDir);
return evaluateExpression(mainBaseDir + "/pom.xml", PROPERTIES + "/*[local-name()='revision']/text()");
}
private static String evaluateExpression(String file, String expression) {
try {
InputSource source = new InputSource(new FileReader(file));
XPath xpath = XPathFactory.newInstance().newXPath();
return xpath.compile(expression).evaluate(source);
Properties gradleProperties = new Properties();
try (FileInputStream input = new FileInputStream("../../../gradle.properties")) {
gradleProperties.load(input);
return gradleProperties.getProperty("version");
}
catch (Exception ex) {
throw new IllegalStateException("Failed to evaluate expression", ex);
catch (IOException ex) {
throw new RuntimeException(ex);
}
}

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>{{localRepository}}</localRepository>
<profiles>
<profile>
<id>repository</id>