-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjacoco.gradle
55 lines (46 loc) · 1.93 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
apply plugin: 'jacoco'
def connectedExecutionDataPath = "${buildDir}/outputs/code-coverage/connected/connectedExecutionData.ec"
jacoco {
toolVersion = '0.7.7.201606060606'
}
task jacocoTestReport(type: JacocoReport, dependsOn: 'renameAndroidExecutionData') {
// Bit hacky but fixes https://code.google.com/p/android/issues/detail?id=69174.
// We iterate through the compiled .class tree and rename $$ to $.
def renamedFiles = [:]
doFirst {
new File("${buildDir}/intermediates/classes/").eachFileRecurse { file ->
if (file.name.contains('$$')) {
renamedFiles.put(file.path, file.path.replace('$$', '$'))
file.renameTo(file.path.replace('$$', '$'))
}
}
}
doLast {
renamedFiles.each {
entry -> new File(entry.value.toString()).renameTo(entry.key.toString())
}
new File("${buildDir}/reports/coverage/debug").deleteDir()
}
reports {
xml.enabled = true
html.enabled = true
xml.destination "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"
html.destination "${buildDir}/reports/jacoco/test/"
}
jacocoClasspath = configurations['androidJacocoAnt']
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"
sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
executionData = files(["${buildDir}/jacoco/testDebugUnitTest.exec", connectedExecutionDataPath])
}
task renameAndroidExecutionData() {
doFirst {
new File("${buildDir}/outputs/code-coverage/connected/").eachFileRecurse { file ->
if (file.name.contains('.ec')) {
file.renameTo(connectedExecutionDataPath)
}
}
}
}