PR: MPPMD-2
Submitted By: Joakim Erdfelt Reviewed By: Brett Porter PMD plugin cleanup. Rulesets are kept inside PMD jar, upgraded to v1.3. Clean documentation. git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@115459 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
d16ac60251
commit
9c7c08b449
21 files changed
+331
-2312
No files matched your search
@@ -27,7 +27,7 @@ maven.pmd.enable = true
|
||||
# comma seperated list of rules to use
|
||||
# rulesets/experimental.xml is, well, experimental ... use at your own risk
|
||||
|
||||
maven.pmd.rulesetfiles=${plugin.resources}/rulesets/basic.xml,${plugin.resources}/rulesets/unusedcode.xml,${plugin.resources}/rulesets/imports.xml
|
||||
maven.pmd.rulesetfiles=rulesets/basic.xml,rulesets/unusedcode.xml,rulesets/imports.xml
|
||||
|
||||
maven.pmd.includes = **/*.java
|
||||
maven.pmd.excludes =
|
||||
|
||||
+10
-2
@@ -23,7 +23,7 @@
|
||||
<pomVersion>3</pomVersion>
|
||||
<id>maven-pmd-plugin</id>
|
||||
<name>Maven PMD Plug-in</name>
|
||||
<currentVersion>1.4</currentVersion>
|
||||
<currentVersion>1.5-SNAPSHOT</currentVersion>
|
||||
<description>The Maven PMD plugin is a plugin that wraps the PMD framework (http://pmd.sourceforge.net). PMD is a source checking framework that works by scanning Java source code and looks for potential problems like: unused local variables, empty catch blocks, unused parameters, empty 'if' statements, etc.</description>
|
||||
<shortDescription>Maven Plugin for PMD</shortDescription>
|
||||
<url>http://maven.apache.org/reference/plugins/pmd/</url>
|
||||
@@ -90,11 +90,19 @@
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
<contributors>
|
||||
<contributor>
|
||||
<name>Joakim Erdfelt</name>
|
||||
<email>joakim@erdfelt.net</email>
|
||||
<organization>Solshen Inc</organization>
|
||||
<timezone>-5</timezone>
|
||||
</contributor>
|
||||
</contributors>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>pmd</groupId>
|
||||
<artifactId>pmd</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<version>1.3</version>
|
||||
<url>http://pmd.sourceforge.net</url>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -1,375 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
|
||||
<ruleset name="Basic Rules">
|
||||
<description>
|
||||
The Basic Ruleset contains a collection of good practices which everyone should follow.
|
||||
</description>
|
||||
|
||||
|
||||
<rule name="EmptyCatchBlock"
|
||||
message="Avoid empty catch blocks"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Empty Catch Block finds instances where an exception is caught,
|
||||
but nothing is done. In most circumstances, this swallows an exception
|
||||
which should either be acted on or reported.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//TryStatement[@Catch='true']/Block[position() > 1]
|
||||
[count(*) = 0]
|
||||
[../@Finally='false' or following-sibling::Block]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public void doSomething() {
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream("/tmp/bugger");
|
||||
} catch (IOException ioe) {
|
||||
// not good
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="EmptyIfStmt"
|
||||
message="Avoid empty 'if' statements"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Empty If Statement finds instances where a condition is checked but nothing is done about it.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfStatement/Statement/Block[count(*) = 0]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
if (absValue < 1) {
|
||||
// not good
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="EmptyWhileStmt"
|
||||
message="Avoid empty 'while' statements"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Empty While Statement finds all instances where a while statement
|
||||
does nothing. If it is a timing loop, then you should use Thread.sleep() for it; if
|
||||
it's a while loop that does a lot in the exit expression, rewrite it to make it clearer.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//WhileStatement/Statement/Block[count(*) = 0]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
while (a == b) {
|
||||
// not good
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="EmptyTryBlock"
|
||||
message="Avoid empty try blocks"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid empty try blocks - what's the point?
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//TryStatement/Block[1][count(*) = 0]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
// this is bad
|
||||
public void bar() {
|
||||
try {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="EmptyFinallyBlock"
|
||||
message="Avoid empty finally blocks"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid empty finally blocks - these can be deleted.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//TryStatement[@Finally='true']/Block[position() = last()][count(*) = 0]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
// this is bad
|
||||
public void bar() {
|
||||
try {
|
||||
int x=2;
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="EmptySwitchStatements"
|
||||
message="Avoid empty switch statements"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid empty switch statements.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//SwitchStatement[count(*) = 1]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
int x = 2;
|
||||
switch (x) {
|
||||
// once there was code here
|
||||
// but it's been commented out or something
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="JumbledIncrementer"
|
||||
message="Avoid using an outer loop incrementer in an inner loop for update expression"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid jumbled loop incrementers - it's usually a mistake, and it's confusing even if it's what's intended.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ForStatement[ForUpdate//Name/@Image = ancestor::ForStatement/ForInit//VariableDeclaratorId/@Image]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class JumbledIncrementerRule1 {
|
||||
public void foo() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int k = 0; k < 20; i++) {
|
||||
System.out.println("Hello");
|
||||
}
|
||||
}
|
||||
}
|
||||
}}]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="ForLoopShouldBeWhileLoop"
|
||||
message="This for loop could be simplified to a while loop"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Some for loops can be simplified to while loops - this makes them more concise.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ForStatement[count(*) > 1][not(ForInit)][not(ForUpdate)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
void bar() {
|
||||
for (;true;) true; // No Init or Update part, may as well be: while (true)
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="UnnecessaryConversionTemporaryRule"
|
||||
message="Avoid unnecessary temporaries when converting primitives to Strings"
|
||||
class="net.sourceforge.pmd.rules.UnnecessaryConversionTemporaryRule">
|
||||
<description>
|
||||
Avoid unnecessary temporaries when converting primitives to Strings
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public String convert(int x) {
|
||||
// this wastes an object
|
||||
String foo = new Integer(x).toString();
|
||||
// this is better
|
||||
return Integer.toString(x);
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="OverrideBothEqualsAndHashcodeRule"
|
||||
message="Ensure you override both equals() and hashCode()"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither. Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassDeclaration//MethodDeclarator
|
||||
[
|
||||
(@Image = 'equals'
|
||||
and count(FormalParameters/*) = 1
|
||||
and not(//MethodDeclarator[count(FormalParameters/*) = 0][@Image = 'hashCode'])
|
||||
or
|
||||
(@Image='hashCode'
|
||||
and count(FormalParameters/*) = 0
|
||||
and not(//MethodDeclarator[count(FormalParameters//Type/Name[@Image = 'Object']) = 1][@Image = 'equals']))
|
||||
)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
// this is bad
|
||||
public class Bar {
|
||||
public boolean equals(Object o) {
|
||||
// do some comparison
|
||||
}
|
||||
}
|
||||
|
||||
// and so is this
|
||||
public class Baz {
|
||||
public int hashCode() {
|
||||
// return some hash value
|
||||
}
|
||||
}
|
||||
|
||||
// this is OK
|
||||
public class Foo {
|
||||
public boolean equals(Object other) {
|
||||
// do some comparison
|
||||
}
|
||||
public int hashCode() {
|
||||
// return some hash value
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="DoubleCheckedLockingRule"
|
||||
message="Double checked locking is not thread safe in Java."
|
||||
class="net.sourceforge.pmd.rules.DoubleCheckedLockingRule">
|
||||
<description>
|
||||
Partially created objects can be returned by the Double Checked Locking pattern when used in Java.
|
||||
An optimizing JRE may assign a reference to the baz variable before it creates the object the
|
||||
reference is intended to point to. For more details see http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html.
|
||||
</description>
|
||||
<priority>1</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
Object baz;
|
||||
Object bar() {
|
||||
if(baz == null) { //baz may be non-null yet not fully created
|
||||
synchronized(this){
|
||||
if(baz == null){
|
||||
baz = new Object();
|
||||
}
|
||||
}
|
||||
}
|
||||
return baz;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
|
||||
<ruleset name="Braces Rules">
|
||||
<description>
|
||||
The Braces Ruleset contains a collection of braces rules.
|
||||
</description>
|
||||
|
||||
<rule name="IfStmtsMustUseBraces"
|
||||
message="Avoid using if statements without curly braces"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid using if statements without using curly braces
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfStatement[count(*) < 3][not(Statement/Block)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
int x = 0;
|
||||
if (foo) x++;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="WhileLoopsMustUseBracesRule"
|
||||
message="Avoid using 'while' statements without curly braces"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid using 'while' statements without using curly braces
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//WhileStatement[not(Statement/Block)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public void doSomething() {
|
||||
while (true)
|
||||
x++;
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="IfElseStmtsMustUseBracesRule"
|
||||
message="Avoid using 'if...else' statements without curly braces"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid using if..else statements without using curly braces
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfStatement[count(*) > 2][not(Statement/Block)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
|
||||
public void doSomething() {
|
||||
// this is OK
|
||||
if (foo) x++;
|
||||
|
||||
// but this is not
|
||||
if (foo)
|
||||
x=x+1;
|
||||
else
|
||||
x=x-1;
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ForLoopsMustUseBracesRule"
|
||||
message="Avoid using 'for' statements without curly braces"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid using 'for' statements without using curly braces
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ForStatement[not(Statement/Block)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public void foo() {
|
||||
for (int i=0; i<42;i++)
|
||||
foo();
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@@ -1,255 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
|
||||
<ruleset name="Code Size Rules">
|
||||
<description>
|
||||
The Code Size Ruleset contains a collection of rules that find code size related problems.
|
||||
</description>
|
||||
|
||||
|
||||
<rule name="ExcessiveMethodLength"
|
||||
message="Avoid really long methods."
|
||||
class="net.sourceforge.pmd.rules.design.LongMethodRule">
|
||||
<description>
|
||||
Excessive Method Length usually means that the method is doing
|
||||
too much. There is usually quite a bit of Cut and Paste there
|
||||
as well. Try to reduce the method size by creating helper methods,
|
||||
and removing cut and paste.
|
||||
|
||||
Default value is 2.5 sigma greater than the mean.
|
||||
|
||||
NOTE: In version 0.9 and higher, their are three parameters available:
|
||||
minimum - Minimum Length before reporting.
|
||||
sigma - Std Deviations away from the mean before reporting.
|
||||
topscore - The Maximum Number of reports to generate.
|
||||
|
||||
At this time, only one can be used at a time.
|
||||
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimum" value="100"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public void doSomething() {
|
||||
System.out.println("I am a fish.");
|
||||
System.out.println("I am a fish.");
|
||||
System.out.println("I am a fish.");
|
||||
System.out.println("I am a fish.");
|
||||
System.out.println("I am a fish.");
|
||||
// 495 copies omitted for brevity.
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="ExcessiveParameterList"
|
||||
message="Avoid really long parameter lists."
|
||||
class="net.sourceforge.pmd.rules.design.LongParameterListRule">
|
||||
<description>
|
||||
This checks to make sure that the Parameter Lists in the project aren't
|
||||
getting too long. If there are long parameter lists, then that is
|
||||
generally indicative that another object is hiding around there.
|
||||
|
||||
Basically, try to group the parameters together.
|
||||
|
||||
Default value is 2.5 sigma greater than the mean.
|
||||
|
||||
NOTE: In version 0.9 and higher, their are three parameters available:
|
||||
minimum - Minimum Length before reporting.
|
||||
sigma - Std Deviations away from the mean before reporting.
|
||||
topscore - The Maximum Number of reports to generate.
|
||||
|
||||
At this time, only one can be used at a time.
|
||||
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimum" value="10"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public void addData(
|
||||
int p00, int p01, int p02, int p03, int p04, int p05,
|
||||
int p05, int p06, int p07, int p08, int p09, int p10) {
|
||||
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="ExcessiveClassLength"
|
||||
message="Avoid really long Classes."
|
||||
class="net.sourceforge.pmd.rules.design.LongClassRule">
|
||||
<description>
|
||||
Long Class files are indications that the class may be trying to
|
||||
do too much. Try to break it down, and reduce the size to something
|
||||
managable.
|
||||
|
||||
Default value is 2.5 sigma greater than the mean.
|
||||
|
||||
NOTE: In version 0.9 and higher, their are three parameters available:
|
||||
minimum - Minimum Length before reporting.
|
||||
sigma - Std Deviations away from the mean before reporting.
|
||||
topscore - The Maximum Number of reports to generate.
|
||||
|
||||
At this time, only one can be used at a time.
|
||||
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimum" value="1000"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
// 500 lines of code
|
||||
}
|
||||
|
||||
public void baz() {
|
||||
// 500 more lines of code
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="CyclomaticComplexityRule"
|
||||
message = "The {0} ''{1}'' has a Cyclomatic Complexity of {2}."
|
||||
class="net.sourceforge.pmd.rules.CyclomaticComplexityRule">
|
||||
<description>
|
||||
Complexity is determined by the number of decision points in a method plus one for the
|
||||
method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Scale:
|
||||
1-4 (low complexity) 5-7 (moderate complexity) 8-10 (high complexity) 10+ (very high complexity)
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="reportLevel" value="10"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
Cyclomatic Complexity = 12
|
||||
|
||||
public class Foo
|
||||
{
|
||||
1 public void example()
|
||||
{
|
||||
2 if (a == b)
|
||||
{
|
||||
3 if (a1 == b1)
|
||||
{
|
||||
do something;
|
||||
}
|
||||
4 else if a2 == b2)
|
||||
{
|
||||
do something;
|
||||
}
|
||||
else
|
||||
{
|
||||
do something;
|
||||
}
|
||||
}
|
||||
5 else if (c == d)
|
||||
{
|
||||
6 while (c == d)
|
||||
{
|
||||
do something;
|
||||
}
|
||||
}
|
||||
7 else if (e == f)
|
||||
{
|
||||
8 for (int n = 0; n < h; n++)
|
||||
{
|
||||
do something;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (z)
|
||||
{
|
||||
9 case 1:
|
||||
do something;
|
||||
break;
|
||||
|
||||
10 case 2:
|
||||
do something;
|
||||
break;
|
||||
|
||||
11 case 3:
|
||||
do something;
|
||||
break;
|
||||
|
||||
12 default:
|
||||
do something;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ExcessivePublicCountRule"
|
||||
message="A high number of public methods and attributes in an object can indicate the class may need to be broken up for exhaustive testing may prove difficult."
|
||||
class="net.sourceforge.pmd.rules.ExcessivePublicCountRule">
|
||||
<description>
|
||||
A large amount of public methods and attributes declared in an object can indicate the class may need
|
||||
to be broken up as increased effort will be required to thoroughly test such a class.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimum" value="45"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
|
||||
public class Foo {
|
||||
public String value;
|
||||
public Bar something;
|
||||
public Variable var;
|
||||
//more public attributes
|
||||
public void doWork() {}
|
||||
public void doMoreWork() {}
|
||||
public void doWorkAgain() {}
|
||||
public void doWorking() {}
|
||||
public void doWorkIt() {}
|
||||
public void doWorkingAgain() {}
|
||||
public void doWorkAgainAgain() {}
|
||||
public void doWorked() {}
|
||||
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@@ -1,187 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
|
||||
<ruleset name="Controversial Rules">
|
||||
<description>
|
||||
The Controversial Ruleset contains rules that, for whatever reason, are considered controversial. They
|
||||
are separated out here to allow people to include as they see fit via custom rulesets. This ruleset was
|
||||
initially created in response to discussions over UnnecessaryConstructorRule which Tom likes but
|
||||
most people really dislike :-)
|
||||
</description>
|
||||
|
||||
<rule name="UnnecessaryConstructorRule"
|
||||
message="Avoid unnecessary constructors - the compiler will generate these for you"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Unnecessary constructor detects when a constructor is not necessary; i.e., when there's only one constructor,
|
||||
it's public, has an empty body, and takes no arguments.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ConstructorDeclaration[1][position() = last()][@Public='true'][not(FormalParameters/*)][not(BlockStatement)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public Foo() {}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
|
||||
<rule name="NullAssignment"
|
||||
message="Assigning an Object to null is a code smell. Consider refactoring."
|
||||
class="net.sourceforge.pmd.rules.design.NullAssignmentRule">
|
||||
<description>
|
||||
Assigning a "null" to a variable (outside of its declaration) is usually in
|
||||
bad form. Some times, the assignment is an indication that the programmer doesn't
|
||||
completely understand what is going on in the code. NOTE: This sort of assignment
|
||||
may in rare cases be useful to encourage garbage collection. If that's what you're using
|
||||
it for, by all means, disregard this rule :-)
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
Object x = null; // This is OK.
|
||||
x = new Object();
|
||||
// Big, complex piece of code here.
|
||||
x = null; // This is BAD.
|
||||
// Big, complex piece of code here.
|
||||
}
|
||||
}
|
||||
|
||||
]]>
|
||||
</example>
|
||||
|
||||
</rule>
|
||||
<rule name="OnlyOneReturn"
|
||||
message="A method should have only one exit point, and that should be the last statement in the method"
|
||||
class="net.sourceforge.pmd.rules.design.OnlyOneReturnRule">
|
||||
<description>
|
||||
A method should have only one exit point, and that should be the last statement in the method.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class OneReturnOnly1 {
|
||||
public void foo(int x) {
|
||||
if (x > 0) {
|
||||
return "hey"; // oops, multiple exit points!
|
||||
}
|
||||
return "hi";
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="UnusedModifier"
|
||||
message="Unused modifiers are, well, unused"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Unused modifiers are, well, unused.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//InterfaceDeclaration//MethodDeclaration[@Public='true' or @Abstract = 'true']
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public interface Foo {
|
||||
public abstract void bar(); // both abstract and public are ignored by the compiler
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="AssignmentInOperandRule"
|
||||
message="Avoid assigments in operands"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid assigments in operands; this can make code more complicated and harder to read.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//*[name()='WhileStatement' or name()='IfStatement'][Expression//AssignmentOperator]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
int x = 2;
|
||||
if ((x = getX()) == 3) {
|
||||
System.out.println("3!");
|
||||
}
|
||||
}
|
||||
private int getX() {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="AtLeastOneConstructor"
|
||||
message="Each class should declare at least one constructor"
|
||||
class="net.sourceforge.pmd.rules.AtLeastOneConstructorRule">
|
||||
<description>
|
||||
Each class should declare at least one constructor. Note that this rule is the
|
||||
opposite of UnnecessaryConstructorRule, so running them at the same time will
|
||||
result on a rule violation on every class.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
// no constructor! not good!
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
|
||||
<ruleset name="coupling">
|
||||
<description>
|
||||
These are new rules for coupling
|
||||
</description>
|
||||
|
||||
<rule name="CouplingBetweenObjectsRule"
|
||||
message="High amount of different objects as memebers donotes a high coupling"
|
||||
class="net.sourceforge.pmd.rules.CouplingBetweenObjectsRule">
|
||||
<description>
|
||||
Rule counts unique attributes, local variables and return types within an object. An amount
|
||||
higher than specified threshold can indicate a high degree of couping with in an object
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="threshold" value="20"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
import com.Blah;
|
||||
import org.Bar;
|
||||
import org.Bardo;
|
||||
//
|
||||
public class Foo {
|
||||
private Blah var1;
|
||||
private Bar var2;
|
||||
//followed by many imports of unique objects
|
||||
|
||||
void ObjectC doWork() {
|
||||
Bardo var55;
|
||||
ObjectA var44;
|
||||
ObjectZ var93;
|
||||
return something;
|
||||
}
|
||||
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ExcessiveImportsRule"
|
||||
message="A high number of imports can indicate a high degree of coupling within an object."
|
||||
class="net.sourceforge.pmd.rules.ExcessiveImportsRule">
|
||||
<description>
|
||||
A high number of imports can indicate a high degree of coupling within
|
||||
an object. Rule counts the number of unique imports and reports a violation
|
||||
if the count is above the user defined threshold.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimum" value="30"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
import blah.blah.Bardo;
|
||||
import blah.blah.Hardo;
|
||||
import blah.blah.Bar;
|
||||
import blah.net.ObjectA;
|
||||
//imports over some threshold
|
||||
public class Foo {
|
||||
public void doWork() {}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
@@ -1,321 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
|
||||
<ruleset name="Design Rules">
|
||||
<description>
|
||||
The Design Ruleset contains a collection of rules that find questionable designs.
|
||||
</description>
|
||||
|
||||
|
||||
<rule name="UseSingletonRule"
|
||||
message="All methods are static. Consider using Singleton instead."
|
||||
class="net.sourceforge.pmd.rules.design.UseSingletonRule">
|
||||
<description>
|
||||
If you have a class that has nothing but static methods, consider making it a Singleton
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class MaybeASingleton {
|
||||
public static void foo() {
|
||||
// etc
|
||||
}
|
||||
public static void bar() {
|
||||
// etc
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="LooseCouplingRule"
|
||||
message="Avoid using implementation types like ''{0}''; use the interface instead"
|
||||
class="net.sourceforge.pmd.rules.design.LooseCouplingRule">
|
||||
<description>
|
||||
Avoid using implementation types (i.e., HashSet); use the interface (i.e, Set) instead
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
import java.util.*;
|
||||
public class Bar {
|
||||
|
||||
// should be "private List list"
|
||||
private ArrayList list = new ArrayList();
|
||||
|
||||
// should be "public Set getFoo()"
|
||||
public HashSet getFoo() {
|
||||
return new HashSet();
|
||||
}
|
||||
}
|
||||
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="SimplifyBooleanReturnsRule"
|
||||
message="Avoid unnecessary if..then..else statements when returning a boolean"
|
||||
class="net.sourceforge.pmd.rules.SimplifyBooleanReturnsRule">
|
||||
<description>
|
||||
Avoid unnecessary if..then..else statements when returning a boolean
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
private int bar =2;
|
||||
public boolean isBarEqualsTo(int x) {
|
||||
// this bit of code
|
||||
if (bar == x) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
// can be replaced with a simple
|
||||
// return bar == x;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="SwitchStmtsShouldHaveDefault"
|
||||
message="Switch statements should have a default label"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Switch statements should have a default label.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//SwitchStatement[not(SwitchLabel[count(*) = 0])]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
int x = 2;
|
||||
switch (x) {
|
||||
case 2: int j = 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
|
||||
<rule name="AvoidDeeplyNestedIfStmts"
|
||||
message="Deeply nested if..then statements are hard to read"
|
||||
class="net.sourceforge.pmd.rules.AvoidDeeplyNestedIfStmtsRule">
|
||||
<description>
|
||||
Deeply nested if..then statements are hard to read.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="problemDepth" value="3"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
int x=2;
|
||||
int y=3;
|
||||
int z=4;
|
||||
if (x>y) {
|
||||
if (y>z) {
|
||||
if (z==x) {
|
||||
// this is officially out of control now
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="AvoidReassigningParametersRule"
|
||||
message="Avoid reassigning parameters such as ''{0}''"
|
||||
class="net.sourceforge.pmd.rules.AvoidReassigningParametersRule">
|
||||
<description>
|
||||
Reassigning values to parameters is a questionable practice. Use a temporary local variable instead.
|
||||
</description>
|
||||
<priority>2</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
private void foo(String bar) {
|
||||
bar = "something else";
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="SwitchDensity"
|
||||
message="A high ratio of statements to labels in a switch statement. Consider refactoring."
|
||||
class="net.sourceforge.pmd.rules.design.SwitchDensityRule">
|
||||
<description>
|
||||
A high ratio of statements to labels in a switch statement implies that the switch
|
||||
statement is doing too much work. Consider moving the statements either into new
|
||||
methods, or creating subclasses based on the switch variable.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimum" value="10"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
private int x;
|
||||
public void bar() {
|
||||
switch (x) {
|
||||
case 1: {
|
||||
System.out.println("I am a fish.");
|
||||
System.out.println("I am a fish.");
|
||||
System.out.println("I am a fish.");
|
||||
System.out.println("I am a fish.");
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
System.out.println("I am a cow.");
|
||||
System.out.println("I am a cow.");
|
||||
System.out.println("I am a cow.");
|
||||
System.out.println("I am a cow.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ConstructorCallsOverridableMethodRule"
|
||||
message="Avoid calls to overridable methods during construction"
|
||||
class="net.sourceforge.pmd.rules.ConstructorCallsOverridableMethodRule">
|
||||
<description>
|
||||
Calling overridable methods during construction poses a risk of invoking methods on an
|
||||
incompletely constructed object. This situation can be difficult to discern.
|
||||
It may leave the sub-class unable to construct its superclass or forced to
|
||||
replicate the construction process completely within itself, losing the ability to call
|
||||
super(). If the default constructor contains a call to an overridable method,
|
||||
the subclass may be completely uninstantiable.
|
||||
</description>
|
||||
<priority>1</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class SeniorClass {
|
||||
public SeniorClass(){
|
||||
toString(); //may throw NullPointerException if overridden
|
||||
}
|
||||
public String toString(){
|
||||
return "IAmSeniorClass";
|
||||
}
|
||||
}
|
||||
public class JuniorClass extends SeniorClass {
|
||||
private String name;
|
||||
public JuniorClass(){
|
||||
super(); //Automatic call leads to NullPointerException
|
||||
name = "JuniorClass";
|
||||
}
|
||||
public String toString(){
|
||||
return name;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="AccessorClassGenerationRule"
|
||||
message="Avoid instantiation through private constructors from outside of the constructor's class."
|
||||
class="net.sourceforge.pmd.rules.AccessorClassGenerationRule">
|
||||
<description>
|
||||
Instantiation by way of private constructors from outside of the constructor's class often causes the generation of an accessor.
|
||||
A factory method, or non-privitization of the constructor can eliminate this situation.
|
||||
The generated class file is actually an interface. It gives the accessing class the ability to invoke a new hidden package
|
||||
scope constructor that takes the interface as a supplementary parameter. This turns a private constructor effectively into
|
||||
one with package scope, though not visible to the naked eye.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class OuterClass {
|
||||
void method(){
|
||||
InnerClass ic = new InnerClass();//Causes generation of accessor
|
||||
}
|
||||
public class InnerClass {
|
||||
private InnerClass(){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class OuterClass {
|
||||
void method(){
|
||||
InnerClass ic = new InnerClass();//OK, due to public constructor
|
||||
}
|
||||
public class InnerClass {
|
||||
public InnerClass(){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class OuterClass {
|
||||
void method(){
|
||||
InnerClass ic = InnerClass.getInnerClass();//OK
|
||||
}
|
||||
public static class InnerClass {
|
||||
private InnerClass(){
|
||||
}
|
||||
private static InnerClass getInnerClass(){
|
||||
return new InnerClass();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class OuterClass {
|
||||
private OuterClass(){
|
||||
}
|
||||
public class InnerClass {
|
||||
void method(){
|
||||
OuterClass oc = new OuterClass();//Causes generation of accessor
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
@@ -1,108 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
|
||||
<ruleset name="experimental">
|
||||
<description>
|
||||
This is the sandbox.
|
||||
</description>
|
||||
|
||||
<!--<rule name="UnnecessaryCast"
|
||||
message="Avoid unnecessary casts"
|
||||
class="net.sourceforge.pmd.rules.UnnecessaryCastRule">
|
||||
<description>
|
||||
A variable is cast to itself, one of its supertypes or one of its interfaces. Usually
|
||||
indicates that the programmer is not clear on the class structure they
|
||||
are working with.
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public Collection doSomething() {
|
||||
List list = new ArrayList();
|
||||
|
||||
return (Collection) list; // Unnecessary Cast
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="PositionalIterator"
|
||||
message="Avoid positional iterators"
|
||||
class="net.sourceforge.pmd.rules.design.PositionalIteratorRule">
|
||||
<description>
|
||||
Avoid positional iterators. This doesn't work yet,
|
||||
it breaks on stuff like this:
|
||||
public class Foo {
|
||||
private int baz = true;
|
||||
public void bar(Iterator i) {
|
||||
Object x = null;
|
||||
while (i.hasNext()) {
|
||||
if (baz) {
|
||||
x = i.next();
|
||||
} else {
|
||||
x = new Runnable() {public void run() {Object bif = i.next();}}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
See javax.security.auth.Subject.java, inner class SecureSet, method removeAll(), around line 1092 for a good example.
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class PositionalIterators {
|
||||
public void foo(Iterator i) {
|
||||
while(i.hasNext()) {
|
||||
Object one = i.next();
|
||||
// 2 calls to next() inside the loop == bad!
|
||||
Object two = i.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="StringConcatenation"
|
||||
message="Consider replacing String concatenation inside loops with a StringBuffer"
|
||||
class="net.sourceforge.pmd.rules.StringConcatenationRule">
|
||||
<description>
|
||||
Consider replacing String concatenation inside loops with a StringBuffer
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Bar {
|
||||
public String foo(Object[] someArray) {
|
||||
String list = "" ;
|
||||
for( int i = 0; i < someArray.length; i++ ){
|
||||
list = list + "," + someArray[i];
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
-->
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
|
||||
<ruleset name="Favorites">
|
||||
<description>
|
||||
The Favorites ruleset contains links to rules that I like to use. Usually I
|
||||
combine this ruleset with the unusedcode.xml, basic.xml, and import.xml rulesets for my projects.
|
||||
This ruleset also serves as an example of do a custom ruleset.
|
||||
</description>
|
||||
|
||||
<rule ref="rulesets/braces.xml/WhileLoopsMustUseBracesRule"/>
|
||||
<rule ref="rulesets/braces.xml/ForLoopsMustUseBracesRule"/>
|
||||
<rule ref="rulesets/design.xml/LooseCouplingRule"/>
|
||||
<rule ref="rulesets/design.xml/SimplifyBooleanReturnsRule"/>
|
||||
<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>
|
||||
<rule ref="rulesets/strings.xml/StringToString"/>
|
||||
<rule ref="rulesets/strings.xml/StringInstantiation"/>
|
||||
<rule ref="rulesets/controversial.xml/UnnecessaryConstructorRule"/>
|
||||
<rule ref="rulesets/controversial.xml/NullAssignment"/>
|
||||
<rule ref="rulesets/controversial.xml/UnusedModifier"/>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
|
||||
<ruleset name="Import Rules">
|
||||
<description>
|
||||
These rules deal with different problems that can occur with a class' import statements.
|
||||
</description>
|
||||
|
||||
<rule name="DuplicateImports"
|
||||
message="Avoid duplicate imports such as ''{0}''"
|
||||
class="net.sourceforge.pmd.rules.DuplicateImportsRule">
|
||||
<description>
|
||||
Avoid duplicate import statements.
|
||||
</description>
|
||||
<priority>4</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
// this is bad
|
||||
import java.io.File;
|
||||
import java.io.File;
|
||||
public class Foo {}
|
||||
|
||||
// --- in another source code file...
|
||||
|
||||
// this is bad
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
|
||||
public class Foo {}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="DontImportJavaLang"
|
||||
message="Avoid importing anything from the package 'java.lang'"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3).
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ImportDeclaration
|
||||
[starts-with(Name/@Image, 'java.lang')]
|
||||
[not(starts-with(Name/@Image, 'java.lang.ref'))]
|
||||
[not(starts-with(Name/@Image, 'java.lang.reflect'))]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>4</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
// this is bad
|
||||
import java.lang.String;
|
||||
public class Foo {}
|
||||
|
||||
// --- in another source code file...
|
||||
|
||||
// this is bad
|
||||
import java.lang.*;
|
||||
|
||||
public class Foo {}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="UnusedImports"
|
||||
message="Avoid unused imports such as ''{0}''"
|
||||
class="net.sourceforge.pmd.rules.UnusedImportsRule">
|
||||
<description>
|
||||
Avoid unused import statements.
|
||||
</description>
|
||||
<priority>4</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
// this is bad
|
||||
import java.io.File;
|
||||
public class Foo {}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ImportFromSamePackage"
|
||||
message="No need to import a type that's in the same package"
|
||||
class="net.sourceforge.pmd.rules.ImportFromSamePackageRule">
|
||||
<description>
|
||||
No need to import a type that's in the same package.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
package foo;
|
||||
import foo.Buz; // no need for this
|
||||
public class Bar{}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
|
||||
<ruleset name="JUnit Rules">
|
||||
<description>
|
||||
These rules deal with different problems that can occur with JUnit tests.
|
||||
</description>
|
||||
|
||||
<rule name="JUnitStaticSuite"
|
||||
message="You have a suite() method that is not both public and static, so JUnit won't call it to get your TestSuite. Is that what you wanted to do?"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
The suite() method in a JUnit test needs to be both public and static.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//MethodDeclaration[not(@Static='true') or not(@Public='true')][MethodDeclarator/@Image='suite']
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
import junit.framework.*;
|
||||
public class Foo extends TestCase {
|
||||
public void suite() {} // oops, should be static
|
||||
private static void suite() {} // oops, should be public
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="JUnitSpelling"
|
||||
message="You may have misspelled a JUnit framework method (setUp or tearDown)"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Some JUnit framework methods are easy to misspell.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//MethodDeclarator[(not(@Image = 'setUp') and translate(@Image, 'SETuP', 'setUp') = 'setUp') or (not(@Image = 'tearDown') and translate(@Image, 'TEARdOWN', 'tearDown') = 'tearDown')][FormalParameters[count(*) = 0]]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
import junit.framework.*;
|
||||
public class Foo extends TestCase {
|
||||
public void setup() {} // oops, should be setUp
|
||||
public void TearDown() {} // oops, should be tearDown
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="JUnitAssertionsShouldIncludeMessageRule"
|
||||
message="JUnit assertions should include a message"
|
||||
class="net.sourceforge.pmd.rules.junit.JUnitAssertionsShouldIncludeMessageRule">
|
||||
<description>
|
||||
JUnit assertions should include a message - i.e., use the three argument version of
|
||||
assertEquals(), not the two argument version.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo extends TestCase {
|
||||
public void testSomething() {
|
||||
assertEquals("foo", "bar");
|
||||
// not good! use the form:
|
||||
// assertEquals("Foo does not equals bar", "foo", "bar");
|
||||
// instead
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
|
||||
<ruleset name="Naming Rules">
|
||||
<description>
|
||||
The Naming Ruleset contains a collection of rules about names - too long, too short, and so forth.
|
||||
</description>
|
||||
|
||||
|
||||
<rule name="ShortVariable"
|
||||
message="Avoid variables with short names"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Detects when a field, local or parameter has a short name.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//VariableDeclaratorId[string-length(@Image) < 3][not(ancestor::ForInit)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Something {
|
||||
private int q = 15; // VIOLATION - Field
|
||||
|
||||
public static void main( String as[] ) { // VIOLATION - Formal
|
||||
int r = 20 + q; // VIOLATION - Local
|
||||
|
||||
for (int i = 0; i < 10; i++) { // Not a Violation (inside FOR)
|
||||
r += q;
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="LongVariable"
|
||||
message="Avoid excessively long variable names"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Detects when a field, formal or local variable is declared with a big name.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//VariableDeclaratorId[string-length(@Image) > 12]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Something {
|
||||
int reallyLongIntName = -3; // VIOLATION - Field
|
||||
|
||||
public static void main( String argumentsList[] ) { // VIOLATION - Formal
|
||||
int otherReallyLongName = -5; // VIOLATION - Local
|
||||
|
||||
for (int interestingIntIndex = 0; // VIOLATION - For
|
||||
interestingIntIndex < 10;
|
||||
interestingIntIndex ++ ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ShortMethodNameRule"
|
||||
message="Avoid using short method names"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Detects when very short method names are used.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//MethodDeclarator[string-length(@Image) < 3]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class ShortMethod {
|
||||
public void a( int i ) { // Violation
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
|
||||
<ruleset name="newrules">
|
||||
<description>
|
||||
These are new rules for the next release
|
||||
</description>
|
||||
|
||||
|
||||
|
||||
<rule name="SymbolTableTestRule"
|
||||
message="test"
|
||||
class="net.sourceforge.pmd.rules.SymbolTableTestRule">
|
||||
<description>
|
||||
asdsad
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
// asdadas
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
|
||||
<ruleset name="Strings Rules">
|
||||
<description>
|
||||
These rules deal with different problems that can occur with String manipulation.
|
||||
</description>
|
||||
|
||||
|
||||
<rule name="StringInstantiation"
|
||||
message="Avoid instantiating String objects; this is usually unnecessary."
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid instantiating String objects; this is usually unnecessary.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//AllocationExpression[Name/@Image='String'][count(.//Expression) < 2][not(ArrayDimsAndInits)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>2</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
private String bar = new String("bar"); // just do a String bar = "bar";
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="AvoidDuplicateLiterals"
|
||||
message="The same String literal appears {0} times in this file; the first occurrence is on line {1}"
|
||||
class="net.sourceforge.pmd.rules.AvoidDuplicateLiteralsRule">
|
||||
<description>
|
||||
Code containing duplicate String literals can usually be improved by declaring the String as a constant field.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="threshold" value="4"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
private void bar() {
|
||||
buz("Howdy");
|
||||
buz("Howdy");
|
||||
buz("Howdy");
|
||||
buz("Howdy");
|
||||
}
|
||||
private void buz(String x) {}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="StringToString"
|
||||
message="Avoid calling toString() on String objects; this is unnecessary"
|
||||
class="net.sourceforge.pmd.rules.StringToStringRule">
|
||||
<description>
|
||||
Avoid calling toString() on String objects; this is unnecessary
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
private String baz() {
|
||||
String bar = "howdy";
|
||||
return bar.toString();
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
|
||||
<ruleset name="Unused Code Rules">
|
||||
<description>
|
||||
The Unused Code Ruleset contains a collection of rules that find unused code.
|
||||
</description>
|
||||
|
||||
<rule name="UnusedPrivateField"
|
||||
message="Avoid unused private fields such as ''{0}''"
|
||||
class="net.sourceforge.pmd.rules.UnusedPrivateFieldRule">
|
||||
<description>
|
||||
Unused Private Field detects when a private field is declared
|
||||
that is not used by the class.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Something {
|
||||
private static int FOO = 2; // Unused
|
||||
private int i = 5; // Unused
|
||||
private int j = 6;
|
||||
|
||||
public int addOne() {
|
||||
return j++;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="UnusedLocalVariable"
|
||||
message="Avoid unused local variables such as ''{0}''"
|
||||
class="net.sourceforge.pmd.rules.UnusedLocalVariableRule">
|
||||
<description>
|
||||
Unused Local Variables detects when a variable is declared, but not
|
||||
used (except for possibly initial assignment)
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public int doSomething() {
|
||||
int i = 5; // Unused
|
||||
int j = 6;
|
||||
j += 3;
|
||||
return j;
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
|
||||
<rule name="UnusedPrivateMethod"
|
||||
message="Avoid unused private methods such as ''{0}''"
|
||||
class="net.sourceforge.pmd.rules.UnusedPrivateMethodRule">
|
||||
<description>
|
||||
Unused Private Method detects when a private method is declared but is unused.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Something {
|
||||
private void foo() {} // unused
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="UnusedFormalParameter"
|
||||
message="Avoid unused formal parameters such as ''{0}''"
|
||||
class="net.sourceforge.pmd.rules.UnusedFormalParameterRule">
|
||||
<description>
|
||||
Avoid passing parameters to methods and then not using those parameters.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
private void bar(String howdy) {
|
||||
// howdy is not used
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,11 @@
|
||||
<author email="vmassol@apache.org">Vincent Massol</author>
|
||||
</properties>
|
||||
<body>
|
||||
<release version="1.5-SNAPSHOT" date="in CVS">
|
||||
<action dev="brett" due-to="Joakim Erdfelt" issue="MPPMD-2" type="update">
|
||||
Upgrade to PMD 1.3, clean up and improve documentation.
|
||||
</action>
|
||||
</release>
|
||||
<release version="1.4" date="2004-05-15">
|
||||
<action dev="brett" type="fix" issue="MPPMD-7">Create directories that exist under maven.build.dir before using them so it works after clean.</action>
|
||||
<action dev="brett" type="fix">Fix usage of the maven.pmd.cpd.enable property so it is disabled when set to false (the default)</action>
|
||||
|
||||
@@ -0,0 +1,306 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faqs title="Frequently Asked Questions">
|
||||
|
||||
<part id="general">
|
||||
<title>General</title>
|
||||
|
||||
<faq id="whats-pmd">
|
||||
<question>
|
||||
What is PMD?
|
||||
</question>
|
||||
<answer>
|
||||
<p>According to the official website (
|
||||
<a href="http://pmd.sourceforge.net/">pmd.sourceforge.net</a> ),
|
||||
PMD scans Java source code and looks for potential problems like:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li>Unused local variables</li>
|
||||
<li>Empty catch blocks</li>
|
||||
<li>Unused parameters</li>
|
||||
<li>Empty 'if' statements</li>
|
||||
<li>Duplicate import statements</li>
|
||||
<li>Unused private methods</li>
|
||||
<li>Classes which could be Singletons</li>
|
||||
<li>Short/long variable and method names</li>
|
||||
</ul>
|
||||
|
||||
<p>This plugin provides a means to integrate the pmd report into the
|
||||
maven process.</p>
|
||||
|
||||
</answer>
|
||||
</faq>
|
||||
</part>
|
||||
|
||||
<part id="installation">
|
||||
<title>Installation</title>
|
||||
|
||||
<faq id="basic-install">
|
||||
<question>
|
||||
How do I install the maven-pmd-plugin?
|
||||
</question>
|
||||
<answer>
|
||||
<p>
|
||||
The maven-pmd-plugin is considered an optional maven-plugin, but
|
||||
the default installation of maven comes with it.
|
||||
|
||||
There is nothing special you need to do, other than use it.
|
||||
see <a href="#basic-usage">Basic Usage</a> for examples on how to use it.
|
||||
</p>
|
||||
</answer>
|
||||
</faq>
|
||||
|
||||
<faq id="manual-install">
|
||||
<question>
|
||||
I want to install a different version of the maven-pmd-plugin than
|
||||
what is available to me right now. How do I do that?
|
||||
</question>
|
||||
<answer>
|
||||
<p>
|
||||
Starting with the <a href="http://maven.apache.org/reference/plugins/plugin/">
|
||||
maven-plugin-plugin</a> 1.2 (which first appeared with
|
||||
maven 1.0-rc1), you issue the following command to maven to
|
||||
download the version of your choice.
|
||||
</p>
|
||||
<source>
|
||||
<![CDATA[
|
||||
$ maven -DgroupId=maven -DartifactId=maven-pmd-plugin -Dtype=plugin -Dversion=1.3 plugin:download
|
||||
]]>
|
||||
</source>
|
||||
<p>
|
||||
This command will download the plugin, remove the other versions of
|
||||
the maven-pmd-plugin and make this recently downloaded version
|
||||
immediately available to all projects that depend on maven-pmd-plugin.
|
||||
</p>
|
||||
</answer>
|
||||
</faq>
|
||||
|
||||
</part>
|
||||
|
||||
<part id="usage">
|
||||
<title>Usage</title>
|
||||
|
||||
<faq id="basic-usage">
|
||||
<question>
|
||||
How do I use it?
|
||||
</question>
|
||||
<answer>
|
||||
<p>
|
||||
The quickest, and easiest way to use the maven-pmd-plugin is to
|
||||
add the <code>maven-pmd-plugin</code> entry to your
|
||||
<a href="http://maven.apache.org/reference/project-descriptor.html#reports">
|
||||
reports</a> section in your project's project.xml
|
||||
<a href="http://maven.apache.org/reference/project-descriptor.html">
|
||||
project descriptor</a>.
|
||||
</p>
|
||||
|
||||
<source>
|
||||
<![CDATA[
|
||||
<reports>
|
||||
...
|
||||
<report>maven-pmd-plugin</report>
|
||||
...
|
||||
</reports>
|
||||
]]>
|
||||
</source>
|
||||
</answer>
|
||||
</faq>
|
||||
|
||||
<faq id="manual-running">
|
||||
<question>
|
||||
I don't want to use it via the project.xml. What are my options?
|
||||
</question>
|
||||
<answer>
|
||||
<p>
|
||||
The PMD plugin can be started through "maven pmd"
|
||||
or integrated by using the following code snippet in
|
||||
maven.xml:
|
||||
</p>
|
||||
|
||||
<source>
|
||||
<![CDATA[
|
||||
<?xml version="1.0"?>
|
||||
<preGoal name="site:generate">
|
||||
<attainGoal name="pmd"/>
|
||||
</preGoal>
|
||||
]]>
|
||||
</source>
|
||||
|
||||
<p>
|
||||
The generated report has to be added manually to the
|
||||
website which is usually done with navigation.xml.
|
||||
</p>
|
||||
|
||||
<source>
|
||||
<![CDATA[
|
||||
<?xml version="1.0"?>
|
||||
<menu name="Custom Reports">
|
||||
<item name="PMD Report" href="/pmd-report.html"/>
|
||||
<!-- Add more custom reports here -->
|
||||
</menu>
|
||||
]]>
|
||||
</source>
|
||||
</answer>
|
||||
</faq>
|
||||
|
||||
<faq id="disable-subproject">
|
||||
<question>
|
||||
I have a large projects with many sub-projects, I want to use
|
||||
the maven-pmd-plugin, but not for a specific sub-project.
|
||||
How do I accomplish this?
|
||||
</question>
|
||||
<answer>
|
||||
<p>
|
||||
Assume that you have generated a DB layer having a few
|
||||
hundreds Java source files. Apart from being curious you
|
||||
don't want to have a PMD report for generated source files.
|
||||
Simply put <code>maven.pmd.enable=false</code> into your
|
||||
<code>project properties</code> for that one sub-project.
|
||||
</p>
|
||||
</answer>
|
||||
</faq>
|
||||
|
||||
<faq id="disable-select-files">
|
||||
<question>
|
||||
How do I disable certain files from being checked by the
|
||||
maven-pmd-plugin?
|
||||
</question>
|
||||
<answer>
|
||||
<p>
|
||||
The maven-pmd-plugin will scan all <code>*.java</code> files in
|
||||
your defined <code><sourceDirectory></code> path
|
||||
specified in your <a href="http://maven.apache.org/reference/project-descriptor.html">
|
||||
project descriptor</a>.
|
||||
</p>
|
||||
<p>
|
||||
Use the <code>maven.pmd.excludes</code> property to exclude
|
||||
certain files from being checked by the maven-pmd-plugin.
|
||||
</p>
|
||||
<p>
|
||||
Lets assume that you have generated a DB layer within your project.
|
||||
Simply put <code>maven.pmd.excludes=**/database/**</code> into your
|
||||
<code>project.properties</code> file to exclude the files in your
|
||||
database directory and below.
|
||||
</p>
|
||||
</answer>
|
||||
</faq>
|
||||
|
||||
<faq id="zillion-violations">
|
||||
<question>
|
||||
How do I get rid of these zillions of rule violations?
|
||||
</question>
|
||||
<answer>
|
||||
<p>
|
||||
You could fix the rule violations.
|
||||
</p>
|
||||
<p>
|
||||
On the other hand, if you want to configure the maven-pmd-plugin
|
||||
to pick and choose the type of tests to perform, then you need
|
||||
to specify your ruleset.
|
||||
</p>
|
||||
<p>
|
||||
There are two ways to accomplish this.
|
||||
<ol>
|
||||
<li>
|
||||
<p>
|
||||
Define which default pmd rulesets you want to use in the
|
||||
<code>maven.pmd.rulesetfiles</code> property.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The default setting for the <code>maven.pmd.rulesetfiles</code>
|
||||
property is:
|
||||
<source>
|
||||
<![CDATA[
|
||||
maven.pmd.rulesetfiles = rulesets/basic.xml,rulesets/unusedcode.xml,rulesets/imports.xml
|
||||
]]>
|
||||
</source>
|
||||
</p>
|
||||
<p>
|
||||
The following list of default pmd rulesets was obtained from
|
||||
the <a href="http://pmd.sourceforge.net/">official pmd
|
||||
project</a> page.
|
||||
<ul>
|
||||
<li><a href="http://pmd.sourceforge.net/rules/basic.html">Basic</a> = <code>ruleset/basic.xml</code>.</li>
|
||||
<li><a href="http://pmd.sourceforge.net/rules/naming.html">Naming</a> = <code>ruleset/naming.xml</code>.</li>
|
||||
<li><a href="http://pmd.sourceforge.net/rules/unusedcode.html">Unused Code</a> = <code>ruleset/unusedcode.xml</code>.</li>
|
||||
<li><a href="http://pmd.sourceforge.net/rules/design.html">Design</a> = <code>ruleset/design.xml</code>.</li>
|
||||
<li><a href="http://pmd.sourceforge.net/rules/imports.html">Import Statements</a> = <code>ruleset/imports.xml</code>.</li>
|
||||
<li><a href="http://pmd.sourceforge.net/rules/junit.html">JUnit Tests</a> = <code>ruleset/junit.xml</code>.</li>
|
||||
<li><a href="http://pmd.sourceforge.net/rules/strings.html">Strings</a> = <code>ruleset/strings.xml</code>.</li>
|
||||
<li><a href="http://pmd.sourceforge.net/rules/braces.html">Braces</a> = <code>ruleset/braces.xml</code>.</li>
|
||||
<li><a href="http://pmd.sourceforge.net/rules/codesize.html">Code Size</a> = <code>ruleset/codesize.xml</code>.</li>
|
||||
<li><a href="http://pmd.sourceforge.net/rules/javabeans.html">Javabeans</a> = <code>ruleset/javabeans.xml</code>.</li>
|
||||
<li><a href="http://pmd.sourceforge.net/rules/coupling.html">Coupling</a> = <code>ruleset/coupling.xml</code>.</li>
|
||||
<li><a href="http://pmd.sourceforge.net/rules/strictexception.html">Strict Exceptions</a> = <code>ruleset/strictexception.xml</code>.</li>
|
||||
<li><a href="http://pmd.sourceforge.net/rules/controversial.html">Controversial</a> = <code>ruleset/controversial.xml</code>.</li>
|
||||
</ul>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
Define a custom ruleset.xml and reference it via the
|
||||
<code>maven.pmd.rulesetfiles</code> property.
|
||||
</p>
|
||||
<p>
|
||||
Example of a custom ruleset, saved as file called
|
||||
<code>favorite-pmd.xml</code> in your project root.
|
||||
<source>
|
||||
<![CDATA[
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="Favorites">
|
||||
<description>
|
||||
The Favorites ruleset contains links to rules that I like to use.
|
||||
I like the basic.xml, unusedcode.xml, and import.xml, and some of
|
||||
the rules in design.xml, strings.xml, and controversial.xml.
|
||||
</description>
|
||||
|
||||
<rule ref="rulesets/basic.xml" />
|
||||
<rule ref="rulesets/unusedcode.xml" />
|
||||
<rule ref="rulesets/import.xml" />
|
||||
<rule ref="rulesets/design.xml/SimplifyBooleanReturnsRule" />
|
||||
<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault" />
|
||||
<rule ref="rulesets/strings.xml/StringToString" />
|
||||
<rule ref="rulesets/strings.xml/StringInstantiation" />
|
||||
<rule ref="rulesets/controversial.xml/UnnecessaryConstructorRule" />
|
||||
<rule ref="rulesets/controversial.xml/NullAssignment" />
|
||||
<rule ref="rulesets/controversial.xml/UnusedModifier" />
|
||||
|
||||
</ruleset>
|
||||
]]>
|
||||
</source>
|
||||
</p>
|
||||
<p>
|
||||
How it's referenced in your <code>project.properties</code>
|
||||
file.
|
||||
<source>
|
||||
<![CDATA[
|
||||
maven.pmd.rulesetfiles = ${basedir}/favorite-pmd.xml
|
||||
]]>
|
||||
</source>
|
||||
</p>
|
||||
</li>
|
||||
</ol>
|
||||
</p>
|
||||
</answer>
|
||||
</faq>
|
||||
|
||||
<faq id="how-to-upgrade-pmd-jar">
|
||||
<question>
|
||||
How do I manually upgrade to a newer PMD jar?
|
||||
</question>
|
||||
<answer>
|
||||
<p>
|
||||
The JAR picked up the plugin is defined in
|
||||
$MAVEN_HOME/plugins/pmd/project.xml and can be
|
||||
changed.
|
||||
</p>
|
||||
</answer>
|
||||
|
||||
</faq>
|
||||
|
||||
</part>
|
||||
|
||||
</faqs>
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
<document>
|
||||
|
||||
<properties>
|
||||
<title>Maven PMD Plug-in How To</title>
|
||||
<author email="siegfried.goeschl@it20one.at">Siegfried Goeschl</author>
|
||||
</properties>
|
||||
|
||||
<body>
|
||||
<section name="Maven PMD Plugin How To">
|
||||
|
||||
<subsection name="How to enable PMD for all of my projects?">
|
||||
<p>
|
||||
Usually I provide a custom plugin, e.g. "maven-it20one-plugin-1.0"
|
||||
which sets the variable "maven.pmd.enable" to "true". Since all
|
||||
plugins are parsed it is guaranteed that PMD will be executed
|
||||
</p>
|
||||
<p>
|
||||
The simple way is to define the property in
|
||||
$MAVEN_HOME/bin/driver.properties
|
||||
</p>
|
||||
</subsection>
|
||||
|
||||
<subsection name="How to disable PMD for one project?">
|
||||
<p>
|
||||
Assume that you have generated a DB layer having a few
|
||||
hundreds Java source files. Apart from being curious you
|
||||
don't want to have a PMD report for generated source files.
|
||||
Simply put "maven.pmd.enable=false" into your project properties.
|
||||
</p>
|
||||
</subsection>
|
||||
|
||||
<subsection name="How to disable PMD for certain files?">
|
||||
<p>
|
||||
Also assuming that you have generated a DB layer within your project.
|
||||
Simply put "maven.pmd.excludes=**/database/**" into your project
|
||||
properties.
|
||||
</p>
|
||||
</subsection>
|
||||
|
||||
<subsection name="How to get rid of zillions of rule violations?">
|
||||
<p>
|
||||
You could fix the rule violations. On the other hand I find
|
||||
some of the rules quite annoying. Rules can be removed by editing
|
||||
the rulesets.properties.
|
||||
</p>
|
||||
<p>
|
||||
In other case you change the trigger of the rules directly in the
|
||||
ruleset files to fine tune the reports.
|
||||
</p>
|
||||
</subsection>
|
||||
|
||||
<subsection name="How to upgrade to a newer PMD jar?">
|
||||
<p>
|
||||
"Those bloody contributors do not keep up with the
|
||||
release - there is the new JAR out there for two
|
||||
days and no update of the plugin ... having pizza,
|
||||
coke, a joint and doing nothing" - Fine, as
|
||||
long as we do not inhale ... ;-)
|
||||
</p>
|
||||
<p>
|
||||
The JAR picked up the plugin is defined in
|
||||
$MAVEN_HOME/plugins/pmd/project.xml and can be
|
||||
changed.
|
||||
</p>
|
||||
<p>
|
||||
Leave it, try it but don't whine will I have to carve
|
||||
out a living with some paid work ... :-[]
|
||||
</p>
|
||||
</subsection>
|
||||
|
||||
</section>
|
||||
|
||||
</body>
|
||||
|
||||
</document>
|
||||
+4
-72
@@ -32,79 +32,11 @@
|
||||
This plugin generates a report of the PMD static source code
|
||||
analyzer.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
See the <a href="faq.html">FAQ</a> for more information on Installation / Use / Configuring.
|
||||
</p>
|
||||
|
||||
<subsection name="Installation">
|
||||
|
||||
<p>
|
||||
Copy the downloaded plugin into the Maven plugin directory.
|
||||
Any older version of the plugin should to be deleted to make
|
||||
sure that the newest plugin is called
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Download the PMD binary distribution and put the PMD
|
||||
jar into the repository. This has to be done manually
|
||||
unless PMD is hosted on the Maven remote repository.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Run "maven -g" and look out for documented PMD goals.
|
||||
If you see some then the unpacking succeeded.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The PMD plugin can be started through "maven pmd"
|
||||
or integrated by using the following code snippet in
|
||||
maven.xml:
|
||||
</p>
|
||||
|
||||
<source>
|
||||
<![CDATA[
|
||||
<?xml version="1.0"?>
|
||||
<preGoal name="site:generate">
|
||||
<attainGoal name="pmd"/>
|
||||
</preGoal>
|
||||
]]>
|
||||
</source>
|
||||
|
||||
<p>
|
||||
The generated report has to be added manually to the
|
||||
website which is usually done with navigation.xml.
|
||||
</p>
|
||||
|
||||
<source>
|
||||
<![CDATA[
|
||||
<?xml version="1.0"?>
|
||||
<menu name="Custom Reports">
|
||||
<item name="PMD Report" href="/pmd-report.html"/>
|
||||
<!-- Add more custom reports here -->
|
||||
</menu>
|
||||
]]>
|
||||
</source>
|
||||
|
||||
<p>
|
||||
Another way to integrate the PMD plugin is to add it to the <reports>
|
||||
section in your project.xml:
|
||||
</p>
|
||||
|
||||
<source>
|
||||
<![CDATA[
|
||||
<reports>
|
||||
<report>maven-jdepend-plugin</report>
|
||||
<report>maven-checkstyle-plugin</report>
|
||||
<report>maven-pmd-plugin</report>
|
||||
<report>maven-changelog-plugin</report>
|
||||
<report>maven-file-activity-plugin</report>
|
||||
<report>maven-developer-activity-plugin</report>
|
||||
<report>maven-javadoc-plugin</report>
|
||||
<report>maven-jxr-plugin</report>
|
||||
<report>maven-junit-report-plugin</report>
|
||||
<report>maven-tasklist-plugin</report>
|
||||
</reports>
|
||||
]]>
|
||||
</source>
|
||||
|
||||
</subsection>
|
||||
|
||||
<subsection name="Thanks to ...">
|
||||
|
||||
|
||||
@@ -23,11 +23,15 @@
|
||||
<title>Maven PMD Plugin</title>
|
||||
|
||||
<body>
|
||||
<links>
|
||||
<item name="Maven" href="http://maven.apache.org/"/>
|
||||
<item name="PMD" href="http://pmd.sourceforge.net/"/>
|
||||
</links>
|
||||
<menu name="Home">
|
||||
<item name="Front Page" href="/index.html"/>
|
||||
<item name="Properties" href="/properties.html"/>
|
||||
<item name="Sample" href="/images/sample.gif"/>
|
||||
<item name="How To's" href="/how-to.html"/>
|
||||
<item name="FAQs" href="/faq.html"/>
|
||||
</menu>
|
||||
</body>
|
||||
|
||||
|
||||
Reference in new issue
Block a user