I want to know if there is a way to run all PMD rulesets from command line.
I've used PMD integrated with Eclipse IDE and Maven. But now I need to run it from CLI. I've checked this page http://pmd.sourceforge.net/pmd-5.1.0/running.html and it says you can run it from CLI, but with specified rulesets:
C:\tmp\pmd-bin-5.1.0\pmd\bin>pmd -d c:\data\pmd\pmd\test-data\Unused1.java -f xml -R rulesets/java/unusedcode.xml
In that example, you just get results for Java unused code rule and I'm trying to achieve something like:
C:\tmp\pmd-bin-5.1.0\pmd\bin>pmd -d c:\data\pmd\pmd\test-data\Unused1.java -f xml -R rulesets/java/*.xml
and get results for all rules in Java rulesets.
How to open a PMD file. You can open PMD files with PlanMaker, which is included with the SoftMaker Office suite. To open a PMD file with PlanMaker, select File → Open... or click the "Open" file icon in the "File" tab.
PMD is a source code analyzer. It finds common programming flaws like unused variables, empty catch blocks, unnecessary object creation, and so forth. It supports Java, JavaScript, Salesforce.com Apex and Visualforce, PLSQL, Apache Velocity, XML, XSL. Additionally it includes CPD, the copy-paste-detector.
Conceptually, PMD rules work by matching a “pattern” against the AST of a file. Rules explore the AST and find nodes that satisfy some conditions that are characteristic of the specific thing the rule is trying to flag. Rules then report a violation on these nodes.
You can define a config file which includes the rulesets you wish to run. You can give this file as a parameter after the -R
argument on the command line.
An example file is here (MyRules.xml
):
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<ruleset name="PMD.rul" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>This ruleset was created from PMD.rul</description>
<rule ref="rulesets/java/basic.xml">
<exclude name="UnnecessaryFinalModifier"/>
</rule>
<rule ref="rulesets/java/braces.xml"/>
<rule ref="rulesets/java/clone.xml"/>
<rule ref="rulesets/java/comments.xml"/>
<rule ref="rulesets/java/controversial.xml">
<exclude name="AtLeastOneConstructor"/>
<exclude name="UnnecessaryParentheses"/>
</rule>
<rule ref="rulesets/java/design.xml">
<exclude name="GodClass"/>
</rule>
<rule ref="rulesets/java/empty.xml"/>
<rule ref="rulesets/java/finalizers.xml"/>
<rule ref="rulesets/java/imports.xml"/>
<rule ref="rulesets/java/j2ee.xml"/>
<rule ref="rulesets/java/javabeans.xml"/>
<rule ref="rulesets/java/junit.xml"/>
<rule ref="rulesets/java/logging-jakarta-commons.xml"/>
<rule ref="rulesets/java/logging-java.xml"/>
<rule ref="rulesets/java/naming.xml"/>
<rule ref="rulesets/java/optimizations.xml"/>
<rule ref="rulesets/java/strictexception.xml"/>
<rule ref="rulesets/java/strings.xml"/>
<rule ref="rulesets/java/sunsecure.xml"/>
<rule ref="rulesets/java/typeresolution.xml"/>
<rule ref="rulesets/java/unnecessary.xml">
<exclude name="UnnecessaryFinalModifier"/>
<exclude name="UnnecessaryReturn"/>
<exclude name="UselessParentheses"/>
</rule>
<rule ref="rulesets/java/unusedcode.xml"/>
</ruleset>
The command line arguments would look like this:
C:\tmp\pmd-bin-5.1.0\pmd\bin>pmd -d c:\data\pmd\pmd\test-data\Unused1.java -f xml -R MyRules.xml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With