diff --git a/pmd/.cvsignore b/pmd/.cvsignore index 7d49d6b5..904332a8 100644 --- a/pmd/.cvsignore +++ b/pmd/.cvsignore @@ -3,3 +3,4 @@ maven.log .project build.properties velocity.log +target \ No newline at end of file diff --git a/pmd/plugin.jelly b/pmd/plugin.jelly index 9ac3814e..bcfadf45 100644 --- a/pmd/plugin.jelly +++ b/pmd/plugin.jelly @@ -1,66 +1,99 @@ - + + - - - - - + + + + + + - - - - - - - - - - - - + + + + + + - + + - - + + + + + + + + + + + + + + - - - + + + + + + + + - Running the PMD task with ${maven.pmd.rulesetfiles} ... - - - - + + + + - Converting the PMD report to XDOC ... + Converting the PMD report to xdoc ... + input="${maven.build.dir}/pmd-raw-report.xml" + output="pmd-report.xml" + stylesheet="${plugin.resources}/pmd.jsl" + omitXmlDeclaration="true" + outputMode="xml" + prettyPrint="true" + /> diff --git a/pmd/plugin.properties b/pmd/plugin.properties index 42a851fd..2fb63b7d 100644 --- a/pmd/plugin.properties +++ b/pmd/plugin.properties @@ -11,4 +11,4 @@ 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=rulesets/strings.xml,rulesets/junit.xml,rulesets/braces.xml,rulesets/basic.xml,rulesets/unusedcode.xml,rulesets/design.xml,rulesets/naming.xml,rulesets/imports.xml,rulesets/codesize.xml +maven.pmd.rulesetfiles=${plugin.resources}/rulesets/strings.xml,${plugin.resources}/rulesets/junit.xml,${plugin.resources}/rulesets/braces.xml,${plugin.resources}/rulesets/basic.xml,${plugin.resources}/rulesets/unusedcode.xml,${plugin.resources}/rulesets/design.xml,${plugin.resources}/rulesets/naming.xml,${plugin.resources}/rulesets/imports.xml,${plugin.resources}/rulesets/codesize.xml diff --git a/pmd/project.xml b/pmd/project.xml index 2ada3eaa..fc98b2dd 100644 --- a/pmd/project.xml +++ b/pmd/project.xml @@ -1,4 +1,4 @@ - + ${basedir}/../project.xml @@ -64,27 +64,18 @@ pmd 1.04 http://pmd.sourceforge.net - - root - + + + jaxen + jaxen + 1.0-FCS-full + + + saxpath + saxpath + 1.0-FCS - - - - - ${basedir} - - plugin.jelly - plugin.properties - project.properties - project.xml - pmd.jsl - rulesets/** - - - - diff --git a/pmd/rulesets/basic.xml b/pmd/rulesets/basic.xml deleted file mode 100644 index 0e0a286a..00000000 --- a/pmd/rulesets/basic.xml +++ /dev/null @@ -1,209 +0,0 @@ - - - - -The Basic Ruleset contains a collection of good practice rules -which everyone should follow. - - - - - -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. - - - - - - - - - -Empty If Statement finds instances where a condition is checked but nothing is done about it. - - - - - - - - -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. - - - - - - - - - - Avoid unnecessary temporaries when converting primitives to Strings - - - - - - - - - - - -Avoid empty try blocks - what's the point? - - - - - - - - - -Avoid empty finally blocks - these can be deleted. - - - - - - - - - - Avoid empty switch statements. - - - - - - - - - -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. - - - - - - - - - - - Avoid jumbled loop incrementers - it's usually a mistake, and it's confusing even if it's what's intended. - - - - - - - - - - - diff --git a/pmd/rulesets/braces.xml b/pmd/rulesets/braces.xml deleted file mode 100644 index 8e9a3c99..00000000 --- a/pmd/rulesets/braces.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - -The Braces Ruleset contains a collection of braces rules. - - - - - - Avoid using if..else statements without using curly braces - - - - - - - - - - Avoid using 'while' statements without using curly braces - - - - - - - - - - Avoid using 'for' statements without using curly braces - - - - - - - - - - - Avoid using if statements without using curly braces - - - - - - - - - - - - - diff --git a/pmd/rulesets/design.xml b/pmd/rulesets/design.xml deleted file mode 100644 index ddd414f7..00000000 --- a/pmd/rulesets/design.xml +++ /dev/null @@ -1,176 +0,0 @@ - - - - -The Design Ruleset contains a collection of rules that find questionable designs. - - - - - - If you have a class that has nothing but static methods, consider making it a Singleton - - - - - - - - - - - Avoid using implementation types (i.e., HashSet); use the interface (i.e, Set) instead - - - - - - - - - - -Avoid unnecessary if..then..else statements when returning a boolean - - - - - - - - - - Switch statements should have a default label. - - - - - - - - - - A method should have only one exit point, and that should be the last statement in the method. - - - - 0) { - return "hey"; // oops, multiple exit points! - } - return "hi"; - } -} -]]> - - - - - - - Deeply nested if..then statements are hard to read. - - - - - -y) { - if (y>z) { - if (z==x) { - // this is officially out of control now - } - } - } - } -} -]]> - - - - - - -Reassigning values to parameters is a questionable practice. Use a temporary local variable instead. - - - - - - - - - - diff --git a/pmd/rulesets/favorites.xml b/pmd/rulesets/favorites.xml deleted file mode 100644 index a365581e..00000000 --- a/pmd/rulesets/favorites.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - -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 how to reference one ruleset from another. - - - - - - - - - - - - - - - - diff --git a/pmd/rulesets/junit.xml b/pmd/rulesets/junit.xml deleted file mode 100644 index 1983c165..00000000 --- a/pmd/rulesets/junit.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - -These rules deal with different problems that can occur with JUnit tests. - - - - - Some JUnit framework methods are easy to misspell. - - - - - - - - - - - The suite() method in a JUnit test needs to be both public and static. - - - - - - - - - - - diff --git a/pmd/rulesets/newrules.xml b/pmd/rulesets/newrules.xml deleted file mode 100644 index 50b5cfff..00000000 --- a/pmd/rulesets/newrules.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - -These are new rules for the next release - - - - - - - diff --git a/pmd/rulesets/rulesets.properties b/pmd/rulesets/rulesets.properties deleted file mode 100644 index 5a67aed6..00000000 --- a/pmd/rulesets/rulesets.properties +++ /dev/null @@ -1 +0,0 @@ -rulesets.filenames=rulesets/strings.xml,rulesets/junit.xml,rulesets/braces.xml,rulesets/basic.xml,rulesets/unusedcode.xml,rulesets/design.xml,rulesets/naming.xml,rulesets/imports.xml,rulesets/codesize.xml \ No newline at end of file diff --git a/pmd/pmd.jsl b/pmd/src/plugin-resources/pmd.jsl similarity index 100% rename from pmd/pmd.jsl rename to pmd/src/plugin-resources/pmd.jsl diff --git a/pmd/src/plugin-resources/rulesets/basic.xml b/pmd/src/plugin-resources/rulesets/basic.xml new file mode 100644 index 00000000..40a5b831 --- /dev/null +++ b/pmd/src/plugin-resources/rulesets/basic.xml @@ -0,0 +1,357 @@ + + + + +The Basic Ruleset contains a collection of good practices which everyone should follow. + + + + + + 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. + + + + + 1] + [count(*) = 0] + [../@Finally='false' or following-sibling::Block] + ]]> + + + + 3 + + + + + + + + + Empty If Statement finds instances where a condition is checked but nothing is done about it. + + 3 + + + + + + + + + + + + + + + + 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. + + + + + + + + + 3 + + + + + + + + + + Avoid empty try blocks - what's the point? + + + + + + + + + 3 + + + + + + + + + Avoid empty finally blocks - these can be deleted. + + + + + + + + + 3 + + + + + + + + + + Avoid empty switch statements. + + + + + + + + + 3 + + + + + + + + + + Avoid jumbled loop incrementers - it's usually a mistake, and it's confusing even if it's what's intended. + + + + + + + + + 3 + + + + + + + + + + Some for loops can be simplified to while loops - this makes them more concise. + + + + + 1][not(ForInit)][not(ForUpdate)] + ]]> + + + + 3 + + + + + + + + + Avoid unnecessary temporaries when converting primitives to Strings + + 3 + + + + + + + + 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. + + + + + + + + + 3 + + + + + + + + + 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. + + 1 + + + + + + + + + diff --git a/pmd/src/plugin-resources/rulesets/braces.xml b/pmd/src/plugin-resources/rulesets/braces.xml new file mode 100644 index 00000000..10b827a1 --- /dev/null +++ b/pmd/src/plugin-resources/rulesets/braces.xml @@ -0,0 +1,128 @@ + + + + +The Braces Ruleset contains a collection of braces rules. + + + + + Avoid using if statements without using curly braces + + + + + + + + + 3 + + + + + + + + + Avoid using 'while' statements without using curly braces + + + + + + + + + 3 + + + + + + + + + Avoid using if..else statements without using curly braces + + + + + 2][not(Statement/Block)] + ]]> + + + + 3 + + + + + + + + + Avoid using 'for' statements without using curly braces + + + + + + + + + 3 + + + + + + + + + + diff --git a/pmd/rulesets/codesize.xml b/pmd/src/plugin-resources/rulesets/codesize.xml similarity index 53% rename from pmd/rulesets/codesize.xml rename to pmd/src/plugin-resources/rulesets/codesize.xml index 8d9753f7..d252c550 100644 --- a/pmd/rulesets/codesize.xml +++ b/pmd/src/plugin-resources/rulesets/codesize.xml @@ -25,6 +25,7 @@ topscore - The Maximum Number of reports to generate. At this time, only one can be used at a time. + 3 @@ -64,6 +65,7 @@ topscore - The Maximum Number of reports to generate. At this time, only one can be used at a time. + 3 @@ -99,6 +101,7 @@ topscore - The Maximum Number of reports to generate. At this time, only one can be used at a time. + 3 @@ -118,6 +121,116 @@ public class Foo { + + +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) + + 3 + + + + + + + + + + + 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. + + 3 + + + + + + + + + diff --git a/pmd/src/plugin-resources/rulesets/controversial.xml b/pmd/src/plugin-resources/rulesets/controversial.xml new file mode 100644 index 00000000..8b643026 --- /dev/null +++ b/pmd/src/plugin-resources/rulesets/controversial.xml @@ -0,0 +1,169 @@ + + + + +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 :-) + + + + + 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. + + + + + + + + + 3 + + + + + + + + + + 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 :-) + + 3 + + + + + + + + A method should have only one exit point, and that should be the last statement in the method. + + 3 + + + 0) { + return "hey"; // oops, multiple exit points! + } + return "hi"; + } + } + ]]> + + + + + + Unused modifiers are, well, unused. + + + + + + + + + 3 + + + + + + + + Avoid assigments in operands; this can make code more complicated and harder to read. + + + + + + + + + 3 + + + + + + + + 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. + + 3 + + + + + + + + + + diff --git a/pmd/src/plugin-resources/rulesets/coupling.xml b/pmd/src/plugin-resources/rulesets/coupling.xml new file mode 100644 index 00000000..d86b3f76 --- /dev/null +++ b/pmd/src/plugin-resources/rulesets/coupling.xml @@ -0,0 +1,71 @@ + + + + + These are new rules for coupling + + + + + 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 + + 3 + + + + + + + + + + + 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. + + 3 + + + + + + + + + + + + diff --git a/pmd/src/plugin-resources/rulesets/design.xml b/pmd/src/plugin-resources/rulesets/design.xml new file mode 100644 index 00000000..6ce10860 --- /dev/null +++ b/pmd/src/plugin-resources/rulesets/design.xml @@ -0,0 +1,303 @@ + + + + +The Design Ruleset contains a collection of rules that find questionable designs. + + + + + + If you have a class that has nothing but static methods, consider making it a Singleton + + 3 + + + + + + + + + + Avoid using implementation types (i.e., HashSet); use the interface (i.e, Set) instead + + 3 + + + + + + + + + +Avoid unnecessary if..then..else statements when returning a boolean + + 3 + + + + + + + + + Switch statements should have a default label. + + + + + + + + + 3 + + + + + + + + + + + Deeply nested if..then statements are hard to read. + + 3 + + + + +y) { + if (y>z) { + if (z==x) { + // this is officially out of control now + } + } + } + } +} +]]> + + + + + + +Reassigning values to parameters is a questionable practice. Use a temporary local variable instead. + + 2 + + + + + + + + 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. + + 3 + + + + + + + + + + + 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. + + 1 + + + + + + + + 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. + + 3 + + + + + + diff --git a/pmd/rulesets/experimental.xml b/pmd/src/plugin-resources/rulesets/experimental.xml similarity index 100% rename from pmd/rulesets/experimental.xml rename to pmd/src/plugin-resources/rulesets/experimental.xml diff --git a/pmd/src/plugin-resources/rulesets/favorites.xml b/pmd/src/plugin-resources/rulesets/favorites.xml new file mode 100644 index 00000000..b051fd75 --- /dev/null +++ b/pmd/src/plugin-resources/rulesets/favorites.xml @@ -0,0 +1,24 @@ + + + + +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. + + + + + + + + + + + + + + + + + diff --git a/pmd/rulesets/imports.xml b/pmd/src/plugin-resources/rulesets/imports.xml similarity index 61% rename from pmd/rulesets/imports.xml rename to pmd/src/plugin-resources/rulesets/imports.xml index 17471601..090ad915 100644 --- a/pmd/rulesets/imports.xml +++ b/pmd/src/plugin-resources/rulesets/imports.xml @@ -11,6 +11,7 @@ These rules deal with different problems that can occur with a class' import sta Avoid duplicate import statements. + 4 + class="net.sourceforge.pmd.rules.XPathRule"> Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3). + + + + + + + + 4 Avoid unused import statements. + 4 + + + No need to import a type that's in the same package. + + 3 + + + + + diff --git a/pmd/src/plugin-resources/rulesets/junit.xml b/pmd/src/plugin-resources/rulesets/junit.xml new file mode 100644 index 00000000..38f2c5bd --- /dev/null +++ b/pmd/src/plugin-resources/rulesets/junit.xml @@ -0,0 +1,92 @@ + + + + +These rules deal with different problems that can occur with JUnit tests. + + + + + The suite() method in a JUnit test needs to be both public and static. + + + + + + + + + 3 + + + + + + + + + + Some JUnit framework methods are easy to misspell. + + + + + + + + + 3 + + + + + + + + + JUnit assertions should include a message - i.e., use the three argument version of + assertEquals(), not the two argument version. + + 3 + + + + + + + + + + + diff --git a/pmd/rulesets/naming.xml b/pmd/src/plugin-resources/rulesets/naming.xml similarity index 55% rename from pmd/rulesets/naming.xml rename to pmd/src/plugin-resources/rulesets/naming.xml index ffdec972..813b5138 100644 --- a/pmd/rulesets/naming.xml +++ b/pmd/src/plugin-resources/rulesets/naming.xml @@ -7,14 +7,21 @@ The Naming Ruleset contains a collection of rules about names - too long, too sh + message="Avoid variables with short names" + class="net.sourceforge.pmd.rules.XPathRule"> Detects when a field, local or parameter has a short name. - - - + + + + + + + + 3 + message="Avoid excessively long variable names" + class="net.sourceforge.pmd.rules.XPathRule"> Detects when a field, formal or local variable is declared with a big name. - - - + 3 + + + + 12] + ]]> + + + + message="Avoid using short method names" + class="net.sourceforge.pmd.rules.XPathRule"> Detects when very short method names are used. - - - + 3 + + + + + + + + + + +These are new rules for the next release + + + + + + + asdsad + + 3 + + + + + + + + + + + + + diff --git a/pmd/rulesets/strings.xml b/pmd/src/plugin-resources/rulesets/strings.xml similarity index 78% rename from pmd/rulesets/strings.xml rename to pmd/src/plugin-resources/rulesets/strings.xml index b013d19d..a45a3e2a 100644 --- a/pmd/rulesets/strings.xml +++ b/pmd/src/plugin-resources/rulesets/strings.xml @@ -8,10 +8,20 @@ These rules deal with different problems that can occur with String manipulation + class="net.sourceforge.pmd.rules.XPathRule"> Avoid instantiating String objects; this is usually unnecessary. + + + + + + + + 2 Code containing duplicate String literals can usually be improved by declaring the String as a constant field. + 3 @@ -52,6 +63,7 @@ public class Foo { Avoid calling toString() on String objects; this is unnecessary + 3 - @@ -13,6 +12,7 @@ The Unused Code Ruleset contains a collection of rules that find unused code. Unused Private Field detects when a private field is declared that is not used by the class. + 3 + 3 Unused Private Method detects when a private method is declared but is unused. + 3 Avoid passing parameters to methods and then not using those parameters. + 3 - - -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. - - - - - diff --git a/pmd/xdocs/changes.xml b/pmd/xdocs/changes.xml index 32eb4a3e..4bc45e08 100644 --- a/pmd/xdocs/changes.xml +++ b/pmd/xdocs/changes.xml @@ -9,6 +9,12 @@ + + Make the plugin work with Maven b9. + + + Added support for PMD 1.04. + Moved the PMD plugin from the Maven-Plugins SF project