Browse Source

Added findbugs ant task

git-svn-id: http://svn.dmdirc.com/trunk@1467 00569f92-eb28-0410-84fd-f71c24880f
tags/0.4
Gregory Holmes 17 years ago
parent
commit
780c9cd150
4 changed files with 285 additions and 3 deletions
  1. 15
    2
      checkstyle/build.xml
  2. 1
    1
      checkstyle/cpd.xslt
  3. 262
    0
      checkstyle/findbugs.xslt
  4. 7
    0
      checkstyle/index.html

+ 15
- 2
checkstyle/build.xml View File

@@ -2,7 +2,8 @@
2 2
 <project name="DMDirc" default="default" basedir=".">
3 3
     <description>Builds, tests, and runs the project DMDirc.</description>
4 4
     <import file="nbproject/build-impl.xml"/>    
5
-    <target name="checkstyle" depends="
5
+    <target name="checkstyle" depends=" 
6
+            findbugs, 
6 7
 	    cpd, 
7 8
             pmd,
8 9
 	    checkstyle-all, 
@@ -138,11 +139,23 @@
138 139
 
139 140
     <target name="cpd">
140 141
         <taskdef name="cpd" classpath="pmd-3.9.jar" classname="net.sourceforge.pmd.cpd.CPDTask" />
141
-	<cpd format="xml" minimumTokenCount="100" outputFile="reports/report-cpd.xml">
142
+	<cpd format="xml" minimumTokenCount="50" outputFile="reports/report-cpd.xml">
142 143
 		<fileset dir="src/">
143 144
 			<include name="**/*.java"/>
144 145
 		</fileset>
145 146
         </cpd>
146 147
 	<xslt in="reports/report-cpd.xml" style="checkstyle/cpd.xslt" out="reports/report-cpd.html" />
147 148
     </target>
149
+
150
+    <target name="findbugs">
151
+        <taskdef name="findbugs" classpath="findbugs-ant.jar"
152
+                classname="edu.umd.cs.findbugs.anttask.FindBugsTask" />
153
+        <findbugs home="checkstyle/findbugs/" effort="max"
154
+                output="xml:withMessages"
155
+                outputFile="reports/report-fb.xml" >
156
+            <sourcePath path="src/" />
157
+            <class location="dist/DMDirc.jar" />
158
+        </findbugs>
159
+        <xslt in="reports/report-fb.xml" style="checkstyle/findbugs.xslt" out="reports/report-fb.html" />
160
+    </target>
148 161
 </project>

+ 1
- 1
checkstyle/cpd.xslt View File

@@ -73,7 +73,7 @@
73 73
         				<button class="ExpandButton" ><xsl:attribute name="onclick">blur(); toggleCodeSection(this, 'frag_<xsl:value-of select="position()"/>')</xsl:attribute>+</button>
74 74
         			</td>
75 75
         			<td>
76
-        				<textarea cols="100" rows="30" wrap="off" class='CodeFragment' style='display:none;'>
76
+        				<textarea readonly="readonly" cols="100" rows="30" wrap="off" class='CodeFragment' style='display:none;' >
77 77
         					<xsl:attribute name="id">frag_<xsl:value-of select="position()"/></xsl:attribute>
78 78
         					<xsl:value-of select="codefragment"/>
79 79
         				</textarea>

+ 262
- 0
checkstyle/findbugs.xslt View File

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

+ 7
- 0
checkstyle/index.html View File

@@ -14,14 +14,21 @@
14 14
    <div id="content">
15 15
 
16 16
     <h1>DMDirc reports</h1>
17
+    <h2>Findbugs report</h2>
18
+    <ul>
19
+      <li><a href="report-fb.html" title="Findbugs report">Findbugs Report</a></li>
20
+    </ul>
21
+
17 22
     <h2>Copy and paste detection report</h2>
18 23
     <ul>
19 24
       <li><a href="report-cpd.html" title="CPD Report">CPD Report</a></li>
20 25
     </ul>
26
+
21 27
     <h2>PMD Report</h2>
22 28
     <ul>
23 29
       <li><a href="report-pmd.html" title="PMD Report">PMD Report</a></li>
24 30
     </ul>
31
+
25 32
     <h2>Checkstyle reports</h2>
26 33
     <ul>
27 34
       <li><a href="report-all.html" title="Whole project">Whole project</a></li>

Loading…
Cancel
Save