Skip to content

Commit 71e615b

Browse files
committed
Dogfood pmd plugin
This commit applies pmd plugin and rules to p3c-pmd project and fixes two violations.
1 parent 7de6b48 commit 71e615b

File tree

3 files changed

+82
-37
lines changed

3 files changed

+82
-37
lines changed

p3c-pmd/pom.xml

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
<artifactId>oss-parent</artifactId>
77
<version>9</version>
88
</parent>
9-
<modelVersion>4.0.0</modelVersion>
9+
<modelVersion>4.0.0</modelVersion>
1010
<groupId>com.alibaba.p3c</groupId>
11-
<artifactId>p3c-pmd</artifactId>
11+
<artifactId>p3c-pmd</artifactId>
1212
<version>1.3.6</version>
13-
<packaging>jar</packaging>
14-
<name>p3c-pmd</name>
13+
<packaging>jar</packaging>
14+
<name>p3c-pmd</name>
1515
<properties>
16-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17-
<pmd.version>5.5.2</pmd.version>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<pmd.version>5.5.2</pmd.version>
1818
</properties>
1919

2020
<description>Alibaba Java Coding Guidelines PMD implementations</description>
@@ -72,35 +72,72 @@
7272
</developer>
7373
</developers>
7474

75-
<dependencies>
76-
<dependency>
77-
<groupId>net.sourceforge.pmd</groupId>
78-
<artifactId>pmd-java</artifactId>
79-
<version>${pmd.version}</version>
80-
</dependency>
81-
<dependency>
82-
<groupId>net.sourceforge.pmd</groupId>
83-
<artifactId>pmd-vm</artifactId>
84-
<version>${pmd.version}</version>
85-
</dependency>
86-
<dependency>
87-
<groupId>net.sourceforge.pmd</groupId>
88-
<artifactId>pmd-test</artifactId>
89-
<version>${pmd.version}</version>
90-
<scope>test</scope>
75+
<dependencies>
76+
<dependency>
77+
<groupId>net.sourceforge.pmd</groupId>
78+
<artifactId>pmd-java</artifactId>
79+
<version>${pmd.version}</version>
9180
</dependency>
92-
</dependencies>
93-
<build>
94-
<plugins>
95-
<plugin>
96-
<groupId>org.apache.maven.plugins</groupId>
97-
<artifactId>maven-compiler-plugin</artifactId>
98-
<version>3.3</version>
99-
<configuration>
100-
<source>1.7</source>
101-
<target>1.7</target>
102-
<encoding>UTF-8</encoding>
103-
</configuration>
81+
<dependency>
82+
<groupId>net.sourceforge.pmd</groupId>
83+
<artifactId>pmd-vm</artifactId>
84+
<version>${pmd.version}</version>
85+
</dependency>
86+
<dependency>
87+
<groupId>net.sourceforge.pmd</groupId>
88+
<artifactId>pmd-test</artifactId>
89+
<version>${pmd.version}</version>
90+
<scope>test</scope>
91+
</dependency>
92+
</dependencies>
93+
<build>
94+
<plugins>
95+
<plugin>
96+
<groupId>org.apache.maven.plugins</groupId>
97+
<artifactId>maven-pmd-plugin</artifactId>
98+
<version>3.8</version>
99+
<configuration>
100+
<sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
101+
<targetJdk>1.8</targetJdk>
102+
<printFailingErrors>true</printFailingErrors>
103+
<rulesets>
104+
<ruleset>rulesets/java/ali-comment.xml</ruleset>
105+
<ruleset>rulesets/java/ali-concurrent.xml</ruleset>
106+
<ruleset>rulesets/java/ali-constant.xml</ruleset>
107+
<ruleset>rulesets/java/ali-exception.xml</ruleset>
108+
<ruleset>rulesets/java/ali-flowcontrol.xml</ruleset>
109+
<ruleset>rulesets/java/ali-naming.xml</ruleset>
110+
<ruleset>rulesets/java/ali-oop.xml</ruleset>
111+
<ruleset>rulesets/java/ali-orm.xml</ruleset>
112+
<ruleset>rulesets/java/ali-other.xml</ruleset>
113+
<ruleset>rulesets/java/ali-set.xml</ruleset>
114+
</rulesets>
115+
</configuration>
116+
<executions>
117+
<execution>
118+
<phase>verify</phase>
119+
<goals>
120+
<goal>check</goal>
121+
</goals>
122+
</execution>
123+
</executions>
124+
<dependencies>
125+
<dependency>
126+
<groupId>com.alibaba.p3c</groupId>
127+
<artifactId>p3c-pmd</artifactId>
128+
<version>1.3.6</version>
129+
</dependency>
130+
</dependencies>
131+
</plugin>
132+
<plugin>
133+
<groupId>org.apache.maven.plugins</groupId>
134+
<artifactId>maven-compiler-plugin</artifactId>
135+
<version>3.3</version>
136+
<configuration>
137+
<source>1.7</source>
138+
<target>1.7</target>
139+
<encoding>UTF-8</encoding>
140+
</configuration>
104141
</plugin>
105142
<plugin>
106143
<groupId>org.apache.maven.plugins</groupId>
@@ -136,6 +173,6 @@
136173
</execution>
137174
</executions>
138175
</plugin>
139-
</plugins>
140-
</build>
176+
</plugins>
177+
</build>
141178
</project>

p3c-pmd/src/main/java/com/alibaba/p3c/pmd/fix/FixClassTypeResolver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ public FixClassTypeResolver(ClassLoader classLoader) {
157157

158158
// FUTURE ASTCompilationUnit should not be a TypeNode. Clean this up
159159
// accordingly.
160+
161+
/**
162+
* {@inheritDoc}
163+
*/
160164
@Override
161165
public Object visit(ASTCompilationUnit node, Object data) {
162166
String className = null;

p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/orm/IbatisMethodQueryForListRule.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private void visitPrimaryExpression(ASTPrimaryExpression node, Object data,
146146
}
147147
//method parameters not match
148148
List<Node> literals = node.findChildNodesWithXPath(PRIMARY_METHOD_ARGUMENT_XPATH);
149-
if (!(literals != null && (literals.size() == 3))) {
149+
if (!methodHasTreeParameters(literals)) {
150150
continue;
151151
}
152152
boolean firstMethodArgumentString = "java.lang.String".equals(
@@ -165,6 +165,10 @@ private void visitPrimaryExpression(ASTPrimaryExpression node, Object data,
165165
}
166166
}
167167

168+
private boolean methodHasTreeParameters(List<Node> argumentNodes) {
169+
return argumentNodes != null && argumentNodes.size() == 3;
170+
}
171+
168172
/**
169173
* if the attributes of a class defines the SqlMapClient object,collect these object name
170174
*/

0 commit comments

Comments
 (0)