Skip to content

Commit b7ac487

Browse files
committed
Merge remote-tracking branch 'elastic/6.x' into ccr-6.x
* elastic/6.x: Tests: Fix XPack upgrade tests (#32352) Remove invalid entry from 6.3.2 release notes Number of utilities for writing gradle integration tests (#32282) Determine the minimum gradle version based on the wrapper (#32226) Enable FIPS JVM in CI (#32330) Build: Fix jarHell error I caused by last backport Build: Shadow x-pack:protocol into x-pack:plugin:core (#32240)
2 parents eef3abf + 41b12e2 commit b7ac487

File tree

58 files changed

+219
-109
lines changed

Some content is hidden

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

58 files changed

+219
-109
lines changed

.ci/matrix-runtime-javas.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77

88
ES_RUNTIME_JAVA:
99
- java8
10+
- java8fips
1011
- java10

CONTRIBUTING.md

+36-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ If your changes affect only the documentation, run:
180180
```sh
181181
./gradlew -p docs check
182182
```
183-
For more information about testing code examples in the documentation, see
183+
For more information about testing code examples in the documentation, see
184184
https://github.com/elastic/elasticsearch/blob/master/docs/README.asciidoc
185185

186186
### Project layout
@@ -271,6 +271,39 @@ the `qa` subdirectory functions just like the top level `qa` subdirectory. The
271271
Elasticsearch process. The `transport-client` subdirectory contains extensions
272272
to Elasticsearch's standard transport client to work properly with x-pack.
273273

274+
### Gradle Build
275+
276+
We use Gradle to build Elasticsearch because it is flexible enough to not only
277+
build and package Elasticsearch, but also orchestrate all of the ways that we
278+
have to test Elasticsearch.
279+
280+
#### Configurations
281+
282+
Gradle organizes dependencies and build artifacts into "configurations" and
283+
allows you to use these configurations arbitrarilly. Here are some of the most
284+
common configurations in our build and how we use them:
285+
286+
<dl>
287+
<dt>`compile`</dt><dd>Code that is on the classpath at both compile and
288+
runtime. If the [`shadow`][shadow-plugin] plugin is applied to the project then
289+
this code is bundled into the jar produced by the project.</dd>
290+
<dt>`runtime`</dt><dd>Code that is not on the classpath at compile time but is
291+
on the classpath at runtime. We mostly use this configuration to make sure that
292+
we do not accidentally compile against dependencies of our dependencies also
293+
known as "transitive" dependencies".</dd>
294+
<dt>`compileOnly`</dt><dd>Code that is on the classpath at comile time but that
295+
should not be shipped with the project because it is "provided" by the runtime
296+
somehow. Elasticsearch plugins use this configuration to include dependencies
297+
that are bundled with Elasticsearch's server.</dd>
298+
<dt>`shadow`</dt><dd>Only available in projects with the shadow plugin. Code
299+
that is on the classpath at both compile and runtime but it *not* bundled into
300+
the jar produced by the project. If you depend on a project with the `shadow`
301+
plugin then you need to depend on this configuration because it will bring
302+
along all of the dependencies you need at runtime.</dd>
303+
<dt>`testCompile`</dt><dd>Code that is on the classpath for compiling tests
304+
that are part of this project but not production code. The canonical example
305+
of this is `junit`.</dd>
306+
</dl>
274307

275308
Contributing as part of a class
276309
-------------------------------
@@ -300,3 +333,5 @@ especially when they are unlikely to become long time contributors.
300333
Finally, we require that you run `./gradlew check` before submitting a
301334
non-documentation contribution. This is mentioned above, but it is worth
302335
repeating in this section because it has come up in this context.
336+
337+
[shadow-plugin]: https://github.com/johnrengelman/shadow

build.gradle

+32-7
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,17 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
2019
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
21-
import org.apache.tools.ant.taskdefs.condition.Os
22-
import org.apache.tools.ant.filters.ReplaceTokens
2320
import org.elasticsearch.gradle.BuildPlugin
2421
import org.elasticsearch.gradle.LoggedExec
2522
import org.elasticsearch.gradle.Version
2623
import org.elasticsearch.gradle.VersionCollection
2724
import org.elasticsearch.gradle.VersionProperties
2825
import org.gradle.plugins.ide.eclipse.model.SourceFolder
29-
30-
import org.gradle.api.tasks.wrapper.Wrapper
31-
import org.gradle.api.tasks.wrapper.Wrapper.DistributionType
3226
import org.gradle.util.GradleVersion
3327
import org.gradle.util.DistributionLocator
28+
import org.apache.tools.ant.taskdefs.condition.Os
29+
import org.apache.tools.ant.filters.ReplaceTokens
3430

3531
import java.nio.file.Files
3632
import java.nio.file.Path
@@ -510,6 +506,31 @@ allprojects {
510506
tasks.eclipse.dependsOn(cleanEclipse, copyEclipseSettings)
511507
}
512508

509+
allprojects {
510+
/*
511+
* IntelliJ and Eclipse don't know about the shadow plugin so when we're
512+
* in "IntelliJ mode" or "Eclipse mode" add "runtime" dependencies
513+
* eveywhere where we see a "shadow" dependency which will cause them to
514+
* reference shadowed projects directly rather than rely on the shadowing
515+
* to include them. This is the correct thing for it to do because it
516+
* doesn't run the jar shadowing at all. This isn't needed for the project
517+
* itself because the IDE configuration is done by SourceSets but it is
518+
* *is* needed for projects that depends on the project doing the shadowing.
519+
* Without this they won't properly depend on the shadowed project.
520+
*/
521+
if (isEclipse || isIdea) {
522+
configurations.all { Configuration configuration ->
523+
dependencies.all { Dependency dep ->
524+
if (dep instanceof ProjectDependency) {
525+
if (dep.getTargetConfiguration() == 'shadow') {
526+
configuration.dependencies.add(project.dependencies.project(path: dep.dependencyProject.path, configuration: 'runtime'))
527+
}
528+
}
529+
}
530+
}
531+
}
532+
}
533+
513534
// we need to add the same --debug-jvm option as
514535
// the real RunTask has, so we can pass it through
515536
class Run extends DefaultTask {
@@ -531,7 +552,7 @@ task run(type: Run) {
531552
}
532553

533554
wrapper {
534-
distributionType = DistributionType.ALL
555+
distributionType = 'ALL'
535556
doLast {
536557
final DistributionLocator locator = new DistributionLocator()
537558
final GradleVersion version = GradleVersion.version(wrapper.gradleVersion)
@@ -540,6 +561,10 @@ wrapper {
540561
final String sha256Sum = new String(sha256Uri.toURL().bytes)
541562
wrapper.getPropertiesFile() << "distributionSha256Sum=${sha256Sum}\n"
542563
println "Added checksum to wrapper properties"
564+
// Update build-tools to reflect the Gradle upgrade
565+
// TODO: we can remove this once we have tests to make sure older versions work.
566+
project(':build-tools').file('src/main/resources/minimumGradleVersion').text = gradleVersion
567+
println "Updated minimum Gradle Version"
543568
}
544569
}
545570

buildSrc/build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ plugins {
2525

2626
group = 'org.elasticsearch.gradle'
2727

28-
if (GradleVersion.current() < GradleVersion.version('4.9')) {
29-
throw new GradleException('Gradle 4.9+ is required to build elasticsearch')
28+
String minimumGradleVersion = file('src/main/resources/minimumGradleVersion').text.trim()
29+
if (GradleVersion.current() < GradleVersion.version(minimumGradleVersion)) {
30+
throw new GradleException("Gradle ${minimumGradleVersion}+ is required to build elasticsearch")
3031
}
3132

3233
if (JavaVersion.current() < JavaVersion.VERSION_1_8) {

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

+21-10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package org.elasticsearch.gradle
2020

2121
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
2222
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
23+
import org.apache.commons.io.IOUtils
2324
import org.apache.tools.ant.taskdefs.condition.Os
2425
import org.eclipse.jgit.lib.Constants
2526
import org.eclipse.jgit.lib.RepositoryBuilder
@@ -53,6 +54,7 @@ import org.gradle.internal.jvm.Jvm
5354
import org.gradle.process.ExecResult
5455
import org.gradle.util.GradleVersion
5556

57+
import java.nio.charset.StandardCharsets
5658
import java.time.ZoneOffset
5759
import java.time.ZonedDateTime
5860
/**
@@ -67,8 +69,13 @@ class BuildPlugin implements Plugin<Project> {
6769
+ 'elasticearch.standalone-rest-test, and elasticsearch.build '
6870
+ 'are mutually exclusive')
6971
}
70-
if (GradleVersion.current() < GradleVersion.version('4.9')) {
71-
throw new GradleException('Gradle 4.9+ is required to use elasticsearch.build plugin')
72+
final String minimumGradleVersion
73+
InputStream is = getClass().getResourceAsStream("/minimumGradleVersion")
74+
try { minimumGradleVersion = IOUtils.toString(is, StandardCharsets.UTF_8.toString()) } finally { is.close() }
75+
if (GradleVersion.current() < GradleVersion.version(minimumGradleVersion.trim())) {
76+
throw new GradleException(
77+
"Gradle ${minimumGradleVersion}+ is required to use elasticsearch.build plugin"
78+
)
7279
}
7380
project.pluginManager.apply('java')
7481
project.pluginManager.apply('carrotsearch.randomized-testing')
@@ -153,14 +160,6 @@ class BuildPlugin implements Plugin<Project> {
153160
}
154161
println " Random Testing Seed : ${project.testSeed}"
155162

156-
// enforce Gradle version
157-
final GradleVersion currentGradleVersion = GradleVersion.current();
158-
159-
final GradleVersion minGradle = GradleVersion.version('4.3')
160-
if (currentGradleVersion < minGradle) {
161-
throw new GradleException("${minGradle} or above is required to build Elasticsearch")
162-
}
163-
164163
// enforce Java version
165164
if (compilerJavaVersionEnum < minimumCompilerVersion) {
166165
final String message =
@@ -391,6 +390,9 @@ class BuildPlugin implements Plugin<Project> {
391390
project.configurations.compile.dependencies.all(disableTransitiveDeps)
392391
project.configurations.testCompile.dependencies.all(disableTransitiveDeps)
393392
project.configurations.compileOnly.dependencies.all(disableTransitiveDeps)
393+
project.plugins.withType(ShadowPlugin).whenPluginAdded {
394+
project.configurations.shadow.dependencies.all(disableTransitiveDeps)
395+
}
394396
}
395397

396398
/** Adds repositories used by ES dependencies */
@@ -883,11 +885,20 @@ class BuildPlugin implements Plugin<Project> {
883885
project.dependencyLicenses.dependencies = project.configurations.runtime.fileCollection {
884886
it.group.startsWith('org.elasticsearch') == false
885887
} - project.configurations.compileOnly
888+
project.plugins.withType(ShadowPlugin).whenPluginAdded {
889+
project.dependencyLicenses.dependencies += project.configurations.shadow.fileCollection {
890+
it.group.startsWith('org.elasticsearch') == false
891+
}
892+
}
886893
}
887894

888895
private static configureDependenciesInfo(Project project) {
889896
Task deps = project.tasks.create("dependenciesInfo", DependenciesInfoTask.class)
890897
deps.runtimeConfiguration = project.configurations.runtime
898+
project.plugins.withType(ShadowPlugin).whenPluginAdded {
899+
deps.runtimeConfiguration = project.configurations.create('infoDeps')
900+
deps.runtimeConfiguration.extendsFrom(project.configurations.runtime, project.configurations.shadow)
901+
}
891902
deps.compileOnlyConfiguration = project.configurations.compileOnly
892903
project.afterEvaluate {
893904
deps.mappings = project.dependencyLicenses.mappings

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

+7-14
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,6 @@ public class PluginBuildPlugin extends BuildPlugin {
4848
@Override
4949
public void apply(Project project) {
5050
super.apply(project)
51-
project.plugins.withType(ShadowPlugin).whenPluginAdded {
52-
/*
53-
* We've not tested these plugins together and we're fairly sure
54-
* they aren't going to work properly as is *and* we're not really
55-
* sure *why* you'd want to shade stuff in plugins. So we throw an
56-
* exception here to make you come and read this comment. If you
57-
* have a need for shadow while building plugins then know that you
58-
* are probably going to have to fight with gradle for a while....
59-
*/
60-
throw new InvalidUserDataException('elasticsearch.esplugin is not '
61-
+ 'compatible with com.github.johnrengelman.shadow');
62-
}
6351
configureDependencies(project)
6452
// this afterEvaluate must happen before the afterEvaluate added by integTest creation,
6553
// so that the file name resolution for installing the plugin will be setup
@@ -151,8 +139,13 @@ public class PluginBuildPlugin extends BuildPlugin {
151139
include(buildProperties.descriptorOutput.name)
152140
}
153141
from pluginMetadata // metadata (eg custom security policy)
154-
from project.jar // this plugin's jar
155-
from project.configurations.runtime - project.configurations.compileOnly // the dep jars
142+
/*
143+
* If the plugin is using the shadow plugin then we need to bundle
144+
* "shadow" things rather than the default jar and dependencies so
145+
* we don't hit jar hell.
146+
*/
147+
from { project.plugins.hasPlugin(ShadowPlugin) ? project.shadowJar : project.jar }
148+
from { project.plugins.hasPlugin(ShadowPlugin) ? project.configurations.shadow : project.configurations.runtime - project.configurations.compileOnly }
156149
// extra files for the plugin to go into the zip
157150
from('src/main/packaging') // TODO: move all config/bin/_size/etc into packaging
158151
from('src/main') {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.9

buildSrc/src/test/java/org/elasticsearch/gradle/test/GradleIntegrationTestCase.java

+48
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package org.elasticsearch.gradle.test;
22

3+
import org.gradle.testkit.runner.GradleRunner;
4+
35
import java.io.File;
6+
import java.util.List;
7+
import java.util.stream.Collectors;
8+
import java.util.stream.Stream;
49

510
public abstract class GradleIntegrationTestCase extends GradleUnitTestCase {
611

@@ -13,4 +18,47 @@ protected File getProjectDir(String name) {
1318
return new File(root, name);
1419
}
1520

21+
protected GradleRunner getGradleRunner(String sampleProject) {
22+
return GradleRunner.create()
23+
.withProjectDir(getProjectDir(sampleProject))
24+
.withPluginClasspath();
25+
}
26+
27+
protected File getBuildDir(String name) {
28+
return new File(getProjectDir(name), "build");
29+
}
30+
31+
protected void assertOutputContains(String output, String... lines) {
32+
for (String line : lines) {
33+
assertOutputContains(output, line);
34+
}
35+
List<Integer> index = Stream.of(lines).map(line -> output.indexOf(line)).collect(Collectors.toList());
36+
if (index.equals(index.stream().sorted().collect(Collectors.toList())) == false) {
37+
fail("Expected the following lines to appear in this order:\n" +
38+
Stream.of(lines).map(line -> " - `" + line + "`").collect(Collectors.joining("\n")) +
39+
"\nBut they did not. Output is:\n\n```" + output + "\n```\n"
40+
);
41+
}
42+
}
43+
44+
protected void assertOutputContains(String output, String line) {
45+
assertTrue(
46+
"Expected the following line in output:\n\n" + line + "\n\nOutput is:\n" + output,
47+
output.contains(line)
48+
);
49+
}
50+
51+
protected void assertOutputDoesNotContain(String output, String line) {
52+
assertFalse(
53+
"Expected the following line not to be in output:\n\n" + line + "\n\nOutput is:\n" + output,
54+
output.contains(line)
55+
);
56+
}
57+
58+
protected void assertOutputDoesNotContain(String output, String... lines) {
59+
for (String line : lines) {
60+
assertOutputDoesNotContain(line);
61+
}
62+
}
63+
1664
}

docs/reference/release-notes/6.3.asciidoc

-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ SQL::
4040
* Allow long literals {pull}31777[#31777] (issue: {issue}31750[#31750])
4141
* Fix stackoverflow on getObject and timestamp conversion {pull}31735[#31735] (issue: {issue}31734[#31734])
4242

43-
Search::
44-
* Fix multi level nested sort {pull}32204[#32204] (issues: {issue}31554[#31554], {issue}31776[#31776], {issue}31783[#31783], {issue}32130[#32130])
45-
4643
Security::
4744
* Detect old trial licenses and mimic behaviour {pull}32209[#32209]
4845

gradle/wrapper/gradle-wrapper.jar

-4 Bytes
Binary file not shown.

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/XPackIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void testIndexTemplatesCreated() throws Exception {
8484
List<String> expectedTemplates = new ArrayList<>();
8585
// Watcher creates its templates as soon as the first watcher node connects
8686
expectedTemplates.add(".triggered_watches");
87-
expectedTemplates.add(".watch-history-8");
87+
expectedTemplates.add(".watch-history-9");
8888
expectedTemplates.add(".watches");
8989
if (masterIsNewVersion()) {
9090
// Everything else waits until the master is upgraded to create its templates

x-pack/docs/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ buildRestTests.expectedUnconvertedCandidates = [
3030
]
3131

3232
dependencies {
33-
testCompile project(path: xpackModule('core'), configuration: 'runtime')
33+
testCompile project(path: xpackModule('core'), configuration: 'shadow')
3434
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
3535
testCompile project(path: xpackProject('plugin').path, configuration: 'testArtifacts')
3636
}
@@ -265,7 +265,7 @@ setups['farequote_index'] = '''
265265
airline:
266266
type: keyword
267267
doc_count:
268-
type: integer
268+
type: integer
269269
'''
270270
setups['farequote_data'] = setups['farequote_index'] + '''
271271
- do:
@@ -278,7 +278,7 @@ setups['farequote_data'] = setups['farequote_index'] + '''
278278
{"airline":"JZA","responsetime":990.4628,"time":"2016-02-07T00:00:00+0000", "doc_count": 5}
279279
{"index": {"_id":"2"}}
280280
{"airline":"JBU","responsetime":877.5927,"time":"2016-02-07T00:00:00+0000", "doc_count": 23}
281-
{"index": {"_id":"3"}}
281+
{"index": {"_id":"3"}}
282282
{"airline":"KLM","responsetime":1355.4812,"time":"2016-02-07T00:00:00+0000", "doc_count": 42}
283283
'''
284284
setups['farequote_job'] = setups['farequote_data'] + '''
@@ -310,7 +310,7 @@ setups['farequote_datafeed'] = setups['farequote_job'] + '''
310310
"job_id":"farequote",
311311
"indexes":"farequote"
312312
}
313-
'''
313+
'''
314314
setups['server_metrics_index'] = '''
315315
- do:
316316
indices.create:

x-pack/license-tools/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply plugin: 'elasticsearch.build'
22

33
dependencies {
4-
compile project(xpackModule('core'))
4+
compile project(path: xpackModule('core'), configuration: 'shadow')
55
compile "org.elasticsearch:elasticsearch:${version}"
66
testCompile "org.elasticsearch.test:framework:${version}"
77
}
@@ -17,7 +17,7 @@ task buildZip(type: Zip, dependsOn: jar) {
1717
into(parentDir + '/lib') {
1818
from jar
1919
from configurations.runtime
20-
}
20+
}
2121
into(parentDir + '/bin') {
2222
from 'bin'
2323
}

0 commit comments

Comments
 (0)