<!-- this highlights the active parent class in the navgoco sidebar. this is critical so that the parent expands when you're viewing a page. This must appear below the sidebar code above. Otherwise, if placed inside customscripts.js, the script runs before the sidebar code runs and the class never gets inserted.-->
<!-- this handles the automatic toc. use ## for subheads to auto-generate the on-page minitoc. if you use html tags, you must supply an ID for the heading element in order for it to appear in the minitoc. -->
<p><ahref="https://www.codacy.com/">Codacy</a> automates code reviews and monitors code quality on every commit and pull request.
It gives visibility into the technical debt and it can track code style and security issues, code coverage, code duplication, cyclomatic complexity and enforce best practices.
Codacy is static analysis without the hassle.</p>
<p>With Codacy you have PMDJava analysis out-of-the-box, and it is free for open source projects.</p>
<p>A general note - most plugins include the PMD jar files, which has the rulesets
inside it. So even though the rulesets parameter that some plugins
use (i.e., “rulesets/java/unusedcode.xml”) looks like a filesystem reference, it’s really
being used by a getResourceAsStream() call to load it out of the PMD jar files.</p>
<h3id="bluej">BlueJ</h3>
<p><ahref="http://bluej.org/">BlueJ</a> is a teaching IDE. To install the PMD extension for BlueJ, download
the <ahref="http://sourceforge.net/projects/pmd/files/pmd-bluej/pmd-bluej-1.0/">PMDExtension jar file</a>
and place it in your <codeclass="highlighter-rouge">bluej/lib/extensions/</code> directory.</p>
<h3id="eclipse">Eclipse</h3>
<p>To install the PMD plugin for Eclipse:</p>
<ul>
<li>Start Eclipse and open a project</li>
<li>Select “Help”->”Software Updates”->”Find and Install”</li>
<li>Click “Next”, then click “New remote site”</li>
<li>Enter “PMD” into the Name field and <ahref="https://dl.bintray.com/pmd/pmd-eclipse-plugin/updates/">https://dl.bintray.com/pmd/pmd-eclipse-plugin/updates/</a> into the URL field</li>
<li>Click through the rest of the dialog boxes to install the plugin</li>
</ul>
<p>Alternatively, you can download the latest zip file and follow the above procedures
except for using “New local site” and browsing to the downloaded zip file.</p>
<p>To configure PMD, select “Windows”->”Preferences”, then select PMD.</p>
<p>To run PMD, right-click on a project node and select “PMD”->”Check code with PMD”.</p>
<p>To run the duplicate code detector, right-click on a project node and
select “PMD”->”Find suspect cut and paste”. The report will be placed in a “reports” directory
in a file called “cpd-report.txt”.</p>
<p>To find additional help for other features, please read included help by selecting
Help->Help Contents and browse the “How to…” section in the “PMD Plugin Documentation” book.</p>
<p>After installing an update, if you get an Exception such as
“java.lang.RuntimeException: Couldn’t find that class xxxxx”,
try deleting the ruleset.xml file in the .metadata/plugins/net.sourceforge.pmd.eclipse directory in your workspace.</p>
<p>To get Eclipse to not flag the @SuppressWarnings(“PMD”) annotation, look
under the menu headings Java -> Compiler -> Errors/Warnings -> Annotations -> Unhandled Warning Token.</p>
<h3id="emacs">Emacs</h3>
<p>Integration with GNU Emacs is performed through an ELisp package, pmd.el.
It supports two commands, “pmd-current-buffer” and “pmd-current-dir”.
The output is captured in a compilation buffer which allows the user to “jump”
directly to the source code position associated with the PMD warnings.</p>
<h3id="gel">Gel</h3>
<p>Here’s how to set up the Gel plugin:</p>
<ul>
<li>Download the pmd-gel-[version].zip file</li>
<li>Close Gel</li>
<li>Remove any old plugin versions from your gel\plugins directory</li>
<li>Unzip the new zip file into your gel\plugins directory</li>
<li>Start Gel</li>
<li>Go to Tools->Options->Plugin</li>
<li>Select the PMD plugin and click “Remove”</li>
<li>Click “Add” and select “net.sourceforge.pmd.gel.PMDPlugin”</li>
<li>Restart Gel</li>
</ul>
<p>That’s pretty much it. Now you can open a Java project and click on Plugins->PMD and
a configuration panel will pop up. You can pick which ruleset you want to run and
you can also pick whether you want to run PMD on the current file or on every
source file in your project.</p>
<h3id="idea">IDEA</h3>
<p>You can use an integrated plugin or just use it as an IDEA “External Tool”.</p>
<p>Amit Dev wrote an integrated plugin for IDEA; you can download that
<ahref="http://plugins.jetbrains.com/idea/plugin/1137-pmdplugin">from the IntelliJ plugins site</a>.</p>
<p>Here’s how to set it up as an “External Tool”:</p>
<ul>
<li>Open IDEA and go to File->Settings</li>
<li>Click on the “External Tools” icon</li>
<li>Click on the Add button</li>
<li>Fill in the blocks
<ul>
<li>Name: PMD</li>
<li>Description: PMD, good for what ails you.</li>
<li>Menu: Select the “Main menu”, “Project views”, “Editor menu”, and “Search results” checkboxes.</li>
<li>Program: $JDKPath$\bin\java.exe</li>
<li>For the next parameter you’ll need to plug in the location of your PMD installation
<p>Note that you can select individual rules by going to Utilities->Global Options->Plugin Options->PMD.
Also, you can change the plugin to prompt you for a directory to check by going to that same menu and
selecting the “Ask for Directory” checkbox.</p>
<h3id="netbeans">NetBeans</h3>
<p>The <ahref="http://kenai.com/projects/sqe/">SQE</a> project includes PMD integration for NetBeans.</p>
<h3id="textpad">TextPad</h3>
<p><strong>Assumptions</strong></p>
<ul>
<li>The Java Development Kit, version 1.4.2 (versions 1.4 and higher are acceptable) is properly installed
into your machine, and exists in <codeclass="highlighter-rouge">D:\java\jdk\_142\</code>. This means that <codeclass="highlighter-rouge">D:\java\jdk\_142\bin\java.exe</code> exists.</li>
<li>PMD version 5.0 exists in <codeclass="highlighter-rouge">D:\java\pmd-bin-\</code>.
This means that <codeclass="highlighter-rouge">D:\java\pmd-bin-\lib\pmd-.jar</code> (among other jar files
in the same directory) exist.</li>
</ul>
<p><strong>To integrate into TextPad</strong></p>
<ol>
<li>In the <strong>Configure</strong> menu, choose <strong>Preferences…</strong>. This opens the Preferences dialog</li>
<li>In the left pane of the Preferences dialog, choose the <strong>Tools</strong> branch by clicking on the <em>word</em> “Tools”.</li>
<li>On the far right of the dialog, click on the <strong>Add</strong> button, and then select <strong>Program…</strong> from the drop-down.
This opens the standard Windows Open File dialog.</li>
<li>Type <codeclass="highlighter-rouge">D:\java\jdk_142\bin\java.exe</code> and click the <strong>Open</strong> button. In the center pane of the Preferences dialog,
an item “Java” has now been added, and is currently selected.</li>
<li>Click the word Java, which makes the word editable. Select the entire word, and type “PMD directory”. Press Return.</li>
<li>Repeat steps three through five, but type “PMD file”, instead of “PMD directory”.</li>
<li>Click <strong>Apply</strong>.</li>
<li>Expand the <strong>Tools</strong> branch (if not already) by clicking on the ‘<codeclass="highlighter-rouge">+</code>’ directly to its left.</li>
<li>In the expanded list, select <strong>PMD directory</strong>. This changes the right side of this dialog to the “tool” form.</li>
<li>In the expanded list, select <strong>PMD file</strong>.</li>
<li>In the “tool” form, enter the same parameters as above, except replace ‘<codeclass="highlighter-rouge">$FileDir</code>’ with ‘<codeclass="highlighter-rouge">$File</code>’,
in the Parameters textbox.</li>
<li>To save your work (truly, given a quirk of TextPad), click on <strong>OK</strong>, which closes the Preferences dialog.
Restart TextPad and re-open the Preferences dialog.</li>
<li>Go back to both the “PMD directory” and “PMD file” Tools branches, and replace ‘<codeclass="highlighter-rouge">E:\directory\my_pmd_ruleset.xml</code>’
with the ruleset of your choice. For example, <codeclass="highlighter-rouge">basic</code>.</li>
<li>Go to the <strong>Keyboard</strong> branch in the left pane (above <strong>Tools</strong>), which changes the right side to
the “keyboard configuration” form.</li>
<li>In the <strong>Categories</strong> list box, select <strong>Tools</strong>.</li>
<li>In the <strong>Command</strong> list box, select <strong>PMD directory</strong>.</li>
<li>Put your cursor into the <strong>Press new shortcut key</strong>, and type your desired key command.
For example <codeclass="highlighter-rouge">Ctrl+Page Up</code></li>
<li>Click <strong>Assign</strong>.</li>
<li>In the <strong>Command</strong> list box, select <strong>PMD file</strong>.</li>
<li>Put your cursor into the <strong>Press new shortcut key</strong>, and type your desired key command.
For example <codeclass="highlighter-rouge">Ctrl+Page Down</code></li>
<li>Click <strong>Assign</strong>.</li>
<li>Save your work again: Click on <strong>OK</strong>, which closes the Preferences dialog, and then restart TextPad.</li>
</ol>
<p><strong>To run PMD against a single Java file</strong></p>
<ol>
<li>In TextPad, open any Java file.</li>
<li>Click <codeclass="highlighter-rouge">Ctrl+Page Down</code>. This opens an empty, read-only text document (titled “Command Results”).
When PMD completes its analysis, this document will be populated with a listing of violated rules
(or “Command completed successfully” indicating no violations).</li>
<li>Double click any line to go to it.</li>
</ol>
<p><strong>To run PMD against a directory of Java files</strong></p>
<ol>
<li>In TextPad, open <em>any</em> file in the <em>root</em> directory you wish to analyze. Unfortunately, you’ll need to
create a dummy file, if no file exists there.</li>
<li>Click <codeclass="highlighter-rouge">Ctrl+Page Up</code>. This opens an empty, read-only text document (titled “Command Results”).
When PMD completes its analysis, this document will be populated with a listing of violated rules
(or “Command completed successfully” indicating no violations).</li>
<li>Double click any line to go to it.</li>
</ol>
<p><em>Because directory analysis may take a while, you may choose to cancel this operation. Do so by closing
the (blank Command Results) document, and then confirming that, “yes, I do really want to exit the tool”.</em></p>