Skip to content

Commit 5ea0985

Browse files
committed
Merge remote-tracking branch 'es/7.x' into enrich-7.x
2 parents db57d22 + 4a67645 commit 5ea0985

File tree

313 files changed

+8770
-2538
lines changed

Some content is hidden

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

313 files changed

+8770
-2538
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,9 @@ allprojects {
527527
def checkPart2 = tasks.register('checkPart2')
528528
plugins.withId('lifecycle-base') {
529529
if (project.path.startsWith(":x-pack:")) {
530-
checkPart1.configure { dependsOn 'check' }
531-
} else {
532530
checkPart2.configure { dependsOn 'check' }
531+
} else {
532+
checkPart1.configure { dependsOn 'check' }
533533
}
534534
}
535535
}

buildSrc/build.gradle

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ sourceSets {
7171
minimumRuntime { }
7272
}
7373

74-
allprojects {
75-
apply plugin: 'java'
76-
targetCompatibility = 11
77-
sourceCompatibility = 11
78-
}
79-
8074
configurations {
8175
reaper
8276
}
@@ -160,8 +154,8 @@ if (project != rootProject) {
160154
apply plugin: 'nebula.maven-scm'
161155

162156
allprojects {
163-
targetCompatibility = 11
164-
sourceCompatibility = 11
157+
targetCompatibility = 10
158+
sourceCompatibility = 10
165159
}
166160

167161
// groovydoc succeeds, but has some weird internal exception...

buildSrc/reaper/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
apply plugin: 'java'
2+
13
jar {
24
archiveName = "${project.name}.jar"
35
manifest {

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -848,10 +848,9 @@ class BuildPlugin implements Plugin<Project> {
848848
test.exclude '**/*$*.class'
849849

850850
test.jvmArgs "-Xmx${System.getProperty('tests.heap.size', '512m')}",
851-
"-Xms${System.getProperty('tests.heap.size', '512m')}",
852-
'-XX:+HeapDumpOnOutOfMemoryError',
853-
"-XX:HeapDumpPath=$heapdumpDir"
851+
"-Xms${System.getProperty('tests.heap.size', '512m')}"
854852

853+
test.jvmArgumentProviders.add({ ['-XX:+HeapDumpOnOutOfMemoryError', "-XX:HeapDumpPath=$heapdumpDir"] } as CommandLineArgumentProvider)
855854

856855
if (System.getProperty('tests.jvm.argline')) {
857856
test.jvmArgs System.getProperty('tests.jvm.argline').split(" ")
@@ -862,8 +861,7 @@ class BuildPlugin implements Plugin<Project> {
862861
}
863862

864863
// we use './temp' since this is per JVM and tests are forbidden from writing to CWD
865-
test.systemProperties 'gradle.dist.lib': new File(project.class.location.toURI()).parent,
866-
'java.io.tmpdir': './temp',
864+
test.systemProperties 'java.io.tmpdir': './temp',
867865
'java.awt.headless': 'true',
868866
'tests.gradle': 'true',
869867
'tests.artifact': project.name,
@@ -879,6 +877,7 @@ class BuildPlugin implements Plugin<Project> {
879877
}
880878

881879
// don't track these as inputs since they contain absolute paths and break cache relocatability
880+
nonInputProperties.systemProperty('gradle.dist.lib', new File(project.class.location.toURI()).parent)
882881
nonInputProperties.systemProperty('gradle.worker.jar', "${project.gradle.getGradleUserHomeDir()}/caches/${project.gradle.gradleVersion}/workerMain/gradle-worker.jar")
883882
nonInputProperties.systemProperty('gradle.user.home', project.gradle.getGradleUserHomeDir())
884883

buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,12 @@ class PrecommitTasks {
237237
// on them. We also want `precommit` to depend on `checkstyle`.
238238
project.pluginManager.apply('checkstyle')
239239
project.checkstyle {
240-
config = project.resources.text.fromFile(checkstyleConf, 'UTF-8')
241-
configProperties = [
242-
suppressions: checkstyleSuppressions
243-
]
240+
configDir = checkstyleDir
244241
toolVersion = CHECKSTYLE_VERSION
245242
}
246243

247244
project.tasks.withType(Checkstyle).configureEach { task ->
248245
task.dependsOn(copyCheckstyleConf)
249-
task.inputs.file(checkstyleSuppressions)
250246
task.reports {
251247
html.enabled false
252248
}

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/DistroTestPlugin.java

Lines changed: 146 additions & 85 deletions
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
import org.gradle.api.logging.Logger;
2525
import org.gradle.internal.jvm.Jvm;
2626

27+
import java.io.FileWriter;
2728
import java.io.IOException;
2829
import java.io.InputStream;
2930
import java.io.OutputStream;
3031
import java.io.UncheckedIOException;
3132
import java.net.URL;
3233
import java.nio.file.Files;
3334
import java.nio.file.Path;
35+
import java.nio.file.Paths;
3436
import java.util.regex.Matcher;
3537
import java.util.regex.Pattern;
3638

@@ -68,8 +70,8 @@ public void registerPid(String serviceId, long pid) {
6870
public void registerCommand(String serviceId, String... command) {
6971
ensureReaperStarted();
7072

71-
try {
72-
Files.writeString(getCmdFile(serviceId), String.join(" ", command));
73+
try (FileWriter writer = new FileWriter(getCmdFile(serviceId).toFile())) {
74+
writer.write(String.join(" ", command));
7375
} catch (IOException e) {
7476
throw new UncheckedIOException(e);
7577
}
@@ -143,7 +145,7 @@ private Path locateReaperJar() {
143145

144146
if (matcher.matches()) {
145147
String path = matcher.group(1);
146-
return Path.of(
148+
return Paths.get(
147149
OS.<String>conditional()
148150
.onWindows(() -> path.substring(1))
149151
.onUnix(() -> path)

buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.gradle.api.Project;
88
import org.gradle.api.plugins.ExtraPropertiesExtension;
99
import org.gradle.internal.jvm.Jvm;
10-
import org.gradle.process.ExecResult;
1110

1211
import java.io.BufferedReader;
1312
import java.io.ByteArrayOutputStream;
@@ -16,18 +15,19 @@
1615
import java.io.IOException;
1716
import java.io.InputStreamReader;
1817
import java.io.UncheckedIOException;
18+
import java.nio.charset.StandardCharsets;
19+
import java.nio.file.Files;
20+
import java.nio.file.Path;
21+
import java.nio.file.Paths;
1922
import java.time.ZoneOffset;
2023
import java.time.ZonedDateTime;
2124
import java.util.ArrayList;
2225
import java.util.Arrays;
2326
import java.util.HashMap;
2427
import java.util.List;
2528
import java.util.Map;
26-
import java.util.concurrent.atomic.AtomicReference;
2729
import java.util.stream.Collectors;
2830

29-
import static java.nio.charset.StandardCharsets.UTF_8;
30-
3131
public class GlobalBuildInfoPlugin implements Plugin<Project> {
3232
private static final String GLOBAL_INFO_EXTENSION_NAME = "globalInfo";
3333
private static Integer _defaultParallel = null;
@@ -46,8 +46,6 @@ public void apply(Project project) {
4646
File compilerJavaHome = findCompilerJavaHome();
4747
File runtimeJavaHome = findRuntimeJavaHome(compilerJavaHome);
4848

49-
Object gitRevisionResolver = createGitRevisionResolver(project);
50-
5149
final List<JavaHome> javaVersions = new ArrayList<>();
5250
for (int version = 8; version <= Integer.parseInt(minimumCompilerVersion.getMajorVersion()); version++) {
5351
if (System.getenv(getJavaHomeEnvVarName(Integer.toString(version))) != null) {
@@ -95,7 +93,7 @@ public void apply(Project project) {
9593
ext.set("minimumCompilerVersion", minimumCompilerVersion);
9694
ext.set("minimumRuntimeVersion", minimumRuntimeVersion);
9795
ext.set("gradleJavaVersion", Jvm.current().getJavaVersion());
98-
ext.set("gitRevision", gitRevisionResolver);
96+
ext.set("gitRevision", gitRevision(project));
9997
ext.set("buildDate", ZonedDateTime.now(ZoneOffset.UTC));
10098
});
10199
}
@@ -206,35 +204,65 @@ private static int findDefaultParallel(Project project) {
206204
return _defaultParallel;
207205
}
208206

209-
private Object createGitRevisionResolver(final Project project) {
210-
return new Object() {
211-
private final AtomicReference<String> gitRevision = new AtomicReference<>();
212-
213-
@Override
214-
public String toString() {
215-
if (gitRevision.get() == null) {
216-
final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
217-
final ByteArrayOutputStream stderr = new ByteArrayOutputStream();
218-
final ExecResult result = project.exec(spec -> {
219-
spec.setExecutable("git");
220-
spec.setArgs(Arrays.asList("rev-parse", "HEAD"));
221-
spec.setStandardOutput(stdout);
222-
spec.setErrorOutput(stderr);
223-
spec.setIgnoreExitValue(true);
224-
});
225-
226-
final String revision;
227-
if (result.getExitValue() != 0) {
228-
revision = "unknown";
229-
} else {
230-
revision = stdout.toString(UTF_8).trim();
231-
}
232-
this.gitRevision.compareAndSet(null, revision);
207+
private String gitRevision(final Project project) {
208+
try {
209+
/*
210+
* We want to avoid forking another process to run git rev-parse HEAD. Instead, we will read the refs manually. The
211+
* documentation for this follows from https://git-scm.com/docs/gitrepository-layout and https://git-scm.com/docs/git-worktree.
212+
*
213+
* There are two cases to consider:
214+
* - a plain repository with .git directory at the root of the working tree
215+
* - a worktree with a plain text .git file at the root of the working tree
216+
*
217+
* In each case, our goal is to parse the HEAD file to get either a ref or a bare revision (in the case of being in detached
218+
* HEAD state).
219+
*
220+
* In the case of a plain repository, we can read the HEAD file directly, resolved directly from the .git directory.
221+
*
222+
* In the case of a worktree, we read the gitdir from the plain text .git file. This resolves to a directory from which we read
223+
* the HEAD file and resolve commondir to the plain git repository.
224+
*/
225+
final Path dotGit = project.getRootProject().getRootDir().toPath().resolve(".git");
226+
final String revision;
227+
if (Files.exists(dotGit) == false) {
228+
return "unknown";
229+
}
230+
final Path head;
231+
final Path gitDir;
232+
if (Files.isDirectory(dotGit)) {
233+
// this is a git repository, we can read HEAD directly
234+
head = dotGit.resolve("HEAD");
235+
gitDir = dotGit;
236+
} else {
237+
// this is a git worktree, follow the pointer to the repository
238+
final Path workTree = Paths.get(readFirstLine(dotGit).substring("gitdir:".length()).trim());
239+
head = workTree.resolve("HEAD");
240+
final Path commonDir = Paths.get(readFirstLine(workTree.resolve("commondir")));
241+
if (commonDir.isAbsolute()) {
242+
gitDir = commonDir;
243+
} else {
244+
// this is the common case
245+
gitDir = workTree.resolve(commonDir);
233246
}
234-
return gitRevision.get();
235247
}
236-
};
248+
final String ref = readFirstLine(head);
249+
if (ref.startsWith("ref:")) {
250+
revision = readFirstLine(gitDir.resolve(ref.substring("ref:".length()).trim()));
251+
} else {
252+
// we are in detached HEAD state
253+
revision = ref;
254+
}
255+
return revision;
256+
} catch (final IOException e) {
257+
// for now, do not be lenient until we have better understanding of real-world scenarios where this happens
258+
throw new GradleException("unable to read the git revision", e);
259+
}
260+
}
237261

262+
private String readFirstLine(final Path path) throws IOException {
263+
return Files.lines(path, StandardCharsets.UTF_8)
264+
.findFirst()
265+
.orElseThrow(() -> new IOException("file [" + path + "] is empty"));
238266
}
239267

240268
}

buildSrc/src/main/java/org/elasticsearch/gradle/test/BatsTestTask.java

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121

2222
import org.gradle.api.DefaultTask;
2323
import org.gradle.api.file.Directory;
24+
import org.gradle.api.file.DirectoryProperty;
25+
import org.gradle.api.provider.Provider;
2426
import org.gradle.api.tasks.Input;
2527
import org.gradle.api.tasks.InputDirectory;
28+
import org.gradle.api.tasks.Optional;
2629
import org.gradle.api.tasks.TaskAction;
2730

2831
import java.util.ArrayList;
@@ -31,36 +34,66 @@
3134

3235
public class BatsTestTask extends DefaultTask {
3336

34-
private Directory testsDir;
35-
private Directory utilsDir;
36-
private Directory archivesDir;
37+
private final DirectoryProperty testsDir;
38+
private final DirectoryProperty utilsDir;
39+
private final DirectoryProperty distributionsDir;
40+
private final DirectoryProperty pluginsDir;
41+
private final DirectoryProperty upgradeDir;
3742
private String packageName;
3843

44+
public BatsTestTask() {
45+
this.testsDir = getProject().getObjects().directoryProperty();
46+
this.utilsDir = getProject().getObjects().directoryProperty();
47+
this.distributionsDir = getProject().getObjects().directoryProperty();
48+
this.pluginsDir = getProject().getObjects().directoryProperty();
49+
this.upgradeDir = getProject().getObjects().directoryProperty();
50+
}
51+
3952
@InputDirectory
40-
public Directory getTestsDir() {
53+
public Provider<Directory> getTestsDir() {
4154
return testsDir;
4255
}
4356

4457
public void setTestsDir(Directory testsDir) {
45-
this.testsDir = testsDir;
58+
this.testsDir.set(testsDir);
4659
}
4760

4861
@InputDirectory
49-
public Directory getUtilsDir() {
62+
public Provider<Directory> getUtilsDir() {
5063
return utilsDir;
5164
}
5265

5366
public void setUtilsDir(Directory utilsDir) {
54-
this.utilsDir = utilsDir;
67+
this.utilsDir.set(utilsDir);
68+
}
69+
70+
@InputDirectory
71+
public Provider<Directory> getDistributionsDir() {
72+
return distributionsDir;
73+
}
74+
75+
public void setDistributionsDir(Provider<Directory> distributionsDir) {
76+
this.distributionsDir.set(distributionsDir);
77+
}
78+
79+
@InputDirectory
80+
@Optional
81+
public Provider<Directory> getPluginsDir() {
82+
return pluginsDir;
83+
}
84+
85+
public void setPluginsDir(Provider<Directory> pluginsDir) {
86+
this.pluginsDir.set(pluginsDir);
5587
}
5688

5789
@InputDirectory
58-
public Directory getArchivesDir() {
59-
return archivesDir;
90+
@Optional
91+
public Provider<Directory> getUpgradeDir() {
92+
return upgradeDir;
6093
}
6194

62-
public void setArchivesDir(Directory archivesDir) {
63-
this.archivesDir = archivesDir;
95+
public void setUpgradeDir(Provider<Directory> upgradeDir) {
96+
this.upgradeDir.set(upgradeDir);
6497
}
6598

6699
@Input
@@ -81,10 +114,16 @@ public void runBats() {
81114
.filter(f -> f.getName().endsWith(".bats"))
82115
.sorted().collect(Collectors.toList()));
83116
getProject().exec(spec -> {
84-
spec.setWorkingDir(archivesDir.getAsFile());
117+
spec.setWorkingDir(distributionsDir.getAsFile());
85118
spec.environment(System.getenv());
86-
spec.environment("BATS_TESTS", testsDir.getAsFile().toString());
87-
spec.environment("BATS_UTILS", utilsDir.getAsFile().toString());
119+
spec.environment("BATS_TESTS", testsDir.getAsFile().get().toString());
120+
spec.environment("BATS_UTILS", utilsDir.getAsFile().get().toString());
121+
if (pluginsDir.isPresent()) {
122+
spec.environment("BATS_PLUGINS", pluginsDir.getAsFile().get().toString());
123+
}
124+
if (upgradeDir.isPresent()) {
125+
spec.environment("BATS_UPGRADE", upgradeDir.getAsFile().get().toString());
126+
}
88127
spec.environment("PACKAGE_NAME", packageName);
89128
spec.setCommandLine(command);
90129
});

buildSrc/src/main/resources/checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<property name="charset" value="UTF-8" />
88

99
<module name="SuppressionFilter">
10-
<property name="file" value="${suppressions}" />
10+
<property name="file" value="${config_loc}/checkstyle_suppressions.xml" />
1111
</module>
1212

1313
<!-- Checks Java files and forbids empty Javadoc comments -->

0 commit comments

Comments
 (0)