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