-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathcoverage-report.gradle
More file actions
63 lines (52 loc) · 2.27 KB
/
coverage-report.gradle
File metadata and controls
63 lines (52 loc) · 2.27 KB
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
import groovy.xml.XmlSlurper
task coverageReportSummary {
group = 'Verification'
description = 'Prints Jacoco coverage summary for all subprojects'
doLast {
def totalCovered = 0
def totalMissed = 0
def results = []
println ""
println "+---------------------------+---------------------+"
println "| Project | Branch Coverage (%) |"
println "+---------------------------+---------------------+"
subprojects.each { subproject ->
def reportFile = file("${subproject.name}/target/jacoco.xml")
if (reportFile.exists()) {
def xmlText = reportFile.text.replaceFirst(/<!DOCTYPE[^>]*>\s*/, '')
def report = new XmlSlurper().parseText(xmlText)
def counter = report.counter.find { it.@type == 'BRANCH' }
if (counter) {
def missed = counter.@missed.toInteger()
def covered = counter.@covered.toInteger()
def total = missed + covered
def percent = total > 0 ? (covered * 100.0 / total) : 0
results << [project: subproject.name, percent: percent]
totalCovered += covered
totalMissed += missed
} else {
results << [project: subproject.name, percent: null]
}
} else {
results << [project: subproject.name, percent: null]
}
}
results.each {
def name = it.project.padRight(26)
def coverage = it.percent != null ?
String.format("%20.2f", it.percent) :
" N/A "
println "| ${name}|${coverage} |"
}
println "+---------------------------+---------------------+"
def grandTotal = totalCovered + totalMissed
if (grandTotal > 0) {
def totalPercent = totalCovered * 100.0 / grandTotal
println "| TOTAL |" +
String.format("%20.2f", totalPercent) + " |"
} else {
println "| TOTAL | N/A |"
}
println "+---------------------------+---------------------+\n"
}
}