Browse Source

Allow spring-boot-image-tests to run without an existing snapshot

Closes gh-28817
pull/28830/head
Andy Wilkinson 4 years ago
parent
commit
4bd86a6e20
  1. 17
      spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java
  2. 11
      spring-boot-system-tests/spring-boot-image-tests/build.gradle
  3. 7
      spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/PaketoBuilderTests.java
  4. 8
      spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-bootDistZipJarApp.gradle
  5. 8
      spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-executableWarApp.gradle
  6. 8
      spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainDistZipJarApp.gradle
  7. 8
      spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainWarApp.gradle
  8. 8
      spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests.gradle
  9. 15
      spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/settings.gradle

17
spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java

@ -186,16 +186,11 @@ public class GradleBuild { @@ -186,16 +186,11 @@ public class GradleBuild {
}
public GradleRunner prepareRunner(String... arguments) throws IOException {
String scriptContent = FileCopyUtils.copyToString(new FileReader(this.script));
this.scriptProperties.put("bootVersion", getBootVersion());
this.scriptProperties.put("dependencyManagementPluginVersion", getDependencyManagementPluginVersion());
for (Entry<String, String> property : this.scriptProperties.entrySet()) {
scriptContent = scriptContent.replace("{" + property.getKey() + "}", property.getValue());
}
FileCopyUtils.copy(scriptContent, new FileWriter(new File(this.projectDir, "build" + this.dsl.getExtension())));
copyTransformedScript(this.script, new File(this.projectDir, "build" + this.dsl.getExtension()));
if (this.settings != null) {
FileCopyUtils.copy(new FileReader(this.settings),
new FileWriter(new File(this.projectDir, "settings.gradle")));
copyTransformedScript(this.settings, new File(this.projectDir, "settings.gradle"));
}
File repository = new File("src/test/resources/repository");
if (repository.exists()) {
@ -223,6 +218,14 @@ public class GradleBuild { @@ -223,6 +218,14 @@ public class GradleBuild {
return gradleRunner.withArguments(allArguments);
}
private void copyTransformedScript(String script, File destination) throws IOException {
String scriptContent = FileCopyUtils.copyToString(new FileReader(script));
for (Entry<String, String> property : this.scriptProperties.entrySet()) {
scriptContent = scriptContent.replace("{" + property.getKey() + "}", property.getValue());
}
FileCopyUtils.copy(scriptContent, new FileWriter(destination));
}
private File getTestKitDir() {
File temp = new File(System.getProperty("java.io.tmpdir"));
String username = System.getProperty("user.name");

11
spring-boot-system-tests/spring-boot-image-tests/build.gradle

@ -7,12 +7,19 @@ plugins { @@ -7,12 +7,19 @@ plugins {
description = "Spring Boot Image Building Tests"
configurations {
app
providedRuntime {
extendsFrom dependencyManagement
}
}
task syncMavenRepository(type: Sync) {
from configurations.app
into "${buildDir}/system-test-maven-repository"
}
systemTest {
dependsOn syncMavenRepository
if (project.hasProperty("springBootVersion")) {
systemProperty "springBootVersion", project.properties["springBootVersion"]
} else {
@ -21,11 +28,15 @@ systemTest { @@ -21,11 +28,15 @@ systemTest {
}
dependencies {
app project(path: ":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin", configuration: "mavenRepository")
app project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-web", configuration: "mavenRepository")
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) {
exclude group: "org.hibernate.validator"
}
systemTestImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
systemTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin"))
systemTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-gradle-test-support"))
systemTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-buildpack-platform"))
systemTestImplementation(gradleTestKit())

7
spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/PaketoBuilderTests.java

@ -32,6 +32,7 @@ import com.github.dockerjava.api.model.ContainerConfig; @@ -32,6 +32,7 @@ import com.github.dockerjava.api.model.ContainerConfig;
import org.assertj.core.api.Condition;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testcontainers.containers.GenericContainer;
@ -61,6 +62,12 @@ class PaketoBuilderTests { @@ -61,6 +62,12 @@ class PaketoBuilderTests {
GradleBuild gradleBuild;
@BeforeEach
void configureGradleBuild() {
this.gradleBuild.scriptProperty("systemTestMavenRepository",
new File("build/system-test-maven-repository").getAbsoluteFile().toURI().toASCIIString());
}
@Test
void executableJarApp() throws Exception {
writeMainClass();

8
spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-bootDistZipJarApp.gradle

@ -6,6 +6,14 @@ plugins { @@ -6,6 +6,14 @@ plugins {
}
repositories {
exclusiveContent {
forRepository {
maven { url '{systemTestMavenRepository}' }
}
filter {
includeGroup "org.springframework.boot"
}
}
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }

8
spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-executableWarApp.gradle

@ -6,6 +6,14 @@ plugins { @@ -6,6 +6,14 @@ plugins {
}
repositories {
exclusiveContent {
forRepository {
maven { url '{systemTestMavenRepository}' }
}
filter {
includeGroup "org.springframework.boot"
}
}
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }

8
spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainDistZipJarApp.gradle

@ -6,6 +6,14 @@ plugins { @@ -6,6 +6,14 @@ plugins {
}
repositories {
exclusiveContent {
forRepository {
maven { url '{systemTestMavenRepository}' }
}
filter {
includeGroup "org.springframework.boot"
}
}
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }

8
spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainWarApp.gradle

@ -6,6 +6,14 @@ plugins { @@ -6,6 +6,14 @@ plugins {
}
repositories {
exclusiveContent {
forRepository {
maven { url '{systemTestMavenRepository}' }
}
filter {
includeGroup "org.springframework.boot"
}
}
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }

8
spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests.gradle

@ -5,6 +5,14 @@ plugins { @@ -5,6 +5,14 @@ plugins {
}
repositories {
exclusiveContent {
forRepository {
maven { url '{systemTestMavenRepository}' }
}
filter {
includeGroup "org.springframework.boot"
}
}
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }

15
spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/settings.gradle

@ -1,7 +1,22 @@ @@ -1,7 +1,22 @@
pluginManagement {
repositories {
exclusiveContent {
forRepository {
maven { url '{systemTestMavenRepository}' }
}
filter {
includeGroup "org.springframework.boot"
}
}
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
gradlePluginPortal()
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == "org.springframework.boot") {
useModule "org.springframework.boot:spring-boot-gradle-plugin:${requested.version}"
}
}
}
}
Loading…
Cancel
Save