Last active
April 29, 2022 03:30
-
-
Save Tempest1000/6fedd1d562ca334b012a4fcb0adb1c0b to your computer and use it in GitHub Desktop.
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.*; | |
import groovy.json.*; | |
def filePath = "/home/ssd/source/repos/spring-petclinic/target/site/jacoco/jacoco.xml" | |
def output = StringBuilder.newInstance() | |
output << "# Code Coverage Report\n" | |
output << "\n" | |
//def file = new File(filePath) | |
//def fileContents = file.text | |
//println fileContents | |
def parser = new XmlSlurper() | |
parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false) | |
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); | |
def report = parser.parse(filePath) | |
def list = [] | |
def packageName | |
report.package.each { pkg -> | |
packageName = pkg.@name.text() | |
output << "## ${packageName}\n" | |
output << "\n" | |
pkg.class.each { cls -> | |
def clsName = cls.@name.text().replaceAll(packageName, "").replaceAll("/", "") | |
output << "### ${clsName}\n" | |
output << "\n" | |
output << " * _classSummary\n" | |
cls.counter.each { cnt -> | |
if (cnt.@type.text() == "INSTRUCTION" ) { | |
output << " * INSTRUCTION\n" | |
output << " * missed: ${cnt.@missed.text()}\n" | |
output << " * covered: ${cnt.@covered.text()}\n" | |
} | |
if (cnt.@type.text() == "LINE" ) { | |
output << " * LINE\n" | |
output << " * missed: ${cnt.@missed.text()}\n" | |
output << " * covered: ${cnt.@covered.text()}\n" | |
} | |
if (cnt.@type.text() == "COMPLEXITY" ) { | |
output << " * COMPLEXITY\n" | |
output << " * missed: ${cnt.@missed.text()}\n" | |
output << " * covered: ${cnt.@covered.text()}\n" | |
} | |
if (cnt.@type.text() == "METHOD" ) { | |
output << " * METHOD\n" | |
output << " * missed: ${cnt.@missed.text()}\n" | |
output << " * covered: ${cnt.@covered.text()}\n" | |
} | |
} | |
output << "\n" | |
output << " * _methods\n" | |
cls.method.each { mth -> | |
def mthName = mth.@name.text().replaceAll("<", "").replaceAll(">", "") | |
output << " * ${mthName}\n" | |
mth.counter.each { ctr -> | |
if (ctr.@type.text() == "INSTRUCTION" ) { | |
output << " * INSTRUCTION\n" | |
output << " * missed: ${ctr.@missed.text()}\n" | |
output << " * covered: ${ctr.@covered.text()}\n" | |
} | |
if (ctr.@type.text() == "LINE" ) { | |
output << " * LINE\n" | |
output << " * missed: ${ctr.@missed.text()}\n" | |
output << " * covered: ${ctr.@covered.text()}\n" | |
} | |
if (ctr.@type.text() == "COMPLEXITY" ) { | |
output << " * COMPLEXITY\n" | |
output << " * missed: ${ctr.@missed.text()}\n" | |
output << " * covered: ${ctr.@covered.text()}\n" | |
} | |
if (ctr.@type.text() == "METHOD" ) { | |
output << " * METHOD\n" | |
output << " * missed: ${ctr.@missed.text()}\n" | |
output << " * covered: ${ctr.@covered.text()}\n" | |
} | |
} | |
output << "\n" | |
} | |
} | |
output << "\n" | |
} | |
println output.toString() | |
//report.package.class.@sourcefilename.each { x -> println x } | |
// parse sourcefile | |
//report.package.sourcefile.each { x -> println x.@name.text() } | |
// println report.'*'.size() | |
// def allRecords = report.package.class | |
// println allRecords.size() | |
// def firstRecord = report.package.class[0] | |
// println firstRecord.@name.text() | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment