Skip to content

Commit 0a55e0a

Browse files
Merge branch 'master' into return-200-for-cluster-health-timeout
2 parents e1ad212 + 377f546 commit 0a55e0a

File tree

147 files changed

+3412
-694
lines changed

Some content is hidden

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

147 files changed

+3412
-694
lines changed

build-tools-internal/src/main/groovy/elasticsearch.ide.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ if (providers.systemProperty('idea.active').forUseAtConfigurationTime().getOrNul
8888
tasks.register('buildDependencyArtifacts') {
8989
group = 'ide'
9090
description = 'Builds artifacts needed as dependency for IDE modules'
91-
dependsOn ':client:rest-high-level:shadowJar', ':plugins:repository-hdfs:hadoop-common:shadowJar', ':plugins:repository-azure:azure-storage-blob:shadowJar'
91+
dependsOn ':client:rest-high-level:shadowJar', ':plugins:repository-hdfs:hadoop-client-api:shadowJar', ':plugins:repository-azure:azure-storage-blob:shadowJar'
9292
}
9393

9494
idea {
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.gradle.internal.release;
10+
11+
import com.google.common.annotations.VisibleForTesting;
12+
13+
import org.elasticsearch.gradle.VersionProperties;
14+
import org.gradle.api.DefaultTask;
15+
import org.gradle.api.GradleException;
16+
import org.gradle.api.Project;
17+
import org.gradle.api.file.FileCollection;
18+
import org.gradle.api.logging.Logger;
19+
import org.gradle.api.logging.Logging;
20+
import org.gradle.api.model.ObjectFactory;
21+
import org.gradle.api.tasks.Internal;
22+
import org.gradle.api.tasks.SkipWhenEmpty;
23+
import org.gradle.api.tasks.TaskAction;
24+
import org.gradle.api.tasks.options.Option;
25+
import org.gradle.process.ExecOperations;
26+
27+
import java.io.File;
28+
import java.nio.file.Path;
29+
import java.util.Set;
30+
import java.util.TreeSet;
31+
import java.util.stream.Collectors;
32+
import java.util.stream.Stream;
33+
import javax.inject.Inject;
34+
35+
/**
36+
* Once a minor release has happened, we no longer need to keep the changelog files that went into
37+
* that release in the development branch for that major series or the branch for the next major
38+
* series
39+
* <p>
40+
* This last examines the git history in order to work out which files can be deleted, and
41+
* does the deletion after confirming with the user.
42+
*/
43+
public class PruneChangelogsTask extends DefaultTask {
44+
private static final Logger LOGGER = Logging.getLogger(PruneChangelogsTask.class);
45+
46+
private FileCollection changelogs;
47+
private final GitWrapper gitWrapper;
48+
private final Path rootDir;
49+
50+
private boolean dryRun;
51+
52+
@Inject
53+
public PruneChangelogsTask(Project project, ObjectFactory objectFactory, ExecOperations execOperations) {
54+
changelogs = objectFactory.fileCollection();
55+
gitWrapper = new GitWrapper(execOperations);
56+
rootDir = project.getRootDir().toPath();
57+
}
58+
59+
@Internal
60+
public FileCollection getChangelogs() {
61+
return changelogs;
62+
}
63+
64+
public void setChangelogs(FileCollection files) {
65+
this.changelogs = files;
66+
}
67+
68+
@Internal
69+
public boolean isDryRun() {
70+
return dryRun;
71+
}
72+
73+
@Option(option = "dry-run", description = "Find and print files to prune but don't actually delete them")
74+
public void setDryRun(boolean dryRun) {
75+
this.dryRun = dryRun;
76+
}
77+
78+
@TaskAction
79+
public void executeTask() {
80+
findAndDeleteFiles(
81+
this.gitWrapper,
82+
files -> files.stream().filter(each -> each.delete() == false).collect(Collectors.toSet()),
83+
QualifiedVersion.of(VersionProperties.getElasticsearch()),
84+
this.getChangelogs().getFiles(),
85+
this.dryRun,
86+
this.rootDir
87+
);
88+
}
89+
90+
@VisibleForTesting
91+
static void findAndDeleteFiles(
92+
GitWrapper gitWrapper,
93+
DeleteHelper deleteHelper,
94+
QualifiedVersion version,
95+
Set<File> allFilesInCheckout,
96+
boolean dryRun,
97+
Path rootDir
98+
) {
99+
if (allFilesInCheckout.isEmpty()) {
100+
LOGGER.warn("No changelog files in checkout, so nothing to delete.");
101+
return;
102+
}
103+
104+
final Set<String> earlierFiles = findAllFilesInEarlierVersions(gitWrapper, version);
105+
106+
if (earlierFiles.isEmpty()) {
107+
LOGGER.warn("No files need to be deleted.");
108+
return;
109+
}
110+
111+
final Set<File> filesToDelete = allFilesInCheckout.stream()
112+
.filter(each -> earlierFiles.contains(each.getName()))
113+
.collect(Collectors.toCollection(TreeSet::new));
114+
115+
if (filesToDelete.isEmpty()) {
116+
LOGGER.warn("No files need to be deleted.");
117+
return;
118+
}
119+
120+
LOGGER.warn("The following changelog files {} be deleted:", dryRun ? "can" : "will");
121+
LOGGER.warn("");
122+
filesToDelete.forEach(file -> LOGGER.warn("\t{}", rootDir.relativize(file.toPath())));
123+
124+
if (dryRun == false) {
125+
final Set<File> failedToDelete = deleteHelper.deleteFiles(filesToDelete);
126+
127+
if (failedToDelete.isEmpty() == false) {
128+
throw new GradleException(
129+
"Failed to delete some files:\n\n"
130+
+ failedToDelete.stream().map(file -> "\t" + rootDir.relativize(file.toPath())).collect(Collectors.joining("\n"))
131+
+ "\n"
132+
);
133+
}
134+
}
135+
}
136+
137+
/**
138+
* Find the releases prior to the supplied version, and find the changelog files in those releases by inspecting the
139+
* git trees at each tag.
140+
* <p>
141+
* If the supplied version is the very first in a new major series, then the method will look tag in the previous
142+
* major series. Otherwise, all git tags in the current major series will be inspected.
143+
*
144+
* @param gitWrapper used for git operations
145+
* @param version the git history is inspected relative to this version
146+
* @return filenames for changelog files in previous releases, without any path
147+
*/
148+
private static Set<String> findAllFilesInEarlierVersions(GitWrapper gitWrapper, QualifiedVersion version) {
149+
return findPreviousVersion(gitWrapper, version)
150+
.flatMap(earlierVersion -> gitWrapper.listFiles("v" + earlierVersion, "docs/changelog"))
151+
.map(line -> Path.of(line).getFileName().toString())
152+
.collect(Collectors.toSet());
153+
}
154+
155+
/**
156+
* Find the releases prior to the supplied version. If the supplied version is the very first in a new
157+
* major series, then the method will look tag in the previous major series. Otherwise, all git tags
158+
* in the current major series will be inspected.
159+
*
160+
* @param gitWrapper used for git operations
161+
* @param version the git tags are inspected relative to this version
162+
* @return a stream of earlier versions
163+
*/
164+
@VisibleForTesting
165+
static Stream<QualifiedVersion> findPreviousVersion(GitWrapper gitWrapper, QualifiedVersion version) {
166+
final int majorSeries = version.getMinor() == 0 && version.getRevision() == 0 ? version.getMajor() - 1 : version.getMajor();
167+
final String tagPattern = "v" + majorSeries + ".*";
168+
169+
return gitWrapper.listVersions(tagPattern)
170+
.filter(v -> v.isBefore(version));
171+
}
172+
173+
/**
174+
* Used to make it possible to mock destructive operations in tests.
175+
*/
176+
@VisibleForTesting
177+
@FunctionalInterface
178+
interface DeleteHelper {
179+
Set<File> deleteFiles(Set<File> filesToDelete);
180+
}
181+
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/release/ReleaseToolsPlugin.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ public void apply(Project project) {
9292
task.dependsOn(validateChangelogsTask);
9393
});
9494

95+
project.getTasks().register("pruneChangelogs", PruneChangelogsTask.class).configure(task -> {
96+
task.setGroup("Documentation");
97+
task.setDescription("Removes changelog files that have been used in a previous release");
98+
task.setChangelogs(yamlFiles);
99+
});
100+
95101
project.getTasks().named("precommit").configure(task -> task.dependsOn(validateChangelogsTask));
96102
}
97103
}

0 commit comments

Comments
 (0)