Skip to content

Commit 3ef3cc5

Browse files
authored
Add Watcher to available rest resources (#53620)
Prior to this commit Watcher explicitly copied test between two projects with a copy task. This commit removes the explicit copy in favor of adding the Watcher tests to the available restResources that may be copied between projects. This is how inter-project dependencies should be modeled. However, only Watcher is included here since it is (currently) the only project with inter-project test dependencies. Note - this re-introduces: commit: 4f48e05 with some additional fixes.
1 parent 9f0562b commit 3ef3cc5

File tree

6 files changed

+28
-24
lines changed

6 files changed

+28
-24
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void copy() {
114114
if (BuildParams.isInternal()) {
115115
getLogger().debug("Rest tests for project [{}] will be copied to the test resources.", project.getPath());
116116
project.copy(c -> {
117-
c.from(coreConfig.getSingleFile());
117+
c.from(coreConfig.getAsFileTree());
118118
c.into(getOutputDir());
119119
c.include(corePatternSet.getIncludes());
120120
});
@@ -138,7 +138,7 @@ void copy() {
138138
if (includeXpack.get().isEmpty() == false) {
139139
getLogger().debug("X-pack rest tests for project [{}] will be copied to the test resources.", project.getPath());
140140
project.copy(c -> {
141-
c.from(xpackConfig.getSingleFile());
141+
c.from(xpackConfig.getAsFileTree());
142142
c.into(getOutputDir());
143143
c.include(xpackPatternSet.getIncludes());
144144
});

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.gradle.info.BuildParams;
2323
import org.gradle.api.Plugin;
2424
import org.gradle.api.Project;
25+
import org.gradle.api.artifacts.Configuration;
2526
import org.gradle.api.artifacts.Dependency;
2627
import org.gradle.api.provider.Provider;
2728

@@ -86,21 +87,31 @@ public class RestResourcesPlugin implements Plugin<Project> {
8687
public void apply(Project project) {
8788
RestResourcesExtension extension = project.getExtensions().create(EXTENSION_NAME, RestResourcesExtension.class);
8889

90+
// tests
91+
Configuration testConfig = project.getConfigurations().create("restTestConfig");
92+
Configuration xpackTestConfig = project.getConfigurations().create("restXpackTest");
93+
project.getConfigurations().create("restTests");
94+
project.getConfigurations().create("restXpackTests");
8995
Provider<CopyRestTestsTask> copyRestYamlTestTask = project.getTasks()
9096
.register("copyYamlTestsTask", CopyRestTestsTask.class, task -> {
9197
task.includeCore.set(extension.restTests.getIncludeCore());
9298
task.includeXpack.set(extension.restTests.getIncludeXpack());
93-
task.coreConfig = project.getConfigurations().create("restTest");
99+
task.coreConfig = testConfig;
94100
if (BuildParams.isInternal()) {
101+
// core
95102
Dependency restTestdependency = project.getDependencies()
96103
.project(Map.of("path", ":rest-api-spec", "configuration", "restTests"));
97104
project.getDependencies().add(task.coreConfig.getName(), restTestdependency);
98-
99-
task.xpackConfig = project.getConfigurations().create("restXpackTest");
105+
// x-pack
106+
task.xpackConfig = xpackTestConfig;
100107
Dependency restXPackTestdependency = project.getDependencies()
101108
.project(Map.of("path", ":x-pack:plugin", "configuration", "restXpackTests"));
102109
project.getDependencies().add(task.xpackConfig.getName(), restXPackTestdependency);
103110
task.dependsOn(task.xpackConfig);
111+
// watcher
112+
Dependency restWatcherTests = project.getDependencies()
113+
.project(Map.of("path", ":x-pack:plugin:watcher:qa:rest", "configuration", "restXpackTests"));
114+
project.getDependencies().add(task.xpackConfig.getName(), restWatcherTests);
104115
} else {
105116
Dependency dependency = project.getDependencies()
106117
.create("org.elasticsearch:rest-api-spec:" + VersionProperties.getElasticsearch());
@@ -109,18 +120,22 @@ public void apply(Project project) {
109120
task.dependsOn(task.coreConfig);
110121
});
111122

123+
// api
124+
Configuration specConfig = project.getConfigurations().create("restSpec"); // name chosen for passivity
125+
Configuration xpackSpecConfig = project.getConfigurations().create("restXpackSpec");
126+
project.getConfigurations().create("restSpecs");
127+
project.getConfigurations().create("restXpackSpecs");
112128
Provider<CopyRestApiTask> copyRestYamlSpecTask = project.getTasks()
113129
.register("copyRestApiSpecsTask", CopyRestApiTask.class, task -> {
114130
task.includeCore.set(extension.restApi.getIncludeCore());
115131
task.includeXpack.set(extension.restApi.getIncludeXpack());
116132
task.dependsOn(copyRestYamlTestTask);
117-
task.coreConfig = project.getConfigurations().create("restSpec");
133+
task.coreConfig = specConfig;
118134
if (BuildParams.isInternal()) {
119135
Dependency restSpecDependency = project.getDependencies()
120136
.project(Map.of("path", ":rest-api-spec", "configuration", "restSpecs"));
121137
project.getDependencies().add(task.coreConfig.getName(), restSpecDependency);
122-
123-
task.xpackConfig = project.getConfigurations().create("restXpackSpec");
138+
task.xpackConfig = xpackSpecConfig;
124139
Dependency restXpackSpecDependency = project.getDependencies()
125140
.project(Map.of("path", ":x-pack:plugin", "configuration", "restXpackSpecs"));
126141
project.getDependencies().add(task.xpackConfig.getName(), restXpackSpecDependency);

rest-api-spec/build.gradle

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
apply plugin: 'elasticsearch.build'
22
apply plugin: 'nebula.maven-base-publish'
33
apply plugin: 'nebula.maven-scm'
4+
apply plugin: 'elasticsearch.rest-resources'
45

56
test.enabled = false
67
jarHell.enabled = false
78

8-
configurations {
9-
restSpecs
10-
restTests
11-
}
12-
139
artifacts {
1410
restSpecs(new File(projectDir, "src/main/resources/rest-api-spec/api"))
1511
restTests(new File(projectDir, "src/main/resources/rest-api-spec/test"))

x-pack/plugin/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ dependencies {
1212

1313
configurations {
1414
testArtifacts.extendsFrom testRuntime
15-
restXpackSpecs
16-
restXpackTests
1715
}
1816

1917
artifacts {

x-pack/plugin/watcher/qa/rest/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ task testJar(type: Jar) {
1717

1818
artifacts {
1919
testArtifacts testJar
20+
restXpackTests(new File(projectDir, "src/test/resources/rest-api-spec/test"))
2021
}
2122

2223
restResources {

x-pack/plugin/watcher/qa/with-security/build.gradle

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,15 @@ dependencies {
77
testCompile project(path: ':x-pack:plugin:watcher:qa:rest', configuration: 'testArtifacts')
88
}
99

10-
11-
// bring in watcher rest test suite from the rest project
12-
task copyWatcherRestTests(type: Copy) {
13-
into project.sourceSets.test.output.resourcesDir
14-
from project(xpackProject('plugin:watcher:qa:rest').path).sourceSets.test.resources.srcDirs
15-
include 'rest-api-spec/test/watcher/**'
16-
}
17-
1810
restResources {
1911
restApi {
2012
includeXpack 'watcher', 'security', 'xpack'
2113
}
14+
restTests {
15+
includeXpack 'watcher'
16+
}
2217
}
2318

24-
integTest.runner.dependsOn copyWatcherRestTests
2519
testClusters.integTest {
2620
testDistribution = 'DEFAULT'
2721
setting 'xpack.ilm.enabled', 'false'

0 commit comments

Comments
 (0)