Skip to content

Commit ecd1e53

Browse files
committed
Refine workaround for JDK-8156584
The previous workaround worked but prevented caching of every test task as the value of system property pointing to the custom security properties file varied from build to build. This commit refines the workaround to copy the file into the build directory of the test task's project and reference it using a URL that's relative to the task's working directory. This ensures that the value of the system property doesn't change from build to build. Closes gh-26252
1 parent e7bf0a0 commit ecd1e53

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
package org.springframework.boot.build;
1818

1919
import java.io.File;
20+
import java.io.IOException;
21+
import java.io.InputStream;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
2024
import java.util.Arrays;
2125
import java.util.Collections;
2226
import java.util.List;
@@ -28,8 +32,10 @@
2832

2933
import io.spring.javaformat.gradle.FormatTask;
3034
import io.spring.javaformat.gradle.SpringJavaFormatPlugin;
35+
import org.gradle.api.Action;
3136
import org.gradle.api.JavaVersion;
3237
import org.gradle.api.Project;
38+
import org.gradle.api.Task;
3339
import org.gradle.api.artifacts.Configuration;
3440
import org.gradle.api.artifacts.ConfigurationContainer;
3541
import org.gradle.api.artifacts.Dependency;
@@ -142,10 +148,14 @@ private void configureTestConventions(Project project) {
142148
withOptionalBuildJavaHome(project, (javaHome) -> test.setExecutable(javaHome + "/bin/java"));
143149
test.useJUnitPlatform();
144150
test.setMaxHeapSize("1024M");
151+
CopyJdk8156584SecurityProperties copyJdk8156584SecurityProperties = new CopyJdk8156584SecurityProperties(
152+
project);
145153
if (buildingWithJava8(project)) {
146154
test.systemProperty("java.security.properties",
147-
getClass().getClassLoader().getResource("jdk-8156584-security.properties"));
155+
"file:" + test.getWorkingDir().toPath().relativize(copyJdk8156584SecurityProperties.output));
156+
test.setDebug(true);
148157
}
158+
test.doFirst(copyJdk8156584SecurityProperties);
149159
});
150160
project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> project.getDependencies()
151161
.add(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME, "org.junit.platform:junit-platform-launcher"));
@@ -226,4 +236,27 @@ private void configureDependencyManagement(Project project) {
226236
.getByName(OptionalDependenciesPlugin.OPTIONAL_CONFIGURATION_NAME).extendsFrom(dependencyManagement));
227237
}
228238

239+
private static final class CopyJdk8156584SecurityProperties implements Action<Task> {
240+
241+
private static final String SECURITY_PROPERTIES_FILE_NAME = "jdk-8156584-security.properties";
242+
243+
private final Path output;
244+
245+
private CopyJdk8156584SecurityProperties(Project project) {
246+
this.output = new File(project.getBuildDir(), SECURITY_PROPERTIES_FILE_NAME).toPath();
247+
}
248+
249+
@Override
250+
public void execute(Task task) {
251+
try (InputStream input = getClass().getClassLoader()
252+
.getResourceAsStream(CopyJdk8156584SecurityProperties.SECURITY_PROPERTIES_FILE_NAME)) {
253+
Files.copy(input, this.output);
254+
}
255+
catch (IOException ex) {
256+
throw new RuntimeException(ex);
257+
}
258+
}
259+
260+
}
261+
229262
}

0 commit comments

Comments
 (0)