How to use static code analyzer CPD ignoreLiterals and ignoreIdentifiers from command-line?

StackOverflow https://stackoverflow.com/questions/8978282

  •  18-04-2021
  •  | 
  •  

That's about PMD static analyzer's feature: Copy-Paste Detector.

Yes, I read http://pmd.sourceforge.net/cpd.html thoroughly.

But if I run CPD from ant-task, I can fine-tune its work by specifying ignoreLiterals and ignoreIdentifiers. How can I specify these keys using command-line?

有帮助吗?

解决方案

I think it's currently not possible (with pmd 4.2.6 and pmd 4.1.1).

A simple Properties object contains the ignoreLiterals and ignoreIdentifiers settings, but the command line CPD.main() method does not pass any Properties object to the LanguageFactory as the ant task (CPDTask) does. Furthermore, if I'm correct, the CPDTask pass these properties to the LanguageFactory.createLanguage(String language, Properties properties) method, but this method does not use the properties argument. So, IMO the ignoreLiterals and ignoreIdentifiers settings are ignored by the ant task.

Here is an old issue about this, which is still open. The patch looks correct, maybe it still works. Unfortunately it does not contain any fixes for the command line CPD class. Perhaps it fixes the ant task. Anyway, if you really need this functionality it does not look too hard to fix these issues.

其他提示

According to the notes for PMD 4.3 at sourceforge this issue has been fixed.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top