You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

findbugs.xslt 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. FindBugs - Find bugs in Java programs
  4. Copyright (C) 2004,2005 University of Maryland
  5. Copyright (C) 2005, Chris Nappin
  6. This library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. -->
  18. <xsl:stylesheet version="1.0"
  19. xmlns="http://www.w3.org/1999/xhtml"
  20. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  21. <xsl:output
  22. method="xml"
  23. omit-xml-declaration="yes"
  24. standalone="yes"
  25. doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
  26. doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
  27. indent="yes"
  28. encoding="UTF-8"/>
  29. <!--xsl:key name="bug-category-key" match="/BugCollection/BugInstance" use="@category"/-->
  30. <xsl:variable name="bugTableHeader">
  31. <tr class="tableheader">
  32. <th align="left">Warning</th>
  33. <th align="left">Priority</th>
  34. <th align="left">Details</th>
  35. </tr>
  36. </xsl:variable>
  37. <xsl:template match="/">
  38. <html>
  39. <head>
  40. <title>FindBugs Report</title>
  41. <style type="text/css">
  42. .tablerow0 {
  43. background: #EEEEEE;
  44. }
  45. .tablerow1 {
  46. background: white;
  47. }
  48. .detailrow0 {
  49. background: #EEEEEE;
  50. }
  51. .detailrow1 {
  52. background: white;
  53. }
  54. .tableheader {
  55. background: #b9b9fe;
  56. font-size: larger;
  57. }
  58. </style>
  59. </head>
  60. <xsl:variable name="unique-catkey" select="/BugCollection/BugCategory/@category"/>
  61. <!--xsl:variable name="unique-catkey" select="/BugCollection/BugInstance[generate-id() = generate-id(key('bug-category-key',@category))]/@category"/-->
  62. <body>
  63. <h2>Metrics</h2>
  64. <xsl:apply-templates select="/BugCollection/FindBugsSummary"/>
  65. <h2>Summary</h2>
  66. <table width="500" cellpadding="5" cellspacing="2">
  67. <tr class="tableheader">
  68. <th align="left">Warning Type</th>
  69. <th align="right">Number</th>
  70. </tr>
  71. <xsl:for-each select="$unique-catkey">
  72. <xsl:sort select="." order="ascending"/>
  73. <xsl:variable name="catkey" select="."/>
  74. <xsl:variable name="catdesc" select="/BugCollection/BugCategory[@category=$catkey]/Description"/>
  75. <xsl:variable name="styleclass">
  76. <xsl:choose><xsl:when test="position() mod 2 = 1">tablerow0</xsl:when>
  77. <xsl:otherwise>tablerow1</xsl:otherwise>
  78. </xsl:choose>
  79. </xsl:variable>
  80. <tr class="{$styleclass}">
  81. <td><a href="#Warnings_{$catkey}"><xsl:value-of select="$catdesc"/> Warnings</a></td>
  82. <td align="right"><xsl:value-of select="count(/BugCollection/BugInstance[@category=$catkey])"/></td>
  83. </tr>
  84. </xsl:for-each>
  85. <xsl:variable name="styleclass">
  86. <xsl:choose><xsl:when test="count($unique-catkey) mod 2 = 0">tablerow0</xsl:when>
  87. <xsl:otherwise>tablerow1</xsl:otherwise>
  88. </xsl:choose>
  89. </xsl:variable>
  90. <tr class="{$styleclass}">
  91. <td><b>Total</b></td>
  92. <td align="right"><b><xsl:value-of select="count(/BugCollection/BugInstance)"/></b></td>
  93. </tr>
  94. </table>
  95. <p><br/><br/></p>
  96. <h1>Warnings</h1>
  97. <p>Click on each warning link to see a full description of the issue, and
  98. details of how to resolve it.</p>
  99. <xsl:for-each select="$unique-catkey">
  100. <xsl:sort select="." order="ascending"/>
  101. <xsl:variable name="catkey" select="."/>
  102. <xsl:variable name="catdesc" select="/BugCollection/BugCategory[@category=$catkey]/Description"/>
  103. <xsl:call-template name="generateWarningTable">
  104. <xsl:with-param name="warningSet" select="/BugCollection/BugInstance[@category=$catkey]"/>
  105. <xsl:with-param name="sectionTitle"><xsl:value-of select="$catdesc"/> Warnings</xsl:with-param>
  106. <xsl:with-param name="sectionId">Warnings_<xsl:value-of select="$catkey"/></xsl:with-param>
  107. </xsl:call-template>
  108. </xsl:for-each>
  109. <p><br/><br/></p>
  110. <h1><a name="Details">Warning Types</a></h1>
  111. <xsl:apply-templates select="/BugCollection/BugPattern">
  112. <xsl:sort select="@abbrev"/>
  113. <xsl:sort select="ShortDescription"/>
  114. </xsl:apply-templates>
  115. </body>
  116. </html>
  117. </xsl:template>
  118. <xsl:template match="BugInstance">
  119. <xsl:variable name="warningId"><xsl:value-of select="generate-id()"/></xsl:variable>
  120. <tr class="tablerow{position() mod 2}">
  121. <td width="20%" valign="top">
  122. <a href="#{@type}"><xsl:value-of select="ShortMessage"/></a>
  123. </td>
  124. <td width="10%" valign="top">
  125. <xsl:choose>
  126. <xsl:when test="@priority = 1">High</xsl:when>
  127. <xsl:when test="@priority = 2">Medium</xsl:when>
  128. <xsl:when test="@priority = 3">Low</xsl:when>
  129. <xsl:otherwise>Unknown</xsl:otherwise>
  130. </xsl:choose>
  131. </td>
  132. <td width="70%">
  133. <p><xsl:value-of select="LongMessage"/><br/><br/>
  134. <!-- add source filename and line number(s), if any -->
  135. <xsl:if test="SourceLine">
  136. <br/>In file <xsl:value-of select="SourceLine/@sourcefile"/>,
  137. <xsl:choose>
  138. <xsl:when test="SourceLine/@start = SourceLine/@end">
  139. line <xsl:value-of select="SourceLine/@start"/>
  140. </xsl:when>
  141. <xsl:otherwise>
  142. lines <xsl:value-of select="SourceLine/@start"/>
  143. to <xsl:value-of select="SourceLine/@end"/>
  144. </xsl:otherwise>
  145. </xsl:choose>
  146. </xsl:if>
  147. <xsl:for-each select="./*/Message">
  148. <br/><xsl:value-of select="text()"/>
  149. </xsl:for-each>
  150. </p>
  151. </td>
  152. </tr>
  153. </xsl:template>
  154. <xsl:template match="BugPattern">
  155. <h2><a name="{@type}"><xsl:value-of select="ShortDescription"/></a></h2>
  156. <xsl:value-of select="Details" disable-output-escaping="yes"/>
  157. <p><br/><br/></p>
  158. </xsl:template>
  159. <xsl:template name="generateWarningTable">
  160. <xsl:param name="warningSet"/>
  161. <xsl:param name="sectionTitle"/>
  162. <xsl:param name="sectionId"/>
  163. <h2><a name="{$sectionId}"><xsl:value-of select="$sectionTitle"/></a></h2>
  164. <table class="warningtable" width="100%" cellspacing="2" cellpadding="5">
  165. <xsl:copy-of select="$bugTableHeader"/>
  166. <xsl:choose>
  167. <xsl:when test="count($warningSet) &gt; 0">
  168. <xsl:apply-templates select="$warningSet">
  169. <xsl:sort select="@priority"/>
  170. <xsl:sort select="@abbrev"/>
  171. <xsl:sort select="Class/@classname"/>
  172. </xsl:apply-templates>
  173. </xsl:when>
  174. <xsl:otherwise>
  175. <tr><td colspan="2"><p><i>None</i></p></td></tr>
  176. </xsl:otherwise>
  177. </xsl:choose>
  178. </table>
  179. <p><br/><br/></p>
  180. </xsl:template>
  181. <xsl:template match="FindBugsSummary">
  182. <xsl:variable name="kloc" select="@total_size div 1000.0"/>
  183. <xsl:variable name="format" select="'#######0.00'"/>
  184. <p><xsl:value-of select="@total_size"/> lines of code analysed,
  185. in <xsl:value-of select="@total_classes"/> classes,
  186. in <xsl:value-of select="@num_packages"/> packages.</p>
  187. <table width="500" cellpadding="5" cellspacing="2">
  188. <tr class="tableheader">
  189. <th align="left">Metric</th>
  190. <th align="right">Total</th>
  191. <th align="right">Density*</th>
  192. </tr>
  193. <tr class="tablerow0">
  194. <td>High Priority Warnings</td>
  195. <td align="right"><xsl:value-of select="@priority_1"/></td>
  196. <td align="right"><xsl:value-of select="format-number(@priority_1 div $kloc, $format)"/></td>
  197. </tr>
  198. <tr class="tablerow1">
  199. <td>Medium Priority Warnings</td>
  200. <td align="right"><xsl:value-of select="@priority_2"/></td>
  201. <td align="right"><xsl:value-of select="format-number(@priority_2 div $kloc, $format)"/></td>
  202. </tr>
  203. <xsl:choose>
  204. <xsl:when test="@priority_3">
  205. <tr class="tablerow1">
  206. <td>Low Priority Warnings</td>
  207. <td align="right"><xsl:value-of select="@priority_3"/></td>
  208. <td align="right"><xsl:value-of select="format-number(@priority_3 div $kloc, $format)"/></td>
  209. </tr>
  210. <xsl:variable name="totalClass" select="tablerow0"/>
  211. </xsl:when>
  212. <xsl:otherwise>
  213. <xsl:variable name="totalClass" select="tablerow1"/>
  214. </xsl:otherwise>
  215. </xsl:choose>
  216. <tr class="$totalClass">
  217. <td><b>Total Warnings</b></td>
  218. <td align="right"><b><xsl:value-of select="@total_bugs"/></b></td>
  219. <td align="right"><b><xsl:value-of select="format-number(@total_bugs div $kloc, $format)"/></b></td>
  220. </tr>
  221. </table>
  222. <p><i>(* Defects per Thousand lines of non-commenting source statetements)</i></p>
  223. <p><br/><br/></p>
  224. </xsl:template>
  225. </xsl:stylesheet>