1

I want to use PMD 4.2.5 to find duplicates in my C code. I use the example commandline from their documentation:

java net.sourceforge.pmd.cpd.CPD --minimum-tokens 100 --files C:\src --language cpp

this gives me the error:

Can't find the custom format --language: java.lang.ClassNotFoundException

I tried a lot of different other things too, none worked. The GUI version of the PMD works nicely.

What commandline do i have to use to get PMD to detect duplicate code?

ldav1s
  • 15,885
  • 2
  • 53
  • 56
thumbmunkeys
  • 20,606
  • 8
  • 62
  • 110

2 Answers2

2

It seems it wants to load a class to do the language-specific parsing; make sure your CLASSPATH is set up properly.

unwind
  • 391,730
  • 64
  • 469
  • 606
1

On the command line you can pass a category for a given language (here ) to pmd

// best practice
pmd check -d C:\src\ -f html -R category/apex/bestpractices.xml -r C:\src\best.html
// security
pmd check -d C:\src\ -f html -R category/apex/security.xml -r C:\src\security.html
// error prone
pmd check -d C:\src\ -f html -R category/apex/errorprone.xml -r C:\src\errorprn.html

You can also combine the categories

pmd check -d C:\src\ -f html 
         -R category/apex/bestpractices.xml, 
            category/apex/codestyle.xml, category/apex/design.xml, 
            category/apex/documentation.xml, category/apex/errorprone.xml, 
            category/apex/performance.xml, category/apex/security.xml 
         -r C:\src\PMD_Report_all_categories.html

The categories available for a language can be found by unpacking the jar file for your language below ...\pmd-bin-7.0.0-rc3\lib.

I could not find any rules for

  • neither on the page 3rd party rulesets
  • nor below Making rulesets any page for a language specific rule
  • i could not match any files below the folder pmd-bin-7.0.0-rc3\liblib to (see screen)

pmd lib folder rulesets

surfmuggle
  • 5,527
  • 7
  • 48
  • 77