Skip to content

Commit ed42795

Browse files
committed
Merge branch 'master' into ccr
* master: [TEST] REST client request without leading '/' (#29471) Using ObjectParser in UpdateRequest (#29293) Prevent accidental changes of default values (#29528) [Docs] Add definitions to glossary (#29127) Avoid self-deadlock in the translog (#29520) Minor cleanup in NodeInfo.groovy Lazy configure build tasks that require older JDKs (#29519) Simplify snapshot check in root build file Make NodeInfo#nodeVersion strongly-typed as Version (#29515) Enable license header exclusions (#29379) Use proper Java version for BWC builds (#29493) Mute TranslogTests#testFatalIOExceptionsWhileWritingConcurrently Enable skipping fetching latest for BWC builds (#29497)
2 parents db2713b + 62e33ee commit ed42795

File tree

36 files changed

+372
-335
lines changed

36 files changed

+372
-335
lines changed

TESTING.asciidoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,13 @@ will contain your change.
498498
. Push both branches to your remote repository.
499499
. Run the tests with `./gradlew check -Dtests.bwc.remote=${remote} -Dtests.bwc.refspec.5.x=index_req_bwc_5.x`.
500500

501+
== Skip fetching latest
502+
503+
For some BWC testing scenarios, you want to use the local clone of the
504+
repository without fetching latest. For these use cases, you can set the system
505+
property `tests.bwc.git_fetch_latest` to `false` and the BWC builds will skip
506+
fetching the latest from the remote.
507+
501508
== Test coverage analysis
502509

503510
Generating test coverage reports for Elasticsearch is currently not possible through Gradle.

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import java.security.MessageDigest
3636
// common maven publishing configuration
3737
subprojects {
3838
group = 'org.elasticsearch'
39-
version = VersionProperties.elasticsearch
39+
version = VersionProperties.elasticsearch.toString()
4040
description = "Elasticsearch subproject ${project.path}"
4141
}
4242

@@ -80,7 +80,7 @@ configure(subprojects.findAll { it.projectDir.toPath().startsWith(rootPath) }) {
8080
* in a branch if there are only betas and rcs in the branch so we have
8181
* *something* to test against. */
8282
VersionCollection versions = new VersionCollection(file('server/src/main/java/org/elasticsearch/Version.java').readLines('UTF-8'))
83-
if (versions.currentVersion.toString() != VersionProperties.elasticsearch) {
83+
if (versions.currentVersion != VersionProperties.elasticsearch) {
8484
throw new GradleException("The last version in Versions.java [${versions.currentVersion}] does not match " +
8585
"VersionProperties.elasticsearch [${VersionProperties.elasticsearch}]")
8686
}
@@ -245,7 +245,7 @@ subprojects {
245245
// other packages (e.g org.elasticsearch.client) will point to server rather than
246246
// their own artifacts.
247247
if (project.plugins.hasPlugin(BuildPlugin)) {
248-
String artifactsHost = VersionProperties.elasticsearch.endsWith("-SNAPSHOT") ? "https://snapshots.elastic.co" : "https://artifacts.elastic.co"
248+
String artifactsHost = VersionProperties.elasticsearch.isSnapshot() ? "https://snapshots.elastic.co" : "https://artifacts.elastic.co"
249249
Closure sortClosure = { a, b -> b.group <=> a.group }
250250
Closure depJavadocClosure = { dep ->
251251
if (dep.group != null && dep.group.startsWith('org.elasticsearch')) {

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

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ class BuildPlugin implements Plugin<Project> {
9797
String compilerJavaHome = findCompilerJavaHome()
9898
String runtimeJavaHome = findRuntimeJavaHome(compilerJavaHome)
9999
File gradleJavaHome = Jvm.current().javaHome
100+
101+
final Map<Integer, String> javaVersions = [:]
102+
for (int version = 7; version <= Integer.parseInt(minimumCompilerVersion.majorVersion); version++) {
103+
javaVersions.put(version, findJavaHome(version));
104+
}
105+
100106
String javaVendor = System.getProperty('java.vendor')
101107
String javaVersion = System.getProperty('java.version')
102108
String gradleJavaVersionDetails = "${javaVendor} ${javaVersion}" +
@@ -158,10 +164,32 @@ class BuildPlugin implements Plugin<Project> {
158164
throw new GradleException(message)
159165
}
160166

167+
for (final Map.Entry<Integer, String> javaVersionEntry : javaVersions.entrySet()) {
168+
final String javaHome = javaVersionEntry.getValue()
169+
if (javaHome == null) {
170+
continue
171+
}
172+
JavaVersion javaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, javaHome))
173+
final JavaVersion expectedJavaVersionEnum
174+
final int version = javaVersionEntry.getKey()
175+
if (version < 9) {
176+
expectedJavaVersionEnum = JavaVersion.toVersion("1." + version)
177+
} else {
178+
expectedJavaVersionEnum = JavaVersion.toVersion(Integer.toString(version))
179+
}
180+
if (javaVersionEnum != expectedJavaVersionEnum) {
181+
final String message =
182+
"the environment variable JAVA" + version + "_HOME must be set to a JDK installation directory for Java" +
183+
" ${expectedJavaVersionEnum} but is [${javaHome}] corresponding to [${javaVersionEnum}]"
184+
throw new GradleException(message)
185+
}
186+
}
187+
161188
project.rootProject.ext.compilerJavaHome = compilerJavaHome
162189
project.rootProject.ext.runtimeJavaHome = runtimeJavaHome
163190
project.rootProject.ext.compilerJavaVersion = compilerJavaVersionEnum
164191
project.rootProject.ext.runtimeJavaVersion = runtimeJavaVersionEnum
192+
project.rootProject.ext.javaVersions = javaVersions
165193
project.rootProject.ext.buildChecksDone = true
166194
}
167195

@@ -173,6 +201,7 @@ class BuildPlugin implements Plugin<Project> {
173201
project.ext.runtimeJavaHome = project.rootProject.ext.runtimeJavaHome
174202
project.ext.compilerJavaVersion = project.rootProject.ext.compilerJavaVersion
175203
project.ext.runtimeJavaVersion = project.rootProject.ext.runtimeJavaVersion
204+
project.ext.javaVersions = project.rootProject.ext.javaVersions
176205
}
177206

178207
private static String findCompilerJavaHome() {
@@ -188,6 +217,27 @@ class BuildPlugin implements Plugin<Project> {
188217
return javaHome
189218
}
190219

220+
private static String findJavaHome(int version) {
221+
return System.getenv('JAVA' + version + '_HOME')
222+
}
223+
224+
/**
225+
* Get Java home for the project for the specified version. If the specified version is not configured, an exception with the specified
226+
* message is thrown.
227+
*
228+
* @param project the project
229+
* @param version the version of Java home to obtain
230+
* @param message the exception message if Java home for the specified version is not configured
231+
* @return Java home for the specified version
232+
* @throws GradleException if Java home for the specified version is not configured
233+
*/
234+
static String getJavaHome(final Project project, final int version, final String message) {
235+
if (project.javaVersions.get(version) == null) {
236+
throw new GradleException(message)
237+
}
238+
return project.javaVersions.get(version)
239+
}
240+
191241
private static String findRuntimeJavaHome(final String compilerJavaHome) {
192242
assert compilerJavaHome != null
193243
return System.getenv('RUNTIME_JAVA_HOME') ?: compilerJavaHome
@@ -517,17 +567,18 @@ class BuildPlugin implements Plugin<Project> {
517567
jarTask.destinationDir = new File(project.buildDir, 'distributions')
518568
// fixup the jar manifest
519569
jarTask.doFirst {
520-
boolean isSnapshot = VersionProperties.elasticsearch.endsWith("-SNAPSHOT");
521-
String version = VersionProperties.elasticsearch;
522-
if (isSnapshot) {
523-
version = version.substring(0, version.length() - 9)
524-
}
570+
final Version versionWithoutSnapshot = new Version(
571+
VersionProperties.elasticsearch.major,
572+
VersionProperties.elasticsearch.minor,
573+
VersionProperties.elasticsearch.revision,
574+
VersionProperties.elasticsearch.suffix,
575+
false)
525576
// this doFirst is added before the info plugin, therefore it will run
526577
// after the doFirst added by the info plugin, and we can override attributes
527578
jarTask.manifest.attributes(
528-
'X-Compile-Elasticsearch-Version': version,
579+
'X-Compile-Elasticsearch-Version': versionWithoutSnapshot,
529580
'X-Compile-Lucene-Version': VersionProperties.lucene,
530-
'X-Compile-Elasticsearch-Snapshot': isSnapshot,
581+
'X-Compile-Elasticsearch-Snapshot': VersionProperties.elasticsearch.isSnapshot(),
531582
'Build-Date': ZonedDateTime.now(ZoneOffset.UTC),
532583
'Build-Java-Version': project.compilerJavaVersion)
533584
if (jarTask.manifest.attributes.containsKey('Change') == false) {

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,36 @@ public class Version {
7474
return "${major}.${minor}.${revision}${suffix}${snapshotStr}"
7575
}
7676

77+
public boolean before(Version compareTo) {
78+
return id < compareTo.id
79+
}
80+
7781
public boolean before(String compareTo) {
78-
return id < fromString(compareTo).id
82+
return before(fromString(compareTo))
83+
}
84+
85+
public boolean onOrBefore(Version compareTo) {
86+
return id <= compareTo.id
7987
}
8088

8189
public boolean onOrBefore(String compareTo) {
82-
return id <= fromString(compareTo).id
90+
return onOrBefore(fromString(compareTo))
91+
}
92+
93+
public boolean onOrAfter(Version compareTo) {
94+
return id >= compareTo.id
8395
}
8496

8597
public boolean onOrAfter(String compareTo) {
86-
return id >= fromString(compareTo).id
98+
return onOrAfter(fromString(compareTo))
99+
}
100+
101+
public boolean after(Version compareTo) {
102+
return id > compareTo.id
87103
}
88104

89105
public boolean after(String compareTo) {
90-
return id > fromString(compareTo).id
106+
return after(fromString(compareTo))
91107
}
92108

93109
public boolean onOrBeforeIncludingSuffix(Version otherVersion) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ package org.elasticsearch.gradle
2222
* Accessor for shared dependency versions used by elasticsearch, namely the elasticsearch and lucene versions.
2323
*/
2424
class VersionProperties {
25-
static final String elasticsearch
25+
static final Version elasticsearch
2626
static final String lucene
2727
static final Map<String, String> versions = new HashMap<>()
2828
static {
@@ -32,7 +32,7 @@ class VersionProperties {
3232
throw new RuntimeException('/version.properties resource missing')
3333
}
3434
props.load(propsStream)
35-
elasticsearch = props.getProperty('elasticsearch')
35+
elasticsearch = Version.fromString(props.getProperty('elasticsearch'))
3636
lucene = props.getProperty('lucene')
3737
for (String property : props.stringPropertyNames()) {
3838
versions.put(property, props.getProperty(property))

buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/DocsTestPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class DocsTestPlugin extends RestTestPlugin {
4141
* to the version being built for testing but needs to resolve to
4242
* the last released version for docs. */
4343
'\\{version\\}':
44-
VersionProperties.elasticsearch.replace('-SNAPSHOT', ''),
44+
VersionProperties.elasticsearch.toString().replace('-SNAPSHOT', ''),
4545
'\\{lucene_version\\}' : VersionProperties.lucene.replaceAll('-snapshot-\\w+$', ''),
4646
]
4747
Task listSnippets = project.tasks.create('listSnippets', SnippetsTask)

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginPropertiesTask.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class PluginPropertiesTask extends Copy {
7777
'name': extension.name,
7878
'description': extension.description,
7979
'version': stringSnap(extension.version),
80-
'elasticsearchVersion': stringSnap(VersionProperties.elasticsearch),
80+
'elasticsearchVersion': stringSnap(VersionProperties.elasticsearch.toString()),
8181
'javaVersion': project.targetCompatibility as String,
8282
'classname': extension.classname,
8383
'extendedPlugins': extension.extendedPlugins.join(','),

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ public class LicenseHeadersTask extends AntTask {
4949
@Input
5050
List<String> approvedLicenses = ['Apache', 'Generated']
5151

52+
/**
53+
* Files that should be excluded from the license header check. Use with extreme care, only in situations where the license on the
54+
* source file is compatible with the codebase but we do not want to add the license to the list of approved headers (to avoid the
55+
* possibility of inadvertently using the license on our own source files).
56+
*/
57+
@Input
58+
List<String> excludes = []
59+
5260
/**
5361
* Additional license families that may be found. The key is the license category name (5 characters),
5462
* followed by the family name and the value list of patterns to search for.
@@ -95,7 +103,7 @@ public class LicenseHeadersTask extends AntTask {
95103
for (File dir: dirSet.srcDirs) {
96104
// sometimes these dirs don't exist, e.g. site-plugin has no actual java src/main...
97105
if (dir.exists()) {
98-
ant.fileset(dir: dir)
106+
ant.fileset(dir: dir, excludes: excludes.join(' '))
99107
}
100108
}
101109
}

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.elasticsearch.gradle.test
2020

21+
import org.elasticsearch.gradle.Version
2122
import org.gradle.api.GradleException
2223
import org.gradle.api.Project
2324
import org.gradle.api.tasks.Input
@@ -37,7 +38,7 @@ class ClusterConfiguration {
3738
int numBwcNodes = 0
3839

3940
@Input
40-
String bwcVersion = null
41+
Version bwcVersion = null
4142

4243
@Input
4344
int httpPort = 0

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,14 @@ class ClusterFormationTasks {
107107
for (int i = 0; i < config.numNodes; i++) {
108108
// we start N nodes and out of these N nodes there might be M bwc nodes.
109109
// for each of those nodes we might have a different configuration
110-
String elasticsearchVersion = VersionProperties.elasticsearch
111-
Configuration distro = currentDistro
110+
final Configuration distro
111+
final Version elasticsearchVersion
112112
if (i < config.numBwcNodes) {
113113
elasticsearchVersion = config.bwcVersion
114114
distro = bwcDistro
115+
} else {
116+
elasticsearchVersion = VersionProperties.elasticsearch
117+
distro = currentDistro
115118
}
116119
NodeInfo node = new NodeInfo(config, i, project, prefix, elasticsearchVersion, sharedDir)
117120
nodes.add(node)
@@ -126,7 +129,7 @@ class ClusterFormationTasks {
126129
}
127130

128131
/** Adds a dependency on the given distribution */
129-
static void configureDistributionDependency(Project project, String distro, Configuration configuration, String elasticsearchVersion) {
132+
static void configureDistributionDependency(Project project, String distro, Configuration configuration, Version elasticsearchVersion) {
130133
String packaging = distro
131134
if (distro == 'tar') {
132135
packaging = 'tar.gz'
@@ -137,7 +140,7 @@ class ClusterFormationTasks {
137140
}
138141

139142
/** Adds a dependency on a different version of the given plugin, which will be retrieved using gradle's dependency resolution */
140-
static void configureBwcPluginDependency(String name, Project project, Project pluginProject, Configuration configuration, String elasticsearchVersion) {
143+
static void configureBwcPluginDependency(String name, Project project, Project pluginProject, Configuration configuration, Version elasticsearchVersion) {
141144
verifyProjectHasBuildPlugin(name, elasticsearchVersion, project, pluginProject)
142145
final String pluginName = findPluginName(pluginProject)
143146
project.dependencies.add(configuration.name, "org.elasticsearch.plugin:${pluginName}:${elasticsearchVersion}@zip")
@@ -303,7 +306,7 @@ class ClusterFormationTasks {
303306
// Default the watermarks to absurdly low to prevent the tests from failing on nodes without enough disk space
304307
esConfig['cluster.routing.allocation.disk.watermark.low'] = '1b'
305308
esConfig['cluster.routing.allocation.disk.watermark.high'] = '1b'
306-
if (Version.fromString(node.nodeVersion).major >= 6) {
309+
if (node.nodeVersion.major >= 6) {
307310
esConfig['cluster.routing.allocation.disk.watermark.flood_stage'] = '1b'
308311
}
309312
// increase script compilation limit since tests can rapid-fire script compilations
@@ -803,7 +806,7 @@ class ClusterFormationTasks {
803806
return retVal
804807
}
805808

806-
static void verifyProjectHasBuildPlugin(String name, String version, Project project, Project pluginProject) {
809+
static void verifyProjectHasBuildPlugin(String name, Version version, Project project, Project pluginProject) {
807810
if (pluginProject.plugins.hasPlugin(PluginBuildPlugin) == false && pluginProject.plugins.hasPlugin(MetaPluginBuildPlugin) == false) {
808811
throw new GradleException("Task [${name}] cannot add plugin [${pluginProject.path}] with version [${version}] to project's " +
809812
"[${project.path}] dependencies: the plugin is not an esplugin or es_meta_plugin")

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19+
1920
package org.elasticsearch.gradle.test
2021

2122
import com.sun.jna.Native
@@ -29,6 +30,8 @@ import java.nio.file.Files
2930
import java.nio.file.Path
3031
import java.nio.file.Paths
3132

33+
import static org.elasticsearch.gradle.BuildPlugin.getJavaHome
34+
3235
/**
3336
* A container for the files and configuration associated with a single node in a test cluster.
3437
*/
@@ -100,10 +103,10 @@ class NodeInfo {
100103
ByteArrayOutputStream buffer = new ByteArrayOutputStream()
101104

102105
/** the version of elasticsearch that this node runs */
103-
String nodeVersion
106+
Version nodeVersion
104107

105108
/** Holds node configuration for part of a test cluster. */
106-
NodeInfo(ClusterConfiguration config, int nodeNum, Project project, String prefix, String nodeVersion, File sharedDir) {
109+
NodeInfo(ClusterConfiguration config, int nodeNum, Project project, String prefix, Version nodeVersion, File sharedDir) {
107110
this.config = config
108111
this.nodeNum = nodeNum
109112
this.sharedDir = sharedDir
@@ -162,7 +165,14 @@ class NodeInfo {
162165
args.add("${esScript}")
163166
}
164167

165-
env = ['JAVA_HOME': project.runtimeJavaHome]
168+
if (nodeVersion.before("6.2.0")) {
169+
env = ['JAVA_HOME': "${-> getJavaHome(project, 8, "JAVA8_HOME must be set to run BWC tests against [" + nodeVersion + "]")}"]
170+
} else if (nodeVersion.onOrAfter("6.2.0") && nodeVersion.before("6.3.0")) {
171+
env = ['JAVA_HOME': "${-> getJavaHome(project, 9, "JAVA9_HOME must be set to run BWC tests against [" + nodeVersion + "]")}"]
172+
} else {
173+
env = ['JAVA_HOME': (String) project.runtimeJavaHome]
174+
}
175+
166176
args.addAll("-E", "node.portsfile=true")
167177
String collectedSystemProperties = config.systemProperties.collect { key, value -> "-D${key}=${value}" }.join(" ")
168178
String esJavaOpts = config.jvmArgs.isEmpty() ? collectedSystemProperties : collectedSystemProperties + " " + config.jvmArgs
@@ -284,7 +294,7 @@ class NodeInfo {
284294
}
285295

286296
/** Returns the directory elasticsearch home is contained in for the given distribution */
287-
static File homeDir(File baseDir, String distro, String nodeVersion) {
297+
static File homeDir(File baseDir, String distro, Version nodeVersion) {
288298
String path
289299
switch (distro) {
290300
case 'integ-test-zip':
@@ -302,7 +312,7 @@ class NodeInfo {
302312
return new File(baseDir, path)
303313
}
304314

305-
static File pathConf(File baseDir, String distro, String nodeVersion) {
315+
static File pathConf(File baseDir, String distro, Version nodeVersion) {
306316
switch (distro) {
307317
case 'integ-test-zip':
308318
case 'zip':

0 commit comments

Comments
 (0)