-
Notifications
You must be signed in to change notification settings - Fork 8
/
jacoco-aggregation.groovy
69 lines (59 loc) · 2.27 KB
/
jacoco-aggregation.groovy
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
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
ext.COVERAGE_REPORT_TASK_NAME = 'createDebugCoverageReport'
gradle.projectsEvaluated {
ext.applyJacocoTestReport = {
if (project.hasProperty('android')) {
if (project.tasks.findByName(COVERAGE_REPORT_TASK_NAME)) {
addJacocoTestReport project
}
}
}
if (rootProject.subprojects.isEmpty()) {
rootProject applyJacocoTestReport
} else {
rootProject.subprojects applyJacocoTestReport
}
}
ext.FILE_FILTER =
['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*',]
// Jacoco aggregation report
void addJacocoTestReport(final Project project) {
project.apply plugin:'jacoco'
project.jacoco {
toolVersion = '0.8.2'
}
project.tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
project.tasks.create([name:'jacocoTestReport',
type:JacocoReport,
dependsOn:['testDebugUnitTest', COVERAGE_REPORT_TASK_NAME],]) {
reports {
xml.enabled = true
html.enabled = true
}
final FileCollection DEBUG_TREE =
fileTree(dir:"$project.buildDir/tmp/kotlin-classes/debug", excludes:FILE_FILTER) +
getDebugSources(project)
final String MAIN_SRC = "$project.projectDir/src/main/java"
sourceDirectories = files([MAIN_SRC])
classDirectories = files([DEBUG_TREE])
executionData = fileTree(dir:project.buildDir, includes:[
'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec', '../jacoco.exec',
])
}
}
FileCollection getDebugSources(final Project project) {
FileCollection classes = project.files()
for (final String variantType : ['applicationVariants', 'libraryVariants', 'testVariants']) {
if (project.android.hasProperty(variantType)) {
project.android."${variantType}".all { variant ->
if (variant.buildType.name == 'debug') {
classes += fileTree(dir:"${variant.javaCompileProvider.get().destinationDir}", excludes:FILE_FILTER)
}
}
}
}
classes
}