1 | |
package org.apache.maven.plugin.pmd; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.IOException; |
23 | |
import java.util.HashMap; |
24 | |
import java.util.Map; |
25 | |
|
26 | |
import org.apache.maven.plugin.MojoExecutionException; |
27 | |
import org.apache.maven.plugin.MojoFailureException; |
28 | |
import org.codehaus.plexus.util.xml.pull.XmlPullParser; |
29 | |
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 5 | public class PmdViolationCheckMojo |
41 | |
extends AbstractPmdViolationCheckMojo |
42 | |
{ |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
private int failurePriority; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
private boolean skip; |
61 | |
|
62 | |
|
63 | |
public void execute() |
64 | |
throws MojoExecutionException, MojoFailureException |
65 | |
{ |
66 | 3 | if ( !skip ) |
67 | |
{ |
68 | 3 | executeCheck( "pmd.xml", "violation", "PMD violation", failurePriority ); |
69 | |
} |
70 | 2 | } |
71 | |
|
72 | |
|
73 | |
protected void printError( Map item, String severity ) |
74 | |
{ |
75 | |
|
76 | 6 | StringBuffer buff = new StringBuffer( 100 ); |
77 | 6 | buff.append( "PMD " + severity + ": " ); |
78 | 6 | if ( item.containsKey( "class" ) ) |
79 | |
{ |
80 | 5 | if ( item.containsKey( "package" ) ) |
81 | |
{ |
82 | 5 | buff.append( item.get( "package" ) ); |
83 | 5 | buff.append( "." ); |
84 | |
} |
85 | 5 | buff.append( item.get( "class" ) ); |
86 | |
} |
87 | |
else |
88 | |
{ |
89 | 1 | buff.append( item.get( "filename" ) ); |
90 | |
} |
91 | 6 | buff.append( ":" ); |
92 | 6 | buff.append( item.get( "beginline" ) ); |
93 | 6 | buff.append( " Rule:" ).append( item.get( "rule" ) ); |
94 | 6 | buff.append( " Priority:" ).append( item.get( "priority" ) ); |
95 | 6 | buff.append( " " ).append( item.get( "text" ) ).append( "." ); |
96 | |
|
97 | 6 | this.getLog().info( buff.toString() ); |
98 | 6 | } |
99 | |
|
100 | |
|
101 | |
protected Map getErrorDetails( XmlPullParser xpp ) |
102 | |
throws XmlPullParserException, IOException |
103 | |
{ |
104 | 18 | int index = 0; |
105 | 18 | int attributeCount = 0; |
106 | 18 | HashMap msgs = new HashMap(); |
107 | |
|
108 | 18 | attributeCount = xpp.getAttributeCount(); |
109 | 207 | while ( index < attributeCount ) |
110 | |
{ |
111 | |
|
112 | 189 | msgs.put( xpp.getAttributeName( index ), xpp.getAttributeValue( index ) ); |
113 | |
|
114 | 189 | index++; |
115 | |
} |
116 | |
|
117 | |
|
118 | 18 | if ( xpp.next() == XmlPullParser.TEXT ) |
119 | |
{ |
120 | 18 | msgs.put( "text", xpp.getText().trim() ); |
121 | |
} |
122 | 18 | return msgs; |
123 | |
} |
124 | |
} |