2022-06-10 00:58:04 +02:00
|
|
|
def excludes = [
|
|
|
|
// dependency injection graph
|
|
|
|
'**/*Module.*',
|
|
|
|
'**/*Module*.*',
|
|
|
|
|
|
|
|
// Framework entry points
|
|
|
|
'**/*Activity*',
|
|
|
|
'**/*Fragment*',
|
|
|
|
'**/*Application*',
|
2022-07-05 11:17:40 +02:00
|
|
|
'**/*AndroidService*',
|
2022-06-10 00:58:04 +02:00
|
|
|
|
|
|
|
// 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.*'
|
|
|
|
]
|
2022-03-03 11:40:11 +01:00
|
|
|
|
|
|
|
def initializeReport(report, projects, classExcludes) {
|
|
|
|
projects.each { project -> project.apply plugin: 'jacoco' }
|
|
|
|
|
2022-05-04 16:48:23 +02:00
|
|
|
report.executionData {
|
|
|
|
fileTree(rootProject.rootDir.absolutePath).include(
|
2022-08-11 10:50:10 +02:00
|
|
|
"**/build/**/*.exec",
|
|
|
|
"**/build/outputs/code_coverage/**/coverage.ec",
|
2022-05-04 16:48:23 +02:00
|
|
|
)
|
|
|
|
}
|
2022-03-03 11:40:11 +01:00
|
|
|
report.reports {
|
2024-07-15 18:12:08 +02:00
|
|
|
xml.required = true
|
|
|
|
html.required = true
|
|
|
|
csv.required = false
|
2022-03-03 11:40:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
gradle.projectsEvaluated {
|
|
|
|
def androidSourceDirs = []
|
|
|
|
def androidClassDirs = []
|
|
|
|
|
|
|
|
projects.each { project ->
|
|
|
|
switch (project) {
|
|
|
|
case { project.plugins.hasPlugin("com.android.application") }:
|
2022-04-13 15:17:24 +02:00
|
|
|
androidClassDirs.add("${project.buildDir}/tmp/kotlin-classes/gplayDebug")
|
2022-03-03 11:40:11 +01:00
|
|
|
androidSourceDirs.add("${project.projectDir}/src/main/kotlin")
|
|
|
|
androidSourceDirs.add("${project.projectDir}/src/main/java")
|
|
|
|
break
|
|
|
|
case { project.plugins.hasPlugin("com.android.library") }:
|
2022-03-04 16:03:12 +01:00
|
|
|
androidClassDirs.add("${project.buildDir}/tmp/kotlin-classes/debug")
|
2022-03-03 11:40:11 +01:00
|
|
|
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) }
|
|
|
|
}
|
|
|
|
|
2022-06-14 16:56:16 +02:00
|
|
|
task generateCoverageReport(type: JacocoReport) {
|
2022-03-03 11:40:11 +01:00
|
|
|
outputs.upToDateWhen { false }
|
|
|
|
rootProject.apply plugin: 'jacoco'
|
2022-08-11 10:50:10 +02:00
|
|
|
def projects = collectProjects { ['vector-app', 'vector', 'matrix-sdk-android'].contains(it.name) }
|
2022-03-03 11:40:11 +01:00
|
|
|
initializeReport(it, projects, excludes)
|
|
|
|
}
|
2022-06-14 16:56:16 +02:00
|
|
|
|
|
|
|
task unitTestsWithCoverage(type: GradleBuild) {
|
|
|
|
// the 7.1.3 android gradle plugin has a bug where enableTestCoverage generates invalid coverage
|
2023-01-11 11:22:46 +01:00
|
|
|
startParameter.projectProperties.coverage = "false"
|
2022-09-14 12:23:16 +02:00
|
|
|
tasks = ['testDebugUnitTest']
|
2022-06-14 16:56:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
task instrumentationTestsWithCoverage(type: GradleBuild) {
|
2023-01-11 11:22:46 +01:00
|
|
|
startParameter.projectProperties.coverage = "true"
|
2022-06-14 19:35:22 +02:00
|
|
|
startParameter.projectProperties['android.testInstrumentationRunnerArguments.notPackage'] = 'im.vector.app.ui'
|
2023-10-02 13:58:51 +02:00
|
|
|
tasks = [':vector-app:connectedGplayDebugAndroidTest', ':vector:connectedDebugAndroidTest', 'matrix-sdk-android:connectedDebugAndroidTest']
|
2023-04-25 16:40:43 +02:00
|
|
|
}
|