1 <?xml version="1.0" encoding="UTF-8"?>
4 FindBugs - Find bugs in Java programs
5 Copyright (C) 2004,2005 University of Maryland
6 Copyright (C) 2005, Chris Nappin
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.
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.
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
24 A simple XSLT stylesheet to transform FindBugs XML results
25 annotated with messages into HTML.
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
33 findbugs -textui -xml:withMessages -project myProject.fb > results.xml
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
42 Chris Nappin (summary table)
47 xmlns="http://www.w3.org/1999/xhtml"
48 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
53 omit-xml-declaration="yes"
55 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
56 doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
59 <xsl:variable name="literalNbsp">&nbsp;</xsl:variable>
61 <!--xsl:key name="bug-category-key" match="/BugCollection/BugInstance" use="@category"/-->
63 <xsl:variable name="bugTableHeader">
64 <tr class="tableheader">
65 <th align="left">Code<xsl:value-of select="$literalNbsp"/></th>
66 <th align="left">Warning</th>
70 <xsl:template match="/">
73 <title>FindBugs Report</title>
74 <style type="text/css">
96 .tablerow0:hover, .tablerow1:hover {
117 <script type="text/javascript">
118 function toggleRow(elid) {
119 if (document.getElementById) {
120 element = document.getElementById(elid);
122 if (element.style.display == 'none') {
123 element.style.display = 'block';
124 //window.status = 'Toggle on!';
126 element.style.display = 'none';
127 //window.status = 'Toggle off!';
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"/-->
140 <h1><a href="http://findbugs.sourceforge.net">FindBugs</a> Report</h1>
142 <h2>Project Information</h2>
143 <xsl:apply-templates select="/BugCollection/Project"/>
146 <xsl:apply-templates select="/BugCollection/FindBugsSummary"/>
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"/>
155 <li><a href="#Warnings_{$catkey}"><xsl:value-of select="$catdesc"/> Warnings</a></li>
158 <li><a href="#Details">Details</a></li>
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>
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>
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])"/></td>
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>
189 <tr class="{$styleclass}">
190 <td><b>Total</b></td>
191 <td align="right"><b><xsl:value-of select="count(/BugCollection/BugInstance)"/></b></td>
197 <p>Click on a warning row to see full context information.</p>
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"/>
204 <xsl:call-template name="generateWarningTable">
205 <xsl:with-param name="warningSet" select="/BugCollection/BugInstance[@category=$catkey]"/>
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>
211 <h1><a name="Details">Details</a></h1>
213 <xsl:apply-templates select="/BugCollection/BugPattern">
214 <xsl:sort select="@abbrev"/>
215 <xsl:sort select="ShortDescription"/>
216 </xsl:apply-templates>
222 <xsl:template match="Project">
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>
229 <p>FindBugs version: <xsl:value-of select="/BugCollection/@version"/></p>
231 <p>Code analyzed:</p>
233 <xsl:for-each select="./Jar">
234 <li><xsl:value-of select="text()"/></li>
240 <xsl:template match="BugInstance">
241 <xsl:variable name="warningId"><xsl:value-of select="generate-id()"/></xsl:variable>
243 <tr class="tablerow{position() mod 2}" onclick="toggleRow('{$warningId}');">
246 <span><xsl:attribute name="class">priority-<xsl:value-of select="@priority"/></xsl:attribute>
247 <xsl:value-of select="@abbrev"/>
252 <xsl:value-of select="LongMessage"/>
257 <!-- Add bug annotation elements: Class, Method, Field, SourceLine, Field -->
258 <tr class="detailrow{position() mod 2}">
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"/>
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"/>
276 <xsl:template name="generateWarningTable">
277 <xsl:param name="warningSet"/>
278 <xsl:param name="sectionTitle"/>
279 <xsl:param name="sectionId"/>
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>
291 <xsl:template match="FindBugsSummary">
292 <xsl:variable name="kloc" select="@total_size div 1000.0"/>
293 <xsl:variable name="format" select="'#######0.00'"/>
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>
304 <tr class="tablerow0">
305 <td>High Priority Warnings</td>
306 <td align="right"><xsl:value-of select="@priority_1"/></td>
309 <xsl:when test= "number($kloc) > 0.0">
310 <xsl:value-of select="format-number(@priority_1 div $kloc, $format)"/>
313 <xsl:value-of select="format-number(0.0, $format)"/>
318 <tr class="tablerow1">
319 <td>Medium Priority Warnings</td>
320 <td align="right"><xsl:value-of select="@priority_2"/></td>
323 <xsl:when test= "number($kloc) > 0.0">
324 <xsl:value-of select="format-number(@priority_2 div $kloc, $format)"/>
327 <xsl:value-of select="format-number(0.0, $format)"/>
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>
340 <xsl:when test= "number($kloc) > 0.0">
341 <xsl:value-of select="format-number(@priority_3 div $kloc, $format)"/>
344 <xsl:value-of select="format-number(0.0, $format)"/>
349 <xsl:variable name="totalClass" select="tablerow0"/>
352 <xsl:variable name="totalClass" select="tablerow1"/>
356 <tr class="$totalClass">
357 <td><b>Total Warnings</b></td>
358 <td align="right"><b><xsl:value-of select="@total_bugs"/></b></td>
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>
364 <td align="right"><b><xsl:value-of select="format-number(0.0, $format)"/></b></td>
369 <p><i>(* Defects per Thousand lines of non-commenting source statements)</i></p>
376 <!-- vim:set ts=4: -->