Skip to content

Commit 5398a9c

Browse files
authored
Consolidate REST API specifications and publish under Apache 2.0 license (#70940)
1 parent 687e190 commit 5398a9c

File tree

958 files changed

+231
-443
lines changed

Some content is hidden

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

958 files changed

+231
-443
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class RestResourcesPluginFuncTest extends AbstractRestResourcesFuncTest {
5252
file("/build/restResources/yamlSpecs/rest-api-spec/api/" + api).exists()
5353
}
5454

55-
def "restResources copies all core API (but not x-pack) by default for projects with copied tests"() {
55+
def "restResources copies all API by default for projects with copied tests"() {
5656
given:
5757
internalBuild()
5858
buildFile << """
@@ -71,7 +71,7 @@ class RestResourcesPluginFuncTest extends AbstractRestResourcesFuncTest {
7171
String apiXpack = "xpack.json"
7272
String coreTest = "foo/10_basic.yml"
7373
String xpackTest = "bar/10_basic.yml"
74-
setupRestResources([apiCore1, apiCore2], [coreTest], [apiXpack], [xpackTest])
74+
setupRestResources([apiCore1, apiCore2, apiXpack], [coreTest], [xpackTest])
7575
// intentionally not adding tests to project, they will be copied over via the plugin
7676
// this tests that the test copy happens before the api copy since the api copy will only trigger if there are tests in the project
7777

@@ -83,7 +83,7 @@ class RestResourcesPluginFuncTest extends AbstractRestResourcesFuncTest {
8383
result.task(':copyYamlTestsTask').outcome == TaskOutcome.SUCCESS
8484
file("/build/restResources/yamlSpecs/rest-api-spec/api/" + apiCore1).exists()
8585
file("/build/restResources/yamlSpecs/rest-api-spec/api/" + apiCore2).exists()
86-
file("/build/restResources/yamlSpecs/rest-api-spec/api/" + apiXpack).exists() == false //x-pack specs must be explicitly configured
86+
file("/build/restResources/yamlSpecs/rest-api-spec/api/" + apiXpack).exists()
8787
file("/build/restResources/yamlTests/rest-api-spec/test/" + coreTest).exists()
8888
file("/build/restResources/yamlTests/rest-api-spec/test/" + xpackTest).exists()
8989
}
@@ -97,16 +97,15 @@ class RestResourcesPluginFuncTest extends AbstractRestResourcesFuncTest {
9797
9898
restResources {
9999
restApi {
100-
includeCore 'foo'
101-
includeXpack 'xpackfoo'
100+
include 'foo', 'xpackfoo'
102101
}
103102
}
104103
"""
105104
String apiFoo = "foo.json"
106105
String apiXpackFoo = "xpackfoo.json"
107106
String apiBar = "bar.json"
108107
String apiXpackBar = "xpackbar.json"
109-
setupRestResources([apiFoo, apiBar], [], [apiXpackFoo, apiXpackBar])
108+
setupRestResources([apiFoo, apiBar, apiXpackFoo, apiXpackBar])
110109
addRestTestsToProject(["10_basic.yml"])
111110

112111
when:
@@ -130,8 +129,7 @@ class RestResourcesPluginFuncTest extends AbstractRestResourcesFuncTest {
130129
131130
restResources {
132131
restApi {
133-
includeCore '*'
134-
includeXpack '*'
132+
include '*'
135133
}
136134
restTests {
137135
includeCore 'foo'
@@ -144,7 +142,7 @@ class RestResourcesPluginFuncTest extends AbstractRestResourcesFuncTest {
144142
String apiXpack = "xpack.json"
145143
String coreTest = "foo/10_basic.yml"
146144
String xpackTest = "bar/10_basic.yml"
147-
setupRestResources([apiCore1, apiCore2], [coreTest], [apiXpack], [xpackTest])
145+
setupRestResources([apiCore1, apiCore2, apiXpack], [coreTest], [xpackTest])
148146
// intentionally not adding tests to project, they will be copied over via the plugin
149147
// this tests that the test copy happens before the api copy since the api copy will only trigger if there are tests in the project
150148

buildSrc/src/integTest/groovy/org/elasticsearch/gradle/fixtures/AbstractRestResourcesFuncTest.groovy

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,32 @@ package org.elasticsearch.gradle.fixtures;
1111

1212
abstract class AbstractRestResourcesFuncTest extends AbstractGradleFuncTest {
1313

14-
void setupRestResources(List<String> apis, List<String> tests = [], List<String> xpackApis = [], List<String> xpackTests = []) {
14+
void setupRestResources(List<String> apis, List<String> tests = [], List<String> xpackTests = []) {
1515
addSubProject(":test:framework") << "apply plugin: 'elasticsearch.java'"
1616
addSubProject(":distribution:archives:integ-test-zip") << "configurations { extracted }"
1717
addSubProject(":rest-api-spec") << """
1818
configurations { restSpecs\nrestTests }
1919
artifacts {
2020
restSpecs(new File(projectDir, "src/main/resources/rest-api-spec/api"))
21-
restTests(new File(projectDir, "src/main/resources/rest-api-spec/test"))
21+
restTests(new File(projectDir, "src/yamlRestTest/resources/rest-api-spec/test"))
2222
}
2323
"""
2424
addSubProject(":x-pack:plugin") << """
2525
configurations { restXpackSpecs\nrestXpackTests }
2626
artifacts {
27-
//The api and tests need to stay at src/test/... since some external tooling depends on that exact file path.
28-
restXpackSpecs(new File(projectDir, "src/test/resources/rest-api-spec/api"))
29-
restXpackTests(new File(projectDir, "src/test/resources/rest-api-spec/test"))
27+
restXpackTests(new File(projectDir, "src/yamlRestTest/resources/rest-api-spec/test"))
3028
}
3129
"""
3230

33-
xpackApis.each { api ->
34-
file("x-pack/plugin/src/test/resources/rest-api-spec/api/" + api) << ""
35-
}
3631
xpackTests.each { test ->
37-
file("x-pack/plugin/src/test/resources/rest-api-spec/test/" + test) << ""
32+
file("x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/" + test) << ""
3833
}
3934

4035
apis.each { api ->
4136
file("rest-api-spec/src/main/resources/rest-api-spec/api/" + api) << ""
4237
}
4338
tests.each { test ->
44-
file("rest-api-spec/src/main/resources/rest-api-spec/test/" + test) << ""
39+
file("rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/" + test) << ""
4540
}
4641
}
4742

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

Lines changed: 26 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,18 @@
4747
public class CopyRestApiTask extends DefaultTask {
4848
private static final String REST_API_PREFIX = "rest-api-spec/api";
4949
private static final String REST_TEST_PREFIX = "rest-api-spec/test";
50-
private final ListProperty<String> includeCore;
51-
private final ListProperty<String> includeXpack;
50+
private final ListProperty<String> include;
5251
private final DirectoryProperty outputResourceDir;
5352
private final DirectoryProperty additionalYamlTestsDir;
5453

5554
private File sourceResourceDir;
5655
private boolean skipHasRestTestCheck;
57-
private FileCollection coreConfig;
58-
private FileCollection xpackConfig;
56+
private FileCollection config;
5957
private FileCollection additionalConfig;
60-
private Function<FileCollection, FileTree> coreConfigToFileTree = FileCollection::getAsFileTree;
61-
private Function<FileCollection, FileTree> xpackConfigToFileTree = FileCollection::getAsFileTree;
58+
private Function<FileCollection, FileTree> configToFileTree = FileCollection::getAsFileTree;
6259
private Function<FileCollection, FileTree> additionalConfigToFileTree = FileCollection::getAsFileTree;
6360

64-
private final PatternFilterable corePatternSet;
65-
private final PatternFilterable xpackPatternSet;
61+
private final PatternFilterable patternSet;
6662
private final ProjectLayout projectLayout;
6763
private final FileSystemOperations fileSystemOperations;
6864
private final ArchiveOperations archiveOperations;
@@ -75,25 +71,18 @@ public CopyRestApiTask(
7571
ArchiveOperations archiveOperations,
7672
ObjectFactory objectFactory
7773
) {
78-
this.includeCore = objectFactory.listProperty(String.class);
79-
this.includeXpack = objectFactory.listProperty(String.class);
74+
this.include = objectFactory.listProperty(String.class);
8075
this.outputResourceDir = objectFactory.directoryProperty();
8176
this.additionalYamlTestsDir = objectFactory.directoryProperty();
82-
this.corePatternSet = patternSetFactory.create();
83-
this.xpackPatternSet = patternSetFactory.create();
77+
this.patternSet = patternSetFactory.create();
8478
this.projectLayout = projectLayout;
8579
this.fileSystemOperations = fileSystemOperations;
8680
this.archiveOperations = archiveOperations;
8781
}
8882

8983
@Input
90-
public ListProperty<String> getIncludeCore() {
91-
return includeCore;
92-
}
93-
94-
@Input
95-
public ListProperty<String> getIncludeXpack() {
96-
return includeXpack;
84+
public ListProperty<String> getInclude() {
85+
return include;
9786
}
9887

9988
@Input
@@ -105,29 +94,22 @@ public boolean isSkipHasRestTestCheck() {
10594
@InputFiles
10695
public FileTree getInputDir() {
10796
FileTree coreFileTree = null;
108-
FileTree xpackFileTree = null;
109-
if (includeXpack.get().isEmpty() == false) {
110-
xpackPatternSet.setIncludes(includeXpack.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
111-
xpackFileTree = xpackConfigToFileTree.apply(xpackConfig).matching(xpackPatternSet);
112-
}
11397
boolean projectHasYamlRestTests = skipHasRestTestCheck || projectHasYamlRestTests();
114-
if (includeCore.get().isEmpty() == false || projectHasYamlRestTests) {
98+
if (include.get().isEmpty() == false || projectHasYamlRestTests) {
11599
if (BuildParams.isInternal()) {
116-
corePatternSet.setIncludes(includeCore.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
117-
coreFileTree = coreConfigToFileTree.apply(coreConfig).matching(corePatternSet); // directory on disk
100+
patternSet.setIncludes(include.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
101+
coreFileTree = configToFileTree.apply(config).matching(patternSet); // directory on disk
118102
} else {
119-
coreFileTree = coreConfig.getAsFileTree(); // jar file
103+
coreFileTree = config.getAsFileTree(); // jar file
120104
}
121105
}
122106

123107
FileCollection fileCollection = additionalConfig == null
124-
? projectLayout.files(coreFileTree, xpackFileTree)
125-
: projectLayout.files(coreFileTree, xpackFileTree, additionalConfigToFileTree.apply(additionalConfig));
108+
? coreFileTree
109+
: projectLayout.files(coreFileTree, additionalConfigToFileTree.apply(additionalConfig));
126110

127111
// if project has rest tests or the includes are explicitly configured execute the task, else NO-SOURCE due to the null input
128-
return projectHasYamlRestTests || includeCore.get().isEmpty() == false || includeXpack.get().isEmpty() == false
129-
? fileCollection.getAsFileTree()
130-
: null;
112+
return projectHasYamlRestTests || include.get().isEmpty() == false ? fileCollection.getAsFileTree() : null;
131113
}
132114

133115
@OutputDirectory
@@ -152,9 +134,9 @@ void copy() {
152134
if (BuildParams.isInternal()) {
153135
getLogger().debug("Rest specs for project [{}] will be copied to the test resources.", projectPath);
154136
fileSystemOperations.copy(c -> {
155-
c.from(coreConfigToFileTree.apply(coreConfig));
137+
c.from(configToFileTree.apply(config));
156138
c.into(restSpecOutputDir);
157-
c.include(corePatternSet.getIncludes());
139+
c.include(patternSet.getIncludes());
158140
});
159141
} else {
160142
getLogger().debug(
@@ -163,26 +145,15 @@ void copy() {
163145
VersionProperties.getElasticsearch()
164146
);
165147
fileSystemOperations.copy(c -> {
166-
c.from(archiveOperations.zipTree(coreConfig.getSingleFile())); // jar file
148+
c.from(archiveOperations.zipTree(config.getSingleFile())); // jar file
167149
c.into(outputResourceDir);
168-
if (includeCore.get().isEmpty()) {
150+
if (include.get().isEmpty()) {
169151
c.include(REST_API_PREFIX + "/**");
170152
} else {
171-
c.include(
172-
includeCore.get().stream().map(prefix -> REST_API_PREFIX + "/" + prefix + "*/**").collect(Collectors.toList())
173-
);
153+
c.include(include.get().stream().map(prefix -> REST_API_PREFIX + "/" + prefix + "*/**").collect(Collectors.toList()));
174154
}
175155
});
176156
}
177-
// only copy x-pack specs if explicitly instructed
178-
if (includeXpack.get().isEmpty() == false) {
179-
getLogger().debug("X-pack rest specs for project [{}] will be copied to the test resources.", projectPath);
180-
fileSystemOperations.copy(c -> {
181-
c.from(xpackConfigToFileTree.apply(xpackConfig));
182-
c.into(restSpecOutputDir);
183-
c.include(xpackPatternSet.getIncludes());
184-
});
185-
}
186157

187158
// copy any additional config
188159
if (additionalConfig != null) {
@@ -222,38 +193,24 @@ public void setSkipHasRestTestCheck(boolean skipHasRestTestCheck) {
222193
this.skipHasRestTestCheck = skipHasRestTestCheck;
223194
}
224195

225-
public void setCoreConfig(FileCollection coreConfig) {
226-
this.coreConfig = coreConfig;
227-
}
228-
229-
public void setXpackConfig(FileCollection xpackConfig) {
230-
this.xpackConfig = xpackConfig;
196+
public void setConfig(FileCollection config) {
197+
this.config = config;
231198
}
232199

233200
public void setAdditionalConfig(FileCollection additionalConfig) {
234201
this.additionalConfig = additionalConfig;
235202
}
236203

237-
public void setCoreConfigToFileTree(Function<FileCollection, FileTree> coreConfigToFileTree) {
238-
this.coreConfigToFileTree = coreConfigToFileTree;
239-
}
240-
241-
public void setXpackConfigToFileTree(Function<FileCollection, FileTree> xpackConfigToFileTree) {
242-
this.xpackConfigToFileTree = xpackConfigToFileTree;
204+
public void setConfigToFileTree(Function<FileCollection, FileTree> configToFileTree) {
205+
this.configToFileTree = configToFileTree;
243206
}
244207

245208
public void setAdditionalConfigToFileTree(Function<FileCollection, FileTree> additionalConfigToFileTree) {
246209
this.additionalConfigToFileTree = additionalConfigToFileTree;
247210
}
248211

249212
@Internal
250-
public FileCollection getCoreConfig() {
251-
return coreConfig;
213+
public FileCollection getConfig() {
214+
return config;
252215
}
253-
254-
@Internal
255-
public FileCollection getXpackConfig() {
256-
return xpackConfig;
257-
}
258-
259216
}

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

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,58 @@
1919
*/
2020
public class RestResourcesExtension {
2121

22-
final RestResourcesSpec restApi;
23-
final RestResourcesSpec restTests;
22+
private final RestResourcesSpec restApi;
23+
private final XpackRestResourcesSpec restTests;
2424

2525
@Inject
2626
public RestResourcesExtension(ObjectFactory objects) {
2727
restApi = new RestResourcesSpec(objects);
28-
restTests = new RestResourcesSpec(objects);
28+
restTests = new XpackRestResourcesSpec(objects);
2929
}
3030

3131
void restApi(Action<? super RestResourcesSpec> spec) {
3232
spec.execute(restApi);
3333
}
3434

35-
void restTests(Action<? super RestResourcesSpec> spec) {
35+
void restTests(Action<? super XpackRestResourcesSpec> spec) {
36+
if (BuildParams.isInternal() == false) {
37+
// TODO: Separate this out into an "internal" plugin so we don't even expose this API to external folks
38+
throw new UnsupportedOperationException("Including tests is not supported from external builds.");
39+
}
3640
spec.execute(restTests);
3741
}
3842

39-
static class RestResourcesSpec {
43+
public RestResourcesSpec getRestApi() {
44+
return restApi;
45+
}
46+
47+
public XpackRestResourcesSpec getRestTests() {
48+
return restTests;
49+
}
50+
51+
public static class RestResourcesSpec {
52+
53+
private final ListProperty<String> include;
54+
55+
RestResourcesSpec(ObjectFactory objects) {
56+
include = objects.listProperty(String.class);
57+
}
58+
59+
public void include(String... include) {
60+
this.include.addAll(include);
61+
}
62+
63+
public ListProperty<String> getInclude() {
64+
return include;
65+
}
66+
}
67+
68+
public static class XpackRestResourcesSpec {
4069

4170
private final ListProperty<String> includeCore;
4271
private final ListProperty<String> includeXpack;
4372

44-
RestResourcesSpec(ObjectFactory objects) {
73+
XpackRestResourcesSpec(ObjectFactory objects) {
4574
includeCore = objects.listProperty(String.class);
4675
includeXpack = objects.listProperty(String.class);
4776
}
@@ -51,9 +80,6 @@ public void includeCore(String... include) {
5180
}
5281

5382
public void includeXpack(String... include) {
54-
if (BuildParams.isInternal() == false) {
55-
throw new IllegalStateException("Can not include x-pack rest resources from an external build.");
56-
}
5783
this.includeXpack.addAll(include);
5884
}
5985

0 commit comments

Comments
 (0)