[英]How to change PMD's Copy Paste Detector (CPD) report output
I'd like to modify CPD to only spit out the Found a X line (Y tokens) duplication in the following files: ...
when generating a report, ie suppress the source lines of code. 我想将CPD修改为仅
Found a X line (Y tokens) duplication in the following files: ...
吐出“ Found a X line (Y tokens) duplication in the following files: ...
生成报告时,即取消源代码行。 I have the /src/ files and attempted to modify SimpleRenderer.java in /src/net/sourceforge/pmd/cpd/ by commenting out 我有/ src /文件,并试图通过注释掉来修改/ src / net / sourceforge / pmd / cpd /中的SimpleRenderer.java
String source = match.getSourceCodeSlice();
if (trimLeadingWhitespace) {
String[] lines = source.split("[" + PMD.EOL + "]");
int trimDepth = StringUtil.maxCommonLeadingWhitespaceForAll(lines);
if (trimDepth > 0) {
lines = StringUtil.trimStartOn(lines, trimDepth);
}
for (int i=0; i<lines.length; i++) {
rpt.append(lines[i]).append(PMD.EOL);
}
return;
}
However the report has not changed. 但是该报告没有更改。 I'm a bit of a Java novice, so keep that in mind.
我是Java的新手,因此请记住这一点。 Do I need to rebuild the pmd-4.2.x in Eclipse somehow?
我是否需要以某种方式在Eclipse中重建pmd-4.2.x?
There are different ways to achieve this: 有多种方法可以实现此目的:
Without modifying PMD/CPD at all by using egrep. 完全不使用egrep修改PMD / CPD。 You can eg post-filter the report:
您可以例如对报告进行后过滤:
bin/run.sh cpd --minimum-tokens 100 --files src --encoding UTF-8 \\ | egrep "^Found a |^Starting at line "
This would output now only the lines which start with "Found a " or "Starting at line ". 现在仅输出以“ Found a”或“ Starting at line”开头的行。
Modifying PMD/CPD to adjust the report format. 修改PMD / CPD以调整报告格式。 I would however suggest, to implement this modified report format as a separate format, eg naming it "text_without_sources", rather than changing the default format.
但是,我建议将这种修改后的报告格式实现为单独的格式,例如将其命名为“ text_without_sources”,而不是更改默认格式。 You would then call CPD with
bin/run.sh cpd --format text_without_sources ...
. 然后,您将使用
bin/run.sh cpd --format text_without_sources ...
调用CPD。
In that case, you'll need to build PMD from sources. 在这种情况下,您将需要从源代码构建PMD。 PMD uses Maven to build (you can use eclipse during development - but the package is built with maven).
PMD使用Maven进行构建(您可以在开发过程中使用eclipse-但该软件包是使用maven进行构建的)。 After a
mvn clean package
in the top-directory of the cloned sources from https://github.com/pmd/pmd you'll find the binary in the directory pmd-dist/target/
. 在来自https://github.com/pmd/pmd的克隆源的顶级目录中的
mvn clean package
,您将在目录pmd-dist/target/
找到二进制文件。
Look at how the reports are integrated in CPDConfiguration.java - you can add your own version of the SimpleRenderer. 查看报告如何在CPDConfiguration.java中集成-您可以添加自己的版本的SimpleRenderer。
Create a feature-request at https://sourceforge.net/p/pmd/bugs/ 在https://sourceforge.net/p/pmd/bugs/创建功能请求
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.