Table of Contents
Automated Code Review
Codacy
Codacy 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.
With Codacy you have PMDJava analysis out-of-the-box, and it is free for open source projects.
- Homepage: https://www.codacy.com/
- Source code: https://github.com/codacy/codacy-pmdjava
- Maintainer: Codacy
Codiga
Codiga automates code review, check your code quality and helps you manage your technical debt. It is integrated with GitHub, GitLab and Bitbucket. The platform also analyzes code directly in your IDE using its integration plugins for VS Code and IntelliJ, providing a consistent analysis along your development cycle (from the IDE to the CI/CD pipeline).
Codiga uses PMD to check Java and Apex code.
- Homepage: https://www.codiga.io
- Documentation: https://doc.codiga.io
GitHub Actions
PMD provides its own GitHub Action, that can be integrated in custom workflows.
It can execute PMD with your own ruleset against your project. It creates a SARIF report which is uploaded as a build artifact. Furthermore the build can be failed based on the number of violations.
The action can also be used as a code scanner to create “Code scanning alerts”.
- Homepage: pmd/pmd-github-action
TCA
Tencent Cloud Code Analysis (TCA for short, code-named CodeDog inside the company early) is a comprehensive platform for code analysis and issue tracking. TCA consist of three components, server, web and client. It integrates of a number of self-developed tools, and also supports dynamic integration of code analysis tools in various programming languages.
Using TCA can help team find normative, structural, security vulnerabilities and other issues in the code, continuously monitor the quality of the project code and issue alerts. At the same time, TCA opens up APIs to support connection with upstream and downstream systems, so as to integrate code analysis capabilities, ensure code quality, and be more conducive to inheriting an excellent team code culture.
With TCA you have PMD analysis out-of-the-box, and it is open source under the MIT license.
- Homepage: http://tca.tencent.com/
- Source code: https://github.com/Tencent/CodeAnalysis
- Documentation: https://tencent.github.io/CodeAnalysis
- Maintainer: TCA
IDE Integrations
Summary
IDE | Homepage | Source Code | Maintainers |
---|---|---|---|
BlueJ | pmd-bluej | Tom Copeland | |
CodeGuide | N/A | Austin Moore | |
Eclipse | github: pmd/pmd-eclipse | Philippe Herlin | |
qa-Eclipse | qa-Eclipse | Christian Wulf | |
eclipse-pmd | http://acanda.github.io/eclipse-pmd/ | github: acanda/eclipse-pmd | Philip Graf |
Emacs | github: pmd/pmd-emacs | Nascif Abousalh Neto | |
Gel | github: pmd/pmd-misc/pmd-gel | Andrei Lumianski | |
Gradle | Gradle: The PMD Plugin | github: gradle/gradle | Gradle.org |
IntelliJ IDEA | github: amitdev/PMD-Intellij | Amit Dev | |
IntelliJ IDEA - QAPlug | http://qaplug.com/ | N/A | Jakub Sławiński |
JBuilder | github: pmd/pmd-misc/pmd-jbuilder | Tom Copeland | |
JCreator | N/A | Brant Gurganus | |
JDeveloper | github: pmd/pmd-jdeveloper | Torsten Kleiber | |
JEdit | jEdit - PMD Plugin | sourceforge: jedit/PMDPlugin | Jiger Patel, Dale Anson |
NetBeans | SQE | github: sqe-team/sqe | N/A |
TextPad | N/A | Jeff Epstein | |
WebLogic Workshop 8.1.x | N/A | Kevin Conaway |
General comments
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.
BlueJ
BlueJ is a teaching IDE. To install the PMD extension for BlueJ, download
the PMDExtension jar file
and place it in your bluej/lib/extensions/
directory.
Eclipse
To install the PMD plugin for Eclipse:
- Start Eclipse and open a project
- Select “Help”->”Software Updates”->”Find and Install”
- Click “Next”, then click “New remote site”
- Enter “PMD” into the Name field and https://pmd.github.io/pmd-eclipse-plugin-p2-site/ into the URL field
- Click through the rest of the dialog boxes to install the plugin
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.
To configure PMD, select “Windows”->”Preferences”, then select PMD.
To run PMD, right-click on a project node and select “PMD”->”Check code with PMD”.
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”.
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.
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.
To get Eclipse to not flag the @SuppressWarnings(“PMD”) annotation, look under the menu headings Java -> Compiler -> Errors/Warnings -> Annotations -> Unhandled Warning Token.
Emacs
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.
Gel
Here’s how to set up the Gel plugin:
- Download the pmd-gel-[version].zip file
- Close Gel
- Remove any old plugin versions from your gel\plugins directory
- Unzip the new zip file into your gel\plugins directory
- Start Gel
- Go to Tools->Options->Plugin
- Select the PMD plugin and click “Remove”
- Click “Add” and select “net.sourceforge.pmd.gel.PMDPlugin”
- Restart Gel
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.
IDEA
You can use an integrated plugin or just use it as an IDEA “External Tool”.
Amit Dev wrote an integrated plugin for IDEA; you can download that from the IntelliJ plugins site.
Here’s how to set it up as an “External Tool”:
- Open IDEA and go to File->Settings
- Click on the “External Tools” icon
- Click on the Add button
- Fill in the blocks
- Name: PMD
- Description: PMD, good for what ails you.
- Menu: Select the “Main menu”, “Project views”, “Editor menu”, and “Search results” checkboxes.
- Program:
c:\pmd\bin\pmd.bat
- For the next parameter you’ll need to plug in the location of your PMD installation and the rulesets you want to use
- Parameters:
-d "$FilePath$" -f ideaj -R rulesets/java/quickstart.xml -P sourcePath="$Sourcepath$" -P classAndMethodName=$FileClass$.method -P fileName=$FileName$
That’s pretty much it. Now you can right click on a source directory and select PMD, it’ll run recursively on the source files, and the results should be displayed in a window and hyperlinked into the correct file and line of code. I usually right-click on the message window title bar and unselect “autohide” so the window doesn’t go away every time I fix something in the code window.
IDEA - QAPlug
QAPlug is an Intellij IDEA plugin to manage code quality. It integrates no less than Checkstyle, FindBugs, and PMD.
The plugin is available at http://www.qaplug.com/.
Also available at the JetBrains site, QAPlug-PMD and QAPlug.
JBuilder
To enable this OpenTool in JBuilder:
- Download the latest binary release
- Unzip it into your
jbuilder/lib/ext/
directory - Restart JBuilder
What you can do:
- Check a single file by bringing up the context menu from the file tab and selecting PMDCheck
- Configure the rulesets that the PMD OpenTool will use by selecting Tools->PMD->Configure PMD
- Check all the files in a project by bringing up the context menu for the project node and selecting PMD Check Project
- Locate duplicate code by right clicking on a package and selection “Check with CPD”
When running PMD, the results will be displayed in the MessageView under a tab called PMD Results. If you click on a violation message within this view, you will be taken to the line in the source code where the violation was detected.
Things still to do:
- Enable selection of individual rules within a rule set (maybe)
- Optional insertion of @todo comments at the point of a violation
- Possibly provide configurable ability to limit the number of violations per rule per file
JCreator
- Open Configure > Options
- Go to the Tools panel
- Click New > Program
- Browse for PMD’s pmd.bat
- Put quotations around the path if it has spaces.
- Set the initial directory to PMD’s \bin directory
- Check capture output
- Put ‘”$[PrjDir]” emacs’ followed by desired rulesets in the arguments
To run PMD on a project, just pick pmd from the Tools menu.
JDeveloper
To install the PMD plugin for JDeveloper:
- JDeveloper 10.1.2: Download the binary release and unzip it into your jdev/lib/ext directory
- JDeveloper 10.1.3 upwards: Click “Help”, click “Check for Updates”
- JDeveloper 10.1.3:
- Press “Add” to add a new update center
- Name: PMD Update Center
- Location: http://pmd.sourceforge.net/center.xml
- Select Update Center: PMD Update Center
- JDeveloper 11 upwards: Select Update Center: Open Source and Partner Extensions
- Press Next and select the actual PMD Plugin and install it
- JDeveloper 10.1.3:
- Restart JDeveloper
To run the PMD plugin for JDeveloper:
- Open the Tools-&Preferences menu
- Click on the PMD option
- Select a couple of rules to try
- To run PMD, right click on either a file, folder, package, project or workspace and select PMD via Toolbar Icon, Context Menu or File Menu
- Any rule violations should show up in a LogWindow tab at the bottom of the screen
JEdit
The way I use the JEdit plugin is:
- Dock the ErrorList by going to Utilities->Global Options->Docking and putting ErrorList at the bottom of the screen
- Open the File Browser if it isn’t already open
- Double-click on a source directory
- Select Plugins->PMD->Check directory recursively
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.
NetBeans
The SQE project includes PMD integration for NetBeans.
TextPad
Assumptions
- The Java Development Kit, version 1.4.2 (versions 1.4 and higher are acceptable) is properly installed
into your machine, and exists in
D:\java\jdk\_142\
. This means thatD:\java\jdk\_142\bin\java.exe
exists. - PMD version 5.0 exists in
D:\java\pmd-bin-\
. This means thatD:\java\pmd-bin-\lib\pmd-.jar
(among other jar files in the same directory) exist.
To integrate into TextPad
- In the Configure menu, choose Preferences…. This opens the Preferences dialog
- In the left pane of the Preferences dialog, choose the Tools branch by clicking on the word “Tools”.
- On the far right of the dialog, click on the Add button, and then select Program… from the drop-down. This opens the standard Windows Open File dialog.
- Type
D:\java\jdk_142\bin\java.exe
and click the Open button. In the center pane of the Preferences dialog, an item “Java” has now been added, and is currently selected. - Click the word Java, which makes the word editable. Select the entire word, and type “PMD directory”. Press Return.
- Repeat steps three through five, but type “PMD file”, instead of “PMD directory”.
- Click Apply.
- Expand the Tools branch (if not already) by clicking on the ‘
+
’ directly to its left. - In the expanded list, select PMD directory. This changes the right side of this dialog to the “tool” form.
- In the “tool” form, enter these parameters:
- Parameters:
-classpath D:\java\pmd-bin-\lib\pmd-.jar;D:\java\pmd-bin-\lib\asm-3.2.jar;D:\java\pmd-bin-\lib\jaxen-1.1.1.jar net.sourceforge.pmd.PMD -d <i><b>$FileDir</b></i> -f net.sourceforge.pmd.renderers.TextPadRenderer -R E:\directory\my_pmd_ruleset.xml -debug
- Initial Folder:
$FileDir
- Save all documents first:
Checked
- Capture output:
Checked
- All other checkboxes: Unchecked
- Regular expression to match output:
^\([^(]+\)(\([0-9]+\),
- Registers/File:
1
- Registers/Line:
2
- Parameters:
- In the expanded list, select PMD file.
- In the “tool” form, enter the same parameters as above, except replace ‘
$FileDir
’ with ‘$File
’, in the Parameters textbox. - To save your work (truly, given a quirk of TextPad), click on OK, which closes the Preferences dialog. Restart TextPad and re-open the Preferences dialog.
- Go back to both the “PMD directory” and “PMD file” Tools branches, and replace ‘
E:\directory\my_pmd_ruleset.xml
’ with the ruleset of your choice. For example,basic
. - Go to the Keyboard branch in the left pane (above Tools), which changes the right side to the “keyboard configuration” form.
- In the Categories list box, select Tools.
- In the Command list box, select PMD directory.
- Put your cursor into the Press new shortcut key, and type your desired key command.
For example
Ctrl+Page Up
- Click Assign.
- In the Command list box, select PMD file.
- Put your cursor into the Press new shortcut key, and type your desired key command.
For example
Ctrl+Page Down
- Click Assign.
- Save your work again: Click on OK, which closes the Preferences dialog, and then restart TextPad.
To run PMD against a single Java file
- In TextPad, open any Java file.
- Click
Ctrl+Page Down
. 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). - Double click any line to go to it.
To run PMD against a directory of Java files
- In TextPad, open any file in the root directory you wish to analyze. Unfortunately, you’ll need to create a dummy file, if no file exists there.
- Click
Ctrl+Page Up
. 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). - Double click any line to go to it.
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”.
WebLogic Workshop 8.1.x
Please see the WebLogic Workshop plugin project home page for more information.