-
Notifications
You must be signed in to change notification settings - Fork 12
/
cpd2pmd.xslt
69 lines (63 loc) · 2.29 KB
/
cpd2pmd.xslt
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
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE xml>
<xsl:stylesheet version="2.0"
xmlns="http://pmd.sourceforge.net/report/2.0.0"
xmlns:pmd="http://pmd.sourceforge.net/report/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:zenta="http://magwas.rulez.org/zenta"
xmlns:zentatools="java:org.rulez.magwas.zentatools.XPathFunctions"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="pmd zenta zentatools">
<xsl:output method="xml" version="1.0" encoding="utf-8"
indent="yes" omit-xml-declaration="yes" />
<xsl:variable name="cpd"
select="document('target/cpd.xml')" />
<xsl:variable name="pmd"
select="document('target/pmd.xml')" />
<xsl:template match="/">
<pmd>
<xsl:namespace name=""
select="'http://pmd.sourceforge.net/report/2.0.0'" />
<xsl:copy-of select="/*/@*" />
<xsl:for-each
select="distinct-values($cpd//file/@path|$pmd//pmd:file/@name)">
<xsl:variable name="filename" select="." />
<file>
<xsl:attribute name="name" select="$filename" />
<xsl:copy-of
select="$pmd//pmd:file[@name=$filename]/pmd:violation" />
<xsl:for-each
select="$cpd//duplication[file/@path=$filename]">
<xsl:variable name="duplication" select="." />
<xsl:variable name="currentfile"
select="$duplication/file[@path=$filename][1]" />
<violation rule="Code Duplication" ruleset="Code Style"
begincolumn="1" endcolumn="40"
externalInfoUrl="https://en.wikipedia.org/wiki/Duplicate_code"
package="org.rulez.demokracia.pdengine" class="VoteRegistry"
method="setVoteParameters" variable="vote" priority="5">
<xsl:attribute name="beginline"
select="$currentfile/@line" />
<xsl:attribute name="endLine"
select="$currentfile/@line + $duplication/@lines" />
Code duplication (
<xsl:value-of select="$duplication/@lines" />
lines,
<xsl:value-of select="$duplication/@tokens" />
tokens):
<xsl:text>
</xsl:text>
<xsl:for-each select="$duplication/file">
<xsl:value-of
select="concat(@path,', line ',@line)" />
<xsl:text>
</xsl:text>
</xsl:for-each>
</violation>
</xsl:for-each>
</file>
</xsl:for-each>
<foo />
</pmd>
</xsl:template>
</xsl:stylesheet>