Skip to content

Commit 115997b

Browse files
committed
Merge branch 'master' into feature/searchable-snapshots
2 parents aea62f5 + 09c98cb commit 115997b

File tree

111 files changed

+2533
-1696
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+2533
-1696
lines changed

build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ subprojects {
106106
// is greater than the number of unformatted projects, this can be
107107
// switched to an exclude list, and eventualy removed completely.
108108
def projectPathsToFormat = [
109+
':build-tools',
109110
':x-pack:plugin:enrich'
110111
]
111112

@@ -114,6 +115,10 @@ subprojects {
114115

115116
spotless {
116117
java {
118+
// Normally this isn't necessary, but we have Java sources in
119+
// non-standard places
120+
target '**/*.java'
121+
117122
removeUnusedImports()
118123
eclipse().configFile rootProject.file('.eclipseformat.xml')
119124
trimTrailingWhitespace()

buildSrc/reaper/src/main/java/org/elasticsearch/gradle/reaper/Reaper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ public static void main(String[] args) throws Exception {
6565
}
6666
Path inputDir = Paths.get(args[0]);
6767

68-
try (Reaper reaper = new Reaper(inputDir)){
68+
try (Reaper reaper = new Reaper(inputDir)) {
6969
System.in.read();
7070
reaper.reap();
7171
}
7272
}
7373

7474
private void reap() {
75-
try (Stream<Path> stream = Files.list(inputDir)){
75+
try (Stream<Path> stream = Files.list(inputDir)) {
7676
final List<Path> inputFiles = stream.filter(p -> p.getFileName().toString().endsWith(".cmd")).collect(Collectors.toList());
7777

7878
for (Path inputFile : inputFiles) {
@@ -118,7 +118,7 @@ private void delete(Path toDelete) {
118118
@Override
119119
public void close() {
120120
if (failed == false) {
121-
try (Stream<Path> stream = Files.walk(inputDir)){
121+
try (Stream<Path> stream = Files.walk(inputDir)) {
122122
stream.sorted(Comparator.reverseOrder()).forEach(this::delete);
123123
} catch (IOException e) {
124124
throw new UncheckedIOException(e);

buildSrc/src/main/java/org/elasticsearch/gradle/BwcVersions.java

Lines changed: 47 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,20 @@ public BwcVersions(List<String> versionLines) {
109109
}
110110

111111
protected BwcVersions(List<String> versionLines, Version currentVersionProperty) {
112-
this(versionLines.stream()
113-
.map(LINE_PATTERN::matcher)
114-
.filter(Matcher::matches)
115-
.map(match -> new Version(
116-
Integer.parseInt(match.group(1)),
117-
Integer.parseInt(match.group(2)),
118-
Integer.parseInt(match.group(3))
119-
))
120-
.collect(Collectors.toCollection(TreeSet::new)), currentVersionProperty);
112+
this(
113+
versionLines.stream()
114+
.map(LINE_PATTERN::matcher)
115+
.filter(Matcher::matches)
116+
.map(
117+
match -> new Version(
118+
Integer.parseInt(match.group(1)),
119+
Integer.parseInt(match.group(2)),
120+
Integer.parseInt(match.group(3))
121+
)
122+
)
123+
.collect(Collectors.toCollection(TreeSet::new)),
124+
currentVersionProperty
125+
);
121126
}
122127

123128
// for testkit tests, until BwcVersions is extracted into an extension
@@ -140,27 +145,29 @@ public BwcVersions(SortedSet<Version> allVersions, Version currentVersionPropert
140145

141146
Map<Version, UnreleasedVersionInfo> unreleased = new HashMap<>();
142147
for (Version unreleasedVersion : getUnreleased()) {
143-
unreleased.put(unreleasedVersion,
144-
new UnreleasedVersionInfo(unreleasedVersion, getBranchFor(unreleasedVersion), getGradleProjectPathFor(unreleasedVersion)));
148+
unreleased.put(
149+
unreleasedVersion,
150+
new UnreleasedVersionInfo(unreleasedVersion, getBranchFor(unreleasedVersion), getGradleProjectPathFor(unreleasedVersion))
151+
);
145152
}
146153
this.unreleased = Collections.unmodifiableMap(unreleased);
147154
}
148155

149156
private void assertNoOlderThanTwoMajors() {
150157
Set<Integer> majors = groupByMajor.keySet();
151158
if (majors.size() != 2 && currentVersion.getMinor() != 0 && currentVersion.getRevision() != 0) {
152-
throw new IllegalStateException(
153-
"Expected exactly 2 majors in parsed versions but found: " + majors
154-
);
159+
throw new IllegalStateException("Expected exactly 2 majors in parsed versions but found: " + majors);
155160
}
156161
}
157162

158163
private void assertCurrentVersionMatchesParsed(Version currentVersionProperty) {
159164
if (currentVersionProperty.equals(currentVersion) == false) {
160165
throw new IllegalStateException(
161-
"Parsed versions latest version does not match the one configured in build properties. " +
162-
"Parsed latest version is " + currentVersion + " but the build has " +
163-
currentVersionProperty
166+
"Parsed versions latest version does not match the one configured in build properties. "
167+
+ "Parsed latest version is "
168+
+ currentVersion
169+
+ " but the build has "
170+
+ currentVersionProperty
164171
);
165172
}
166173
}
@@ -175,12 +182,7 @@ public UnreleasedVersionInfo unreleasedInfo(Version version) {
175182
public void forPreviousUnreleased(Consumer<UnreleasedVersionInfo> consumer) {
176183
List<UnreleasedVersionInfo> collect = getUnreleased().stream()
177184
.filter(version -> version.equals(currentVersion) == false)
178-
.map(version -> new UnreleasedVersionInfo(
179-
version,
180-
getBranchFor(version),
181-
getGradleProjectPathFor(version)
182-
)
183-
)
185+
.map(version -> new UnreleasedVersionInfo(version, getBranchFor(version), getGradleProjectPathFor(version)))
184186
.collect(Collectors.toList());
185187

186188
collect.forEach(uvi -> consumer.accept(uvi));
@@ -196,22 +198,18 @@ private String getGradleProjectPathFor(Version version) {
196198
Map<Integer, List<Version>> releasedMajorGroupedByMinor = getReleasedMajorGroupedByMinor();
197199

198200
if (version.getRevision() == 0) {
199-
List<Version> unreleasedStagedOrMinor = getUnreleased().stream()
200-
.filter(v -> v.getRevision() == 0)
201-
.collect(Collectors.toList());
201+
List<Version> unreleasedStagedOrMinor = getUnreleased().stream().filter(v -> v.getRevision() == 0).collect(Collectors.toList());
202202
if (unreleasedStagedOrMinor.size() > 2) {
203203
if (unreleasedStagedOrMinor.get(unreleasedStagedOrMinor.size() - 2).equals(version)) {
204204
return ":distribution:bwc:minor";
205-
} else{
205+
} else {
206206
return ":distribution:bwc:staged";
207207
}
208208
} else {
209209
return ":distribution:bwc:minor";
210210
}
211211
} else {
212-
if (releasedMajorGroupedByMinor
213-
.getOrDefault(version.getMinor(), emptyList())
214-
.contains(version)) {
212+
if (releasedMajorGroupedByMinor.getOrDefault(version.getMinor(), emptyList()).contains(version)) {
215213
return ":distribution:bwc:bugfix";
216214
} else {
217215
return ":distribution:bwc:maintenance";
@@ -229,7 +227,7 @@ private String getBranchFor(Version version) {
229227
return "master";
230228
case ":distribution:bwc:minor":
231229
// The .x branch will always point to the latest minor (for that major), so a "minor" project will be on the .x branch
232-
// unless there is more recent (higher) minor.
230+
// unless there is more recent (higher) minor.
233231
final Version latestInMajor = getLatestVersionByKey(groupByMajor, version.getMajor());
234232
if (latestInMajor.getMinor() == version.getMinor()) {
235233
return version.getMajor() + ".x";
@@ -279,23 +277,16 @@ public List<Version> getUnreleased() {
279277
}
280278
}
281279

282-
return unmodifiableList(
283-
unreleased.stream()
284-
.sorted()
285-
.distinct()
286-
.collect(Collectors.toList())
287-
);
280+
return unmodifiableList(unreleased.stream().sorted().distinct().collect(Collectors.toList()));
288281
}
289282

290283
private Version getLatestInMinor(int major, int minor) {
291-
return groupByMajor.get(major).stream()
292-
.filter(v -> v.getMinor() == minor)
293-
.max(Version::compareTo)
294-
.orElse(null);
284+
return groupByMajor.get(major).stream().filter(v -> v.getMinor() == minor).max(Version::compareTo).orElse(null);
295285
}
296286

297287
private Version getLatestVersionByKey(Map<Integer, List<Version>> groupByMajor, int key) {
298-
return groupByMajor.getOrDefault(key, emptyList()).stream()
288+
return groupByMajor.getOrDefault(key, emptyList())
289+
.stream()
299290
.max(Version::compareTo)
300291
.orElseThrow(() -> new IllegalStateException("Unexpected number of versions in collection"));
301292
}
@@ -307,11 +298,9 @@ private Map<Integer, List<Version>> getReleasedMajorGroupedByMinor() {
307298
final Map<Integer, List<Version>> groupByMinor;
308299
if (currentMajorVersions.size() == 1) {
309300
// Current is an unreleased major: x.0.0 so we have to look for other unreleased versions in the previous major
310-
groupByMinor = previousMajorVersions.stream()
311-
.collect(Collectors.groupingBy(Version::getMinor, Collectors.toList()));
301+
groupByMinor = previousMajorVersions.stream().collect(Collectors.groupingBy(Version::getMinor, Collectors.toList()));
312302
} else {
313-
groupByMinor = currentMajorVersions.stream()
314-
.collect(Collectors.groupingBy(Version::getMinor, Collectors.toList()));
303+
groupByMinor = currentMajorVersions.stream().collect(Collectors.groupingBy(Version::getMinor, Collectors.toList()));
315304
}
316305
return groupByMinor;
317306
}
@@ -321,37 +310,37 @@ public void compareToAuthoritative(List<Version> authoritativeReleasedVersions)
321310
notReallyReleased.removeAll(authoritativeReleasedVersions);
322311
if (notReallyReleased.isEmpty() == false) {
323312
throw new IllegalStateException(
324-
"out-of-date released versions" +
325-
"\nFollowing versions are not really released, but the build thinks they are: " + notReallyReleased
313+
"out-of-date released versions"
314+
+ "\nFollowing versions are not really released, but the build thinks they are: "
315+
+ notReallyReleased
326316
);
327317
}
328318

329319
Set<Version> incorrectlyConsideredUnreleased = new HashSet<>(authoritativeReleasedVersions);
330320
incorrectlyConsideredUnreleased.retainAll(getUnreleased());
331321
if (incorrectlyConsideredUnreleased.isEmpty() == false) {
332322
throw new IllegalStateException(
333-
"out-of-date released versions" +
334-
"\nBuild considers versions unreleased, " +
335-
"but they are released according to an authoritative source: " + incorrectlyConsideredUnreleased +
336-
"\nThe next versions probably needs to be added to Version.java (CURRENT doesn't count)."
323+
"out-of-date released versions"
324+
+ "\nBuild considers versions unreleased, "
325+
+ "but they are released according to an authoritative source: "
326+
+ incorrectlyConsideredUnreleased
327+
+ "\nThe next versions probably needs to be added to Version.java (CURRENT doesn't count)."
337328
);
338329
}
339330
}
340331

341332
private List<Version> getReleased() {
342333
List<Version> unreleased = getUnreleased();
343-
return groupByMajor.values().stream()
334+
return groupByMajor.values()
335+
.stream()
344336
.flatMap(Collection::stream)
345337
.filter(each -> unreleased.contains(each) == false)
346338
.collect(Collectors.toList());
347339
}
348340

349341
public List<Version> getIndexCompatible() {
350342
return unmodifiableList(
351-
Stream.concat(
352-
groupByMajor.get(currentVersion.getMajor() - 1).stream(),
353-
groupByMajor.get(currentVersion.getMajor()).stream()
354-
)
343+
Stream.concat(groupByMajor.get(currentVersion.getMajor() - 1).stream(), groupByMajor.get(currentVersion.getMajor()).stream())
355344
.collect(Collectors.toList())
356345
);
357346
}
@@ -361,10 +350,7 @@ public List<Version> getWireCompatible() {
361350

362351
List<Version> prevMajors = groupByMajor.get(currentVersion.getMajor() - 1);
363352
int minor = prevMajors.get(prevMajors.size() - 1).getMinor();
364-
for (int i = prevMajors.size() - 1;
365-
i > 0 && prevMajors.get(i).getMinor() == minor;
366-
i--
367-
) {
353+
for (int i = prevMajors.size() - 1; i > 0 && prevMajors.get(i).getMinor() == minor; i--) {
368354
wireCompat.add(prevMajors.get(i));
369355
}
370356
wireCompat.addAll(groupByMajor.get(currentVersion.getMajor()));

buildSrc/src/main/java/org/elasticsearch/gradle/ConcatFilesTask.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,19 @@ public void setFiles(FileTree files) {
5555
}
5656

5757
@InputFiles
58-
public FileTree getFiles() { return files; }
58+
public FileTree getFiles() {
59+
return files;
60+
}
5961

6062
public void setHeaderLine(String headerLine) {
6163
this.headerLine = headerLine;
6264
}
6365

6466
@Input
6567
@Optional
66-
public String getHeaderLine() { return headerLine; }
68+
public String getHeaderLine() {
69+
return headerLine;
70+
}
6771

6872
public void setTarget(File target) {
6973
this.target = target;
@@ -77,20 +81,15 @@ public File getTarget() {
7781
@TaskAction
7882
public void concatFiles() throws IOException {
7983
if (getHeaderLine() != null) {
80-
Files.write(
81-
getTarget().toPath(),
82-
(getHeaderLine() + '\n').getBytes(StandardCharsets.UTF_8)
83-
);
84+
Files.write(getTarget().toPath(), (getHeaderLine() + '\n').getBytes(StandardCharsets.UTF_8));
8485
}
8586

8687
// To remove duplicate lines
8788
LinkedHashSet<String> uniqueLines = new LinkedHashSet<>();
8889
for (File f : getFiles()) {
8990
uniqueLines.addAll(Files.readAllLines(f.toPath(), StandardCharsets.UTF_8));
9091
}
91-
Files.write(
92-
getTarget().toPath(), uniqueLines, StandardCharsets.UTF_8, StandardOpenOption.APPEND
93-
);
92+
Files.write(getTarget().toPath(), uniqueLines, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
9493
}
9594

9695
}

buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ void setupDistributions(Project project) {
105105
if (distribution.getType().shouldExtract()) {
106106
// for the distribution extracted, add a root level task that does the extraction, and depend on that
107107
// extracted configuration as an artifact consisting of the extracted distribution directory
108-
dependencies.add(distribution.getExtracted().configuration.getName(),
109-
projectDependency(project, ":", configName("extracted_elasticsearch", distribution)));
108+
dependencies.add(
109+
distribution.getExtracted().configuration.getName(),
110+
projectDependency(project, ":", configName("extracted_elasticsearch", distribution))
111+
);
110112
// ensure a root level download task exists
111113
setupRootDownload(project.getRootProject(), distribution);
112114
}
@@ -139,7 +141,7 @@ private void setupRootDownload(Project rootProject, ElasticsearchDistribution di
139141
TaskProvider<Sync> extractTask = rootProject.getTasks().register(extractTaskName, Sync.class, syncTask -> {
140142
syncTask.dependsOn(downloadConfig);
141143
syncTask.into(extractDir);
142-
syncTask.from((Callable<FileTree>)() -> {
144+
syncTask.from((Callable<FileTree>) () -> {
143145
File archiveFile = archiveGetter.get();
144146
String archivePath = archiveFile.toString();
145147
if (archivePath.endsWith(".zip")) {
@@ -150,9 +152,12 @@ private void setupRootDownload(Project rootProject, ElasticsearchDistribution di
150152
throw new IllegalStateException("unexpected file extension on [" + archivePath + "]");
151153
});
152154
});
153-
rootProject.getArtifacts().add(extractedConfigName,
154-
rootProject.getLayout().getProjectDirectory().dir(extractDir),
155-
artifact -> artifact.builtBy(extractTask));
155+
rootProject.getArtifacts()
156+
.add(
157+
extractedConfigName,
158+
rootProject.getLayout().getProjectDirectory().dir(extractDir),
159+
artifact -> artifact.builtBy(extractTask)
160+
);
156161
}
157162
}
158163

@@ -219,7 +224,6 @@ private Object dependencyNotation(Project project, ElasticsearchDistribution dis
219224
return "org.elasticsearch.distribution.integ-test-zip:elasticsearch:" + distribution.getVersion() + "@zip";
220225
}
221226

222-
223227
Version distroVersion = Version.fromString(distribution.getVersion());
224228
String extension = distribution.getType().toString();
225229
String classifier = ":x86_64";
@@ -293,9 +297,16 @@ private static String distributionProjectName(ElasticsearchDistribution distribu
293297
}
294298

295299
private static String configName(String prefix, ElasticsearchDistribution distribution) {
296-
return prefix + "_" + distribution.getVersion() + "_" + distribution.getType() + "_" +
297-
(distribution.getPlatform() == null ? "" : distribution.getPlatform() + "_")
298-
+ distribution.getFlavor() + (distribution.getBundledJdk() ? "" : "_nojdk");
300+
return String.format(
301+
Locale.ROOT,
302+
"%s_%s_%s_%s%s%s",
303+
prefix,
304+
distribution.getVersion(),
305+
distribution.getType(),
306+
distribution.getPlatform() == null ? "" : distribution.getPlatform() + "_",
307+
distribution.getFlavor(),
308+
distribution.getBundledJdk() ? "" : "_nojdk"
309+
);
299310
}
300311

301312
private static String capitalize(String s) {

0 commit comments

Comments
 (0)