Last active
December 13, 2022 23:02
-
-
Save zerotacg/a131d73bf3f85c5e0309762ac8bbdf06 to your computer and use it in GitHub Desktop.
print coverage stats for usage in gitlab coverage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.xml.XmlParser | |
import java.text.DecimalFormat | |
tasks.register('koverStats') { | |
dependsOn ':koverXmlReport' | |
def percentageFormat = new DecimalFormat("#.##%") | |
ext.srcFile = new File(buildDir, 'reports/kover/xml/report.xml') | |
inputs.file srcFile | |
doLast { | |
println "Coverage Stats." | |
def report = new XmlParser().parse(srcFile) | |
report.counter.each { counter -> | |
def type = counter.@type | |
def missed = Integer.parseInt(counter.@missed) | |
def covered = Integer.parseInt(counter.@covered) | |
def total = missed + covered | |
def percentage = covered / total | |
println "Type: $type missed: $missed covered: $covered percentage: ${percentageFormat.format(percentage)}" | |
} | |
} | |
} |
Thx for your remark I added the missing imports to the snippet
Thx for your remark I added the missing imports to the snippet
thank you for your snippet :)
I can't import this, may be I should implement some repository for import...
If the XmlParser is not available you could try and implement it by just reading it as plain text and find the coresponding line with an regex as in the kotlin version of the task
I tried to convert this to the Groovy, but had a fail. Maybe, will more simple to convert my .gradle file to gradle.kts. Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, this snippet looks like solution may help me (I went from here) until collaborators from Kover add own task.
But I can't run this snippet :(
I see message "Cannot resolve symbol 'XmlParser'". and I don't know .
Tell me, please, what should I import to Gradle-file (using Groovy). Thank you.