|
11 | 11 | import com.google.common.annotations.VisibleForTesting;
|
12 | 12 |
|
13 | 13 | import org.elasticsearch.gradle.VersionProperties;
|
14 |
| -import org.gradle.api.GradleException; |
15 | 14 |
|
16 | 15 | import java.io.File;
|
17 | 16 | import java.io.FileWriter;
|
18 | 17 | import java.io.IOException;
|
19 | 18 | import java.nio.file.Files;
|
20 | 19 | import java.util.HashMap;
|
21 | 20 | import java.util.List;
|
22 |
| -import java.util.Locale; |
23 | 21 | import java.util.Map;
|
24 | 22 | import java.util.Objects;
|
25 |
| -import java.util.Set; |
26 | 23 | import java.util.TreeMap;
|
27 |
| -import java.util.TreeSet; |
28 |
| -import java.util.stream.Collectors; |
29 | 24 |
|
30 | 25 | import static java.util.Comparator.comparing;
|
31 | 26 | import static java.util.stream.Collectors.groupingBy;
|
32 |
| -import static java.util.stream.Collectors.toCollection; |
| 27 | +import static java.util.stream.Collectors.toList; |
33 | 28 |
|
34 | 29 | /**
|
35 |
| - * Generates the page that contains an index into the breaking changes and lists deprecations for a minor version release, |
36 |
| - * and the individual pages for each breaking area. |
| 30 | + * Generates the page that contains breaking changes deprecations for a minor release series. |
37 | 31 | */
|
38 | 32 | public class BreakingChangesGenerator {
|
39 | 33 |
|
40 |
| - // Needs to match `changelog-schema.json` |
41 |
| - private static final List<String> BREAKING_AREAS = List.of( |
42 |
| - "Cluster and node setting", |
43 |
| - "Command line tool", |
44 |
| - "Index setting", |
45 |
| - "JVM option", |
46 |
| - "Java API", |
47 |
| - "Logging", |
48 |
| - "Mapping", |
49 |
| - "Packaging", |
50 |
| - "Painless", |
51 |
| - "REST API", |
52 |
| - "System requirement", |
53 |
| - "Transform" |
54 |
| - ); |
55 |
| - |
56 |
| - static void update( |
57 |
| - File indexTemplateFile, |
58 |
| - File indexOutputFile, |
59 |
| - File outputDirectory, |
60 |
| - File areaTemplateFile, |
61 |
| - List<ChangelogEntry> entries |
62 |
| - ) throws IOException { |
63 |
| - if (outputDirectory.exists()) { |
64 |
| - if (outputDirectory.isDirectory() == false) { |
65 |
| - throw new GradleException("Path [" + outputDirectory + "] exists but isn't a directory!"); |
66 |
| - } |
67 |
| - } else { |
68 |
| - Files.createDirectory(outputDirectory.toPath()); |
69 |
| - } |
70 |
| - |
71 |
| - try (FileWriter output = new FileWriter(indexOutputFile)) { |
| 34 | + static void update(File migrationTemplateFile, File migrationOutputFile, List<ChangelogEntry> entries) throws IOException { |
| 35 | + try (FileWriter output = new FileWriter(migrationOutputFile)) { |
72 | 36 | output.write(
|
73 |
| - generateIndexFile( |
| 37 | + generateMigrationFile( |
74 | 38 | QualifiedVersion.of(VersionProperties.getElasticsearch()),
|
75 |
| - Files.readString(indexTemplateFile.toPath()), |
| 39 | + Files.readString(migrationTemplateFile.toPath()), |
76 | 40 | entries
|
77 | 41 | )
|
78 | 42 | );
|
79 | 43 | }
|
80 |
| - |
81 |
| - String areaTemplate = Files.readString(areaTemplateFile.toPath()); |
82 |
| - |
83 |
| - for (String breakingArea : BREAKING_AREAS) { |
84 |
| - final List<ChangelogEntry.Breaking> entriesForArea = entries.stream() |
85 |
| - .map(ChangelogEntry::getBreaking) |
86 |
| - .filter(entry -> entry != null && breakingArea.equals(entry.getArea())) |
87 |
| - .collect(Collectors.toList()); |
88 |
| - |
89 |
| - if (entriesForArea.isEmpty()) { |
90 |
| - continue; |
91 |
| - } |
92 |
| - |
93 |
| - final String outputFilename = breakingArea.toLowerCase(Locale.ROOT).replaceFirst(" and", "").replaceAll(" ", "-") |
94 |
| - + "-changes.asciidoc"; |
95 |
| - |
96 |
| - try (FileWriter output = new FileWriter(outputDirectory.toPath().resolve(outputFilename).toFile())) { |
97 |
| - output.write( |
98 |
| - generateBreakingAreaFile( |
99 |
| - QualifiedVersion.of(VersionProperties.getElasticsearch()), |
100 |
| - areaTemplate, |
101 |
| - breakingArea, |
102 |
| - entriesForArea |
103 |
| - ) |
104 |
| - ); |
105 |
| - } |
106 |
| - } |
107 | 44 | }
|
108 | 45 |
|
109 | 46 | @VisibleForTesting
|
110 |
| - static String generateIndexFile(QualifiedVersion version, String template, List<ChangelogEntry> entries) throws IOException { |
111 |
| - final Map<String, List<ChangelogEntry.Deprecation>> deprecationsByArea = entries.stream() |
| 47 | + static String generateMigrationFile(QualifiedVersion version, String template, List<ChangelogEntry> entries) throws IOException { |
| 48 | + final Map<Boolean, Map<String, List<ChangelogEntry.Deprecation>>> deprecationsByNotabilityByArea = entries.stream() |
112 | 49 | .map(ChangelogEntry::getDeprecation)
|
113 | 50 | .filter(Objects::nonNull)
|
114 | 51 | .sorted(comparing(ChangelogEntry.Deprecation::getTitle))
|
115 |
| - .collect(groupingBy(ChangelogEntry.Deprecation::getArea, TreeMap::new, Collectors.toList())); |
116 |
| - |
117 |
| - final List<String> breakingIncludeList = entries.stream() |
118 |
| - .filter(each -> each.getBreaking() != null) |
119 |
| - .map(each -> each.getBreaking().getArea().toLowerCase(Locale.ROOT).replaceFirst(" and", "").replaceAll(" ", "-")) |
120 |
| - .distinct() |
121 |
| - .sorted() |
122 |
| - .toList(); |
123 |
| - |
124 |
| - final Map<String, Object> bindings = new HashMap<>(); |
125 |
| - bindings.put("breakingIncludeList", breakingIncludeList); |
126 |
| - bindings.put("deprecationsByArea", deprecationsByArea); |
127 |
| - bindings.put("isElasticsearchSnapshot", version.isSnapshot()); |
128 |
| - bindings.put("majorDotMinor", version.major() + "." + version.minor()); |
129 |
| - bindings.put("majorMinor", String.valueOf(version.major()) + version.minor()); |
130 |
| - bindings.put("nextMajor", (version.major() + 1) + ".0"); |
131 |
| - bindings.put("version", version); |
132 |
| - |
133 |
| - return TemplateUtils.render(template, bindings); |
134 |
| - } |
| 52 | + .collect( |
| 53 | + groupingBy( |
| 54 | + ChangelogEntry.Deprecation::isNotable, |
| 55 | + TreeMap::new, |
| 56 | + groupingBy(ChangelogEntry.Deprecation::getArea, TreeMap::new, toList()) |
| 57 | + ) |
| 58 | + ); |
135 | 59 |
|
136 |
| - @VisibleForTesting |
137 |
| - static String generateBreakingAreaFile( |
138 |
| - QualifiedVersion version, |
139 |
| - String template, |
140 |
| - String breakingArea, |
141 |
| - List<ChangelogEntry.Breaking> entriesForArea |
142 |
| - ) throws IOException { |
143 |
| - final Map<Boolean, Set<ChangelogEntry.Breaking>> breakingEntriesByNotability = entriesForArea.stream() |
| 60 | + final Map<Boolean, Map<String, List<ChangelogEntry.Breaking>>> breakingByNotabilityByArea = entries.stream() |
| 61 | + .map(ChangelogEntry::getBreaking) |
| 62 | + .filter(Objects::nonNull) |
| 63 | + .sorted(comparing(ChangelogEntry.Breaking::getTitle)) |
144 | 64 | .collect(
|
145 | 65 | groupingBy(
|
146 | 66 | ChangelogEntry.Breaking::isNotable,
|
147 |
| - toCollection(() -> new TreeSet<>(comparing(ChangelogEntry.Breaking::getTitle))) |
| 67 | + TreeMap::new, |
| 68 | + groupingBy(ChangelogEntry.Breaking::getArea, TreeMap::new, toList()) |
148 | 69 | )
|
149 | 70 | );
|
150 | 71 |
|
151 | 72 | final Map<String, Object> bindings = new HashMap<>();
|
152 |
| - bindings.put("breakingArea", breakingArea); |
153 |
| - bindings.put("breakingEntriesByNotability", breakingEntriesByNotability); |
154 |
| - bindings.put("breakingAreaAnchor", breakingArea.toLowerCase(Locale.ROOT).replaceFirst(" and", "").replaceAll(" ", "_")); |
| 73 | + bindings.put("breakingByNotabilityByArea", breakingByNotabilityByArea); |
| 74 | + bindings.put("deprecationsByNotabilityByArea", deprecationsByNotabilityByArea); |
| 75 | + bindings.put("isElasticsearchSnapshot", version.isSnapshot()); |
| 76 | + bindings.put("majorDotMinor", version.major() + "." + version.minor()); |
155 | 77 | bindings.put("majorMinor", String.valueOf(version.major()) + version.minor());
|
| 78 | + bindings.put("nextMajor", (version.major() + 1) + ".0"); |
| 79 | + bindings.put("version", version); |
156 | 80 |
|
157 | 81 | return TemplateUtils.render(template, bindings);
|
158 | 82 | }
|
|
0 commit comments