From b50b00d6297672b3d424a0b04c954cf31bede4fa Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 27 May 2020 20:14:36 +0100 Subject: [PATCH] Use sorted properties to ensure output is repeatable Closes gh-21593 --- .../boot/build/autoconfigure/AutoConfigurationMetadata.java | 4 +++- .../springframework/boot/build/starters/StarterMetadata.java | 4 +++- .../boot/build/test/autoconfigure/TestSliceMetadata.java | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/autoconfigure/AutoConfigurationMetadata.java b/buildSrc/src/main/java/org/springframework/boot/build/autoconfigure/AutoConfigurationMetadata.java index c4664062b4..804425fed9 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/autoconfigure/AutoConfigurationMetadata.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/autoconfigure/AutoConfigurationMetadata.java @@ -30,6 +30,8 @@ import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.TaskAction; +import org.springframework.core.CollectionFactory; + /** * A {@link Task} for generating metadata describing a project's auto-configuration * classes. @@ -73,7 +75,7 @@ public class AutoConfigurationMetadata extends AbstractTask { } private Properties readAutoConfiguration() throws IOException { - Properties autoConfiguration = new Properties(); + Properties autoConfiguration = CollectionFactory.createSortedProperties(true); Properties springFactories = readSpringFactories( new File(this.sourceSet.getOutput().getResourcesDir(), "META-INF/spring.factories")); autoConfiguration.setProperty("autoConfigurationClassNames", diff --git a/buildSrc/src/main/java/org/springframework/boot/build/starters/StarterMetadata.java b/buildSrc/src/main/java/org/springframework/boot/build/starters/StarterMetadata.java index 75e09c1273..545d7c7392 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/starters/StarterMetadata.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/starters/StarterMetadata.java @@ -32,6 +32,8 @@ import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; +import org.springframework.core.CollectionFactory; + /** * A {@link Task} for generating metadata that describes a starter. * @@ -68,7 +70,7 @@ public class StarterMetadata extends AbstractTask { @TaskAction void generateMetadata() throws IOException { - Properties properties = new Properties(); + Properties properties = CollectionFactory.createSortedProperties(true); properties.setProperty("name", getProject().getName()); properties.setProperty("description", getProject().getDescription()); properties.setProperty("dependencies", String.join(",", this.dependencies.getResolvedConfiguration() diff --git a/buildSrc/src/main/java/org/springframework/boot/build/test/autoconfigure/TestSliceMetadata.java b/buildSrc/src/main/java/org/springframework/boot/build/test/autoconfigure/TestSliceMetadata.java index 1a1c5ab9de..d5e1c39550 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/test/autoconfigure/TestSliceMetadata.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/test/autoconfigure/TestSliceMetadata.java @@ -42,6 +42,7 @@ import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.TaskAction; +import org.springframework.core.CollectionFactory; import org.springframework.core.io.FileSystemResource; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.classreading.MetadataReader; @@ -91,7 +92,7 @@ public class TestSliceMetadata extends AbstractTask { } private Properties readTestSlices() throws IOException { - Properties testSlices = new Properties(); + Properties testSlices = CollectionFactory.createSortedProperties(true); try (URLClassLoader classLoader = new URLClassLoader( StreamSupport.stream(this.sourceSet.getRuntimeClasspath().spliterator(), false).map(this::toURL) .toArray(URL[]::new))) {