Guest User

Untitled

a guest
Jun 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. target( 'coverage_todo' : 'identify largest sections of uncovered code') {
  2.  
  3. def xmlFile = new File('build/reports/coverage.xml')
  4. def coverage = new XmlParser().parse(xmlFile)
  5.  
  6. List classList = []
  7. Integer totalNoHitLines = 0
  8.  
  9. coverage.'packages'.each { pkgs ->
  10.  
  11. pkgs.'package'.each { pkg ->
  12.  
  13. pkg.classes.each { classes ->
  14.  
  15. classes.'class'.each { cls ->
  16.  
  17. Integer classNoHitLines = 0
  18.  
  19. cls.methods.each { methods ->
  20.  
  21. methods.method.each { method ->
  22.  
  23. method.lines.each { lines ->
  24.  
  25. lines.line.each { line ->
  26.  
  27. int hits = Integer.valueOf(line.@hits)
  28. if(hits == 0) {
  29. classNoHitLines++
  30. totalNoHitLines++
  31. }
  32. } // lines
  33. } // method
  34. } // methods
  35. } // class
  36.  
  37. if(classNoHitLines > 0) {
  38. //println "${cls.@name} ${classNoHitLines}"
  39. classList << [className: cls.@name, noHitLines: classNoHitLines]
  40. }
  41. } // classes
  42. } // package
  43. } // packages
  44.  
  45.  
  46. }// coverage
  47.  
  48.  
  49. def c = { ch1, ch2 ->
  50. return ch2.noHitLines.compareTo(ch1.noHitLines)
  51. }
  52.  
  53. classList.sort(c)
  54.  
  55. String rpt = """<html>
  56. <head>
  57. <title>Least Covered Code By Class</title>
  58. <style>
  59. body { font-family: Arial,Helvetica,Sans-Serif;font-size: 13px; }
  60. table.todo { margin-left: 20px; width: 700px; }
  61. table.todo th { text-align: left; }
  62. table.todo th.lines { width: 100px; }
  63. table.todo tr.odd { background-color: #F1F1F1; }
  64. </style>
  65. </head>
  66. <body>
  67. <h1>Coverage TODO List</h1>
  68. <table border='1' class='todo'>
  69. <tr>
  70. <th>Class</th><th class='lines'>Lines</th></tr>
  71. """
  72. int r = 0
  73. String evenOdd = 'even'
  74. classList.each { ch ->
  75. evenOdd = (r++ % 2 == 0 ? 'even' : 'odd' )
  76. rpt += "<tr class='${evenOdd}'><td>${ch.className}</td><td>${ch.noHitLines}</td></tr>\n"
  77. }
  78.  
  79. rpt += """<tr><td>Total</td><td>${totalNoHitLines}</td></tr>
  80. </table>
  81. </body>
  82. </html>
  83. """
  84.  
  85. File htmlF = new File("build/reports/coverage_todo.html")
  86. if(htmlF.exists()) htmlF.delete()
  87. htmlF << rpt
  88.  
  89. }
Add Comment
Please, Sign In to add comment