-
Notifications
You must be signed in to change notification settings - Fork 47
/
KoverAggregateTask.kt
84 lines (66 loc) · 2.92 KB
/
KoverAggregateTask.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
/*
* Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.kover.tasks
import kotlinx.kover.api.*
import kotlinx.kover.engines.commons.*
import kotlinx.kover.engines.commons.Report
import kotlinx.kover.engines.commons.ReportFiles
import kotlinx.kover.engines.intellij.*
import org.gradle.api.*
import org.gradle.api.file.*
import org.gradle.api.model.*
import org.gradle.api.provider.*
import org.gradle.api.tasks.*
import java.io.*
@CacheableTask
open class KoverAggregateTask : DefaultTask() {
@get:Nested
val binaryReportFiles: MapProperty<String, NestedFiles> =
project.objects.mapProperty(String::class.java, NestedFiles::class.java)
@get:Nested
val smapFiles: MapProperty<String, NestedFiles> =
project.objects.mapProperty(String::class.java, NestedFiles::class.java)
@get:Nested
val srcDirs: MapProperty<String, NestedFiles> =
project.objects.mapProperty(String::class.java, NestedFiles::class.java)
@get:Nested
val outputDirs: MapProperty<String, NestedFiles> =
project.objects.mapProperty(String::class.java, NestedFiles::class.java)
@get:Input
internal val coverageEngine: Property<CoverageEngine> = project.objects.property(CoverageEngine::class.java)
@get:Classpath
internal val classpath: Property<FileCollection> = project.objects.property(FileCollection::class.java)
internal fun report(): Report {
val binariesMap = binaryReportFiles.get()
val smapFilesMap = smapFiles.get()
val sourcesMap = srcDirs.get()
val outputsMap = outputDirs.get()
val moduleNames = sourcesMap.keys
val reportFiles: MutableList<ReportFiles> = mutableListOf()
val sourceFiles: MutableList<File> = mutableListOf()
val outputFiles: MutableList<File> = mutableListOf()
// FIXME now all modules joined to one because of incorrect reporter's JSON format
moduleNames.map { name ->
val binaries = binariesMap.getValue(name)
reportFiles += if (coverageEngine.get() == CoverageEngine.INTELLIJ) {
val smapFiles = smapFilesMap.getValue(name).files.get().iterator()
binaries.files.get().map { binary ->
ReportFiles(binary, smapFiles.next())
}
} else {
binaries.files.get().map { binary ->
ReportFiles(binary)
}
}
sourceFiles += sourcesMap.getValue(name).files.get()
outputFiles += outputsMap.getValue(name).files.get()
}
return Report(reportFiles, listOf(ModuleInfo(sourceFiles, outputFiles)))
}
}
class NestedFiles(objects: ObjectFactory, files: Provider<FileCollection>) {
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
val files: Property<FileCollection> = objects.property(FileCollection::class.java).also { it.set(files) }
}