PMD ruleset file
I am trying to figure where is the default ruleset file, name of the default ruleset file and how do we add our own rules to it. I tried to google, but that is just confusing me. S开发者_如何学编程o far, I have put the pmd plugin inside eclipse plugins folder and in preferences I can see PMD.
The standard ruleset file is *.xml inside pmd-bin-x.x.x.zip/.../lib/pmd-x.x.x.jar/rulesets/, refer to http://pmd.sourceforge.net/rules/index.html.
The default ruleset file of PMD Eclipse Plugin is inside pmd___.jar in your {IDE}/plugins/..., but you should not make any changes in that file. Add/edit the rules in Eclipse Preferences, any changes will take precedence over the default ruleset.
After messing with Ant and PMD for a good long while, this is the complete solution I have come up with. Modify to your own taste.
This sets the initial directories I use.
<property name="doc" location="doc" /> <!-- Root for all documentation: -->
<property name="pmddoc" location="${doc}/pmddoc" /> <!-- PMD results -->
This is my task definition, which points to the latest version of PMD at this time where I have it stored. It includes the PMD Jar itself (where all the rules are stored) and all PMD's dependencies as well.
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask">
<classpath>
<fileset dir="C:\development\pmd-bin-5.0-alpha">
<include name="lib/*.jar"/> <!-- also includes pmd's file, which has all the rulesets I need. -->
</fileset>
</classpath>
</taskdef>
In initialization, I create the documentation folder if needed:
<target name="init">
<mkdir dir="${pmddoc}" />
</target>
...And finally, I created a target specifically for creating a PMD report in HTML form. Here it is.
<target name="pmd" depends="init">
<pmd>
<formatter type="html" toFile="${pmddoc}/pmd_src_report.html" toConsole="true"/>
<ruleset>rulesets/java/basic.xml</ruleset> <!-- references file in PMD's .jar -->
<!-- Files PMD will test. -->
<fileset dir="${src}">
<include name="**/*.java"/> <!-- required to avoid firing off .aj errors. This ruleset doesn't support AspectJ. -->
</fileset>
</pmd>
</target>
精彩评论