forked from yeshodha02/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpmd.xsl
More file actions
275 lines (238 loc) · 8.31 KB
/
pmd.xsl
File metadata and controls
275 lines (238 loc) · 8.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
<xsl:decimal-format decimal-separator="." grouping-separator="," />
<!-- keys for violations list -->
<xsl:key name="violations" match="violation" use="@rule" />
<!-- XSL for PMD report. Author : Seshagiri Sriram. -->
<!-- Inspired by Checkstyle -->
<xsl:template name="timestamp">
<!--** Timestamp processing to display date -->
<xsl:value-of select="substring-before(//pmd/@timestamp, 'T')"/> - <xsl:value-of select="substring-before(substring-after(//pmd/@timestamp, 'T'), '.')"/>
</xsl:template>
<xsl:template match="pmd">
<!--** Process root node pmd : html header, style, call templates -->
<html>
<head>
<title>PMD <xsl:value-of select="//pmd/@version"/> Report: Demo Utilities</title>
<style type="text/css">
.bannercell {
border: 0px;
padding: 0px;
}
body {
margin-left: 10px;
margin-right: 10px;
font:normal 80% arial,helvetica,sanserif;
background-color:#FFFFFF;
color:#000000;
}
.a td {
background: #efefef;
}
.b td {
background: #fff;
}
th, td {
text-align: left;
vertical-align: top;
}
th {
font-weight:bold;
background: #ccc;
color: black;
}
table, th, td {
font-size:100%;
border: none
}
table.log tr td, tr th {
}
h2 {
font-weight:bold;
font-size:140%;
margin-bottom: 5;
}
h3 {
font-size:100%;
font-weight:bold;
background: #525D76;
color: white;
text-decoration: none;
padding: 5px;
margin-right: 2px;
margin-left: 2px;
margin-bottom: 0px;
}
.p1 { background:#FF9999; }
.p2 { background:#FFCC66; }
.p3 { background:#FFFF99; }
.p4 { background:#99FF99; }
.p5 { background:#a6caf0; }
</style>
</head>
<body>
<a name="top"></a>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="bannercell" rowspan="2">
</td>
<td class="text-align:right"><h2>PMD <xsl:value-of select="//pmd/@version"/> Report: Addressbook Web Application. Generated on <xsl:call-template name="timestamp"/></h2></td>
</tr>
</table>
<hr size="1"/>
<!-- Summary part -->
<xsl:apply-templates select="." mode="summary"/>
<hr size="1" width="100%" align="left"/>
<!-- Rules part -->
<xsl:apply-templates select="." mode="rulelist"/>
<hr size="1" width="100%" align="left"/>
<!-- Package List part -->
<xsl:apply-templates select="." mode="filelist"/>
<hr size="1" width="100%" align="left"/>
<!-- For each file create its part -->
<xsl:apply-templates select="file" />
<hr size="1" width="100%" align="left"/>
</body>
</html>
</xsl:template>
<xsl:template match="pmd" mode="rulelist">
<!--** Process root node pmd, for mode 'rulelist' : violated rules -->
<h3>Rules</h3>
<table class="log" border="0" cellpadding="5" cellspacing="2"
width="100%">
<tr>
<th style="width:84%">Rule</th>
<th style="width:8%">Violations</th>
<th style="width:8%">Severity</th>
</tr>
<xsl:for-each
select="file/violation[@rule and generate-id(.) = generate-id(key('violations', @rule))]">
<!-- Sort by number of violations -->
<xsl:sort data-type="number" order="descending"
select="count(key('violations', @rule))" />
<xsl:variable name="currentRule" select="@rule" />
<xsl:variable name="currentSeverity" select="@priority" />
<xsl:variable name="violationCount"
select="count(../../file/violation[@rule=$currentRule])" />
<tr>
<xsl:call-template name="alternated-row" />
<td>
[<xsl:value-of select="@ruleset" />] <xsl:value-of select="$currentRule" />
</td>
<td>
<xsl:value-of select="$violationCount" />
</td>
<td><div class="p{$currentSeverity}">
<xsl:text> </xsl:text>
<xsl:value-of select="$currentSeverity" /></div>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="pmd" mode="filelist">
<!--** Process root node pmd, for mode 'filelist' : number of violations for each file -->
<h3>Files</h3>
<table class="log" border="0" cellpadding="5" cellspacing="2"
width="100%">
<tr>
<th>File</th>
<th style="width:40px"><div class="p5">5</div></th>
<th style="width:40px"><div class="p4">4</div></th>
<th style="width:40px"><div class="p3">3</div></th>
<th style="width:40px"><div class="p2">2</div></th>
<th style="width:40px"><div class="p1">1</div></th>
</tr>
<xsl:for-each
select="file">
<!-- Sort by number of violations -->
<xsl:sort data-type="number" order="descending"
select="count(violation)" />
<xsl:variable name="currentSource" select="@name" />
<tr>
<xsl:call-template name="alternated-row" />
<td>
<xsl:variable name="anchor" select="translate(@name, '\/', '__')"></xsl:variable>
<a href="#f-{$anchor}"><xsl:value-of select="@name" /></a>
</td>
<td><xsl:value-of select="count(violation[@priority = 5])" /></td>
<td><xsl:value-of select="count(violation[@priority = 4])" /></td>
<td><xsl:value-of select="count(violation[@priority = 3])" /></td>
<td><xsl:value-of select="count(violation[@priority = 2])" /></td>
<td><xsl:value-of select="count(violation[@priority = 1])" /></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="file">
<!--** Process node 'file' : violations details -->
<xsl:variable name="anchor" select="translate(@name, '\/', '__')"></xsl:variable>
<a name="f-{$anchor}"></a>
<h3>File <xsl:value-of select="@name" /></h3>
<table class="log" border="0" cellpadding="5" cellspacing="2"
width="100%">
<tr>
<th style="width:60px;">Violation</th>
<th>Error Description</th>
<th style="width:40px;">Line</th>
</tr>
<xsl:for-each select="violation">
<xsl:variable name="currentSeverity" select="@priority" />
<tr>
<xsl:call-template name="alternated-row" />
<td><div class="p{$currentSeverity}"><xsl:value-of select="$currentSeverity"/>
</div>
</td>
<td>
[<xsl:value-of select="@ruleset" />.<xsl:value-of select="@rule" />]
-
<xsl:choose>
<xsl:when test="@externalInfoUrl">
<a href="{@externalInfoUrl}"><xsl:value-of select="." disable-output-escaping="yes" /></a>
</xsl:when>
<xsl:otherwise><xsl:value-of select="." disable-output-escaping="yes" /></xsl:otherwise>
</xsl:choose>
</td>
<td>
<xsl:value-of select="@beginline" /> - <xsl:value-of select="@endline"/>
</td>
</tr>
</xsl:for-each>
</table>
<a href="#top">Back to top</a>
</xsl:template>
<xsl:template match="pmd" mode="summary">
<!--** Process root node 'pmd', for mode 'summary' : number of files, number of violations by severity -->
<h3>Summary</h3>
<table class="log" border="0" cellpadding="5" cellspacing="2"
width="100%">
<tr>
<th style="width:25%">Files</th>
<th>Total</th>
<th><div class="p1">Priority 1: ShowStopper</div></th>
<th><div class="p2">Priority 2:Critical</div></th>
<th><div class="p3">Priority 3:Important/Urgent</div></th>
<th><div class="p4">Priority 4:Low - Change recommended</div></th>
<th><div class="p5">Priority 5:Low - Change Optional</div></th>
</tr>
<tr>
<xsl:call-template name="alternated-row" />
<td><xsl:value-of select="count(//file)"/></td>
<td><xsl:value-of select="count(//violation)"/></td>
<td><xsl:value-of select="count(//violation[@priority = 1])"/></td>
<td><xsl:value-of select="count(//violation[@priority = 2])"/></td>
<td><xsl:value-of select="count(//violation[@priority = 3])"/></td>
<td><xsl:value-of select="count(//violation[@priority = 4])"/></td>
<td><xsl:value-of select="count(//violation[@priority = 5])"/></td>
</tr>
</table>
</xsl:template>
<xsl:template name="alternated-row">
<!--** Template alternated-row, for alternated rows style in tables -->
<xsl:attribute name="class">
<xsl:if test="position() mod 2 = 1">a</xsl:if>
<xsl:if test="position() mod 2 = 0">b</xsl:if>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>