Skip to content

Commit

Permalink
Allow spring-boot-image-tests to run without an existing snapshot
Browse files Browse the repository at this point in the history
Closes gh-28817
  • Loading branch information
wilkinsona committed Nov 26, 2021
1 parent cd4d08d commit 4bd86a6
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 7 deletions.
Expand Up @@ -186,16 +186,11 @@ public BuildResult buildAndFail(String... arguments) {
}

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()) {
Expand Down Expand Up @@ -223,6 +218,14 @@ public GradleRunner prepareRunner(String... arguments) throws IOException {
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");
Expand Down
11 changes: 11 additions & 0 deletions spring-boot-system-tests/spring-boot-image-tests/build.gradle
Expand Up @@ -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 {
Expand All @@ -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())
Expand Down
Expand Up @@ -32,6 +32,7 @@
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;
Expand Down Expand Up @@ -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();
Expand Down
Expand Up @@ -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' }
Expand Down
Expand Up @@ -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' }
Expand Down
Expand Up @@ -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' }
Expand Down
Expand Up @@ -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' }
Expand Down
Expand Up @@ -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' }
Expand Down
@@ -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}"
}
}
}
}

0 comments on commit 4bd86a6

Please sign in to comment.