-
Notifications
You must be signed in to change notification settings - Fork 0
/
jacoco.gradle
executable file
·107 lines (79 loc) · 4.47 KB
/
jacoco.gradle
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
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.8"
}
project.afterEvaluate {
def buildTypes = android.buildTypes.collect { type -> type.name }
def productFlavors = android.productFlavors.collect { flavor -> flavor.name }
if (!productFlavors) productFlavors.add('')
productFlavors.each { productFlavorName ->
buildTypes.each { buildTypeName ->
def sourceName
if (!productFlavorName) {
sourceName = "${buildTypeName}"
} else {
sourceName = "${productFlavorName}${buildTypeName.capitalize()}"
}
def testTaskName = "test${sourceName.capitalize()}UnitTest"
def excludes = [
'**/BuildConfig.*',
'**/*_Impl*.*',
'**/*Double.*',
'**/*Binding.*'
]
def classKotlin = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/${sourceName}", excludes: excludes)
def classJava = fileTree(dir: "$project.buildDir/intermediates/javac/${sourceName}/classes", excludes: excludes)
def kotlinSrc = "$project.projectDir/src/main/java"
def javaSrc = "$project.projectDir/src/main/java"
def flavourSrc = "$project.projectDir/src/$productFlavorName/java"
task "test${sourceName.capitalize()}CombinedCoverage"(type: JacocoReport, dependsOn: ["$testTaskName", "connected${sourceName.capitalize()}AndroidTest"]) {
group = "coverage.combined"
description = "Generate Jacoco /test + combined (if avail.) /andoidTest coverage report from ${sourceName.capitalize()}"
classDirectories.setFrom(files([classKotlin, classJava]))
sourceDirectories.setFrom(files([javaSrc, kotlinSrc, flavourSrc]))
executionData.from = fileTree(dir: "${project.buildDir}", includes: [
"outputs/unit_test_code_coverage/${sourceName}UnitTest/${testTaskName}.exec",
"outputs/code_coverage/$productFlavorName${buildTypeName.capitalize()}AndroidTest/connected/**/*.ec"
])
reports {
xml.required = true
xml.destination file("${project.buildDir}/reports/${sourceName.capitalize()}.xml")
html.required = true
html.destination file("$project.buildDir/reports/jacoco")
}
}
///////////////////////////////////////
task "test${sourceName.capitalize()}UnitTestCoverage"(type: JacocoReport, dependsOn: ["$testTaskName"]) {
group = "coverage.unittest"
description = "Generate Jacoco /test coverage report from ${sourceName.capitalize()}"
classDirectories.setFrom(files([classKotlin, classJava]))
sourceDirectories.setFrom(files([javaSrc, kotlinSrc, flavourSrc]))
executionData.from = fileTree(dir: "${project.buildDir}", includes: [
"outputs/unit_test_code_coverage/${sourceName}UnitTest/${testTaskName}.exec"
])
reports {
xml.required = true
xml.destination file("${project.buildDir}/reports/${sourceName.capitalize()}.xml")
html.required = true
html.destination file("$project.buildDir/reports/jacoco")
}
}
///////////////////////////////////////
task "connected${sourceName.capitalize()}AndroidTestCoverage"(type: JacocoReport, dependsOn: ["connected${sourceName.capitalize()}AndroidTest"]) {
group = "coverage.connected"
description = "Generate Jacoco /test coverage report from ${sourceName.capitalize()}"
classDirectories.setFrom(files([classKotlin, classJava]))
sourceDirectories.setFrom(files([javaSrc, kotlinSrc, flavourSrc]))
executionData.from = fileTree(dir: "${project.buildDir}", includes: [
"outputs/code_coverage/$productFlavorName${buildTypeName.capitalize()}AndroidTest/connected/**/*.ec"
])
reports {
xml.required = true
xml.destination file("${project.buildDir}/reports/${sourceName.capitalize()}.xml")
html.required = true
html.destination file("$project.buildDir/reports/jacoco")
}
}
}
}
}