thumbmunkeys
thumbmunkeys

Reputation: 20764

PMD: Commandline to analyze C Code

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?

Upvotes: 1

Views: 777

Answers (2)

surfmuggle
surfmuggle

Reputation: 5954

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

Upvotes: 1

unwind
unwind

Reputation: 400049

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

Upvotes: 2

Related Questions