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

@@ -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);
}
}