Skip to content

Commit c688ae3

Browse files
committed
Improve error report to include expected sorted output
1 parent d47f1d2 commit c688ae3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

buildSrc/src/main/java/org/springframework/boot/build/autoconfigure/CheckAutoConfigurationImports.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import java.io.IOException;
2121
import java.io.UncheckedIOException;
2222
import java.nio.file.Files;
23-
import java.nio.file.StandardOpenOption;
2423
import java.util.ArrayList;
2524
import java.util.Collections;
2625
import java.util.List;
26+
import java.util.stream.Collectors;
2727

2828
import org.gradle.api.file.DirectoryProperty;
2929
import org.gradle.api.file.FileCollection;
@@ -82,7 +82,11 @@ else if (!correctlyAnnotated(classFile)) {
8282
List<String> sortedValues = new ArrayList<>(imports);
8383
Collections.sort(sortedValues);
8484
if (!sortedValues.equals(imports)) {
85-
problems.add("Entries should be sorted alphabetically");
85+
File sortedOutputFile = getOutputDirectory().file("sorted-" + importsFile.getName()).get().getAsFile();
86+
writeString(sortedOutputFile,
87+
sortedValues.stream().collect(Collectors.joining(System.lineSeparator())) + System.lineSeparator());
88+
problems.add("Entries should be sorted alphabetically (expect content written to "
89+
+ sortedOutputFile.getAbsolutePath() + ")");
8690
}
8791
File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile();
8892
writeReport(importsFile, problems, outputFile);
@@ -114,9 +118,12 @@ private void writeReport(File importsFile, List<String> problems, File outputFil
114118
report.append("Found problems in '%s':%n".formatted(importsFile));
115119
problems.forEach((problem) -> report.append(" - %s%n".formatted(problem)));
116120
}
121+
writeString(outputFile, report.toString());
122+
}
123+
124+
private void writeString(File file, String content) {
117125
try {
118-
Files.writeString(outputFile.toPath(), report.toString(), StandardOpenOption.CREATE,
119-
StandardOpenOption.TRUNCATE_EXISTING);
126+
Files.writeString(file.toPath(), content);
120127
}
121128
catch (IOException ex) {
122129
throw new UncheckedIOException(ex);

0 commit comments

Comments
 (0)