Hey i followed the rules from the this http://pmd.sourceforge.net/snapshot/pmd_rules_apex.html
and created the custom rules but when i tried to run the command
pmd.bat -d [sourcecode to the java file] -R -d[the source of the custom xml file]
Example :(below command is the one i tried)
pmd.bat -d C:\Users\user\Desktop\example.java -R -d C:\Users\user\Desktop\mycustomrule.xml
i get the error
"net.sourceforge.pmd.RuleSetNotFoundException: Can't find resource null. Make sure the resource is a valid file or URL and is on the CLASSPATH. Here's the current classpath: "
If i run the following command then i get the error
pmd -d "C:\pmd\src" -f html -R "C:\PMDrulesetfile.xml" -reportfile "C:\git\scanResult.html"
I get the following error
C:\pmd-bin-6.0.0\bin>pmd -d "C:\pmd\src" -f html -R "C:\pmd\PMDrulesetfile.xml"
-reportfile "C:\pmd\scanResult.html"
Jan 11, 2018 7:22:36 PM net.sourceforge.pmd.cache.NoopAnalysisCache <init>
WARNING: This analysis could be faster, please consider using Incremental Analys
is: https://pmd.github.io/pmd/pmd_userdocs_getting_started.html#incremental-anal
ysis
Ignoring language for PMD: java.lang.UnsupportedClassVersionError: net/sourcefor
ge/pmd/lang/apex/ApexLanguageModule : Unsupported major.minor version 52.0
Exception in thread "main" java.lang.UnsupportedClassVersionError: net/sourcefor
ge/pmd/lang/apex/rule/bestpractices/ApexUnitTestClassShouldHaveAssertsRule : Uns
upported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at net.sourceforge.pmd.rules.RuleBuilder.build(RuleBuilder.java:179)
at net.sourceforge.pmd.rules.RuleFactory.buildRule(RuleFactory.java:188)
at net.sourceforge.pmd.RuleSetFactory.parseSingleRuleNode(RuleSetFactory
.java:565)
at net.sourceforge.pmd.RuleSetFactory.parseRuleNode(RuleSetFactory.java:
460)
at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.ja
va:367)
at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:
214)
at net.sourceforge.pmd.RuleSetFactory.createRule(RuleSetFactory.java:313
)
at net.sourceforge.pmd.RuleSetFactory.parseRuleReferenceNode(RuleSetFact
ory.java:612)
at net.sourceforge.pmd.RuleSetFactory.parseRuleNode(RuleSetFactory.java:
462)
at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.ja
va:367)
at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:
214)
at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:
209)
at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java
:170)
at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java
:154)
at net.sourceforge.pmd.RulesetsFactoryUtils.getRuleSets(RulesetsFactoryU
tils.java:37)
at net.sourceforge.pmd.RulesetsFactoryUtils.getRuleSetsWithBenchmark(Rul
esetsFactoryUtils.java:68)
at net.sourceforge.pmd.PMD.doPMD(PMD.java:203)
at net.sourceforge.pmd.PMD.run(PMD.java:453)
at net.sourceforge.pmd.cli.PMDCommandLineInterface.run(PMDCommandLineInt
erface.java:170)
at net.sourceforge.pmd.PMD.main(PMD.java:426)
How do i overcome these error and is there any good free guide from which i can follow to write custom rules
My Machine is windows machine
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm assuming you want to analyze Apex code, is this correct?
Then there are two issues: for analyzing Apex source code, you need to have at least java8 installed and run pmd through java8. It seems, you are using an older version (hence the UnsupportedClassVersionError)
When specifying the ruleset file, no additional "-d" is required - the path to the ruleset file must be directly given after "-R".
The correct command line is:
pmd.bat -d [path to apex source dir] -R [custom ruleset xml file] -f text
or for html output into file "scanResult.html" in the current directory:
pmd.bat -d [path to apex source dir] -R [custom ruleset xml file] -f html -reportfile "scanResult.html"
Hope this helps!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey i followed the rules from the this http://pmd.sourceforge.net/snapshot/pmd_rules_apex.html
and created the custom rules but when i tried to run the command
pmd.bat -d [sourcecode to the java file] -R -d[the source of the custom xml file]
Example :(below command is the one i tried)
pmd.bat -d C:\Users\user\Desktop\example.java -R -d C:\Users\user\Desktop\mycustomrule.xml
i get the error
"net.sourceforge.pmd.RuleSetNotFoundException: Can't find resource null. Make sure the resource is a valid file or URL and is on the CLASSPATH. Here's the current classpath: "
If i run the following command then i get the error
pmd -d "C:\pmd\src" -f html -R "C:\PMDrulesetfile.xml" -reportfile "C:\git\scanResult.html"
I get the following error
C:\pmd-bin-6.0.0\bin>pmd -d "C:\pmd\src" -f html -R "C:\pmd\PMDrulesetfile.xml"
-reportfile "C:\pmd\scanResult.html"
Jan 11, 2018 7:22:36 PM net.sourceforge.pmd.cache.NoopAnalysisCache <init>
WARNING: This analysis could be faster, please consider using Incremental Analys
is: https://pmd.github.io/pmd/pmd_userdocs_getting_started.html#incremental-anal
ysis
Ignoring language for PMD: java.lang.UnsupportedClassVersionError: net/sourcefor
ge/pmd/lang/apex/ApexLanguageModule : Unsupported major.minor version 52.0
Exception in thread "main" java.lang.UnsupportedClassVersionError: net/sourcefor
ge/pmd/lang/apex/rule/bestpractices/ApexUnitTestClassShouldHaveAssertsRule : Uns
upported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at net.sourceforge.pmd.rules.RuleBuilder.build(RuleBuilder.java:179)
at net.sourceforge.pmd.rules.RuleFactory.buildRule(RuleFactory.java:188)
.java:565)
at net.sourceforge.pmd.RuleSetFactory.parseRuleNode(RuleSetFactory.java:
460)
at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.ja
va:367)
at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:
214)
at net.sourceforge.pmd.RuleSetFactory.createRule(RuleSetFactory.java:313
)
at net.sourceforge.pmd.RuleSetFactory.parseRuleReferenceNode(RuleSetFact
ory.java:612)
at net.sourceforge.pmd.RuleSetFactory.parseRuleNode(RuleSetFactory.java:
462)
at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.ja
va:367)
at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:
214)
at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:
209)
at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java
:170)
at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java
:154)
at net.sourceforge.pmd.RulesetsFactoryUtils.getRuleSets(RulesetsFactoryU
tils.java:37)
at net.sourceforge.pmd.RulesetsFactoryUtils.getRuleSetsWithBenchmark(Rul
esetsFactoryUtils.java:68)
at net.sourceforge.pmd.PMD.doPMD(PMD.java:203)
at net.sourceforge.pmd.PMD.run(PMD.java:453)
at net.sourceforge.pmd.cli.PMDCommandLineInterface.run(PMDCommandLineInt
erface.java:170)
at net.sourceforge.pmd.PMD.main(PMD.java:426)
How do i overcome these error and is there any good free guide from which i can follow to write custom rules
My Machine is windows machine
Thanks
Hi,
I'm assuming you want to analyze Apex code, is this correct?
Then there are two issues: for analyzing Apex source code, you need to have at least java8 installed and run pmd through java8. It seems, you are using an older version (hence the UnsupportedClassVersionError)
When specifying the ruleset file, no additional "-d" is required - the path to the ruleset file must be directly given after "-R".
The correct command line is:
or for html output into file "scanResult.html" in the current directory:
Hope this helps!