PMD使用手册
- 文中测试例子均采用JHotDraw7源码,官网关于 JHotDraw的检测结果:http://pmd.sourceforge.net/reports/jhotdraw_JHotDraw.html
- 下载地址:https://sourceforge.net/projects/pmd/files/pmd/5.1.0/
- 安装:解压到任意目录。
3. 使用方法:
3.1 使用命令行:(Windows下)
命令行进入PMD安装目录,bin文件夹,执行命令:
基本命令:pmd -d C:\Users\lsp\Desktop\svn\jhotdraw7\src -f html -R rulesets/java/unusedcode.xml
其中 C:\Users\lsp\Desktop\svn\jhotdraw7\src为所需要分析源码绝对路径,可以是文件夹也可以是单个文件。
-R 表示的采用的检测规则。 此规则都存在于

Rulesets下有多种语言的规则,Java下又包含多种规则,在命令行每次只能检测单个规则(暂时未发现多条规则应用于一次检测),也可以自定义规则,具体怎么定义参见官网。
-f 设置检测结果输出格式,html, xml,text, csv,
该工具默认命令行检测结果输出到控制台,可以通过-r参数导出检测结果:如D:\Program Files\pmd-bin-5.1.0\bin>pmd -d C:\Users\lsp\Desktop\svn\jhotdraw7\src -f html -r D:\pmdreport\PMDoutput.html -R rulesets/java/unusedcode.xml
其他参数:
|
参数 |
说明 |
默认值 |
|
-auxclasspath |
specifies the classpath for libraries used by the source code. This is used by the type resolution.Alternatively, a 'file://' URL to a text file con |
|
|
-benchmark, -b |
Benchmark mode - output a benchmark report upon completion; default to System.err |
False |
|
-dir, -d |
root directory for sources |
|
|
-encoding, -e |
specifies the character set encoding of the source code files PMD is reading (i.e., UTF-8) |
UTF-8 |
|
-format, -f |
report format type |
text |
|
-language, -l |
specify a language PMD should use |
java |
|
-minimumpriority, -min |
rule priority threshold; rules with lower priority than they will not be used |
Low |
|
-property, -P |
{name}={value}: define a property for the report |
{} |
|
-reportfile, -r |
send report output to a file; |
System.out |
|
-rulesets, -R |
comma separated list of rulesets name to use |
|
|
-shortnames |
prints shortened filenames in the report |
false |
|
-showsuppressed |
report should show suppressed rule violations |
false |
|
-stress, -S |
performs a stress test |
|
|
-suppressmarker |
specifies the String that marks the a line which PMD should ignore; default is NOPMD |
NOPMD |
|
-threads, -t |
set the number of threads used by PMD |
1 |
|
-uri, -u |
Database URI for sources |
|
|
-debug, -verbose, -D, -V |
Debug mode |
false |
|
-version, -v |
specify version of a language PMD should use |
1.8 |
3.2 Ant
在项目路径下build.xml文件中加入:
D:\Program Files\pmd-bin-5.1.0\lib为pmd安装路径下的lib
C:\Users\lsp\Desktop\svn\jhotdraw7\src\源码路径
D:\pmdreport\pmd_report.xml分析结果文件
<formatter type="xml" toFile="D:\pmdreport\pmd_report.xml"/> 格式化输出xml
<formatter type="net.sourceforge.pmd.renderers.HTMLRenderer" toFile="D:\pmdreport\foo.html"/> 格式化输出HTML
<path id="pmd.classpath">
<pathelement location="${build}"/>
<fileset dir="D:\Program Files\pmd-bin-5.1.0\lib">
<include name="*.jar"/>
</fileset>
</path>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.classpath"/>
<target name="pmd">
<pmd rulesetfiles="rulesets/java/imports.xml,java-unusedcode">
<formatter type="xml" toFile="D:\pmdreport\pmd_report.xml"/>
<fileset dir="C:\Users\lsp\Desktop\svn\jhotdraw7\src\">
<include name="**/*.java"/>
</fileset>
</pmd>
</target>
3.3 Maven
使用maven插件检测较为简单,只需在pom.xml文件中加入:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
</plugin>
执行mvn pmd:pmd
即可在target文件夹下看到以下文件:

即违反规则的报告文件,每个规则对应一个xml文件。也可以配置规则。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<rulesets>
<ruleset>/rulesets/braces.xml</ruleset>
<ruleset>/rulesets/naming.xml</ruleset>
</rulesets>
</configuration>
</plugin>
3.4 Eclipse Ide
安装网址: http://sourceforge.net/projects/pmd/files/pmd-eclipse/update-site/
安装完右键项目或文件:选择PMD->check code即可使用PMD工具检查代码。
选择PMD-->Find suspect cut and paste。检查结果会放在reports目录下
PMD使用手册的更多相关文章
- java注释指导手册
译文出处: Toien Liu 原文出处:Dani Buiza 编者的话:注解是java的一个主要特性且每个java开发者都应该知道如何使用它. 我们已经在Java Code Geeks提供了丰富 ...
- DPDK2.1开发者手册4-7
Mempool Labrary 一个内存池(memory pool)就是固定大小对象的分配器.在dpdk中,它是通过名字来标示唯一性的,且使用环形队列来保存没有使用的空闲对象.它提供了一些可选项服务例 ...
- DPDK2.1开发者手册3-4
环境抽象层EAL 环境抽象层的任务对访问底层资源例如硬件和内存提供入口.它提供了隐藏应用和库的特殊性性的通用接口.它的责任是初始化分配资源(内存,pci设备,定时器,控制台等等). EAL提供的典型服 ...
- DPDK2.1开发者手册1-2
Programmer’s Guide Release 2.1.0 翻译的目的是强化自己对dpdk的理解,看看2.1版本和现在使用的版本的差异,其次就是可能要走了,为那些要上手dpdk,但是又不想看英文 ...
- DPDK2.1 linux上开发入门手册
1引言 本文档主要包含INTEL DPDK安装和配置说明.目的是让用户快速的开发和运行程序.文档描述了如何在不深入细节的情况下在linux应用开发环境上编译和运行一个DPDK应用程序. 1.1文档总览 ...
- 使用PMD进行代码审查
很久没写博客了,自从上次写的设计模式的博客被不知名的鹳狸猿下架了一次之后兴趣大减,那时候就没什么兴致写博客了,但是这段时间还没有停下来,最近也在研究一些其他的东西,目前有点想做点东西的打算,但好像也没 ...
- 白盒静态自动化测试工具:PMD使用指南
参考文献:http://www.oschina.net/p/pmd/http://www.cnblogs.com/flyme/archive/2011/09/09/2172548.htmlhttp:/ ...
- 使用PMD进行代码审查(转)
原文地址:使用PMD进行代码审查 很久没写博客了,自从上次写的设计模式的博客被不知名的鹳狸猿下架了一次之后兴趣大减,那时候就没什么兴致写博客了,但是这段时间还没有停下来,最近也在研究一些其他的东西,目 ...
- Java 注解指导手册 – 终极向导
原文链接 原文作者:Dani Buiza 译者:Toien Liu 校对:深海 编者的话:注解是java的一个主要特性且每个java开发者都应该知道如何使用它. 我们已经在Java Code Gee ...
随机推荐
- 关于移动div的具体实现(js)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 关于webapp的一个webframe问题
最近重启ios webapp的项目,将之前的框架拿过来发现出现了错误,错误出现在写JSAlart控件的WebFrame上,xcode会报WebFrame是未定义的错误.由于之前使用的是ios5的 sd ...
- Safari浏览器的调试
最近做浏览器兼容的时候发现Safari的脚本调试工具比较难找,因此与大家分享一下 1.找到脚本调试的选项 2.勾选此选项 3.在页面空白处右击打开调试窗口 4.看到下方的调试窗口了 细心的读者会发现, ...
- Make body have 100% of the browser height
Try setting the height of the html element to 100% as well. html, body { height: 100%; } Body looks ...
- Objective-C 入门(给新人的)
http://www.hengxinsoft.com/2010/12/objective-c-%E5%85%A5%E9%97%A8%EF%BC%88%E7%BB%99%E6%96%B0%E4%BA%B ...
- Codeforces Round #315 (Div. 2)
这次可以说是最糟糕的一次比赛了吧, 心没有静下来好好的去思考, 导致没有做好能做的题. Problem_A: 题意: 你要听一首时长为T秒的歌曲, 你点击播放时会立刻下载好S秒, 当你听到没有加载到的 ...
- 欧拉计划 NO05 ps:4题想过,好做,但麻烦,有时间补充,这题也不难!
问题重述: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without an ...
- codeforces C. Jzzhu and Chocolate
http://codeforces.com/contest/450/problem/C 题意:一个n×m的矩形,然后可以通过横着切竖着切,求切完k次之后最小矩形面积的最大值. 思路:设k1为横着切的次 ...
- 【POJ2417】baby step giant step
最近在学习数论,然而发现之前学的baby step giant step又忘了,于是去翻了翻以前的代码,又复习了一下. 觉得总是忘记是因为没有彻底理解啊. 注意baby step giant step ...
- 纯CSS打造可折叠树状菜单
1:Html代码 <li> <label for="subsubfolder1">下级</label> <input id="s ...