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 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 if ( !skip )
67 {
68 executeCheck( "pmd.xml", "violation", "PMD violation", failurePriority );
69 }
70 }
71
72
73 protected void printError( Map item, String severity )
74 {
75
76 StringBuffer buff = new StringBuffer( 100 );
77 buff.append( "PMD " + severity + ": " );
78 if ( item.containsKey( "class" ) )
79 {
80 if ( item.containsKey( "package" ) )
81 {
82 buff.append( item.get( "package" ) );
83 buff.append( "." );
84 }
85 buff.append( item.get( "class" ) );
86 }
87 else
88 {
89 buff.append( item.get( "filename" ) );
90 }
91 buff.append( ":" );
92 buff.append( item.get( "beginline" ) );
93 buff.append( " Rule:" ).append( item.get( "rule" ) );
94 buff.append( " Priority:" ).append( item.get( "priority" ) );
95 buff.append( " " ).append( item.get( "text" ) ).append( "." );
96
97 this.getLog().info( buff.toString() );
98 }
99
100
101 protected Map getErrorDetails( XmlPullParser xpp )
102 throws XmlPullParserException, IOException
103 {
104 int index = 0;
105 int attributeCount = 0;
106 HashMap msgs = new HashMap();
107
108 attributeCount = xpp.getAttributeCount();
109 while ( index < attributeCount )
110 {
111
112 msgs.put( xpp.getAttributeName( index ), xpp.getAttributeValue( index ) );
113
114 index++;
115 }
116
117
118 if ( xpp.next() == XmlPullParser.TEXT )
119 {
120 msgs.put( "text", xpp.getText().trim() );
121 }
122 return msgs;
123 }
124 }