forked from instructure/canvas-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoverage.gradle
74 lines (64 loc) · 2.24 KB
/
coverage.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
// Existing gradle issue: https://github.com/arturdm/jacoco-android-gradle-plugin/issues/37
// Code from: https://gist.github.com/almozavr/3cd46c4b4f0babbfc136db91924ab56e
apply plugin: "jacoco"
jacoco {
toolVersion = Versions.JACOCO
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
task('jacocoReports') {
group = "Reporting"
description = "Generate Jacoco coverage reports for all variants"
}
task('jacocoVerifications') {
group = "Verification"
description = "Generate Jacoco coverage reports for all variants"
}
variants().all { variant ->
def params = prepareJacocoParams(variant)
def reportTask = createReportTask(params)
jacocoReports.dependsOn reportTask
}
def prepareJacocoParams(variant) {
def params = [:]
params.variantName = variant.name
params.variantCapName = variant.name.capitalize()
params.fileFilter = [
'**/com/instructure/**/*.*',
]
params.classDirectories = files([fileTree(
dir: variant.javaCompiler.destinationDir,
includes: params.fileFilter
) + fileTree(
dir: "$buildDir/tmp/kotlin-classes/$params.variantName",
includes: params.fileFilter
)])
params.sourceDirectories = files([
"src/main/java", "src/main/kotlin",
"src/$params.variantName/java", "src/$params.variantName/kotlin"
])
params.executionData = files("${buildDir}/jacoco/test${params.variantCapName}UnitTest.exec")
return params
}
def createReportTask(params) {
return task("jacoco${params.variantCapName}Report", type: JacocoReport, dependsOn: "test${params.variantCapName}UnitTest") {
group = "Reporting"
description = "Generate Jacoco coverage reports for $params.variantCapName"
reports {
xml.enabled = true
html.enabled = true
csv.enabled = false
}
classDirectories.setFrom params.classDirectories
sourceDirectories.setFrom params.sourceDirectories
executionData.setFrom params.executionData
}
}
def variants() {
if (project.android.hasProperty('libraryVariants')) {
return project.android.libraryVariants
} else {
return project.android.applicationVariants
}
}