Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- target( 'coverage_todo' : 'identify largest sections of uncovered code') {
- def xmlFile = new File('build/reports/coverage.xml')
- def coverage = new XmlParser().parse(xmlFile)
- List classList = []
- Integer totalNoHitLines = 0
- coverage.'packages'.each { pkgs ->
- pkgs.'package'.each { pkg ->
- pkg.classes.each { classes ->
- classes.'class'.each { cls ->
- Integer classNoHitLines = 0
- cls.methods.each { methods ->
- methods.method.each { method ->
- method.lines.each { lines ->
- lines.line.each { line ->
- int hits = Integer.valueOf(line.@hits)
- if(hits == 0) {
- classNoHitLines++
- totalNoHitLines++
- }
- } // lines
- } // method
- } // methods
- } // class
- if(classNoHitLines > 0) {
- //println "${cls.@name} ${classNoHitLines}"
- classList << [className: cls.@name, noHitLines: classNoHitLines]
- }
- } // classes
- } // package
- } // packages
- }// coverage
- def c = { ch1, ch2 ->
- return ch2.noHitLines.compareTo(ch1.noHitLines)
- }
- classList.sort(c)
- String rpt = """<html>
- <head>
- <title>Least Covered Code By Class</title>
- <style>
- body { font-family: Arial,Helvetica,Sans-Serif;font-size: 13px; }
- table.todo { margin-left: 20px; width: 700px; }
- table.todo th { text-align: left; }
- table.todo th.lines { width: 100px; }
- table.todo tr.odd { background-color: #F1F1F1; }
- </style>
- </head>
- <body>
- <h1>Coverage TODO List</h1>
- <table border='1' class='todo'>
- <tr>
- <th>Class</th><th class='lines'>Lines</th></tr>
- """
- int r = 0
- String evenOdd = 'even'
- classList.each { ch ->
- evenOdd = (r++ % 2 == 0 ? 'even' : 'odd' )
- rpt += "<tr class='${evenOdd}'><td>${ch.className}</td><td>${ch.noHitLines}</td></tr>\n"
- }
- rpt += """<tr><td>Total</td><td>${totalNoHitLines}</td></tr>
- </table>
- </body>
- </html>
- """
- File htmlF = new File("build/reports/coverage_todo.html")
- if(htmlF.exists()) htmlF.delete()
- htmlF << rpt
- }
Add Comment
Please, Sign In to add comment