Skip to content

Commit 7fd8be8

Browse files
committed
Merge remote-tracking branch 'origin/master' into fetch/values-lookup
2 parents 7cbe6a1 + f28bb2f commit 7fd8be8

File tree

673 files changed

+20691
-5492
lines changed

Some content is hidden

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

673 files changed

+20691
-5492
lines changed

.ci/bwcVersions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ BWC_VERSION:
2828
- "7.10.0"
2929
- "7.10.1"
3030
- "7.10.2"
31-
- "7.10.3"
3231
- "7.11.0"
32+
- "7.11.1"
3333
- "7.12.0"
3434
- "8.0.0"

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Contributing to elasticsearch
22
=============================
33

4-
Elasticsearch is an open source project and we love to receive contributions from our community — you! There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests or writing code which can be incorporated into Elasticsearch itself.
4+
Elasticsearch is a free and open project and we love to receive contributions from our community — you! There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests or writing code which can be incorporated into Elasticsearch itself.
55

66
If you want to be rewarded for your contributions, sign up for the [Elastic Contributor Program](https://www.elastic.co/community/contributor). Each time you
77
make a valid contribution, you’ll earn points that increase your chances of winning prizes and being recognized as a top contributor.

TESTING.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ For example to run a specific tests from the x-pack rolling upgrade from 7.7.0:
518518

519519
Tests are ran for versions that are not yet released but with which the current version will be compatible with.
520520
These are automatically checked out and built from source.
521-
See link:./buildSrc/src/main/java/org/elasticsearch/gradle/VersionCollection.java[VersionCollection]
521+
See link:./buildSrc/src/main/java/org/elasticsearch/gradle/BwcVersions.java[BwcVersions]
522522
and link:./distribution/bwc/build.gradle[distribution/bwc/build.gradle]
523523
for more information.
524524

build.gradle

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,26 @@ subprojects {
103103
}
104104
}
105105

106+
/**
107+
* This is a convenient method for declaring test artifact dependencies provided by the internal
108+
* test artifact plugin. It replaces basically the longer dependency notation with explicit capability
109+
* declaration like this:
110+
*
111+
* testImplementation(project(xpackModule('repositories-metering-api'))) {
112+
* capabilities {
113+
* requireCapability("org.elasticsearch.gradle:repositories-metering-api-test-artifacts")
114+
* }
115+
* }
116+
*
117+
* */
118+
ext.testArtifact = { p ->
119+
def projectDependency = p.dependencies.create(p)
120+
projectDependency.capabilities {
121+
requireCapabilities("org.elasticsearch.gradle:${projectDependency.name}-test-artifacts")
122+
};
123+
}
124+
125+
106126
tasks.register("updateCIBwcVersions") {
107127
doLast {
108128
File yml = file(".ci/bwcVersions")

buildSrc/build.gradle

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ if (project == rootProject) {
3232
Properties props = VersionPropertiesLoader.loadBuildSrcVersion(project.file('version.properties'))
3333
version = props.getProperty("elasticsearch")
3434

35+
gradlePlugin {
36+
// We already configure publication and we don't need or want the one that comes
37+
// with the java-gradle-plugin
38+
automatedPublishing = false
39+
}
3540
def generateVersionProperties = tasks.register("generateVersionProperties", WriteProperties) {
3641
outputFile = "${buildDir}/version.properties"
3742
comment = 'Generated version properties'
@@ -240,16 +245,6 @@ if (project != rootProject) {
240245
maxParallelForks = providers.systemProperty('tests.jvms').forUseAtConfigurationTime().getOrElse(org.elasticsearch.gradle.info.BuildParams.defaultParallel.toString()) as Integer
241246
}
242247

243-
/*
244-
* We already configure publication and we don't need or want this one that
245-
* comes from the java-gradle-plugin.
246-
*/
247-
afterEvaluate {
248-
tasks.named("generatePomFileForPluginMavenPublication").configure {
249-
enabled = false
250-
}
251-
}
252-
253248
publishing.publications.named("nebula").configure {
254249
suppressPomMetadataWarningsFor("testFixturesApiElements")
255250
suppressPomMetadataWarningsFor("testFixturesRuntimeElements")

buildSrc/src/integTest/groovy/org/elasticsearch/gradle/YamlRestCompatTestPluginFuncTest.groovy

Lines changed: 150 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,24 @@
88

99
package org.elasticsearch.gradle
1010

11+
import com.fasterxml.jackson.databind.ObjectMapper
12+
import com.fasterxml.jackson.databind.ObjectReader
13+
import com.fasterxml.jackson.databind.ObjectWriter
14+
import com.fasterxml.jackson.databind.node.ObjectNode
15+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
1116
import org.elasticsearch.gradle.fixtures.AbstractRestResourcesFuncTest
1217
import org.elasticsearch.gradle.internal.rest.compat.YamlRestCompatTestPlugin
1318
import org.gradle.testkit.runner.TaskOutcome
1419

1520
class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
1621

17-
def intermediateDir = YamlRestCompatTestPlugin.TEST_INTERMEDIATE_DIR_NAME;
22+
private static final String intermediateDir = YamlRestCompatTestPlugin.TEST_INTERMEDIATE_DIR_NAME
23+
private static final String transformTask = ":" + YamlRestCompatTestPlugin.TRANSFORM_TASK_NAME
24+
private static final YAMLFactory YAML_FACTORY = new YAMLFactory()
25+
private static final ObjectMapper MAPPER = new ObjectMapper(YAML_FACTORY)
26+
private static final ObjectReader READER = MAPPER.readerFor(ObjectNode.class)
27+
private static final ObjectWriter WRITER = MAPPER.writerFor(ObjectNode.class)
28+
1829

1930
def "yamlRestCompatTest does nothing when there are no tests"() {
2031
given:
@@ -39,7 +50,7 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
3950
result.task(':yamlRestCompatTest').outcome == TaskOutcome.NO_SOURCE
4051
result.task(':copyRestCompatApiTask').outcome == TaskOutcome.NO_SOURCE
4152
result.task(':copyRestCompatTestTask').outcome == TaskOutcome.NO_SOURCE
42-
result.task(':transformCompatTests').outcome == TaskOutcome.NO_SOURCE
53+
result.task(transformTask).outcome == TaskOutcome.NO_SOURCE
4354
}
4455

4556
def "yamlRestCompatTest executes and copies api and transforms tests from :bwc:minor"() {
@@ -91,7 +102,7 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
91102
result.task(':yamlRestCompatTest').outcome == TaskOutcome.SKIPPED
92103
result.task(':copyRestCompatApiTask').outcome == TaskOutcome.SUCCESS
93104
result.task(':copyRestCompatTestTask').outcome == TaskOutcome.SUCCESS
94-
result.task(':transformCompatTests').outcome == TaskOutcome.SUCCESS
105+
result.task(transformTask).outcome == TaskOutcome.SUCCESS
95106

96107
file("/build/resources/yamlRestCompatTest/rest-api-spec/api/" + api).exists()
97108
file("/build/resources/yamlRestCompatTest/rest-api-spec/test/" + test).exists()
@@ -119,7 +130,7 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
119130
result.task(':yamlRestCompatTest').outcome == TaskOutcome.SKIPPED
120131
result.task(':copyRestCompatApiTask').outcome == TaskOutcome.UP_TO_DATE
121132
result.task(':copyRestCompatTestTask').outcome == TaskOutcome.UP_TO_DATE
122-
result.task(':transformCompatTests').outcome == TaskOutcome.UP_TO_DATE
133+
result.task(transformTask).outcome == TaskOutcome.UP_TO_DATE
123134
}
124135

125136
def "yamlRestCompatTest is wired into check and checkRestCompat"() {
@@ -148,7 +159,7 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
148159
result.task(':yamlRestCompatTest').outcome == TaskOutcome.NO_SOURCE
149160
result.task(':copyRestCompatApiTask').outcome == TaskOutcome.NO_SOURCE
150161
result.task(':copyRestCompatTestTask').outcome == TaskOutcome.NO_SOURCE
151-
result.task(':transformCompatTests').outcome == TaskOutcome.NO_SOURCE
162+
result.task(transformTask).outcome == TaskOutcome.NO_SOURCE
152163

153164
when:
154165
buildFile << """
@@ -162,7 +173,140 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
162173
result.task(':yamlRestCompatTest').outcome == TaskOutcome.SKIPPED
163174
result.task(':copyRestCompatApiTask').outcome == TaskOutcome.SKIPPED
164175
result.task(':copyRestCompatTestTask').outcome == TaskOutcome.SKIPPED
165-
result.task(':transformCompatTests').outcome == TaskOutcome.SKIPPED
176+
result.task(transformTask).outcome == TaskOutcome.SKIPPED
177+
}
178+
179+
def "transform task executes and works as configured"() {
180+
given:
181+
internalBuild()
182+
183+
addSubProject(":distribution:bwc:minor") << """
184+
configurations { checkout }
185+
artifacts {
186+
checkout(new File(projectDir, "checkoutDir"))
187+
}
188+
"""
189+
190+
buildFile << """
191+
apply plugin: 'elasticsearch.yaml-rest-compat-test'
192+
193+
// avoids a dependency problem in this test, the distribution in use here is inconsequential to the test
194+
import org.elasticsearch.gradle.testclusters.TestDistribution;
195+
testClusters {
196+
yamlRestCompatTest.setTestDistribution(TestDistribution.INTEG_TEST)
197+
}
198+
199+
dependencies {
200+
yamlRestTestImplementation "junit:junit:4.12"
201+
}
202+
tasks.named("transformV7RestTests").configure({ task ->
203+
task.replaceMatch("_type", "_doc")
204+
task.replaceMatch("_source.values", ["z", "x", "y"], "one")
205+
task.removeMatch("_source.blah")
206+
task.removeMatch("_source.junk", "two")
207+
task.addMatch("_source.added", [name: 'jake', likes: 'cheese'], "one")
208+
})
209+
// can't actually spin up test cluster from this test
210+
tasks.withType(Test).configureEach{ enabled = false }
211+
"""
212+
213+
setupRestResources([], [])
214+
215+
file("distribution/bwc/minor/checkoutDir/src/yamlRestTest/resources/rest-api-spec/test/test.yml" ) << """
216+
"one":
217+
- do:
218+
get:
219+
index: test
220+
id: 1
221+
- match: { _source.values: ["foo"] }
222+
- match: { _type: "_foo" }
223+
- match: { _source.blah: 1234 }
224+
- match: { _source.junk: true }
225+
---
226+
"two":
227+
- do:
228+
get:
229+
index: test
230+
id: 1
231+
- match: { _source.values: ["foo"] }
232+
- match: { _type: "_foo" }
233+
- match: { _source.blah: 1234 }
234+
- match: { _source.junk: true }
235+
236+
""".stripIndent()
237+
when:
238+
def result = gradleRunner("yamlRestCompatTest").build()
239+
240+
then:
241+
242+
result.task(transformTask).outcome == TaskOutcome.SUCCESS
243+
166244

245+
file("/build/resources/yamlRestCompatTest/rest-api-spec/test/test.yml" ).exists()
246+
List<ObjectNode> actual = READER.readValues(file("/build/resources/yamlRestCompatTest/rest-api-spec/test/test.yml")).readAll()
247+
List<ObjectNode> expectedAll = READER.readValues(
248+
"""
249+
---
250+
setup:
251+
- skip:
252+
features: "headers"
253+
---
254+
one:
255+
- do:
256+
get:
257+
index: "test"
258+
id: 1
259+
headers:
260+
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7"
261+
Accept: "application/vnd.elasticsearch+json;compatible-with=7"
262+
- match:
263+
_source.values:
264+
- "z"
265+
- "x"
266+
- "y"
267+
- match:
268+
_type: "_doc"
269+
- match: {}
270+
- match:
271+
_source.junk: true
272+
- match:
273+
_source.added:
274+
name: "jake"
275+
likes: "cheese"
276+
---
277+
two:
278+
- do:
279+
get:
280+
index: "test"
281+
id: 1
282+
headers:
283+
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7"
284+
Accept: "application/vnd.elasticsearch+json;compatible-with=7"
285+
- match:
286+
_source.values:
287+
- "foo"
288+
- match:
289+
_type: "_doc"
290+
- match: {}
291+
- match: {}
292+
""".stripIndent()).readAll()
293+
294+
expectedAll.eachWithIndex{ ObjectNode expected, int i ->
295+
assert expected == actual.get(i)
296+
}
297+
298+
when:
299+
result = gradleRunner(transformTask).build()
300+
301+
then:
302+
result.task(transformTask).outcome == TaskOutcome.UP_TO_DATE
303+
304+
when:
305+
buildFile.write(buildFile.text.replace("blah", "baz"))
306+
result = gradleRunner(transformTask).build()
307+
308+
then:
309+
result.task(transformTask).outcome == TaskOutcome.SUCCESS
167310
}
311+
168312
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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;
10+
11+
import org.gradle.api.Plugin;
12+
import org.gradle.api.Project;
13+
import org.gradle.api.artifacts.Configuration;
14+
import org.gradle.api.artifacts.Dependency;
15+
import org.gradle.api.artifacts.dsl.DependencyHandler;
16+
import org.gradle.api.plugins.BasePluginConvention;
17+
import org.gradle.api.plugins.JavaPlugin;
18+
import org.gradle.api.plugins.JavaPluginExtension;
19+
import org.gradle.api.provider.ProviderFactory;
20+
import org.gradle.api.tasks.SourceSetContainer;
21+
import org.gradle.jvm.tasks.Jar;
22+
23+
import javax.inject.Inject;
24+
25+
/**
26+
* Ideally, this plugin is intended to be temporary and in the long run we want to move
27+
* forward to port our test fixtures to use the gradle test fixtures plugin.
28+
* */
29+
public class InternalTestArtifactPlugin implements Plugin<Project> {
30+
31+
private final ProviderFactory providerFactory;
32+
33+
@Inject
34+
public InternalTestArtifactPlugin(ProviderFactory providers) {
35+
this.providerFactory = providers;
36+
}
37+
38+
@Override
39+
public void apply(Project project) {
40+
JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class);
41+
javaPluginExtension.registerFeature("testArtifacts", featureSpec -> {
42+
featureSpec.usingSourceSet(project.getExtensions().getByType(SourceSetContainer.class).getByName("test"));
43+
featureSpec.capability("org.elasticsearch.gradle", project.getName() + "-test-artifacts", "1.0");
44+
// This feature is only used internally in the
45+
// elasticsearch build so we do not need any publication.
46+
featureSpec.disablePublication();
47+
});
48+
Configuration testApiElements = project.getConfigurations().getByName("testApiElements");
49+
testApiElements.extendsFrom(project.getConfigurations().getByName("testCompileClasspath"));
50+
DependencyHandler dependencies = project.getDependencies();
51+
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
52+
Dependency projectDependency = dependencies.create(project);
53+
dependencies.add("testApiElements", projectDependency);
54+
dependencies.add("testRuntimeElements", projectDependency);
55+
});
56+
// PolicyUtil doesn't handle classifier notation well probably.
57+
// Instead of fixing PoliceUtil we stick to the pattern of changing
58+
// the basename here to indicate its a test artifacts jar.
59+
BasePluginConvention convention = (BasePluginConvention) project.getConvention().getPlugins().get("base");
60+
project.getTasks().named("testJar", Jar.class).configure(jar -> {
61+
jar.getArchiveBaseName().convention(providerFactory.provider(() -> convention.getArchivesBaseName() + "-test-artifacts"));
62+
jar.getArchiveClassifier().set("");
63+
});
64+
}
65+
}

0 commit comments

Comments
 (0)