1:下载pmd
下载pmd-bin-5.8.1.zip(pmd主包配置文件)下载地址:https://sourceforge.net/projects/pmd/files/pmd/5.8.1/pmd-bin-5.8.1.zip/download
2:解压pmd-bin-5.8.1.zip
unzip pmd-bin-5.8.1.zip
3:写相应的ant脚本,如在build.xml中,可以加入下面的target,pmd在/opt/pmd/pmd-5.8.1下,java包在/root/.hudson/jobs/svn-test/workspace下:
<project name="pmd" default="pmd.check" basedir=".">
<!--声明pmdm相关的jar包-->
<path id="pmd.path">
<fileset dir="/opt/pmd/pmd-5.8.1/lib">
<include name="**/*.jar" />
</fileset>
</path>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.path"/>
<target name="pmd">
<pmd shortFilenames="true">
<!--声明pdm检查标准文件-->
<ruleset>rulesets/java/design.xml,rulesets/java/imports.xml,java-unusedcode</ruleset>
<!--生成pdm xml报表的文件和路径-->
<formatter type="xml" toFile="/root/.hudson/jobs/svn-test/workspace/pmd.xml" toConsole="false"/>
<!--生成pdm要检查的项目路径、相关jar和java代码-->
<fileset dir="/root/.hudson/jobs/svn-test/workspace">
<include name="**/*.jar"/>
<include name="**/*.java"/>
</fileset>
</pmd>
</target>
</project>
4:配置hudson执行build.xml中的ant脚本
5:配置Hudson,下载Hudson的PMD Plug-in,进入到工程配置界面,找到Post-build Actions项,里面多出一个Publish PMD analysis results选项。做相应的配置,根据不同的项目要求设置不同的配置,可参照Help.
6:运行工程。可得到如下结果:
图示1:
图示2:
图示3:
文章末尾固定信息
评论