日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

PMD使用手册

發布時間:2024/1/3 综合教程 31 生活家
生活随笔 收集整理的這篇文章主要介紹了 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:UserslspDesktopsvnjhotdraw7src -f html -R rulesets/java/unusedcode.xml

其中 C:UserslspDesktopsvnjhotdraw7src為所需要分析源碼絕對路徑,可以是文件夾也可以是單個文件。

-R 表示的采用的檢測規則。 此規則都存在于

Rulesets下有多種語言的規則,Java下又包含多種規則,在命令行每次只能檢測單個規則(暫時未發現多條規則應用于一次檢測),也可以自定義規則,具體怎么定義參見官網。

-f 設置檢測結果輸出格式,html, xml,text, csv,

該工具默認命令行檢測結果輸出到控制臺,可以通過-r參數導出檢測結果:如D:Program Filespmd-bin-5.1.0in>pmd -d C:UserslspDesktopsvnjhotdraw7src -f html -r D:pmdreportPMDoutput.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 Filespmd-bin-5.1.0lib為pmd安裝路徑下的lib

C:UserslspDesktopsvnjhotdraw7src源碼路徑

D:pmdreportpmd_report.xml分析結果文件

<formatter type="xml" toFile="D:pmdreportpmd_report.xml"/> 格式化輸出xml

<formatter type="net.sourceforge.pmd.renderers.HTMLRenderer" toFile="D:pmdreportfoo.html"/> 格式化輸出HTML

<path id="pmd.classpath">
 <pathelement location="${build}"/>
 <fileset dir="D:Program Filespmd-bin-5.1.0lib">
 <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:pmdreportpmd_report.xml"/>
 <fileset dir="C:UserslspDesktopsvnjhotdraw7src">
 <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-->Findsuspectcutandpaste。檢查結果會放在reports目錄下

總結

以上是生活随笔為你收集整理的PMD使用手册的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。