-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjacoco.gradle
104 lines (94 loc) · 3.48 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
apply plugin: "jacoco"
jacoco {
toolVersion = "0.8.5"
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
variants().all { variant ->
def params = prepareJacocoParams(variant)
def reportTask = createReportTask(params)
def verificationTask = createVerificationTask(params)
verificationTask.dependsOn reportTask
}
def prepareJacocoParams(variant) {
def params = [:]
params.variantName = variant.name
params.variantCapName = variant.name.capitalize()
params.fileFilter = [
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'android/**/*.*',
'**/*Activity**',
'**/*Dialog**',
'**/*Fragment**',
'**/*Item**',
'**/MainNavigationView**',
'**/DashboardMenuView**',
'**/LoanApplicationStatusView**',
'**/LoanSummaryButtonView**',
'**/LoanTypeView**',
'**/LoanSummaryExpandableView**',
'**/com/ubx/loaners/presentation/base/**',
'**/com/ubx/loaners/presentation/common/**',
'**/com/ubx/loaners/presentation/service/**',
'**/com/ubx/loaners/domain/base/**',
'**/com/ubx/loaners/domain/exceptions/**',
'**/com/ubx/loaners/domain/common/util/**',
'**/com/ubx/loaners/domain/models/**',
'**/com/ubx/loaners/data/**',
'**/com/ubx/loaners/di/**',
'**/com/ubx/loaners/App*'
]
def javaClasses = fileTree(dir: variant.javaCompiler.destinationDir, excludes: params.fileFilter)
def kotlinClasses = fileTree(dir: "${buildDir}/tmp/kotlin-classes/${params.variantName}", excludes: params.fileFilter)
params.classDirectories = files([javaClasses, kotlinClasses])
params.sourceDirectories = files([
"$project.projectDir/src/main/java",
"$project.projectDir/src/${params.variantName}/java",
"$project.projectDir/src/main/kotlin",
"$project.projectDir/src/${params.variantName}/kotlin"
])
params.executionData = files("${project.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") {
reports {
xml.enabled = true
html.enabled = true
csv.enabled = false
}
classDirectories.from = params.classDirectories
sourceDirectories.from = params.sourceDirectories
executionData.from = params.executionData
}
}
def createVerificationTask(params) {
return task("jacoco${params.variantCapName}Verification", type: JacocoCoverageVerification) {
group = "Reporting"
description = "Generate Jacoco coverage reports for $params.variantCapName"
sourceDirectories.from = params.sourceDirectories
classDirectories.from = params.classDirectories
executionData.from = params.executionData
violationRules {
rule {
limit {
counter = 'INSTRUCTION'
value = 'COVEREDRATIO'
minimum = 0.8
}
}
}
}
}
def variants() {
if (project.android.hasProperty('libraryVariants')) {
return project.android.libraryVariants
} else {
return project.android.applicationVariants
}
}