Skip to content

Commit 5fcef9a

Browse files
committed
Merge branch 'master' into feature/runtime_fields
2 parents 8bddd84 + 198b2d6 commit 5fcef9a

File tree

144 files changed

+1934
-1339
lines changed

Some content is hidden

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

144 files changed

+1934
-1339
lines changed

CONTRIBUTING.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ dependencies. Fix them:
179179
Next you'll want to import our auto-formatter:
180180

181181
- Select **Window > Preferences**
182-
- Select **Java > Code Style > Formater**
182+
- Select **Java > Code Style > Formatter**
183183
- Click **Import**
184184
- Import the file at **buildSrc/formatterConfig.xml**
185185
- Make sure it is the **Active profile**
@@ -575,10 +575,14 @@ allows you to use these configurations arbitrarily. Here are some of the most
575575
common configurations in our build and how we use them:
576576

577577
<dl>
578-
<dt>`compile`</dt><dd>Code that is on the classpath at both compile and
579-
runtime.</dd>
580-
<dt>`runtime`</dt><dd>Code that is not on the classpath at compile time but is
581-
on the classpath at runtime. We mostly use this configuration to make sure that
578+
<dt>`implementation`</dt><dd>Dependencies that are used by the project
579+
at compile and runtime but are not exposed as a compile dependency to other dependent projects.
580+
Dependencies added to the `implementation` configuration are considered an implementation detail
581+
that can be changed at a later date without affecting any dependent projects.</dd>
582+
<dt>`api`</dt><dd>Dependencies that are used as compile and runtime depdendencies of a project
583+
and are considered part of the external api of the project.
584+
<dt>`runtimeOnly`</dt><dd>Dependencies that not on the classpath at compile time but
585+
are on the classpath at runtime. We mostly use this configuration to make sure that
582586
we do not accidentally compile against dependencies of our dependencies also
583587
known as "transitive" dependencies".</dd>
584588
<dt>`compileOnly`</dt><dd>Code that is on the classpath at compile time but that

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ class PluginBuildPlugin implements Plugin<Project> {
117117
}
118118
}
119119

120+
//disable integTest task if project has been converted to use yaml or java rest test plugin
121+
project.pluginManager.withPlugin("elasticsearch.yaml-rest-test") {
122+
project.tasks.integTest.enabled = false
123+
}
124+
project.pluginManager.withPlugin("elasticsearch.java-rest-test") {
125+
project.tasks.integTest.enabled = false
126+
}
127+
120128
project.tasks.named('testingConventions').configure {
121129
naming.clear()
122130
naming {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.gradle.test.rest;
21+
22+
import org.elasticsearch.gradle.ElasticsearchJavaPlugin;
23+
import org.elasticsearch.gradle.test.RestIntegTestTask;
24+
import org.elasticsearch.gradle.testclusters.TestClustersPlugin;
25+
import org.elasticsearch.gradle.util.GradleUtils;
26+
import org.gradle.api.Plugin;
27+
import org.gradle.api.Project;
28+
import org.gradle.api.plugins.JavaBasePlugin;
29+
import org.gradle.api.tasks.SourceSet;
30+
import org.gradle.api.tasks.SourceSetContainer;
31+
32+
import static org.elasticsearch.gradle.test.rest.RestTestUtil.setupDependencies;
33+
import static org.elasticsearch.gradle.test.rest.RestTestUtil.setupRunnerTask;
34+
import static org.elasticsearch.gradle.test.rest.RestTestUtil.setupTask;
35+
36+
/**
37+
* Apply this plugin to run the Java based REST tests.
38+
*/
39+
public class JavaRestTestPlugin implements Plugin<Project> {
40+
41+
public static final String SOURCE_SET_NAME = "javaRestTest";
42+
43+
@Override
44+
public void apply(Project project) {
45+
46+
project.getPluginManager().apply(ElasticsearchJavaPlugin.class);
47+
project.getPluginManager().apply(TestClustersPlugin.class);
48+
49+
// create source set
50+
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
51+
SourceSet javaTestSourceSet = sourceSets.create(SOURCE_SET_NAME);
52+
53+
// setup the javaRestTest task
54+
RestIntegTestTask javaRestTestTask = setupTask(project, SOURCE_SET_NAME);
55+
56+
// setup the runner task
57+
setupRunnerTask(project, javaRestTestTask, javaTestSourceSet);
58+
59+
// setup dependencies
60+
setupDependencies(project, javaTestSourceSet);
61+
62+
// setup IDE
63+
GradleUtils.setupIdeForTestSourceSet(project, javaTestSourceSet);
64+
65+
// wire this task into check
66+
project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME).configure(check -> check.dependsOn(javaRestTestTask));
67+
}
68+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.gradle.test.rest;
21+
22+
import org.elasticsearch.gradle.VersionProperties;
23+
import org.elasticsearch.gradle.info.BuildParams;
24+
import org.elasticsearch.gradle.plugin.PluginPropertiesExtension;
25+
import org.elasticsearch.gradle.test.RestIntegTestTask;
26+
import org.elasticsearch.gradle.testclusters.RestTestRunnerTask;
27+
import org.gradle.api.Project;
28+
import org.gradle.api.plugins.JavaBasePlugin;
29+
import org.gradle.api.tasks.SourceSet;
30+
import org.gradle.api.tasks.bundling.Zip;
31+
32+
/**
33+
* Utility class to configure the necessary tasks and dependencies.
34+
*/
35+
public class RestTestUtil {
36+
37+
private RestTestUtil() {}
38+
39+
/**
40+
* Creates a task with the source set name of type {@link RestIntegTestTask}
41+
*/
42+
static RestIntegTestTask setupTask(Project project, String sourceSetName) {
43+
// create task - note can not use .register due to the work in RestIntegTestTask's constructor :(
44+
// see: https://github.com/elastic/elasticsearch/issues/47804
45+
RestIntegTestTask testTask = project.getTasks().create(sourceSetName, RestIntegTestTask.class);
46+
testTask.setGroup(JavaBasePlugin.VERIFICATION_GROUP);
47+
testTask.setDescription("Runs the REST tests against an external cluster");
48+
// make the new test run after unit tests
49+
testTask.mustRunAfter(project.getTasks().named("test"));
50+
return testTask;
51+
}
52+
53+
/**
54+
* Creates the runner task and configures the test clusters
55+
*/
56+
static RestTestRunnerTask setupRunnerTask(Project project, RestIntegTestTask testTask, SourceSet sourceSet) {
57+
RestTestRunnerTask runner = testTask.getRunner();
58+
runner.setTestClassesDirs(sourceSet.getOutput().getClassesDirs());
59+
runner.setClasspath(sourceSet.getRuntimeClasspath());
60+
61+
// if this a module or plugin, it may have an associated zip file with it's contents, add that to the test cluster
62+
project.getPluginManager().withPlugin("elasticsearch.esplugin", plugin -> {
63+
Zip bundle = (Zip) project.getTasks().getByName("bundlePlugin");
64+
testTask.dependsOn(bundle);
65+
if (project.getPath().startsWith(":modules:")) {
66+
runner.getClusters().forEach(c -> c.module(bundle.getArchiveFile()));
67+
} else {
68+
runner.getClusters().forEach(c -> c.plugin(project.getObjects().fileProperty().value(bundle.getArchiveFile())));
69+
}
70+
});
71+
72+
// es-plugins may declare dependencies on additional modules, add those to the test cluster too.
73+
project.afterEvaluate(p -> {
74+
PluginPropertiesExtension pluginPropertiesExtension = project.getExtensions().findByType(PluginPropertiesExtension.class);
75+
if (pluginPropertiesExtension != null) { // not all projects are defined as plugins
76+
pluginPropertiesExtension.getExtendedPlugins().forEach(pluginName -> {
77+
Project extensionProject = project.getProject().findProject(":modules:" + pluginName);
78+
if (extensionProject != null) { // extension plugin may be defined, but not required to be a module
79+
Zip extensionBundle = (Zip) extensionProject.getTasks().getByName("bundlePlugin");
80+
testTask.dependsOn(extensionBundle);
81+
runner.getClusters().forEach(c -> c.module(extensionBundle.getArchiveFile()));
82+
}
83+
});
84+
}
85+
});
86+
return runner;
87+
}
88+
89+
/**
90+
* Setup the dependencies needed for the REST tests.
91+
*/
92+
static void setupDependencies(Project project, SourceSet sourceSet) {
93+
if (BuildParams.isInternal()) {
94+
project.getDependencies().add(sourceSet.getImplementationConfigurationName(), project.project(":test:framework"));
95+
} else {
96+
project.getDependencies()
97+
.add(
98+
sourceSet.getImplementationConfigurationName(),
99+
"org.elasticsearch.test:framework:" + VersionProperties.getElasticsearch()
100+
);
101+
}
102+
103+
}
104+
105+
}

buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/YamlRestTestPlugin.java

Lines changed: 11 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@
2020
package org.elasticsearch.gradle.test.rest;
2121

2222
import org.elasticsearch.gradle.ElasticsearchJavaPlugin;
23-
import org.elasticsearch.gradle.VersionProperties;
24-
import org.elasticsearch.gradle.info.BuildParams;
25-
import org.elasticsearch.gradle.plugin.PluginPropertiesExtension;
2623
import org.elasticsearch.gradle.test.RestIntegTestTask;
27-
import org.elasticsearch.gradle.testclusters.RestTestRunnerTask;
2824
import org.elasticsearch.gradle.testclusters.TestClustersPlugin;
2925
import org.elasticsearch.gradle.util.GradleUtils;
3026
import org.gradle.api.Plugin;
3127
import org.gradle.api.Project;
3228
import org.gradle.api.plugins.JavaBasePlugin;
3329
import org.gradle.api.tasks.SourceSet;
3430
import org.gradle.api.tasks.SourceSetContainer;
35-
import org.gradle.api.tasks.bundling.Zip;
31+
32+
import static org.elasticsearch.gradle.test.rest.RestTestUtil.setupDependencies;
33+
import static org.elasticsearch.gradle.test.rest.RestTestUtil.setupRunnerTask;
34+
import static org.elasticsearch.gradle.test.rest.RestTestUtil.setupTask;
3635

3736
/**
3837
* Apply this plugin to run the YAML based REST tests.
@@ -44,37 +43,22 @@ public class YamlRestTestPlugin implements Plugin<Project> {
4443
@Override
4544
public void apply(Project project) {
4645

47-
// yaml Rest tests require a Java test runner
4846
project.getPluginManager().apply(ElasticsearchJavaPlugin.class);
49-
// to spin up the external cluster
5047
project.getPluginManager().apply(TestClustersPlugin.class);
51-
// to copy around the yaml tests and json spec
5248
project.getPluginManager().apply(RestResourcesPlugin.class);
5349

54-
// note - source sets are not created via org.elasticsearch.gradle.util.GradleUtils.addTestSourceSet since unlike normal tests
55-
// we only want the yamlRestTestSourceSet on the classpath by default. The yaml tests should be pure black box testing over HTTP and
56-
// such it should not need the main class on the class path. Also, there are some special setup steps unique to YAML REST tests.
57-
5850
// create source set
5951
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
6052
SourceSet yamlTestSourceSet = sourceSets.create(SOURCE_SET_NAME);
6153

62-
// create task - note can not use .register due to the work in RestIntegTestTask's constructor :(
63-
// see: https://github.com/elastic/elasticsearch/issues/47804
64-
RestIntegTestTask yamlRestTestTask = project.getTasks().create(SOURCE_SET_NAME, RestIntegTestTask.class);
65-
yamlRestTestTask.setGroup(JavaBasePlugin.VERIFICATION_GROUP);
66-
yamlRestTestTask.setDescription("Runs the YAML based REST tests against an external cluster");
54+
// setup the yamlRestTest task
55+
RestIntegTestTask yamlRestTestTask = setupTask(project, SOURCE_SET_NAME);
56+
57+
// setup the runner task
58+
setupRunnerTask(project, yamlRestTestTask, yamlTestSourceSet);
6759

68-
// setup task dependency
69-
if (BuildParams.isInternal()) {
70-
project.getDependencies().add(yamlTestSourceSet.getImplementationConfigurationName(), project.project(":test:framework"));
71-
} else {
72-
project.getDependencies()
73-
.add(
74-
yamlTestSourceSet.getImplementationConfigurationName(),
75-
"org.elasticsearch.test:framework:" + VersionProperties.getElasticsearch()
76-
);
77-
}
60+
// setup the dependencies
61+
setupDependencies(project, yamlTestSourceSet);
7862

7963
// setup the copy for the rest resources
8064
project.getTasks().withType(CopyRestApiTask.class, copyRestApiTask -> {
@@ -83,40 +67,6 @@ public void apply(Project project) {
8367
});
8468
project.getTasks().withType(CopyRestTestsTask.class, copyRestTestTask -> { copyRestTestTask.sourceSetName = SOURCE_SET_NAME; });
8569

86-
// make the new test run after unit tests
87-
yamlRestTestTask.mustRunAfter(project.getTasks().named("test"));
88-
89-
// setup the runner
90-
RestTestRunnerTask runner = yamlRestTestTask.getRunner();
91-
runner.setTestClassesDirs(yamlTestSourceSet.getOutput().getClassesDirs());
92-
runner.setClasspath(yamlTestSourceSet.getRuntimeClasspath());
93-
94-
// if this a module or plugin, it may have an associated zip file with it's contents, add that to the test cluster
95-
project.getPluginManager().withPlugin("elasticsearch.esplugin", plugin -> {
96-
Zip bundle = (Zip) project.getTasks().getByName("bundlePlugin");
97-
yamlRestTestTask.dependsOn(bundle);
98-
if (project.getPath().startsWith(":modules:")) {
99-
runner.getClusters().forEach(c -> c.module(bundle.getArchiveFile()));
100-
} else {
101-
runner.getClusters().forEach(c -> c.plugin(project.getObjects().fileProperty().value(bundle.getArchiveFile())));
102-
}
103-
});
104-
105-
// es-plugins may declare dependencies on additional modules, add those to the test cluster too.
106-
project.afterEvaluate(p -> {
107-
PluginPropertiesExtension pluginPropertiesExtension = project.getExtensions().findByType(PluginPropertiesExtension.class);
108-
if (pluginPropertiesExtension != null) { // not all projects are defined as plugins
109-
pluginPropertiesExtension.getExtendedPlugins().forEach(pluginName -> {
110-
Project extensionProject = project.getProject().findProject(":modules:" + pluginName);
111-
if (extensionProject != null) { // extension plugin may be defined, but not required to be a module
112-
Zip extensionBundle = (Zip) extensionProject.getTasks().getByName("bundlePlugin");
113-
yamlRestTestTask.dependsOn(extensionBundle);
114-
runner.getClusters().forEach(c -> c.module(extensionBundle.getArchiveFile()));
115-
}
116-
});
117-
}
118-
});
119-
12070
// setup IDE
12171
GradleUtils.setupIdeForTestSourceSet(project, yamlTestSourceSet);
12272

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818
#
19-
implementation-class=org.elasticsearch.gradle.EnforceDeprecationFailuresPlugin
19+
20+
implementation-class=org.elasticsearch.gradle.test.rest.JavaRestTestPlugin

0 commit comments

Comments
 (0)