有没有办法告诉PMD忽略检查部分代码是否有重复?
例如,我可以这样做:
// CPD-Ignore-On
...
// CPD-Ignore-Off
Run Code Online (Sandbox Code Playgroud)
目前我使用Maven设置这样的PMD,但是除非我遗漏了什么,否则看不到任何想让我做我想做的事情.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
<configuration>
<minimumTokens>40</minimumTokens>
<targetJdk>1.5</targetJdk>
<ignoreIdentifiers>true</ignoreIdentifiers>
<ignoreLiterals>true</ignoreLiterals>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud) 我试图在我的python代码库上运行CPD的GUI版本,但即使我将min chunk size设置为1,也不会返回重复的代码.
我的代码不是很好.
有没有人在python项目上运行CPD有任何成功?
我们使用PMD复制粘贴检测器(CPD)来分析我们的C和C++代码.但是,代码的一些部分非常相似,但有充分的理由,我们希望抑制这些部分的警告.
PMD CPD的文档仅提及有关注释的内容,但这对我们的这些语言不起作用.
我怎样才能忽略特定部件的警告?
也许有评论吗?
[更新]我正在使用以下Groovy脚本来运行CPD:
@GrabResolver(name = 'jcenter', root = 'https://jcenter.bintray.com/')
@Grab('net.sourceforge.pmd:pmd-core:5.4.+')
@Grab('net.sourceforge.pmd:pmd-cpp:5.4.+')
import net.sourceforge.pmd.cpd.CPD
import net.sourceforge.pmd.cpd.CPDConfiguration
import java.util.regex.Pattern
def tokens = 60
def scanDirs = ['./path/to/scan', './scan/this/too']
def ignores = [
'./ignore/this/path',
'./this/must/be/ignored/too'
].collect({ it.replace('/', File.separator) })
def rootDir = new File('.')
def outputDir = new File('./reports/analysis/')
def filename_date_format = 'yyyyMMdd'
def encoding = System.getProperty('file.encoding')
def language_converter = new CPDConfiguration.LanguageConverter()
def config = new CPDConfiguration()
config.language = new CPDConfiguration.LanguageConverter().convert('c')
config.minimumTileSize = tokens
config.renderer = …Run Code Online (Sandbox Code Playgroud) 我找不到如何告诉PMD-CPD跳过特定方法的选项.我们使用生成equals()和hashCode()方法,因此这些方法看起来非常相似,并且CPD将很多方法报告为重复代码.
我可以//NOPMD在代码中使用一些注释,但在我看来,如何管理我的代码并不是什么方法.因为我在代码中加入了一个与代码无关的工具.CPD有助于避免编码错误/样式,不应强迫我修改我的代码.
如果有人有一些想法如何解决它,那将会非常有用.
最好的祝愿
在我的工作中,我每天都与 Sonarqube 一起工作。但是,我意识到我不知道 CPD 是什么意思。诸如“INFO:CPD 计算完成”之类的短语。我需要一些帮助来了解这一点。
我是新来的PMD/CPD.我PMD在我的maven项目中配置如下:
<groupId>org.parent</groupId>
<artifactId>CustRestExampleOsgi</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>CustRestExampleOsgii</name>
<modules>
<module>CustImplProvider</module>
<module>CustInterface</module>
<module>RestCustConsumer</module>
</modules>
<properties>
<karaf.deploy.build.folder>
G:\apache-karaf-3.0.0.RC1\deploy
</karaf.deploy.build.folder>
</properties>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
</plugin>
</plugins>
</reporting>
Run Code Online (Sandbox Code Playgroud)
我的maven项目正在正常编译并生成所有报告mvn jxr:jxr site.但我无法找到任何显示重复代码的结果.为了测试这个,我在我的代码中故意引入了重复的代码,如:
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Address)) {
return false;
}
Address other = (Address) object; …Run Code Online (Sandbox Code Playgroud)