-
Notifications
You must be signed in to change notification settings - Fork 7
/
coverage.gradle
92 lines (79 loc) · 3.46 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def excludes = [
// dependency injection graph
'**/*Module.*',
'**/*Module*.*',
// Framework entry points
'**/*Activity*',
'**/*Fragment*',
'**/*Application*',
'**/*AndroidService*',
// We would like to exclude android widgets as well but our naming is inconsistent
// Proof of concept
'**/*Login2*',
// Generated
'**/*JsonAdapter*',
'**/*Item.*',
'**/*$Holder.*',
'**/*ViewHolder.*',
'**/*View.*',
'**/*BottomSheet.*'
]
def initializeReport(report, projects, classExcludes) {
projects.each { project -> project.apply plugin: 'jacoco' }
report.executionData {
fileTree(rootProject.rootDir.absolutePath).include(
"**/build/**/*.exec",
"**/build/outputs/code_coverage/**/coverage.ec",
)
}
report.reports {
xml.required = true
html.required = true
csv.required = false
}
gradle.projectsEvaluated {
def androidSourceDirs = []
def androidClassDirs = []
projects.each { project ->
switch (project) {
case { project.plugins.hasPlugin("com.android.application") }:
androidClassDirs.add("${project.buildDir}/tmp/kotlin-classes/gplayDebug")
androidSourceDirs.add("${project.projectDir}/src/main/kotlin")
androidSourceDirs.add("${project.projectDir}/src/main/java")
break
case { project.plugins.hasPlugin("com.android.library") }:
androidClassDirs.add("${project.buildDir}/tmp/kotlin-classes/debug")
androidSourceDirs.add("${project.projectDir}/src/main/kotlin")
androidSourceDirs.add("${project.projectDir}/src/main/java")
break
default:
report.sourceSets project.sourceSets.main
}
}
report.sourceDirectories.setFrom(report.sourceDirectories + files(androidSourceDirs))
def classFiles = androidClassDirs.collect { files(it).files }.flatten()
report.classDirectories.setFrom(files((report.classDirectories.files + classFiles).collect {
fileTree(dir: it, excludes: classExcludes)
}))
}
}
def collectProjects(predicate) {
return subprojects.findAll { it.buildFile.isFile() && predicate(it) }
}
task generateCoverageReport(type: JacocoReport) {
outputs.upToDateWhen { false }
rootProject.apply plugin: 'jacoco'
def projects = collectProjects { ['vector-app', 'vector', 'matrix-sdk-android'].contains(it.name) }
initializeReport(it, projects, excludes)
}
task unitTestsWithCoverage(type: GradleBuild) {
// the 7.1.3 android gradle plugin has a bug where enableTestCoverage generates invalid coverage
startParameter.projectProperties.coverage = "false"
// TCHAP Specify variant for every module
tasks = [/*':matrix-sdk-android:testDebugUnitTest',*/ ':vector:testGplayBtchapWithdmvoipWithoutpinningDebugUnitTest', ':vector-app:testGplayBtchapWithdmvoipWithoutpinningDebugUnitTest', ':vector-config:testBtchapWithdmvoipDebugUnitTest']
}
task instrumentationTestsWithCoverage(type: GradleBuild) {
startParameter.projectProperties.coverage = "true"
startParameter.projectProperties['android.testInstrumentationRunnerArguments.notPackage'] = 'im.vector.app.ui'
tasks = [':vector-app:connectedGplayBtchapWithdmvoipWithoutpinningDebugAndroidTest', ':vector:connectedGplayBtchapWithdmvoipWithoutpinningDebugAndroidTest'/*, 'matrix-sdk-android:connectedDebugAndroidTest'*/]
}