From 4bd86a6e20b006cd3c3526513876ff8c11c8932b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 26 Nov 2021 12:00:30 +0000 Subject: [PATCH] Allow spring-boot-image-tests to run without an existing snapshot Closes gh-28817 --- .../testsupport/gradle/testkit/GradleBuild.java | 17 ++++++++++------- .../spring-boot-image-tests/build.gradle | 11 +++++++++++ .../boot/image/paketo/PaketoBuilderTests.java | 7 +++++++ .../PaketoBuilderTests-bootDistZipJarApp.gradle | 8 ++++++++ .../PaketoBuilderTests-executableWarApp.gradle | 8 ++++++++ ...PaketoBuilderTests-plainDistZipJarApp.gradle | 8 ++++++++ .../PaketoBuilderTests-plainWarApp.gradle | 8 ++++++++ .../boot/image/paketo/PaketoBuilderTests.gradle | 8 ++++++++ .../boot/image/paketo/settings.gradle | 15 +++++++++++++++ 9 files changed, 83 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java index c80c080613..4f38422b81 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java +++ b/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 { } 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 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 { return gradleRunner.withArguments(allArguments); } + private void copyTransformedScript(String script, File destination) throws IOException { + String scriptContent = FileCopyUtils.copyToString(new FileReader(script)); + for (Entry 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"); diff --git a/spring-boot-system-tests/spring-boot-image-tests/build.gradle b/spring-boot-system-tests/spring-boot-image-tests/build.gradle index 2e264fc183..455e14076b 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/build.gradle +++ b/spring-boot-system-tests/spring-boot-image-tests/build.gradle @@ -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 { } 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()) diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/PaketoBuilderTests.java b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/PaketoBuilderTests.java index e6adda36bc..ffe9eca8fb 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/PaketoBuilderTests.java +++ b/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; 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 { 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(); diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-bootDistZipJarApp.gradle b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-bootDistZipJarApp.gradle index a74b6cb9e8..b363aae0f8 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-bootDistZipJarApp.gradle +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-bootDistZipJarApp.gradle @@ -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' } diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-executableWarApp.gradle b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-executableWarApp.gradle index e7892dd5e7..291f22d1a0 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-executableWarApp.gradle +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-executableWarApp.gradle @@ -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' } diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainDistZipJarApp.gradle b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainDistZipJarApp.gradle index fb331a1704..261af47bf7 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainDistZipJarApp.gradle +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainDistZipJarApp.gradle @@ -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' } diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainWarApp.gradle b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainWarApp.gradle index 3a40cc9271..566218f11c 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainWarApp.gradle +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainWarApp.gradle @@ -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' } diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests.gradle b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests.gradle index 305b7f3af2..71fe32355b 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests.gradle +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests.gradle @@ -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' } diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/settings.gradle b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/settings.gradle index fb0915aec8..565cc8f972 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/settings.gradle +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/settings.gradle @@ -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}" + } + } + } } \ No newline at end of file