@@ -38,24 +38,18 @@ class ProjectSchemaAccessorsIntegrationTest : AbstractPluginIntegrationTest() {
38
38
39
39
lateinit var extensionSourceFile: File
40
40
41
- withFolders {
42
-
43
- " buildSrc" {
44
-
45
- withPrecompiledPlugins()
46
-
47
- " src/main/kotlin" {
41
+ withBuildSrc {
42
+ " src/main/kotlin" {
48
43
49
- extensionSourceFile =
50
- withFile(" Extension.kt" , """
51
- internal
52
- class Extension
53
- """ )
54
-
55
- withFile(" plugin.gradle.kts" , """
56
- extensions.add("extension", Extension())
44
+ extensionSourceFile =
45
+ withFile(" Extension.kt" , """
46
+ internal
47
+ class Extension
57
48
""" )
58
- }
49
+
50
+ withFile(" plugin.gradle.kts" , """
51
+ extensions.add("extension", Extension())
52
+ """ )
59
53
}
60
54
}
61
55
@@ -99,25 +93,19 @@ class ProjectSchemaAccessorsIntegrationTest : AbstractPluginIntegrationTest() {
99
93
@Test
100
94
fun `can access extension of default package type` () {
101
95
102
- withFolders {
96
+ withBuildSrc {
103
97
104
- " buildSrc" {
105
-
106
- withPrecompiledPlugins()
98
+ " src/main/kotlin" {
107
99
108
- " src/main/kotlin" {
109
-
110
- withFile(" Extension.kt" , """
111
- class Extension(private val name: String) : org.gradle.api.Named {
112
- override fun getName() = name
113
- }
114
- """ )
100
+ withFile(" Extension.kt" , """
101
+ class Extension(private val name: String) : org.gradle.api.Named {
102
+ override fun getName() = name
103
+ }
104
+ """ )
115
105
116
- withFile(" plugin.gradle.kts" , """
117
- extensions.add("extension", Extension("foo"))
118
- extensions.add("beans", container(Extension::class))
119
- """ )
120
- }
106
+ withFile(" plugin.gradle.kts" , """
107
+ extensions.add("extension", Extension("foo"))
108
+ """ )
121
109
}
122
110
}
123
111
@@ -129,41 +117,30 @@ class ProjectSchemaAccessorsIntegrationTest : AbstractPluginIntegrationTest() {
129
117
130
118
println("extension: " + typeOf(extension))
131
119
extension { println("extension{} " + typeOf(this)) }
132
-
133
- println("beans: " + typeOf(beans))
134
- beans { println("beans{} " + typeOf(beans)) }
135
120
""" )
136
121
137
122
assertThat(
138
123
build(" help" , " -q" ).output,
139
124
containsMultiLineString("""
140
125
extension: Extension
141
126
extension{} Extension
142
- beans: org.gradle.api.NamedDomainObjectContainer<Extension>
143
- beans{} org.gradle.api.NamedDomainObjectContainer<Extension>
144
127
""" )
145
128
)
146
129
}
147
130
148
131
@Test
149
132
fun `can access task of default package type` () {
150
133
151
- withFolders {
152
-
153
- " buildSrc" {
154
-
155
- withPrecompiledPlugins()
156
-
157
- " src/main/kotlin" {
134
+ withBuildSrc {
135
+ " src/main/kotlin" {
158
136
159
- withFile(" CustomTask.kt" , """
160
- open class CustomTask : org.gradle.api.DefaultTask()
161
- """ )
137
+ withFile(" CustomTask.kt" , """
138
+ open class CustomTask : org.gradle.api.DefaultTask()
139
+ """ )
162
140
163
- withFile(" plugin.gradle.kts" , """
164
- tasks.register<CustomTask>("customTask")
165
- """ )
166
- }
141
+ withFile(" plugin.gradle.kts" , """
142
+ tasks.register<CustomTask>("customTask")
143
+ """ )
167
144
}
168
145
}
169
146
@@ -189,35 +166,28 @@ class ProjectSchemaAccessorsIntegrationTest : AbstractPluginIntegrationTest() {
189
166
@Test
190
167
fun `can access extension of nested type` () {
191
168
192
- withFolders {
193
-
194
- " buildSrc" {
195
-
196
- withPrecompiledPlugins()
197
-
198
- " src/main/kotlin/my" {
169
+ withBuildSrc {
170
+ " src/main/kotlin/my" {
199
171
200
- withFile(" Extension.kt" , """
201
- package my
172
+ withFile(" Extension.kt" , """
173
+ package my
202
174
203
- class Nested {
204
- class Extension(private val name: String) : org.gradle.api.Named {
205
- override fun getName() = name
206
- }
175
+ class Nested {
176
+ class Extension(private val name: String) : org.gradle.api.Named {
177
+ override fun getName() = name
207
178
}
208
- """ )
179
+ }
180
+ """ )
209
181
210
- withFile(" plugin.gradle.kts" , """
211
- package my
182
+ withFile(" plugin.gradle.kts" , """
183
+ package my
212
184
213
- extensions.add("nested", Nested.Extension("foo"))
214
- extensions.add("beans", container(Nested.Extension::class))
215
- """ )
216
- }
185
+ extensions.add("nested", Nested.Extension("foo"))
186
+ extensions.add("beans", container(Nested.Extension::class))
187
+ """ )
217
188
}
218
189
}
219
190
220
-
221
191
withBuildScript("""
222
192
223
193
plugins { id("my.plugin") }
@@ -251,40 +221,35 @@ class ProjectSchemaAccessorsIntegrationTest : AbstractPluginIntegrationTest() {
251
221
@Test
252
222
fun `multiple generic extension targets` () {
253
223
254
- withFolders {
224
+ withBuildSrc {
255
225
256
- " buildSrc" {
257
-
258
- withPrecompiledPlugins()
226
+ " src/main/kotlin" {
227
+ withFile(" types.kt" , """
259
228
260
- " src/main/kotlin" {
261
- withFile(" types.kt" , """
262
-
263
- package my
229
+ package my
264
230
265
- data class NamedString(val name: String, var value: String? = null)
231
+ data class NamedString(val name: String, var value: String? = null)
266
232
267
- data class NamedLong(val name: String, var value: Long? = null)
268
- """ )
233
+ data class NamedLong(val name: String, var value: Long? = null)
234
+ """ )
269
235
270
- withFile(" plugin.gradle.kts" , """
236
+ withFile(" plugin.gradle.kts" , """
271
237
272
- package my
238
+ package my
273
239
274
- val strings = container(NamedString::class) { NamedString(it) }
275
- extensions.add("strings", strings)
240
+ val strings = container(NamedString::class) { NamedString(it) }
241
+ extensions.add("strings", strings)
276
242
277
- val longs = container(NamedLong::class) { NamedLong(it) }
278
- extensions.add("longs", longs)
243
+ val longs = container(NamedLong::class) { NamedLong(it) }
244
+ extensions.add("longs", longs)
279
245
280
- tasks.register("printStringsAndLongs") {
281
- doLast {
282
- strings.forEach { println("string: " + it) }
283
- longs.forEach { println("long: " + it) }
284
- }
246
+ tasks.register("printStringsAndLongs") {
247
+ doLast {
248
+ strings.forEach { println("string: " + it) }
249
+ longs.forEach { println("long: " + it) }
285
250
}
286
- """ )
287
- }
251
+ }
252
+ """ )
288
253
}
289
254
}
290
255
@@ -439,25 +404,25 @@ class ProjectSchemaAccessorsIntegrationTest : AbstractPluginIntegrationTest() {
439
404
@Test
440
405
fun `can access NamedDomainObjectContainer extension via generated accessor` () {
441
406
442
- withKotlinBuildSrc()
443
-
444
- withFile(" buildSrc/src/main/kotlin/my/DocumentationPlugin.kt" , """
445
- package my
407
+ withBuildSrc {
408
+ withFile(" src/main/kotlin/my/DocumentationPlugin.kt" , """
409
+ package my
446
410
447
- import org.gradle.api.*
448
- import org.gradle.kotlin.dsl.*
411
+ import org.gradle.api.*
412
+ import org.gradle.kotlin.dsl.*
449
413
450
- class DocumentationPlugin : Plugin<Project> {
414
+ class DocumentationPlugin : Plugin<Project> {
451
415
452
- override fun apply(project: Project) {
453
- val books = project.container(Book::class, ::Book)
454
- project.extensions.add("the books", books)
416
+ override fun apply(project: Project) {
417
+ val books = project.container(Book::class, ::Book)
418
+ project.extensions.add("the books", books)
419
+ }
455
420
}
456
- }
457
421
458
- data class Book(val name: String)
422
+ data class Book(val name: String)
459
423
460
- """ )
424
+ """ )
425
+ }
461
426
462
427
val buildFile = withBuildScript("""
463
428
@@ -467,7 +432,8 @@ class ProjectSchemaAccessorsIntegrationTest : AbstractPluginIntegrationTest() {
467
432
468
433
469
434
println (
470
- build(" kotlinDslAccessorsSnapshot" ).output)
435
+ build(" kotlinDslAccessorsSnapshot" ).output
436
+ )
471
437
472
438
473
439
buildFile.appendText("""
@@ -488,7 +454,8 @@ class ProjectSchemaAccessorsIntegrationTest : AbstractPluginIntegrationTest() {
488
454
""" )
489
455
assertThat(
490
456
build(" books" ).output,
491
- containsString(" quickStart, userGuide" ))
457
+ containsString(" quickStart, userGuide" )
458
+ )
492
459
}
493
460
494
461
@Test
@@ -506,7 +473,8 @@ class ProjectSchemaAccessorsIntegrationTest : AbstractPluginIntegrationTest() {
506
473
507
474
assertThat(
508
475
build(" mainClassName" ).output,
509
- containsString(" *App*" ))
476
+ containsString(" *App*" )
477
+ )
510
478
}
511
479
512
480
@Test
@@ -563,7 +531,9 @@ class ProjectSchemaAccessorsIntegrationTest : AbstractPluginIntegrationTest() {
563
531
containsString(" a/build/classes/java/main" ),
564
532
containsString(" b/build/classes/java/main" ),
565
533
not (containsString(" logback-core" )),
566
- not (containsString(" commons-io" ))))
534
+ not (containsString(" commons-io" ))
535
+ )
536
+ )
567
537
}
568
538
569
539
@Test
@@ -577,7 +547,13 @@ class ProjectSchemaAccessorsIntegrationTest : AbstractPluginIntegrationTest() {
577
547
assertThat(aTasks, not (containsString(" kotlinDslAccessorsSnapshot" )))
578
548
579
549
val rootTasks = build(" :tasks" ).output
580
- assertThat(rootTasks, allOf(containsString(" kotlinDslAccessorsReport" ), containsString(" kotlinDslAccessorsSnapshot" )))
550
+ assertThat(
551
+ rootTasks,
552
+ allOf(
553
+ containsString(" kotlinDslAccessorsReport" ),
554
+ containsString(" kotlinDslAccessorsSnapshot" )
555
+ )
556
+ )
581
557
}
582
558
583
559
@Test
@@ -948,6 +924,16 @@ class ProjectSchemaAccessorsIntegrationTest : AbstractPluginIntegrationTest() {
948
924
build(" help" )
949
925
}
950
926
927
+ private
928
+ fun withBuildSrc (contents : FoldersDslExpression ) {
929
+ withFolders {
930
+ " buildSrc" {
931
+ withPrecompiledPlugins()
932
+ contents()
933
+ }
934
+ }
935
+ }
936
+
951
937
private
952
938
fun withFolders (folders : FoldersDslExpression ) =
953
939
projectRoot.withFolders(folders)
0 commit comments