forked from Kotlin/kotlinx-kover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KoverConfig.kt
550 lines (465 loc) · 17.7 KB
/
KoverConfig.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
/*
* Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.kover.api
import org.gradle.api.*
import org.gradle.api.file.*
import org.gradle.api.model.*
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import org.gradle.kotlin.dsl.*
import javax.annotation.*
import javax.inject.*
public open class KoverProjectConfig @Inject constructor(objects: ObjectFactory) {
internal val filters: KoverProjectFilters = objects.newInstance()
internal val instrumentation: KoverProjectInstrumentation = objects.newInstance()
internal val xmlReport: KoverProjectXmlConfig = objects.newInstance()
internal val htmlReport: KoverProjectHtmlConfig = objects.newInstance()
internal val verify: KoverVerifyConfig = objects.newInstance(objects)
/**
* Specifies whether instrumentation is disabled for all test tasks of current project.
*
* `false` by default.
*/
public val isDisabled: Property<Boolean> = objects.property()
/**
* Specifies the coverage engine variant to be used to collect execution data.
*/
public val engine: Property<CoverageEngineVariant> = objects.property()
/**
* Configures filtering for all Kover's tasks of current project by class names and source sets.
*/
public fun filters(config: Action<KoverProjectFilters>) {
config.execute(filters)
}
/**
* Configures a list of tasks, the execution of tests from which is registered in the coverage counters.
*
*/
public fun instrumentation(config: Action<KoverProjectInstrumentation>) {
config.execute(instrumentation)
}
/**
* Configures the task of generating an XML report, including XML report location and whether it should be
* generated during the 'check' task.
*
* By default, [KoverPaths.PROJECT_XML_REPORT_DEFAULT_PATH] location in build directory is used.
*/
public fun xmlReport(config: Action<KoverProjectXmlConfig>) {
config.execute(xmlReport)
}
/**
* Configures the task of generating an HTML report, including HTML report location and whether it should be
* generated during the 'check' task.
*
* By default, [KoverPaths.PROJECT_HTML_REPORT_DEFAULT_PATH] location in build directory is used.
*/
public fun htmlReport(config: Action<KoverProjectHtmlConfig>) {
config.execute(htmlReport)
}
/**
* Configures the verification task, including adding verification rules and whether it should be
* verified during the 'check' task.
*/
public fun verify(config: Action<KoverVerifyConfig>) {
config.execute(verify)
}
// DEPRECATIONS
// TODO delete in 0.7 version
@Suppress("DEPRECATION")
@get:Internal
@Deprecated(
message = "Property was removed in Kover API version 2, use `engine` property instead. Please refer to migration guide in order to migrate: ${KoverMigrations.MIGRATION_0_5_TO_0_6}",
replaceWith = ReplaceWith("engine"),
level = DeprecationLevel.ERROR
)
public val coverageEngine: Property<CoverageEngine> = objects.property()
@get:Internal
@Deprecated(
message = "Property was removed in Kover API version 2, use `engine.set(kotlinx.kover.api.IntellijEngine(\"version\"))` instead. Please refer to migration guide in order to migrate: ${KoverMigrations.MIGRATION_0_5_TO_0_6}",
replaceWith = ReplaceWith("engine"),
level = DeprecationLevel.ERROR
)
public val intellijEngineVersion: Property<String> = objects.property()
@get:Internal
@Deprecated(
message = "Property was removed in Kover API version 2, use `engine.set(kotlinx.kover.api.JacocoEngine(\"version\"))` instead. Please refer to migration guide in order to migrate: ${KoverMigrations.MIGRATION_0_5_TO_0_6}",
replaceWith = ReplaceWith("engine"),
level = DeprecationLevel.ERROR
)
public val jacocoEngineVersion: Property<String> = objects.property()
@get:Internal
@Deprecated(
message = "Property was removed in Kover API version 2. Please refer to migration guide in order to migrate: ${KoverMigrations.MIGRATION_0_5_TO_0_6}",
level = DeprecationLevel.ERROR
)
public var generateReportOnCheck: Boolean = true
@get:Internal
@Deprecated(
message = "Property was removed in Kover API version 2. Please refer to migration guide in order to migrate: ${KoverMigrations.MIGRATION_0_5_TO_0_6}",
level = DeprecationLevel.ERROR
)
public var disabledProjects: Set<String> = emptySet()
@Deprecated(
message = "Property was removed in Kover API version 2. Please refer to migration guide in order to migrate: ${KoverMigrations.MIGRATION_0_5_TO_0_6}",
level = DeprecationLevel.ERROR
)
@get:Internal
public var instrumentAndroidPackage: Boolean = false
@Deprecated(
message = "Property was removed in Kover API version 2. Please refer to migration guide in order to migrate: ${KoverMigrations.MIGRATION_0_5_TO_0_6}",
level = DeprecationLevel.ERROR
)
@get:Internal
public var runAllTestsForProjectTask: Boolean = false
}
// DEPRECATIONS
// TODO delete in 0.7 version
@Deprecated(
message = "Class KoverExtension was renamed to KoverProjectConfig in Kover API version 2",
replaceWith = ReplaceWith("KoverProjectConfig"),
level = DeprecationLevel.ERROR
)
public open class KoverExtension
public open class KoverProjectFilters @Inject constructor(private val objects: ObjectFactory) {
internal val classes: Property<KoverClassFilter> = objects.property()
internal val sourceSets: Property<KoverSourceSetFilter> = objects.property()
/**
* Configures class filter in order to include and exclude specific classes.
*
* Example:
* ```
* classes {
* excludes += "com.example.FooBar"
* includes += "com.example.*Bar"
* }
* ```
* Excludes have priority over includes.
*/
public fun classes(config: Action<KoverClassFilter>) {
val classFilter = objects.newInstance<KoverClassFilter>()
config.execute(classFilter)
classes.set(classFilter)
}
/**
* Configures source set filter.
*/
public fun sourceSets(config: Action<KoverSourceSetFilter>) {
val sourceSetFilters = objects.newInstance<KoverSourceSetFilter>()
config.execute(sourceSetFilters)
sourceSets.set(sourceSetFilters)
}
}
public open class KoverProjectInstrumentation {
/**
* Specifies the names of test tasks for which instrumentation will be disabled.
*/
public val excludeTasks: MutableSet<String> = mutableSetOf()
}
public open class KoverProjectXmlConfig @Inject constructor(objects: ObjectFactory) {
internal val filters: KoverProjectFilters = objects.newInstance()
/**
* Specifies whether the XML report generation task should be executed before the `check` task (if it exists) of the current project.
*
* `false` by default.
*/
public val onCheck: Property<Boolean> = objects.property()
/**
* Specifies file path of generated XML report file with coverage data.
*
* By default, is a value of [KoverPaths.PROJECT_XML_REPORT_DEFAULT_PATH] in the build directory.
*/
public val reportFile: RegularFileProperty = objects.fileProperty()
/**
* Override filters for the XML report generation task.
* Only the explicitly specified filters will be overridden, the rest will be inherited from the common filters (see [KoverProjectConfig.filters]).
*/
public fun overrideFilters(config: Action<KoverProjectFilters>) {
config.execute(filters)
}
}
public open class KoverProjectHtmlConfig @Inject constructor(private val objects: ObjectFactory) {
internal val taskFilters: KoverProjectFilters = objects.newInstance()
/**
* Specifies whether the HTML report generation task should be executed before the `check` task (if it exists) of the current project.
*
* `false` by default.
*/
public val onCheck: Property<Boolean> = objects.property()
/**
* Specifies directory path of generated HTML report.
*
* By default, is a value of [KoverPaths.PROJECT_HTML_REPORT_DEFAULT_PATH] in the build directory.
*/
public val reportDir: DirectoryProperty = objects.directoryProperty()
/**
* Override filters for the HTML report generation task.
* Only the explicitly specified filters will be overrided, the rest will be inherited from the common filters (see [KoverProjectConfig.filters]).
*/
public fun overrideFilters(config: Action<KoverProjectFilters>) {
config.execute(taskFilters)
}
}
public open class KoverMergedConfig @Inject constructor(objects: ObjectFactory) {
internal val isEnabled: Property<Boolean> = objects.property()
internal val filters: KoverMergedFilters = objects.newInstance()
internal val xmlReport: KoverMergedXmlConfig = objects.newInstance()
internal val htmlReport: KoverMergedHtmlConfig = objects.newInstance()
internal val verify: KoverVerifyConfig = objects.newInstance()
/**
* Create Kover tasks for generating merged reports.
*/
public fun enable() {
isEnabled.set(true)
}
/**
* Configures filters for all Kover merged tasks in current project.
*/
public fun filters(config: Action<KoverMergedFilters>) {
config.execute(filters)
}
/**
* Configures the task of generating a merged XML report.
*/
public fun xmlReport(config: Action<KoverMergedXmlConfig>) {
config.execute(xmlReport)
}
/**
* Configures the task of generating a merged HTML report.
*/
public fun htmlReport(config: Action<KoverMergedHtmlConfig>) {
config.execute(htmlReport)
}
/**
* Configures the merged verification task.
*/
public fun verify(config: Action<KoverVerifyConfig>) {
config.execute(verify)
}
}
public open class KoverMergedFilters @Inject constructor(private val objects: ObjectFactory) {
internal val classes: Property<KoverClassFilter> = objects.property()
internal val projects: Property<KoverProjectsFilter> = objects.property()
/**
* Configures class filter.
*/
public fun classes(config: Action<KoverClassFilter>) {
val classFilter = objects.newInstance<KoverClassFilter>()
config.execute(classFilter)
classes.set(classFilter)
}
/**
* Configures projects filter.
*/
public fun projects(config: Action<KoverProjectsFilter>) {
val projectsFilters = objects.newInstance<KoverProjectsFilter>()
config.execute(projectsFilters)
projects.set(projectsFilters)
}
}
public open class KoverMergedXmlConfig @Inject constructor(private val objects: ObjectFactory) {
internal val classFilter: Property<KoverClassFilter> = objects.property()
/**
* Specifies whether the merged XML report generation task should be executed before the `check` task (if it exists) of the current project.
*/
public val onCheck: Property<Boolean> = objects.property()
/**
* Specifies file path of generated XML report file with coverage data.
*/
public val reportFile: RegularFileProperty = objects.fileProperty()
/**
* Override class filter for the merged XML report generation task.
*/
public fun overrideClassFilter(config: Action<KoverClassFilter>) {
val newClassFilter = objects.newInstance<KoverClassFilter>()
config.execute(newClassFilter)
classFilter.set(newClassFilter)
}
}
public open class KoverMergedHtmlConfig @Inject constructor(private val objects: ObjectFactory) {
internal val classFilter: Property<KoverClassFilter> = objects.property()
/**
* Specifies whether the merged HTML report generation task should be executed before the `check` task (if it exists) of the current project.
*/
public val onCheck: Property<Boolean> = objects.property()
/**
* Specifies directory path of generated HTML report.
*/
public val reportDir: DirectoryProperty = objects.directoryProperty()
/**
* Override class filter for the merged HTML report generation task.
*/
public fun overrideClassFilter(config: Action<KoverClassFilter>) {
val newClassFilter = objects.newInstance<KoverClassFilter>()
config.execute(newClassFilter)
classFilter.set(newClassFilter)
}
}
public open class KoverProjectsFilter {
/**
* Specifies the projects excluded from subprojects (included current project) using in the merged tasks. Both the project name (if it is unique) and the project path can be used.
*
* If empty, the current project and all subprojects are used.
*/
@get:Input
public val excludes: MutableList<String> = mutableListOf()
}
public open class KoverVerifyConfig @Inject constructor(private val objects: ObjectFactory) {
internal val rules: ListProperty<VerificationRule> = objects.listProperty()
/**
* Specifies whether the verification task should be executed before the `check` task (if it exists) of the current project.
*
* By default, `true` for project reports and `false` for merged.
*/
public val onCheck: Property<Boolean> = objects.property<Boolean>().value(true)
/**
* Add new coverage verification rule to check after test task execution.
*/
public fun rule(configureRule: Action<VerificationRule>) {
rules.add(objects.newInstance<VerificationRule>().also { configureRule.execute(it) })
}
}
public open class KoverClassFilter {
/**
* Specifies class inclusion rules into report.
* Only the specified classes may be present in the report.
* Exclusion rules have priority over inclusion ones.
*
* Inclusion rules are represented as a set of fully-qualified names of the classes being instrumented.
* It's possible to use `*` and `?` wildcards.
*/
@get:Input
public val includes: MutableList<String> = mutableListOf()
/**
* Specifies class exclusion rules into report.
* The specified classes will definitely be missing from report.
* Exclusion rules have priority over inclusion ones.
*
* Exclusion rules are represented as a set of fully-qualified names of the classes being instrumented.
* It's possible to use `*` and `?` wildcards.
*/
@get:Input
public val excludes: MutableList<String> = mutableListOf()
}
public open class KoverSourceSetFilter {
/**
* Not implemented in beta version.
*/
@get:Input
public val excludes: MutableSet<String> = mutableSetOf()
/**
* Not implemented in beta version.
*/
@get:Input
public var excludeTests: Boolean = true
}
public open class VerificationRule @Inject constructor(private val objects: ObjectFactory) {
@get:Nested
@get:Optional
internal val classFilter: Property<KoverClassFilter> = objects.property()
@get:Nested
internal val bounds: ListProperty<VerificationBound> = objects.listProperty()
/**
* Specifies that the rule will be checked during verification.
*/
@get:Input
public var isEnabled: Boolean = true
/**
* Specifies custom name of the rule.
*/
@get:Input
@get:Nullable
@get:Optional
public var name: String? = null
/**
* Specifies by which entity the code for separate coverage evaluation will be grouped.
*/
@get:Input
public var target: VerificationTarget = VerificationTarget.ALL
/**
* Override class filter for the rule.
*/
public fun overrideClassFilter(config: Action<KoverClassFilter>) {
if (!classFilter.isPresent) {
classFilter.set(objects.newInstance<KoverClassFilter>())
}
config.execute(classFilter.get())
}
/**
* Add a constraint on the value of the code coverage metric.
*/
public fun bound(configureBound: Action<VerificationBound>) {
bounds.add(objects.newInstance<VerificationBound>().also { configureBound.execute(it) })
}
}
public open class VerificationBound {
/**
* Specifies minimal value to compare with counter value.
*/
@get:Input
@get:Nullable
@get:Optional
public var minValue: Int? = null
/**
* Specifies maximal value to compare with counter value.
*/
@get:Input
@get:Nullable
@get:Optional
public var maxValue: Int? = null
/**
* Specifies which metric will be evaluation code coverage.
*/
@get:Input
public var counter: CounterType = CounterType.LINE
/**
* Specifies type of lines counter value to compare with minimal and maximal values if them defined.
* Default is [VerificationValueType.COVERED_PERCENTAGE]
*/
@get:Input
public var valueType: VerificationValueType = VerificationValueType.COVERED_PERCENTAGE
}
/**
* Entity type for grouping code to coverage evaluation.
*/
public enum class VerificationTarget {
/**
* Counts the coverage for all code.
*/
ALL,
/**
* Counts the coverage for each class separately.
*/
CLASS,
/**
* Counts the coverage for each package that has classes separately.
*/
PACKAGE
}
/**
* Type of the metric to evaluate code coverage.
*/
public enum class CounterType {
/**
* Evaluates coverage for lines.
*/
LINE,
/**
* Evaluates coverage for JVM bytecode instructions.
*/
INSTRUCTION,
/**
* Evaluates coverage for code branches excluded dead-branches.
*/
BRANCH
}
/**
* Type of counter value to compare with minimal and maximal values if them defined.
*/
public enum class VerificationValueType {
COVERED_COUNT,
MISSED_COUNT,
COVERED_PERCENTAGE,
MISSED_PERCENTAGE
}