PMD ruleset file

匿名 (未验证) 提交于 2019-12-03 02:55:01

问题:

I am new to PMD. 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. So far, I have put the pmd plugin inside eclipse plugins folder and in preferences I can see PMD.

Can anyone please hep me with this?

Thanks, Nisha

回答1:

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.



回答2:

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> 


文章来源: PMD ruleset file
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!