|
20 | 20 | import java.io.IOException;
|
21 | 21 | import java.io.UncheckedIOException;
|
22 | 22 | import java.nio.file.Files;
|
23 |
| -import java.nio.file.StandardOpenOption; |
24 | 23 | import java.util.ArrayList;
|
25 | 24 | import java.util.Collections;
|
26 | 25 | import java.util.List;
|
| 26 | +import java.util.stream.Collectors; |
27 | 27 |
|
28 | 28 | import org.gradle.api.file.DirectoryProperty;
|
29 | 29 | import org.gradle.api.file.FileCollection;
|
@@ -82,7 +82,11 @@ else if (!correctlyAnnotated(classFile)) {
|
82 | 82 | List<String> sortedValues = new ArrayList<>(imports);
|
83 | 83 | Collections.sort(sortedValues);
|
84 | 84 | 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() + ")"); |
86 | 90 | }
|
87 | 91 | File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile();
|
88 | 92 | writeReport(importsFile, problems, outputFile);
|
@@ -114,9 +118,12 @@ private void writeReport(File importsFile, List<String> problems, File outputFil
|
114 | 118 | report.append("Found problems in '%s':%n".formatted(importsFile));
|
115 | 119 | problems.forEach((problem) -> report.append(" - %s%n".formatted(problem)));
|
116 | 120 | }
|
| 121 | + writeString(outputFile, report.toString()); |
| 122 | + } |
| 123 | + |
| 124 | + private void writeString(File file, String content) { |
117 | 125 | try {
|
118 |
| - Files.writeString(outputFile.toPath(), report.toString(), StandardOpenOption.CREATE, |
119 |
| - StandardOpenOption.TRUNCATE_EXISTING); |
| 126 | + Files.writeString(file.toPath(), content); |
120 | 127 | }
|
121 | 128 | catch (IOException ex) {
|
122 | 129 | throw new UncheckedIOException(ex);
|
|
0 commit comments