-
Notifications
You must be signed in to change notification settings - Fork 47
/
KoverCollectingTask.kt
49 lines (38 loc) · 1.32 KB
/
KoverCollectingTask.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
package kotlinx.kover.tasks
import org.gradle.api.*
import org.gradle.api.file.*
import org.gradle.api.tasks.*
open class KoverCollectingTask : DefaultTask() {
/**
* Specifies directory path for collecting of all XML and HTML reports from all projects.
*/
@get:OutputDirectory
val outputDir: DirectoryProperty = project.objects.directoryProperty()
@get:Internal
internal var xmlFiles: MutableMap<String, RegularFileProperty> = mutableMapOf()
@get:Internal
internal var htmlDirs: MutableMap<String, DirectoryProperty> = mutableMapOf()
@TaskAction
fun collect() {
project.copy {
it.into(outputDir)
xmlFiles.forEach { (p, f) ->
it.from(f) { c ->
c.rename { "${p.pathAsFilename()}.xml" }
}
}
}
htmlDirs.forEach { (p, d) ->
val name = p.pathAsFilename()
// delete directory for HTML reports so that the old reports do not overlap with the new ones
project.delete(outputDir.dir("html/$name"))
project.copy {
it.from(d)
it.into(outputDir.dir("html/$name"))
}
}
}
private fun String.pathAsFilename(): String {
return if (this == ":") "_root_" else replace(':', '_')
}
}