@@ -20,10 +20,15 @@ package org.elasticsearch.gradle.test
20
20
21
21
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
22
22
import org.elasticsearch.gradle.BuildPlugin
23
+ import org.elasticsearch.gradle.VersionProperties
23
24
import org.gradle.api.DefaultTask
25
+ import org.gradle.api.Project
24
26
import org.gradle.api.Task
25
27
import org.gradle.api.execution.TaskExecutionAdapter
26
28
import org.gradle.api.internal.tasks.options.Option
29
+ import org.gradle.api.provider.Property
30
+ import org.gradle.api.provider.Provider
31
+ import org.gradle.api.tasks.Copy
27
32
import org.gradle.api.tasks.Input
28
33
import org.gradle.api.tasks.TaskState
29
34
@@ -47,7 +52,7 @@ public class RestIntegTestTask extends DefaultTask {
47
52
48
53
/* * Flag indicating whether the rest tests in the rest spec should be run. */
49
54
@Input
50
- boolean includePackaged = false
55
+ Property< Boolean > includePackaged = project . objects . property( Boolean )
51
56
52
57
public RestIntegTestTask () {
53
58
runner = project. tasks. create(" ${ name} Runner" , RandomizedTestingTask . class)
@@ -92,10 +97,9 @@ public class RestIntegTestTask extends DefaultTask {
92
97
}
93
98
94
99
// copy the rest spec/tests into the test resources
95
- RestSpecHack . configureDependencies(project)
96
- project. afterEvaluate {
97
- runner. dependsOn(RestSpecHack . configureTask(project, includePackaged))
98
- }
100
+ Task copyRestSpec = createCopyRestSpecTask(project, includePackaged)
101
+ runner. dependsOn(copyRestSpec)
102
+
99
103
// this must run after all projects have been configured, so we know any project
100
104
// references can be accessed as a fully configured
101
105
project. gradle. projectsEvaluated {
@@ -109,6 +113,11 @@ public class RestIntegTestTask extends DefaultTask {
109
113
}
110
114
}
111
115
116
+ /* * Sets the includePackaged property */
117
+ public void includePackaged (boolean include ) {
118
+ includePackaged. set(include)
119
+ }
120
+
112
121
@Option (
113
122
option = " debug-jvm" ,
114
123
description = " Enable debugging configuration, to allow attaching a debugger to elasticsearch."
@@ -184,4 +193,47 @@ public class RestIntegTestTask extends DefaultTask {
184
193
println (' =========================================' )
185
194
186
195
}
196
+
197
+ /**
198
+ * Creates a task (if necessary) to copy the rest spec files.
199
+ *
200
+ * @param project The project to add the copy task to
201
+ * @param includePackagedTests true if the packaged tests should be copied, false otherwise
202
+ */
203
+ private static Task createCopyRestSpecTask (Project project , Provider<Boolean > includePackagedTests ) {
204
+ project. configurations {
205
+ restSpec
206
+ }
207
+ project. dependencies {
208
+ restSpec " org.elasticsearch:rest-api-spec:${ VersionProperties.elasticsearch} "
209
+ }
210
+ Task copyRestSpec = project. tasks. findByName(' copyRestSpec' )
211
+ if (copyRestSpec != null ) {
212
+ return copyRestSpec
213
+ }
214
+ Map copyRestSpecProps = [
215
+ name : ' copyRestSpec' ,
216
+ type : Copy ,
217
+ dependsOn : [project. configurations. restSpec, ' processTestResources' ]
218
+ ]
219
+ copyRestSpec = project. tasks. create(copyRestSpecProps) {
220
+ into project. sourceSets. test. output. resourcesDir
221
+ }
222
+ project. afterEvaluate {
223
+ copyRestSpec. from({ project. zipTree(project. configurations. restSpec. singleFile) }) {
224
+ include ' rest-api-spec/api/**'
225
+ if (includePackagedTests. get()) {
226
+ include ' rest-api-spec/test/**'
227
+ }
228
+ }
229
+ }
230
+ project. idea {
231
+ module {
232
+ if (scopes. TEST != null ) {
233
+ scopes. TEST . plus. add(project. configurations. restSpec)
234
+ }
235
+ }
236
+ }
237
+ return copyRestSpec
238
+ }
187
239
}
0 commit comments