-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjacoco.gradle
More file actions
155 lines (127 loc) · 4.3 KB
/
jacoco.gradle
File metadata and controls
155 lines (127 loc) · 4.3 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import groovy.transform.Memoized
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.8"
}
@Memoized
Properties getLocalProperties() {
final propertiesFile = project.rootProject.file("local.properties")
final properties = new Properties()
if (propertiesFile.exists()) {
properties.load(propertiesFile.newDataInputStream())
}
return properties
}
def openReport(htmlOutDir) {
final reportPath = "$htmlOutDir/index.html"
println "HTML Report: $reportPath"
if (!project.hasProperty("open-report")) {
println "to open the report automatically in your default browser add '-Popen-report' cli argument"
return
}
def os = org.gradle.internal.os.OperatingSystem.current()
if (os.isWindows()) {
exec { commandLine 'cmd', '/c', "start $reportPath" }
} else if (os.isMacOsX()) {
exec { commandLine 'open', "$reportPath" }
} else if (os.isLinux()) {
try {
exec { commandLine 'xdg-open', "$reportPath" }
} catch (Exception ignored) {
if (localProperties.containsKey("linux-html-cmd")) {
exec { commandLine properties.get("linux-html-cmd"), "$reportPath" }
} else {
println "'linux-html-cmd' property could not be found in 'local.properties'"
}
}
}
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
def fileFilter = [
// android
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'android/**/*.*',
// kotlin
'**/*MapperImpl*.*',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/*Component*.*',
'**/*BR*.*',
'**/Manifest*.*',
'**/*$Lambda$*.*',
'**/*Companion*.*',
'**/*Module*.*',
'**/*Dagger*.*',
'**/*Hilt*.*',
'**/*MembersInjector*.*',
'**/*_MembersInjector.class',
'**/*_Factory*.*',
'**/*_Provide*Factory*.*',
'**/*Extensions*.*',
// sealed and data classes
'**/*$Result.*',
'**/*$Result$*.*'
]
// Our merge report task
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'connectedDebugAndroidTest']) {
def htmlOutDir = layout.buildDirectory.dir("reports/jacoco/$name/html").get().asFile
doLast {
openReport htmlOutDir
}
reports {
xml.required = true
html.destination htmlOutDir
}
def kotlinClasses = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"
sourceDirectories.from = files([mainSrc])
classDirectories.from = files([kotlinClasses])
executionData.from = fileTree(dir: project.buildDir, includes: [
'**/*.exec',
'**/*.ec'
])
}
// A unit-test only report task
task jacocoUnitTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
def htmlOutDir = layout.buildDirectory.dir("reports/jacoco/$name/html").get().asFile
doLast {
openReport htmlOutDir
}
reports {
xml.required = true
html.destination htmlOutDir
}
def kotlinClasses = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"
sourceDirectories.from = files([mainSrc])
classDirectories.from = files([kotlinClasses])
executionData.from = fileTree(dir: project.buildDir, includes: [
'**/*.exec'
])
}
// A connected android tests only report task
task jacocoAndroidTestReport(type: JacocoReport, dependsOn: ['connectedDebugAndroidTest']) {
def htmlOutDir = layout.buildDirectory.dir("reports/jacoco/$name/html").get().asFile
doLast {
openReport htmlOutDir
}
reports {
xml.required = true
html.destination htmlOutDir
}
def kotlinClasses = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"
sourceDirectories.from = files([mainSrc])
classDirectories.from = files([kotlinClasses])
executionData.from = fileTree(dir: project.buildDir, includes: [
'**/*.ec'
])
}