##### Overview

- Download PMD 5.0.4
- What's new in PMD 5.0.4
- PMD in the news
- PMD-related products and books
- Best practices
- Future directions
- Similar projects
- Credits
- License
- What does 'PMD' mean?

##### Usage

- Installation
- Command line usage
- Ant task usage
- Maven plugin usage
- Mvn plugin usage
- IDE plugin usage
- Suppressing warnings
- Finding duplicated code
- JSP support

##### Customizing PMD

- Compiling PMD
- How to write a rule
- Writing XPath rules
- How to make a rule set
- How it works
- Rule guidelines
- PMD developers information
- PMD Release Process

##### For example

- Run PMD on a Sourceforge project

##### Misc.

- XPath tutorial (Gregorian)

##### Rule Sets

- ecmascript
  - Basic Ecmascript
  - Braces
  - Unnecessary
- java
  - Android
  - Basic
  - Braces
  - Clone Implementation
  - Code Size
  - Comments
  - Controversial
  - Coupling
  - Design
  - Empty Code
  - Finalizer
  - Import Statements
  - J2EE
  - JavaBeans
  - JUnit
  - Jakarta Commons Logging
  - Java Logging
  - Migration
  - Naming
  - Optimization
  - Strict Exceptions
  - String and StringBuffer
  - Security Code Guidelines
  - Type Resolution
  - Unnecessary
  - Unused Code
- jsp
  - Basic JSF
  - Basic JSP
- xml
  - Basic XML
- xsl
  - XPath in XSL

##### Project Documentation

- Project Information
- Project Reports

## Running PMD via command line

### On Linux and other UNIX based operating system...

PMD comes with several command line utilities. Previously, each of them had its own start up script, but this has been greatly simplified since PMD 5.0... at least for Unix systems. There is now only one script, called "run.sh", inside the bin/ directory of PMD distribution.

The first argument is the name of the utility you want to execute ('pmd', 'designer',...) and the other arguments are specific to the utility used.

    $ ./bin/run.sh pmd -d ../../../src/main/java/ -f text -R rulesets/java/basic.xml  -version 1.7 -language java
    .../src/main/java/net/sourceforge/pmd/RuleSet.java:123  These nested if statements could be combined
    .../src/main/java/net/sourceforge/pmd/RuleSet.java:231  Useless parentheses.
    .../src/main/java/net/sourceforge/pmd/RuleSet.java:232  Useless parentheses.
    .../src/main/java/net/sourceforge/pmd/RuleSet.java:357  These nested if statements could be combined
    .../src/main/java/net/sourceforge/pmd/RuleSetWriter.java:66     Avoid empty catch blocks
    .../src/main/java/net/sourceforge/pmd/RuleSetWriter.java:269    Useless parentheses.

### Basic usage for Windows

- Windows: Type "pmd -d [filename|jar or zip file containing source code|directory] -f [report format] -R [ruleset file]", i.e:

    C:\tmp\pmd-bin-5.0.4\pmd\bin>pmd -d c:\data\pmd\pmd\test-data\Unused1.java -f xml -R rulesets/java/unusedcode.xml
    <?xml version="1.0"?><pmd>
    <file name="c:\data\pmd\pmd\test-data\Unused1.java">
    <violation line="5" rule="UnusedLocalVariable">
    Avoid unused local variables such as 'fr'
    </violation>
    </file></pmd>

    C:\tmp\pmd-bin-5.0.4\pmd\bin>

You can pass a file name, a directory name, or a jar or zip file name containing Java source code to PMD.

Also, the PMD binary distribution includes the ruleset files inside the jar file - even though the "rulesets/java/unusedcode.xml" parameter above looks like a filesystem reference, it's really being used by a getResourceAsStream() call to load it out of the PMD jar file. And the same applies to the example below.

- If you want to run PMD without the batch file, you can do a:

    C:\tmp\pmd-bin-5.0.4\pmd>java -Djava.ext.dirs=lib
                         net.sourceforge.pmd.PMD
                         -d c:\j2sdk1.4.1_01\src\java\lang
                         -f xml
                         -R rulesets/java/imports.xml

- Linux: Type "./run.sh pmd -d [filename|jar or zip file containing source code|directory] -f [report format] -R [ruleset file]", i.e:

    /home/user/tmp/pmd-bin-5.0.4/pmd/bin>./run.sh pmd -d /home/user/data/pmd/pmd/test-data/Unused1.java -f xml -R rulesets/java/unusedcode.xml
    <?xml version="1.0"?><pmd>
    <file name="/home/user/data/pmd/pmd/test-data/Unused1.java">
    <violation line="5" rule="UnusedLocalVariable">
    Avoid unused local variables such as 'fr'
    </violation>
    </file></pmd>

    /home/user/tmp/pmd-bin-5.0.4/pmd/bin>

### Other options

The tool comes with a rather extensive help text, simply running with --help !

### Renderers

PMD comes with four different renderer types:

- csv, provides a Comma Separated Values.
- text, provides a basic text output.
- xml, provides report output in XML format.
- html, provides report as a basic HTML page.
- ... and many more ! See the tool help text...