forked from divkit/divkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiv-tests-coverage.gradle
76 lines (65 loc) · 1.89 KB
/
div-tests-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
apply plugin: 'jacoco'
jacoco {
toolVersion = versions.jacoco
}
def testVariant = project.property('testVariant')
def coverageSourceDirs = [
'src/main/java',
'src/impl/java',
'src/gen'
]
ext.readLinesFromFile = { filepath, skipSymbol ->
final BufferedReader reader = new BufferedReader(new FileReader(new File(filepath)))
String line
List<String> linesAsList = new ArrayList<>()
while ((line = reader.readLine()) != null) {
if (line.trim().isEmpty() || line.startsWith(skipSymbol)) {
continue
}
linesAsList.add(line)
}
return linesAsList
}
if (!tasks.names.contains('jacocoTestReport')) {
task jacocoTestReport(type: JacocoReport) {
final classesDir = "$project.buildDir/intermediates/javac/${testVariant}"
classDirectories.from {
fileTree(dir: classesDir)
}
doFirst {
new File(classesDir).eachFileRecurse { file ->
if (file.name.contains('$$')) {
file.renameTo(file.path.replace('$$', '$'))
}
}
}
}
}
jacocoTestReport {
dependsOn "test${testVariant.capitalize()}UnitTest"
def excludes = readLinesFromFile("${project.projectDir}/jacoco.excludes", "#")
classDirectories.setFrom(
files(classDirectories.files.collect {
fileTree(dir: it, excludes: excludes)
})
)
group = "reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml {
enabled true // coveralls plugin depends on xml format report
}
html {
enabled true
}
csv {
enabled true
}
}
sourceDirectories.from {
files(coverageSourceDirs)
}
executionData.from {
files("build/jacoco/test${testVariant.capitalize()}UnitTest.exec")
}
}