-
Notifications
You must be signed in to change notification settings - Fork 0
/
jacoco.gradle
63 lines (57 loc) · 2.51 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
apply plugin: 'jacoco'
apply plugin: 'com.github.kt3k.coveralls'
def jacocoDaggerMap = [:]
task jacocoTestReport(type: JacocoReport) {
reports {
xml.enabled true
csv.enabled false
xml.destination file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml")
html.destination file("${buildDir}/reports/coverage")
}
getClassDirectories().setFrom(fileTree(
dir: "${buildDir}/intermediates/classes/debug",
exclude: [
'**/R.class',
'**/R$*.class',
'**/*$InjectAdapter.class',
'**/*$ModuleAdapter.class',
'**/*$ViewInjector*.class',
'**/RestServiceFactory*.class',
'**/*Module*.class',
'**/AndroidUtils$*.class',
'**/data/android/*.class',
'**/AlertDialogBuilder.class',
'**/AlertDialogBuilder$Impl.class',
'**/PopupMenu*.class',
'**/ImageUtils$PicassoImpl.class',
'**/ActionViewResolver.class',
'**/SpinnerPreference$*.class',
'**/AsteriskSpan.class',
'**/ImageGetter$URLDrawable.class',
'**/ScrollAwareFABBehavior.class',
'**/SinglePageItemRecyclerViewAdapter$SavedState*.class',
'**/*Dummy*.class',
'**/*ItemDecoration.class'
]))
getSourceDirectories().setFrom(android.sourceSets.main.java.srcDirs)
getExecutionData().setFrom("${buildDir}/jacoco/testDebugUnitTest.exec")
// Bit hacky but fixes https://code.google.com/p/android/issues/detail?id=69174.
// We iterate through the compiled .class tree and rename $$ to $.
doFirst {
new File("${buildDir}/intermediates/classes/debug").eachFileRecurse { file ->
if (file.name.contains('$$')) {
def renamed = file.path.replace '$$', '$'
jacocoDaggerMap[renamed] = file.path
file.renameTo renamed
}
}
}
doLast {
// Revert renamed files back to their generated names
jacocoDaggerMap.each { renamed, original ->
new File(renamed).renameTo original
}
println "coveralls report has been generated to file://${buildDir}/reports/jacoco/test/jacocoTestReport.xml"
println "jacoco report has been generated to file://${reports.html.destination}/index.html"
}
}