1<?xml version="1.0" encoding="UTF-8"?> 2 3<!-- 4 FindBugs - Find bugs in Java programs 5 Copyright (C) 2004,2005 University of Maryland 6 Copyright (C) 2005, Chris Nappin 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Lesser General Public 10 License as published by the Free Software Foundation; either 11 version 2.1 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Lesser General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21--> 22 23<!-- 24 A simple XSLT stylesheet to transform FindBugs XML results 25 annotated with messages into HTML. 26 27 If you want to experiment with modifying this stylesheet, 28 or write your own, you need to generate XML output from FindBugs 29 using a special option which lets it know to include 30 human-readable messages in the XML. Invoke the findbugs script 31 as follows: 32 33 findbugs -textui -xml:withMessages -project myProject.fb > results.xml 34 35 Then you can use your favorite XSLT implementation to transform 36 the XML output into HTML. (But don't use xsltproc. It generates well-nigh 37 unreadable output, and generates incorrect output for the 38 <script> element.) 39 40 Authors: 41 David Hovemeyer 42 Chris Nappin (summary table) 43--> 44 45<xsl:stylesheet 46 version="1.0" 47 xmlns="http://www.w3.org/1999/xhtml" 48 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 49 50<xsl:output 51 method="xml" 52 indent="yes" 53 omit-xml-declaration="yes" 54 standalone="yes" 55 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" 56 doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" 57 encoding="UTF-8"/> 58 59<xsl:variable name="literalNbsp">&nbsp;</xsl:variable> 60 61<!--xsl:key name="bug-category-key" match="/BugCollection/BugInstance" use="@category"/--> 62 63<xsl:variable name="bugTableHeader"> 64 <tr class="tableheader"> 65 <th align="left">Code</th> 66 <th align="left">Warning</th> 67 </tr> 68</xsl:variable> 69 70<xsl:template match="/"> 71 <html> 72 <head> 73 <title>FindBugs Report</title> 74 <style type="text/css"> 75 .tablerow0 { 76 background: #EEEEEE; 77 } 78 79 .tablerow1 { 80 background: white; 81 } 82 83 .detailrow0 { 84 background: #EEEEEE; 85 } 86 87 .detailrow1 { 88 background: white; 89 } 90 91 .tableheader { 92 background: #b9b9fe; 93 font-size: larger; 94 } 95 96 .tablerow0:hover, .tablerow1:hover { 97 background: #aaffaa; 98 } 99 100 .priority-1 { 101 color: red; 102 font-weight: bold; 103 } 104 .priority-2 { 105 color: orange; 106 font-weight: bold; 107 } 108 .priority-3 { 109 color: green; 110 font-weight: bold; 111 } 112 .priority-4 { 113 color: blue; 114 font-weight: bold; 115 } 116 </style> 117 <script type="text/javascript"> 118 function toggleRow(elid) { 119 if (document.getElementById) { 120 element = document.getElementById(elid); 121 if (element) { 122 if (element.style.display == 'none') { 123 element.style.display = 'block'; 124 //window.status = 'Toggle on!'; 125 } else { 126 element.style.display = 'none'; 127 //window.status = 'Toggle off!'; 128 } 129 } 130 } 131 } 132 </script> 133 </head> 134 135 <xsl:variable name="unique-catkey" select="/BugCollection/BugCategory/@category"/> 136 <!--xsl:variable name="unique-catkey" select="/BugCollection/BugInstance[generate-id() = generate-id(key('bug-category-key',@category))]/@category"/--> 137 138 <body> 139 140 <h1><a href="http://findbugs.sourceforge.net">FindBugs</a> Report</h1> 141 142 <h2>Project Information</h2> 143 <xsl:apply-templates select="/BugCollection/Project"/> 144 145 <h2>Metrics</h2> 146 <xsl:apply-templates select="/BugCollection/FindBugsSummary"/> 147 148 <h2>Contents</h2> 149 <ul> 150 <xsl:for-each select="$unique-catkey"> 151 <xsl:sort select="." order="ascending"/> 152 <xsl:variable name="catkey" select="."/> 153 <xsl:variable name="catdesc" select="/BugCollection/BugCategory[@category=$catkey]/Description"/> 154 155 <li><a href="#Warnings_{$catkey}"><xsl:value-of select="$catdesc"/> Warnings</a></li> 156 </xsl:for-each> 157 158 <li><a href="#Details">Details</a></li> 159 </ul> 160 161 <h1>Summary</h1> 162 <table width="500" cellpadding="5" cellspacing="2"> 163 <tr class="tableheader"> 164 <th align="left">Warning Type</th> 165 <th align="right">Number</th> 166 </tr> 167 168 <xsl:for-each select="$unique-catkey"> 169 <xsl:sort select="." order="ascending"/> 170 <xsl:variable name="catkey" select="."/> 171 <xsl:variable name="catdesc" select="/BugCollection/BugCategory[@category=$catkey]/Description"/> 172 <xsl:variable name="styleclass"> 173 <xsl:choose><xsl:when test="position() mod 2 = 1">tablerow0</xsl:when> 174 <xsl:otherwise>tablerow1</xsl:otherwise> 175 </xsl:choose> 176 </xsl:variable> 177 178 <tr class="{$styleclass}"> 179 <td><a href="#Warnings_{$catkey}"><xsl:value-of select="$catdesc"/> Warnings</a></td> 180 <td align="right"><xsl:value-of select="count(/BugCollection/BugInstance[(@category=$catkey) and not(@last)])"/></td> 181 </tr> 182 </xsl:for-each> 183 184 <xsl:variable name="styleclass"> 185 <xsl:choose><xsl:when test="count($unique-catkey) mod 2 = 0">tablerow0</xsl:when> 186 <xsl:otherwise>tablerow1</xsl:otherwise> 187 </xsl:choose> 188 </xsl:variable> 189 <tr class="{$styleclass}"> 190 <td><b>Total</b></td> 191 <td align="right"><b><xsl:value-of select="count(/BugCollection/BugInstance[not(@last)])"/></b></td> 192 </tr> 193 </table> 194 195 <h1>Warnings</h1> 196 197 <p>Click on a warning row to see full context information.</p> 198 199 <xsl:for-each select="$unique-catkey"> 200 <xsl:sort select="." order="ascending"/> 201 <xsl:variable name="catkey" select="."/> 202 <xsl:variable name="catdesc" select="/BugCollection/BugCategory[@category=$catkey]/Description"/> 203 204 <xsl:call-template name="generateWarningTable"> 205 <xsl:with-param name="warningSet" select="/BugCollection/BugInstance[(@category=$catkey) and not(@last)]"/> 206 <xsl:with-param name="sectionTitle"><xsl:value-of select="$catdesc"/> Warnings</xsl:with-param> 207 <xsl:with-param name="sectionId">Warnings_<xsl:value-of select="$catkey"/></xsl:with-param> 208 </xsl:call-template> 209 </xsl:for-each> 210 211 <h1><a name="Details">Details</a></h1> 212 213 <xsl:apply-templates select="/BugCollection/BugPattern"> 214 <xsl:sort select="@abbrev"/> 215 <xsl:sort select="ShortDescription"/> 216 </xsl:apply-templates> 217 218 </body> 219 </html> 220</xsl:template> 221 222<xsl:template match="Project"> 223 <p>Project: 224 <xsl:choose> 225 <xsl:when test='string-length(/BugCollection/Project/@projectName)>0'><xsl:value-of select="/BugCollection/Project/@projectName" /></xsl:when> 226 <xsl:otherwise><xsl:value-of select="/BugCollection/Project/@filename" /></xsl:otherwise> 227 </xsl:choose> 228 </p> 229 <p>FindBugs version: <xsl:value-of select="/BugCollection/@version"/></p> 230 231 <p>Code analyzed:</p> 232 <ul> 233 <xsl:for-each select="./Jar"> 234 <li><xsl:value-of select="text()"/></li> 235 </xsl:for-each> 236 </ul> 237 <p><br/><br/></p> 238</xsl:template> 239 240<xsl:template match="BugInstance[not(@last)]"> 241 <xsl:variable name="warningId"><xsl:value-of select="generate-id()"/></xsl:variable> 242 243 <tr class="tablerow{position() mod 2}" onclick="toggleRow('{$warningId}');"> 244 245 <td> 246 <span><xsl:attribute name="class">priority-<xsl:value-of select="@priority"/></xsl:attribute> 247 <xsl:value-of select="@abbrev"/> 248 </span> 249 </td> 250 251 <td> 252 <xsl:value-of select="LongMessage"/> 253 </td> 254 255 </tr> 256 257 <!-- Add bug annotation elements: Class, Method, Field, SourceLine, Field --> 258 <tr class="detailrow{position() mod 2}"> 259 <td/> 260 <td> 261 <p id="{$warningId}" style="display: none;"> 262 <a href="#{@type}">Bug type <xsl:value-of select="@type"/> (click for details)</a> 263 <xsl:for-each select="./*/Message"> 264 <br/><xsl:value-of select="text()" disable-output-escaping="no"/> 265 </xsl:for-each> 266 </p> 267 </td> 268 </tr> 269</xsl:template> 270 271<xsl:template match="BugPattern"> 272 <h2><a name="{@type}"><xsl:value-of select="@type"/>: <xsl:value-of select="ShortDescription"/></a></h2> 273 <xsl:value-of select="Details" disable-output-escaping="yes"/> 274</xsl:template> 275 276<xsl:template name="generateWarningTable"> 277 <xsl:param name="warningSet"/> 278 <xsl:param name="sectionTitle"/> 279 <xsl:param name="sectionId"/> 280 281 <h2><a name="{$sectionId}"><xsl:value-of select="$sectionTitle"/></a></h2> 282 <table class="warningtable" width="100%" cellspacing="0"> 283 <xsl:copy-of select="$bugTableHeader"/> 284 <xsl:apply-templates select="$warningSet"> 285 <xsl:sort select="@abbrev"/> 286 <xsl:sort select="Class/@classname"/> 287 </xsl:apply-templates> 288 </table> 289</xsl:template> 290 291<xsl:template match="FindBugsSummary"> 292 <xsl:variable name="kloc" select="@total_size div 1000.0"/> 293 <xsl:variable name="format" select="'#######0.00'"/> 294 295 <p><xsl:value-of select="@total_size"/> lines of code analyzed, 296 in <xsl:value-of select="@total_classes"/> classes, 297 in <xsl:value-of select="@num_packages"/> packages.</p> 298 <table width="500" cellpadding="5" cellspacing="2"> 299 <tr class="tableheader"> 300 <th align="left">Metric</th> 301 <th align="right">Total</th> 302 <th align="right">Density*</th> 303 </tr> 304 <tr class="tablerow0"> 305 <td>High Priority Warnings</td> 306 <td align="right"><xsl:value-of select="@priority_1"/></td> 307 <td align="right"> 308 <xsl:choose> 309 <xsl:when test= "number($kloc) > 0.0 and number(@priority_1) > 0.0"> 310 <xsl:value-of select="format-number(@priority_1 div $kloc, $format)"/> 311 </xsl:when> 312 <xsl:otherwise> 313 <xsl:value-of select="format-number(0.0, $format)"/> 314 </xsl:otherwise> 315 </xsl:choose> 316 </td> 317 </tr> 318 <tr class="tablerow1"> 319 <td>Medium Priority Warnings</td> 320 <td align="right"><xsl:value-of select="@priority_2"/></td> 321 <td align="right"> 322 <xsl:choose> 323 <xsl:when test= "number($kloc) > 0.0 and number(@priority_2) > 0.0"> 324 <xsl:value-of select="format-number(@priority_2 div $kloc, $format)"/> 325 </xsl:when> 326 <xsl:otherwise> 327 <xsl:value-of select="format-number(0.0, $format)"/> 328 </xsl:otherwise> 329 </xsl:choose> 330 </td> 331 </tr> 332 333 <xsl:choose> 334 <xsl:when test="@priority_3"> 335 <tr class="tablerow1"> 336 <td>Low Priority Warnings</td> 337 <td align="right"><xsl:value-of select="@priority_3"/></td> 338 <td align="right"> 339 <xsl:choose> 340 <xsl:when test= "number($kloc) > 0.0 and number(@priority_3) > 0.0"> 341 <xsl:value-of select="format-number(@priority_3 div $kloc, $format)"/> 342 </xsl:when> 343 <xsl:otherwise> 344 <xsl:value-of select="format-number(0.0, $format)"/> 345 </xsl:otherwise> 346 </xsl:choose> 347 </td> 348 </tr> 349 <xsl:variable name="totalClass" select="tablerow0"/> 350 </xsl:when> 351 <xsl:otherwise> 352 <xsl:variable name="totalClass" select="tablerow1"/> 353 </xsl:otherwise> 354 </xsl:choose> 355 356 <tr class="$totalClass"> 357 <td><b>Total Warnings</b></td> 358 <td align="right"><b><xsl:value-of select="@total_bugs"/></b></td> 359 <xsl:choose> 360 <xsl:when test="number($kloc) > 0.0"> 361 <td align="right"><b><xsl:value-of select="format-number(@total_bugs div $kloc, $format)"/></b></td> 362 </xsl:when> 363 <xsl:otherwise> 364 <td align="right"><b><xsl:value-of select="format-number(0.0, $format)"/></b></td> 365 </xsl:otherwise> 366 </xsl:choose> 367 </tr> 368 </table> 369 <p><i>(* Defects per Thousand lines of non-commenting source statements)</i></p> 370 <p><br/><br/></p> 371 372</xsl:template> 373 374</xsl:stylesheet> 375 376<!-- vim:set ts=4: --> 377