Skip to content

Commit 7fe7c61

Browse files
committed
Merge branch '3.3.x'
2 parents 8282a90 + e086439 commit 7fe7c61

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

buildSrc/SpringRepositorySupport.groovy

+13-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,19 @@ def apply(settings) {
3636
}
3737

3838
private def property(settings, name) {
39-
def parentValue = settings.gradle.parent?.rootProject?.findProperty(name)
40-
return (parentValue != null) ? parentValue : settings.ext[name]
39+
def value = settings.gradle.parent?.rootProject?.findProperty(name)
40+
value = (value != null) ? value : settings.ext.find(name)
41+
value = (value != null) ? value : loadProperty(settings, name)
42+
return value
43+
}
44+
45+
private def loadProperty(settings, name) {
46+
def scriptDir = new File(getClass().protectionDomain.codeSource.location.path).parent
47+
new File(scriptDir, "../gradle.properties").withInputStream {
48+
def properties = new Properties()
49+
properties.load(it)
50+
return properties.get(name)
51+
}
4152
}
4253

4354
return this

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

+19
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.testsupport.gradle.testkit;
1818

19+
import java.io.File;
1920
import java.lang.reflect.Field;
2021
import java.net.URL;
2122
import java.util.regex.Pattern;
@@ -25,6 +26,7 @@
2526
import org.junit.jupiter.api.extension.Extension;
2627
import org.junit.jupiter.api.extension.ExtensionContext;
2728

29+
import org.springframework.util.Assert;
2830
import org.springframework.util.ReflectionUtils;
2931

3032
/**
@@ -43,6 +45,7 @@ public class GradleBuildExtension implements BeforeEachCallback, AfterEachCallba
4345
@Override
4446
public void beforeEach(ExtensionContext context) throws Exception {
4547
GradleBuild gradleBuild = extractGradleBuild(context);
48+
gradleBuild.scriptProperty("parentRootDir", findParentRootDir().getAbsolutePath());
4649
URL scriptUrl = findDefaultScript(context);
4750
if (scriptUrl != null) {
4851
gradleBuild.script(scriptUrl.getFile());
@@ -54,6 +57,22 @@ public void beforeEach(ExtensionContext context) throws Exception {
5457
gradleBuild.before();
5558
}
5659

60+
private File findParentRootDir() {
61+
File dir = new File("").getAbsoluteFile();
62+
int depth = 0;
63+
while (dir != null && !hasGradleBuildFiles(dir)) {
64+
Assert.state(depth++ < 5, "Unable to find parent root");
65+
dir = dir.getParentFile();
66+
}
67+
Assert.state(dir != null, "Unable to find parent root");
68+
return dir;
69+
}
70+
71+
private boolean hasGradleBuildFiles(File dir) {
72+
return new File(dir, "settings.gradle").exists() && new File(dir, "build.gradle").exists()
73+
&& new File(dir, "gradle.properties").exists();
74+
}
75+
5776
private GradleBuild extractGradleBuild(ExtensionContext context) throws Exception {
5877
Object testInstance = context.getRequiredTestInstance();
5978
Field gradleBuildField = ReflectionUtils.findField(testInstance.getClass(), "gradleBuild");

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

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pluginManagement {
2+
evaluate(new File("{parentRootDir}/buildSrc/SpringRepositorySupport.groovy")).apply(this)
23
repositories {
34
exclusiveContent {
45
forRepository {

0 commit comments

Comments
 (0)