forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChangelogEntry.java
329 lines (272 loc) · 8.79 KB
/
ChangelogEntry.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.gradle.internal.release;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* This class models the contents of a changelog YAML file. We validate it using a
* JSON Schema, as well as some programmatic checks in {@link ValidateChangelogEntryTask}.
* <ul>
* <li><code>buildSrc/src/main/resources/changelog-schema.json</code></li>
* <li><a href="https://json-schema.org/understanding-json-schema/">Understanding JSON Schema</a></li>
* </ul>
*/
public class ChangelogEntry {
private Integer pr;
private List<Integer> issues;
private String area;
private String type;
private String summary;
private Highlight highlight;
private Breaking breaking;
private Deprecation deprecation;
private static final ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
/**
* Create a new instance by parsing the supplied file
* @param file the YAML file to parse
* @return a new instance
*/
public static ChangelogEntry parse(File file) {
try {
return yamlMapper.readValue(file, ChangelogEntry.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
public Integer getPr() {
return pr;
}
public void setPr(Integer pr) {
this.pr = pr;
}
public List<Integer> getIssues() {
return issues;
}
public void setIssues(List<Integer> issues) {
this.issues = issues;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public Highlight getHighlight() {
return highlight;
}
public void setHighlight(Highlight highlight) {
this.highlight = highlight;
}
public Breaking getBreaking() {
return breaking;
}
public void setBreaking(Breaking breaking) {
this.breaking = breaking;
}
public Deprecation getDeprecation() {
return deprecation;
}
public void setDeprecation(Deprecation deprecation) {
this.deprecation = deprecation;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ChangelogEntry that = (ChangelogEntry) o;
return Objects.equals(pr, that.pr)
&& Objects.equals(issues, that.issues)
&& Objects.equals(area, that.area)
&& Objects.equals(type, that.type)
&& Objects.equals(summary, that.summary)
&& Objects.equals(highlight, that.highlight)
&& Objects.equals(breaking, that.breaking);
}
@Override
public int hashCode() {
return Objects.hash(pr, issues, area, type, summary, highlight, breaking);
}
@Override
public String toString() {
return String.format(
Locale.ROOT,
"ChangelogEntry{pr=%d, issues=%s, area='%s', type='%s', summary='%s', highlight=%s, breaking=%s, deprecation=%s}",
pr,
issues,
area,
type,
summary,
highlight,
breaking,
deprecation
);
}
public static class Highlight {
private boolean notable;
private String title;
private String body;
public boolean isNotable() {
return notable;
}
public void setNotable(boolean notable) {
this.notable = notable;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getAnchor() {
return generatedAnchor(this.title);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Highlight highlight = (Highlight) o;
return Objects.equals(notable, highlight.notable)
&& Objects.equals(title, highlight.title)
&& Objects.equals(body, highlight.body);
}
@Override
public int hashCode() {
return Objects.hash(notable, title, body);
}
@Override
public String toString() {
return String.format(Locale.ROOT, "Highlight{notable=%s, title='%s', body='%s'}", notable, title, body);
}
}
public static class Breaking extends CompatibilityChange {}
public static class Deprecation extends CompatibilityChange {}
abstract static class CompatibilityChange {
private String area;
private String title;
private String details;
private String impact;
private boolean notable;
private boolean essSettingChange;
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getImpact() {
return impact;
}
public void setImpact(String impact) {
this.impact = impact;
}
public boolean isNotable() {
return notable;
}
public void setNotable(boolean notable) {
this.notable = notable;
}
public String getAnchor() {
return generatedAnchor(this.title);
}
public boolean isEssSettingChange() {
return essSettingChange;
}
public void setEssSettingChange(boolean essSettingChange) {
this.essSettingChange = essSettingChange;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CompatibilityChange breaking = (CompatibilityChange) o;
return notable == breaking.isNotable()
&& Objects.equals(area, breaking.getArea())
&& Objects.equals(title, breaking.getTitle())
&& Objects.equals(details, breaking.getDetails())
&& Objects.equals(impact, breaking.getImpact())
&& Objects.equals(essSettingChange, breaking.isEssSettingChange());
}
@Override
public int hashCode() {
return Objects.hash(area, title, details, impact, notable, essSettingChange);
}
@Override
public String toString() {
return String.format(
"%s{area='%s', title='%s', details='%s', impact='%s', notable=%s, essSettingChange=%s}",
this.getClass().getSimpleName(),
area,
title,
details,
impact,
notable,
essSettingChange
);
}
}
private static String generatedAnchor(String input) {
final List<String> excludes = List.of("the", "is", "a", "and", "now", "that");
final String[] words = input.toLowerCase(Locale.ROOT)
.replaceAll("'", "")
.replaceAll("[^\\w]+", "_")
.replaceFirst("^_+", "")
.replaceFirst("_+$", "")
.split("_+");
return Arrays.stream(words).filter(word -> excludes.contains(word) == false).collect(Collectors.joining("_"));
}
}