1

Found a X line (Y tokens) duplication in the following files: ...我想将 CPD 修改为仅在生成报告时吐出,即禁止源代码行。我有 /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;
}

但是报告没有改变。我是一个 Java 新手,所以请记住这一点。我是否需要以某种方式在 Eclipse 中重建 pmd-4.2.x?

4

1 回答 1

2

有不同的方法可以实现这一点:

  1. 使用 egrep 完全不修改 PMD/CPD。例如,您可以对报告进行后过滤:

    bin/run.sh cpd --minimum-tokens 100 --files src --encoding UTF-8 \
      | egrep "^Found a |^Starting at line "
    

    这将现在只输出以“Found a”或“Starting at line”开头的行。

  2. 修改 PMD/CPD 以调整报告格式。不过,我建议将此修改后的报告格式作为单独的格式来实现,例如将其命名为“text_without_sources”,而不是更改默认格式。然后,您将使用bin/run.sh cpd --format text_without_sources ....

    在这种情况下,您需要从源代码构建 PMD。PMD 使用Maven构建(开发过程中可以使用 eclipse - 但包是用 maven 构建的)。在来自https://github.com/pmd/pmdmvn clean package的克隆源的顶级目录中之后,您将在目录中找到二进制文件。pmd-dist/target/

    查看报告是如何集成到CPDConfiguration.java中的——您可以添加自己的 SimpleRenderer 版本。

  3. 在https://sourceforge.net/p/pmd/bugs/创建一个功能请求

于 2015-11-01T17:39:49.290 回答