-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathjacoco.gradle
69 lines (59 loc) · 2.26 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
/**
* Apply additional build steps to sub-projects*/
def jacocoToolVersion = rootProject.ext.has('jacocoVersion') ? rootProject.ext.jacocoVersion : '0.7.7.201606060606'
def moduleExcludes = rootProject.ext.has('moduleExcludes') ? rootProject.ext.moduleExcludes : [:]
def ignoredByJacoco = rootProject.ext.has('ignoredByJacoco') ? rootProject.ext.ignoredByJacoco : []
if (shouldApplyJacoco(project, ignoredByJacoco)) {
apply plugin: 'jacoco'
jacoco {
version jacocoToolVersion
}
task jacocoReport(type: JacocoReport, dependsOn: 'test') {
group = 'Reporting'
description = 'Generate Jacoco coverage reports after running tests.'
reports {
html {
enabled true
destination file('build/reports/jacoco/full')
}
xml {
enabled true
destination file('build/reports/jacoco/full/jacocoFullReport.xml')
}
}
sourceDirectories = project.files('src/main/java')
classDirectories = project.fileTree(dir: 'build/intermediates/classes/debug',
excludes: moduleExcludes[project.name] ?: [])
executionData = project.files('build/jacoco/testDebugUnitTest.exec')
doFirst {
renameClasses(project.name + '/build/intermediates/classes/debug')
}
}
}
List<File> listDirRecursive(File rootPath) {
List<File> result = new ArrayList<>()
List<File> children = rootPath.listFiles()
children.each { file ->
if (file.isFile()) {
result.add(file)
} else if (file.isDirectory()) {
result.addAll(listDirRecursive(file))
}
}
return result
}
void renameClasses(String rootPath) {
List<File> classes = listDirRecursive(file(rootPath))
classes.each { file ->
if (file.name.contains('$$')) {
file.renameTo(file.path.replace('$$', '$'))
}
}
}
boolean shouldApplyJacoco(Project project, List<String> ignoredByJacoco) {
def ignored = ignoredByJacoco.contains(project.name)
def isJava = project.plugins.hasPlugin("java")
def isAndroid = project.plugins.hasPlugin("com.android.library") || plugins.hasPlugin(
"com.android.application")
return !ignored && (isJava || isAndroid)
}