Skip to content

Commit 44099d3

Browse files
committed
Build with Gradle 9.1.0
1 parent 2440667 commit 44099d3

File tree

27 files changed

+152
-119
lines changed

27 files changed

+152
-119
lines changed

build-plugin/spring-boot-antlib/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ tasks.register("integrationTest") {
8080
ant.propertyref(name: "ivy.class.path")
8181
}
8282
plainlistener()
83-
file(layout.buildDirectory.dir("test-results/integrationTest")).mkdirs()
8483
xmllistener(toDir: resultsDir)
8584
fileset(dir: layout.buildDirectory.dir("it").get().asFile.toString(), includes: "**/build.xml")
8685
}

build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,13 @@ private void configureFilePermissions(CopySpec copySpec, int mode) {
141141
}
142142
}
143143

144-
@SuppressWarnings("deprecation")
145144
private void configureFileMode(CopySpec copySpec, int mode) {
146-
copySpec.setFileMode(mode);
145+
try {
146+
copySpec.getClass().getMethod("setFileMode", Integer.class).invoke(copySpec, Integer.valueOf(mode));
147+
}
148+
catch (Exception ex) {
149+
throw new RuntimeException("Failed to set file mode on CopySpec", ex);
150+
}
147151
}
148152

149153
}

build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ private void configureAdditionalMetadataLocations(JavaCompile compile) {
285285
private void configureProductionRuntimeClasspathConfiguration(Project project) {
286286
Configuration productionRuntimeClasspath = project.getConfigurations()
287287
.create(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
288-
productionRuntimeClasspath.setVisible(false);
289288
Configuration runtimeClasspath = project.getConfigurations()
290289
.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
291290
productionRuntimeClasspath.attributes((attributes) -> {

build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/WarPluginAction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ private TaskProvider<BootWar> configureBootWarTask(Project project) {
104104
.set(project.provider(() -> javaPluginExtension(project).getTargetCompatibility()));
105105
bootWar.resolvedArtifacts(runtimeClasspath.getIncoming().getArtifacts().getResolvedArtifacts());
106106
});
107-
bootWarProvider.map(War::getClasspath);
108107
return bootWarProvider;
109108
}
110109

build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/aot/ProcessTestAot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* @since 3.0.0
4444
*/
4545
@CacheableTask
46-
public class ProcessTestAot extends AbstractAot {
46+
public abstract class ProcessTestAot extends AbstractAot {
4747

4848
private @Nullable FileCollection classpathRoots;
4949

build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,19 @@
2222
import java.io.InputStream;
2323
import java.util.Collections;
2424
import java.util.HashSet;
25-
import java.util.Map;
2625
import java.util.Set;
27-
import java.util.TreeMap;
2826
import java.util.function.Function;
2927

3028
import org.gradle.api.file.ConfigurableFilePermissions;
3129
import org.gradle.api.file.CopySpec;
3230
import org.gradle.api.file.FileCopyDetails;
3331
import org.gradle.api.file.FileTreeElement;
34-
import org.gradle.api.file.RelativePath;
3532
import org.gradle.api.internal.file.copy.CopyAction;
36-
import org.gradle.api.internal.file.copy.CopyActionProcessingStream;
37-
import org.gradle.api.internal.file.copy.FileCopyDetailsInternal;
3833
import org.gradle.api.java.archives.Attributes;
3934
import org.gradle.api.java.archives.Manifest;
4035
import org.gradle.api.provider.Property;
4136
import org.gradle.api.specs.Spec;
4237
import org.gradle.api.specs.Specs;
43-
import org.gradle.api.tasks.WorkResult;
4438
import org.gradle.api.tasks.bundling.Jar;
4539
import org.gradle.api.tasks.util.PatternSet;
4640
import org.gradle.util.GradleVersion;
@@ -142,7 +136,7 @@ CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies,
142136
CopyAction action = new BootZipCopyAction(output, manifest, preserveFileTimestamps, dirPermissions,
143137
filePermissions, includeDefaultLoader, jarmodeToolsLocation, requiresUnpack, exclusions, launchScript,
144138
librarySpec, compressionResolver, encoding, resolvedDependencies, supportsSignatureFile, layerResolver);
145-
return jar.isReproducibleFileOrder() ? new ReproducibleOrderingCopyAction(action) : action;
139+
return action;
146140
}
147141

148142
private @Nullable Integer getUnixNumericDirPermissions(CopySpec copySpec) {
@@ -159,14 +153,22 @@ CopyAction createCopyAction(Jar jar, ResolvedDependencies resolvedDependencies,
159153
return permissions.isPresent() ? permissions.get().toUnixNumeric() : null;
160154
}
161155

162-
@SuppressWarnings("deprecation")
163156
private @Nullable Integer getDirMode(CopySpec copySpec) {
164-
return copySpec.getDirMode();
157+
try {
158+
return (Integer) copySpec.getClass().getMethod("getDirMode").invoke(copySpec);
159+
}
160+
catch (Exception ex) {
161+
throw new RuntimeException("Failed to get dir mode from CopySpec", ex);
162+
}
165163
}
166164

167-
@SuppressWarnings("deprecation")
168165
private @Nullable Integer getFileMode(CopySpec copySpec) {
169-
return copySpec.getFileMode();
166+
try {
167+
return (Integer) copySpec.getClass().getMethod("getFileMode").invoke(copySpec);
168+
}
169+
catch (Exception ex) {
170+
throw new RuntimeException("Failed to get file mode from CopySpec", ex);
171+
}
170172
}
171173

172174
private boolean isUsingDefaultLoader(Jar jar) {
@@ -229,26 +231,4 @@ void moveToRoot(FileCopyDetails details) {
229231
details.setRelativePath(details.getRelativeSourcePath());
230232
}
231233

232-
/**
233-
* {@link CopyAction} variant that sorts entries to ensure reproducible ordering.
234-
*/
235-
private static final class ReproducibleOrderingCopyAction implements CopyAction {
236-
237-
private final CopyAction delegate;
238-
239-
private ReproducibleOrderingCopyAction(CopyAction delegate) {
240-
this.delegate = delegate;
241-
}
242-
243-
@Override
244-
public WorkResult execute(CopyActionProcessingStream stream) {
245-
return this.delegate.execute((action) -> {
246-
Map<RelativePath, FileCopyDetailsInternal> detailsByPath = new TreeMap<>();
247-
stream.process((details) -> detailsByPath.put(details.getRelativePath(), details));
248-
detailsByPath.values().forEach(action::processFile);
249-
});
250-
}
251-
252-
}
253-
254234
}

build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,13 @@ private int getPermissions(FileCopyDetails details) {
504504
? details.getPermissions().toUnixNumeric() : getMode(details);
505505
}
506506

507-
@SuppressWarnings("deprecation")
508507
private int getMode(FileCopyDetails details) {
509-
return details.getMode();
508+
try {
509+
return (int) details.getClass().getMethod("getMode").invoke(details);
510+
}
511+
catch (Exception ex) {
512+
throw new RuntimeException("Failed to get mode from FileCopyDetails", ex);
513+
}
510514
}
511515

512516
}

build-plugin/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoTests.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import java.util.Properties;
2525

2626
import org.gradle.api.Project;
27-
import org.gradle.api.internal.project.ProjectInternal;
28-
import org.gradle.initialization.GradlePropertiesController;
2927
import org.junit.jupiter.api.Test;
3028
import org.junit.jupiter.api.io.TempDir;
3129

@@ -173,11 +171,7 @@ void nullAdditionalPropertyProducesInformativeFailure() {
173171

174172
private Project createProject(String projectName) {
175173
File projectDir = new File(this.temp, projectName);
176-
Project project = GradleProjectBuilder.builder().withProjectDir(projectDir).withName(projectName).build();
177-
((ProjectInternal) project).getServices()
178-
.get(GradlePropertiesController.class)
179-
.loadGradlePropertiesFrom(projectDir, false);
180-
return project;
174+
return GradleProjectBuilder.builder().withProjectDir(projectDir).withName(projectName).build();
181175
}
182176

183177
private BuildInfo createTask(Project project) {

build-plugin/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,8 @@ void versionMismatchBetweenTransitiveDevelopmentOnlyImplementationDependenciesDo
233233
.filter((entry) -> !entry.isDirectory())
234234
.map(JarEntry::getName)
235235
.filter((name) -> name.startsWith(this.libPath));
236-
if (this.gradleBuild.gradleVersionIsLessThan("9.0.0-rc-1")) {
237-
assertThat(libEntryNames).containsExactly(this.libPath + "two-1.0.jar",
238-
this.libPath + "commons-io-2.19.0.jar");
239-
}
240-
else {
241-
assertThat(libEntryNames).containsExactly(this.libPath + "commons-io-2.19.0.jar",
242-
this.libPath + "two-1.0.jar");
243-
}
236+
assertThat(libEntryNames).containsExactly(this.libPath + "two-1.0.jar",
237+
this.libPath + "commons-io-2.19.0.jar");
244238
}
245239
}
246240

build-plugin/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.nio.file.Path;
2828
import java.nio.file.StandardOpenOption;
2929
import java.nio.file.attribute.PosixFilePermission;
30+
import java.time.OffsetDateTime;
31+
import java.time.ZoneOffset;
3032
import java.util.ArrayList;
3133
import java.util.Enumeration;
3234
import java.util.HashMap;
@@ -35,6 +37,7 @@
3537
import java.util.Map;
3638
import java.util.Set;
3739
import java.util.TreeSet;
40+
import java.util.UUID;
3841
import java.util.jar.JarEntry;
3942
import java.util.jar.JarFile;
4043
import java.util.jar.JarOutputStream;
@@ -407,23 +410,46 @@ void constantTimestampMatchesGradleInternalTimestamp() {
407410
}
408411

409412
@Test
410-
void reproducibleOrderingCanBeEnabled() throws IOException {
413+
void archiveIsReproducibleByDefault() throws IOException {
411414
this.task.getMainClass().set("com.example.Main");
412-
this.task.from(newFile("bravo.txt"), newFile("alpha.txt"), newFile("charlie.txt"));
413-
this.task.setReproducibleFileOrder(true);
415+
this.task.from(newFiles("files/b/bravo.txt", "files/a/alpha.txt", "files/c/charlie.txt"));
414416
executeTask();
415417
assertThat(this.task.getArchiveFile().get().getAsFile()).exists();
416-
List<String> textFiles = new ArrayList<>();
418+
List<String> files = new ArrayList<>();
417419
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
418420
Enumeration<JarEntry> entries = jarFile.entries();
419421
while (entries.hasMoreElements()) {
420422
JarEntry entry = entries.nextElement();
421-
if (entry.getName().endsWith(".txt")) {
422-
textFiles.add(entry.getName());
423+
OffsetDateTime lastModifiedTime = entry.getLastModifiedTime().toInstant().atOffset(ZoneOffset.UTC);
424+
assertThat(lastModifiedTime).isEqualTo(OffsetDateTime.of(1980, 2, 1, 0, 0, 0, 0, ZoneOffset.UTC));
425+
if (entry.getName().startsWith("files/")) {
426+
files.add(entry.getName());
427+
}
428+
}
429+
}
430+
assertThat(files).containsExactly("files/", "files/a/", "files/a/alpha.txt", "files/b/", "files/b/bravo.txt",
431+
"files/c/", "files/c/charlie.txt");
432+
}
433+
434+
@Test
435+
void archiveReproducibilityCanBeDisabled() throws IOException {
436+
this.task.getMainClass().set("com.example.Main");
437+
this.task.from(newFiles("files/b/bravo.txt", "files/a/alpha.txt", "files/c/charlie.txt"));
438+
this.task.setPreserveFileTimestamps(true);
439+
this.task.setReproducibleFileOrder(false);
440+
executeTask();
441+
assertThat(this.task.getArchiveFile().get().getAsFile()).exists();
442+
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
443+
Enumeration<JarEntry> entries = jarFile.entries();
444+
while (entries.hasMoreElements()) {
445+
JarEntry entry = entries.nextElement();
446+
if (entry.getName().endsWith(".txt") || entry.getName().startsWith("BOOT-INF/lib/")) {
447+
OffsetDateTime lastModifiedTime = entry.getLastModifiedTime().toInstant().atOffset(ZoneOffset.UTC);
448+
assertThat(lastModifiedTime)
449+
.isNotEqualTo(OffsetDateTime.of(1980, 2, 1, 0, 0, 0, 0, ZoneOffset.UTC));
423450
}
424451
}
425452
}
426-
assertThat(textFiles).containsExactly("alpha.txt", "bravo.txt", "charlie.txt");
427453
}
428454

429455
@Test
@@ -663,6 +689,19 @@ protected List<String> getEntryNames(JarFile jarFile) {
663689
return entryNames;
664690
}
665691

692+
protected File newFiles(String... names) throws IOException {
693+
File dir = new File(this.temp, UUID.randomUUID().toString());
694+
dir.mkdir();
695+
List<File> files = new ArrayList<>();
696+
for (String name : names) {
697+
File file = new File(dir, name);
698+
file.getParentFile().mkdirs();
699+
file.createNewFile();
700+
files.add(file);
701+
}
702+
return dir;
703+
}
704+
666705
protected File newFile(String name) throws IOException {
667706
File file = new File(this.temp, name);
668707
file.createNewFile();

0 commit comments

Comments
 (0)