diff --git a/pmd/LICENSE.txt b/pmd/LICENSE.txt new file mode 100644 index 00000000..c7fddaed --- /dev/null +++ b/pmd/LICENSE.txt @@ -0,0 +1,57 @@ + + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Wiki Maven Plugin" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Interactive Maven Plugin", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ diff --git a/pmd/plugin.jelly b/pmd/plugin.jelly new file mode 100644 index 00000000..9ac3814e --- /dev/null +++ b/pmd/plugin.jelly @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Running the PMD task with ${maven.pmd.rulesetfiles} ... + + + + + + + + + + + Converting the PMD report to XDOC ... + + + + + + diff --git a/pmd/plugin.properties b/pmd/plugin.properties new file mode 100644 index 00000000..42a851fd --- /dev/null +++ b/pmd/plugin.properties @@ -0,0 +1,14 @@ +# ------------------------------------------------------------------- +# P L U G I N P R O P E R I E S +# ------------------------------------------------------------------- +# PMD plugin. +# ------------------------------------------------------------------- + +# enable/disable PMD + +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 diff --git a/pmd/pmd.jsl b/pmd/pmd.jsl new file mode 100644 index 00000000..8e982780 --- /dev/null +++ b/pmd/pmd.jsl @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + PMD Results + + + +
+

+ The following document contains the results of + PMD. +

+
+ +
+ + + + + + + + + + + +
FilesErrors
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
FilesViolations
+ ${name} +
+ + + + + + + + + + + + + + + + + + + + + +
ViolationLine
+ + ${htmlescape.getText(errorMessage)} + + + + + + + + + ${line} + + + ${line} + + +
+
+
+
+
+ +
+
+
diff --git a/pmd/project.properties b/pmd/project.properties new file mode 100644 index 00000000..b443601d --- /dev/null +++ b/pmd/project.properties @@ -0,0 +1 @@ +maven.xdoc.date = bottom diff --git a/pmd/project.xml b/pmd/project.xml new file mode 100644 index 00000000..768ef821 --- /dev/null +++ b/pmd/project.xml @@ -0,0 +1,109 @@ + + + + 3 + maven-pmd-plugin + Maven PMD Plug-in + 0.5 + + SourceForge + http://www.sourceforge.net/projects/maven-plugins/ + http://sourceforge.net/sflogo.php?group_id=61626&type=5 + + 2002 + org.apache.maven + http://jakarta.apache.org/turbine/maven/images/maven.jpg + + + jakarta + + + This plugin provides a more or less seamless integration + with Maven and the PMD static source code analyzer + + + Maven Plugin for PMD + + http://maven-plugins.sourceforge.net/pmd/ + http://nagoya.apache.org/scarab/servlet/scarab/ + maven-plugins.sf.net + /home/groups/m/ma/maven-plugins/htdocs/pmd/ + /home/groups/m/ma/maven-plugins/htdocs/pmd/distributions/ + + + scm:cvs:pserver:anoncvs@cvs.maven-plugins.sourceforge.net:/cvsroot/maven-plugins/:maven-plugins/pmd + http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/maven-plugins/maven-plugins/pmd/ + + + + + Maven-Plugins User List + maven-plugins-developer-subscribe@lists.sourceforge.net + maven-plugins-user-unsubscribe@lists.sourceforge.net + http://sourceforge.net/mailarchive/forum.php?forum_id=11777 + + + Maven-Plugins Developer List + maven-plugins-developer-subscribe@lists.sourceforge.net + maven-plugins-developer-unsubscribe@lists.sourceforge.net + http://sourceforge.net/mailarchive/forum.php?forum_id=11782 + + + Maven-Plugins CVS Commits List + ${pom.id}-cvs-subscribe@lists.sourceforge.net + ${pom.id}-cvs-unsubscribe@lists.sourceforge.net + http://sourceforge.net/mailarchive/forum.php?forum_id=11781 + + + + + + Siegfried Goeschl + wdsgoe + siegfried.goeschl@it20one.at + IT20one + + Software Developer + + + + Martin Poeschl + mpoeschl + mpoeschl@marmot.at + Tucana.at + + Software Developer + + + + + + + pmd + 1.03 + http://pmd.sourceforge.net + + root + + + + + + + + ${basedir} + + plugin.jelly + plugin.properties + project.properties + project.xml + pmd.jsl + rulesets/** + + + + + + + + diff --git a/pmd/rulesets/basic.xml b/pmd/rulesets/basic.xml new file mode 100644 index 00000000..0e0a286a --- /dev/null +++ b/pmd/rulesets/basic.xml @@ -0,0 +1,209 @@ + + + + +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 new file mode 100644 index 00000000..8e9a3c99 --- /dev/null +++ b/pmd/rulesets/braces.xml @@ -0,0 +1,92 @@ + + + + +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/codesize.xml b/pmd/rulesets/codesize.xml new file mode 100644 index 00000000..8d9753f7 --- /dev/null +++ b/pmd/rulesets/codesize.xml @@ -0,0 +1,124 @@ + + + + +The Code Size Ruleset contains a collection of rules that find code size related problems. + + + + + +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. + + + + + + + + + + + + + + +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. + + + + + + + + + + + + + + +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. + + + + + + + + + + + + + + + diff --git a/pmd/rulesets/design.xml b/pmd/rulesets/design.xml new file mode 100644 index 00000000..ddd414f7 --- /dev/null +++ b/pmd/rulesets/design.xml @@ -0,0 +1,176 @@ + + + + +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/experimental.xml b/pmd/rulesets/experimental.xml new file mode 100644 index 00000000..01510879 --- /dev/null +++ b/pmd/rulesets/experimental.xml @@ -0,0 +1,90 @@ + + + + +This is the sandbox. + + + + + + + diff --git a/pmd/rulesets/favorites.xml b/pmd/rulesets/favorites.xml new file mode 100644 index 00000000..a365581e --- /dev/null +++ b/pmd/rulesets/favorites.xml @@ -0,0 +1,23 @@ + + + + +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/imports.xml b/pmd/rulesets/imports.xml new file mode 100644 index 00000000..17471601 --- /dev/null +++ b/pmd/rulesets/imports.xml @@ -0,0 +1,75 @@ + + + + +These rules deal with different problems that can occur with a class' import statements. + + + + + Avoid duplicate import statements. + + + + + + + + + + Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3). + + + + + + + + + + Avoid unused import statements. + + + + + + + + + + + diff --git a/pmd/rulesets/junit.xml b/pmd/rulesets/junit.xml new file mode 100644 index 00000000..1983c165 --- /dev/null +++ b/pmd/rulesets/junit.xml @@ -0,0 +1,48 @@ + + + + +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/naming.xml b/pmd/rulesets/naming.xml new file mode 100644 index 00000000..ffdec972 --- /dev/null +++ b/pmd/rulesets/naming.xml @@ -0,0 +1,85 @@ + + + + +The Naming Ruleset contains a collection of rules about names - too long, too short, and so forth. + + + + + +Detects when a field, local or parameter has a short name. + + + + + + + + + + + +Detects when a field, formal or local variable is declared with a big name. + + + + + + + + + + + +Detects when very short method names are used. + + + + + + + + + + + + + diff --git a/pmd/rulesets/newrules.xml b/pmd/rulesets/newrules.xml new file mode 100644 index 00000000..50b5cfff --- /dev/null +++ b/pmd/rulesets/newrules.xml @@ -0,0 +1,12 @@ + + + + +These are new rules for the next release + + + + + + + diff --git a/pmd/rulesets/rulesets.properties b/pmd/rulesets/rulesets.properties new file mode 100644 index 00000000..5a67aed6 --- /dev/null +++ b/pmd/rulesets/rulesets.properties @@ -0,0 +1 @@ +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/rulesets/strings.xml b/pmd/rulesets/strings.xml new file mode 100644 index 00000000..b013d19d --- /dev/null +++ b/pmd/rulesets/strings.xml @@ -0,0 +1,71 @@ + + + + +These rules deal with different problems that can occur with String manipulation. + + + + + + Avoid instantiating String objects; this is usually unnecessary. + + + + + + + + + +Code containing duplicate String literals can usually be improved by declaring the String as a constant field. + + + + + + + + + + + + Avoid calling toString() on String objects; this is unnecessary + + + + + + + + + + + diff --git a/pmd/rulesets/unusedcode.xml b/pmd/rulesets/unusedcode.xml new file mode 100644 index 00000000..947fe5f9 --- /dev/null +++ b/pmd/rulesets/unusedcode.xml @@ -0,0 +1,105 @@ + + + + +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. + + + + + + + + +Unused Local Variables detects when a variable is declared, but not +used (except for possibly initial assignment) + + + + + + + + + + + +Unused Private Method detects when a private method is declared but is unused. + + + + + + + + + +Avoid passing parameters to methods and then not using those parameters. + + + + + + + + + +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 new file mode 100644 index 00000000..32eb4a3e --- /dev/null +++ b/pmd/xdocs/changes.xml @@ -0,0 +1,52 @@ + + + + Changes + Siegfried Goeschl + Vincent Massol + + + + + + + Moved the PMD plugin from the + Maven-Plugins SF project + to the Maven project. + + + + + + Updated to used PMD 1.03 + + + Updated to work for maven-1,0-beta8 + + + + + + PMD can be enabled/disabled by setting maven.pmd.enable + + + Upgraded to PMD 1.01 and removed the DVSLPath Tool + since it is not longer needed + + + Added files for integration with the existing maven-plugin buikd + + + Tom Copeland fixed some stuff in the Jelly script + + + + + + Updated to used PMD 1.0 + + + + + + diff --git a/pmd/xdocs/how-to.xml b/pmd/xdocs/how-to.xml new file mode 100644 index 00000000..2a80c39c --- /dev/null +++ b/pmd/xdocs/how-to.xml @@ -0,0 +1,68 @@ + + + + + Maven PMD Plug-in How To + Siegfried Goeschl + + + +
+ + +

+ 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 +

+

+ The simple way is to define the property in + $MAVEN_HOME/bin/driver.properties +

+
+ + +

+ 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. + Simple put "maven.pmd.enable=false" into your project properties +

+
+ + +

+ 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. +

+

+ In other case you change the trigger of the rules directly in the + ruleset files to fine tune the reports. +

+
+ + +

+ "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 ... ;-) +

+

+ The JAR picked up the plugin is defined in + $MAVEN_HOME/plugins/pmd/project.xml and can be + changed. +

+

+ Leave it, try it but don't whine will I have to carve + out a living with some paid work ... :-[] +

+
+ +
+ + + +
diff --git a/pmd/xdocs/images/sample.gif b/pmd/xdocs/images/sample.gif new file mode 100644 index 00000000..c6a7ebbd Binary files /dev/null and b/pmd/xdocs/images/sample.gif differ diff --git a/pmd/xdocs/index.xml b/pmd/xdocs/index.xml new file mode 100644 index 00000000..1d112b63 --- /dev/null +++ b/pmd/xdocs/index.xml @@ -0,0 +1,107 @@ + + + + + + Maven PMD Plug-in + Siegfried Goeschl + + + +
+ +

+ This plugin generates a report of the PMD static source code + analyzer. +

+ + + +

+ 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 +

+ +

+ 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. +

+ +

+ Run "maven -g" and look out for documented PMD goals. + If you see some then the unpacking succeeded. +

+ +

+ The PMD plugin can be started through "maven pmd" + or integrated by using the following code snippet in + maven.xml: +

+ + + + + + +]]> + + +

+ The generated report has to be added manually to the + website which is usually done with navigation.xml. +

+ + + + + + + +]]> + + +

+ Another way to integrate the PMD plugin is to add it to the <reports> + section in your project.xml: +

+ + + + maven-jdepend-plugin + maven-checkstyle-plugin + maven-pmd-plugin + maven-changelog-plugin + maven-file-activity-plugin + maven-developer-activity-plugin + maven-javadoc-plugin + maven-jxr-plugin + maven-junit-report-plugin + maven-tasklist-plugin + +]]> + + +
+ + + +

+ And last but not least - thanks to + Together Teamlösungen for + their support of Open Source Software and their contributions + such as Enhydra Application + Server 5.0 ("Aonyx") and a couple of Maven plugins. +

+ +
+ +
+ + + +
diff --git a/pmd/xdocs/navigation.xml b/pmd/xdocs/navigation.xml new file mode 100644 index 00000000..0b5787be --- /dev/null +++ b/pmd/xdocs/navigation.xml @@ -0,0 +1,18 @@ + + + + + Maven PMD Plugin + + + + + + + + + + + + + diff --git a/pmd/xdocs/properties.xml b/pmd/xdocs/properties.xml new file mode 100644 index 00000000..9b02180a --- /dev/null +++ b/pmd/xdocs/properties.xml @@ -0,0 +1,36 @@ + + + + + PMD Plug-in Properties + Siegfried Goeschl + + + +
+ + + + + + + + + + + + + + + + +
PropertyOptional?Description
maven.pmd.enableNo + Enable/disable the PMD plugin. Has to be set to "true" + to enable the plugin +
maven.pmd.rulesetfilesYes + Defines the rule to be used for running PMD. Is + already defined in the plugin +
+
+ +
diff --git a/pmd/xdocs/tasks.xml b/pmd/xdocs/tasks.xml new file mode 100644 index 00000000..b1f9b193 --- /dev/null +++ b/pmd/xdocs/tasks.xml @@ -0,0 +1,22 @@ + + + + + Tasks + Siegfried Goeschl + + + +
+ +
    +
  • + Add a description of the violation if the PMD report + contains more metadata +
  • +
+
+
+ +
+