47
47
public class CopyRestApiTask extends DefaultTask {
48
48
private static final String REST_API_PREFIX = "rest-api-spec/api" ;
49
49
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 ;
52
51
private final DirectoryProperty outputResourceDir ;
53
52
private final DirectoryProperty additionalYamlTestsDir ;
54
53
55
54
private File sourceResourceDir ;
56
55
private boolean skipHasRestTestCheck ;
57
- private FileCollection coreConfig ;
58
- private FileCollection xpackConfig ;
56
+ private FileCollection config ;
59
57
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 ;
62
59
private Function <FileCollection , FileTree > additionalConfigToFileTree = FileCollection ::getAsFileTree ;
63
60
64
- private final PatternFilterable corePatternSet ;
65
- private final PatternFilterable xpackPatternSet ;
61
+ private final PatternFilterable patternSet ;
66
62
private final ProjectLayout projectLayout ;
67
63
private final FileSystemOperations fileSystemOperations ;
68
64
private final ArchiveOperations archiveOperations ;
@@ -75,25 +71,18 @@ public CopyRestApiTask(
75
71
ArchiveOperations archiveOperations ,
76
72
ObjectFactory objectFactory
77
73
) {
78
- this .includeCore = objectFactory .listProperty (String .class );
79
- this .includeXpack = objectFactory .listProperty (String .class );
74
+ this .include = objectFactory .listProperty (String .class );
80
75
this .outputResourceDir = objectFactory .directoryProperty ();
81
76
this .additionalYamlTestsDir = objectFactory .directoryProperty ();
82
- this .corePatternSet = patternSetFactory .create ();
83
- this .xpackPatternSet = patternSetFactory .create ();
77
+ this .patternSet = patternSetFactory .create ();
84
78
this .projectLayout = projectLayout ;
85
79
this .fileSystemOperations = fileSystemOperations ;
86
80
this .archiveOperations = archiveOperations ;
87
81
}
88
82
89
83
@ 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 ;
97
86
}
98
87
99
88
@ Input
@@ -105,29 +94,22 @@ public boolean isSkipHasRestTestCheck() {
105
94
@ InputFiles
106
95
public FileTree getInputDir () {
107
96
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
- }
113
97
boolean projectHasYamlRestTests = skipHasRestTestCheck || projectHasYamlRestTests ();
114
- if (includeCore .get ().isEmpty () == false || projectHasYamlRestTests ) {
98
+ if (include .get ().isEmpty () == false || projectHasYamlRestTests ) {
115
99
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
118
102
} else {
119
- coreFileTree = coreConfig .getAsFileTree (); // jar file
103
+ coreFileTree = config .getAsFileTree (); // jar file
120
104
}
121
105
}
122
106
123
107
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 ));
126
110
127
111
// 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 ;
131
113
}
132
114
133
115
@ OutputDirectory
@@ -152,9 +134,9 @@ void copy() {
152
134
if (BuildParams .isInternal ()) {
153
135
getLogger ().debug ("Rest specs for project [{}] will be copied to the test resources." , projectPath );
154
136
fileSystemOperations .copy (c -> {
155
- c .from (coreConfigToFileTree .apply (coreConfig ));
137
+ c .from (configToFileTree .apply (config ));
156
138
c .into (restSpecOutputDir );
157
- c .include (corePatternSet .getIncludes ());
139
+ c .include (patternSet .getIncludes ());
158
140
});
159
141
} else {
160
142
getLogger ().debug (
@@ -163,26 +145,15 @@ void copy() {
163
145
VersionProperties .getElasticsearch ()
164
146
);
165
147
fileSystemOperations .copy (c -> {
166
- c .from (archiveOperations .zipTree (coreConfig .getSingleFile ())); // jar file
148
+ c .from (archiveOperations .zipTree (config .getSingleFile ())); // jar file
167
149
c .into (outputResourceDir );
168
- if (includeCore .get ().isEmpty ()) {
150
+ if (include .get ().isEmpty ()) {
169
151
c .include (REST_API_PREFIX + "/**" );
170
152
} 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 ()));
174
154
}
175
155
});
176
156
}
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
- }
186
157
187
158
// copy any additional config
188
159
if (additionalConfig != null ) {
@@ -222,38 +193,24 @@ public void setSkipHasRestTestCheck(boolean skipHasRestTestCheck) {
222
193
this .skipHasRestTestCheck = skipHasRestTestCheck ;
223
194
}
224
195
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 ;
231
198
}
232
199
233
200
public void setAdditionalConfig (FileCollection additionalConfig ) {
234
201
this .additionalConfig = additionalConfig ;
235
202
}
236
203
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 ;
243
206
}
244
207
245
208
public void setAdditionalConfigToFileTree (Function <FileCollection , FileTree > additionalConfigToFileTree ) {
246
209
this .additionalConfigToFileTree = additionalConfigToFileTree ;
247
210
}
248
211
249
212
@ Internal
250
- public FileCollection getCoreConfig () {
251
- return coreConfig ;
213
+ public FileCollection getConfig () {
214
+ return config ;
252
215
}
253
-
254
- @ Internal
255
- public FileCollection getXpackConfig () {
256
- return xpackConfig ;
257
- }
258
-
259
216
}
0 commit comments