Git Product home page Git Product logo

eclipse-pmd's Introduction

⚠️ The repository of eclipse-pmd has been moved to https://github.com/eclipse-pmd/eclipse-pmd. This repository has been archived and is not in use anymore.

eclipse-pmd

The eclipse-pmd plug-in integrates the well-known source code analyzer PMD into the Eclipse IDE.

Everytime you save your work, eclipse-pmd scans your source code and looks for potential problems like possible bugs and suboptimal, duplicate, dead or overly complicated code.

Where possible, eclipse-pmd offers quick fixes that automatically fix the problems. These quick fixes can be used to fix a single problem or all occurrences in your entire code base.

How to get started

You need Eclipse 3.7 or later and Java 7 or later to run eclipse-pmd. Please follow the instructions on how to get started with eclipse-pmd on the website.

How to build and install eclipse-pmd

Building eclipse-pmd is fairly easy. Please note, however, that building eclipse-pmd is not required if you are only interested in using it, since there is a pre-built version available in the Eclipse Marketplace.

Requirements

You need the following tools:

  • JDK 8
  • Maven 3
  • Git

Build instructions

The first thing you need to do is to check out the source code.

git clone https://github.com/acanda/eclipse-pmd.git
cd eclipse-pmd

Once you have the source code you can build it with Maven.

cd ch.acanda.eclipse.pmd
mvn clean verify

This will compile, test and build a local repository for eclipse-pmd. If the build was successful you will find the repository in ch.acanda.eclipse.pmd.repository/target/repository.

Installation

Once you have built the repository you can install eclipse-pmd by adding a new repository to Eclipse:

  • from within Eclipse select Help > Install New Software...
  • click the button Add... of the Install dialog
  • click the button Local... of the Add Repository dialog
  • select the folder ch.acanda.eclipse.pmd.repository/target/repository
  • click the button OK of the Add Repository dialog
  • select Eclipse PMD Plug-in and proceed with the installation

From now on you can simply update Eclipse with Help > Check for Updates after you rebuilt eclipse-pmd.

Testing against different Eclipse releases

Building eclipse-pmd with mvn clean verify compiles and tests it against the oldest supported release of Eclipse which is Eclipse 3.7 Indigo. To ensure eclipse-pmd also works with newer releases the Eclipse release can be set with the parameter eclipse-release.

Compile and test against Eclipse Juno: mvn clean verify -Declipse-release=juno

Compile and test against Eclipse Kepler: mvn clean verify -Declipse-release=kepler

Compile and test against Eclipse Luna: mvn clean verify -Declipse-release=luna

Compile and test against Eclipse Mars: mvn clean verify -Declipse-release=mars

Compile and test against Eclipse Neon: mvn clean verify -Declipse-release=neon

Compile and test against Eclipse Oxygen: mvn clean verify -Declipse-release=oxygen

Compile an test against Eclipse Photon: mvn clean verify -Declipse-release=photon

Compile an test against Eclipse 2018-09: mvn clean verify -Declipse-release=2018-09

Compile an test against Eclipse 2018-12: mvn clean verify -Declipse-release=2018-12

Compile an test against Eclipse 2019-03: mvn clean verify -Declipse-release=2019-03

Compile an test against Eclipse 2019-06: mvn clean verify -Declipse-release=2019-06

Compile an test against Eclipse 2019-09: mvn clean verify -Declipse-release=2019-09

Compile an test against Eclipse 2019-12: mvn clean verify -Declipse-release=2019-12

Compile an test against Eclipse 2020-03: mvn clean verify -Declipse-release=2020-03

Regardless of the chosen release, the built plug-in will always be the same as the one built without the parameter. So there isn't any advantage in building the plug-in yourself if you are using a newer Eclipse release.

eclipse-pmd's People

Contributors

acanda avatar sratz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eclipse-pmd's Issues

Classpath based ruleset resolution

Hello

Is it currently possible to reference a ruleset.xml file that resides in the classpath of the target project?

E.g., some rulset.xml file that is shipped with a maven dependency that the project depends upon?

This would help us centralize the rule sets, since our maven PMD analysis runs are based on such "classpath based rulesets".

What do you think?

Thanks a lot.

PMD analyzes files located outside of the source directories

I a have a lot of project having directories containing java files, but these directories are not configured in Eclipse to be source directories for the project. So, the files in these directories are not compiled (and sometimes these files does not compile at all).

However, PMD analyzes theses files anyway, giving several hundred of warnings for things which must be ignored.

Unknown Language 'java' for Rule JumbledIncrementer, supported Languages are

I just updated Eclipse with the PMD plugin and I get the following error:
Errors occurred during the build.
Errors running builder 'PMD Builder' on project 'etouchpoint-test'.
java.lang.IllegalArgumentException: Unknown Language 'java' for Rule JumbledIncrementer, supported Languages are
Info from the Error Log:
eclipse.buildId=3.6.3.201411281415-RELEASE-e44
java.version=1.8.0_20
java.vendor=Oracle Corporation
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
Framework arguments: -product org.springsource.sts.ide -keyring ~/.eclipse_keyring -showlocation
Command-line arguments: -os macosx -ws cocoa -arch x86_64 -product org.springsource.sts.ide -keyring ~/.eclipse_keyring -showlocation
org.eclipse.core.resources
Error
Thu Dec 04 13:39:06 PST 2014
Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalArgumentException: Unknown Language 'java' for Rule JumbledIncrementer, supported Languages are
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2203)
at com.google.common.cache.LocalCache.get(LocalCache.java:3937)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4830)
at ch.acanda.eclipse.pmd.cache.RuleSetsCache.getRuleSets(RuleSetsCache.java:127)
at ch.acanda.eclipse.pmd.builder.PMDBuilder.analyze(PMDBuilder.java:74)
at ch.acanda.eclipse.pmd.builder.PMDBuilder$DeltaVisitor.visit(PMDBuilder.java:86)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:69)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:80)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:80)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:80)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:80)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:80)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:49)
at ch.acanda.eclipse.pmd.builder.PMDBuilder.incrementalBuild(PMDBuilder.java:69)
at ch.acanda.eclipse.pmd.builder.PMDBuilder.build(PMDBuilder.java:54)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:299)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:302)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:358)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:381)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: java.lang.IllegalArgumentException: Unknown Language 'java' for Rule JumbledIncrementer, supported Languages are
at net.sourceforge.pmd.RuleSetFactory.parseSingleRuleNode(RuleSetFactory.java:353)
at net.sourceforge.pmd.RuleSetFactory.parseRuleNode(RuleSetFactory.java:264)
at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.java:219)
at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:164)
at net.sourceforge.pmd.RuleSetFactory.parseRuleSetReferenceNode(RuleSetFactory.java:303)
at net.sourceforge.pmd.RuleSetFactory.parseRuleNode(RuleSetFactory.java:262)
at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.java:219)
at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:164)
at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java:129)
at ch.acanda.eclipse.pmd.cache.RuleSetsCacheLoader.load(RuleSetsCacheLoader.java:46)
at ch.acanda.eclipse.pmd.cache.RuleSetsCacheLoader.load(RuleSetsCacheLoader.java:1)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3527)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2319)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2282)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2197)
... 28 more

Support for custom PMD rules (JAR)

Hi,

Couldn't see any documentation about how to associate a Custom PMD Rules JAR in eclipse-pmd plugin.

The Custom JAR has the following layout:

custompmd.jar:  
    ├─ META-INF
    │       └─ MANIFEST.MF
    ├─ com
        └─ pmd
            └─ custom
                   └─ AvoidHardcodingRule.class

(The AvoidHardcodingRule class extends AbstractJavaRule)

java.lang.NoClassDefFoundError: net/sf/saxon/trans/XPathException

I just updated the Eclipse plugin for PMD and am getting errors now:

Dialog Box:

Errors occurred during the build.
Errors running builder 'PMD Builder' on project 'etouchpoint-batch'.
net/sf/saxon/trans/XPathException

Error Log:

java.lang.NoClassDefFoundError: net/sf/saxon/trans/XPathException
    at net.sourceforge.pmd.lang.rule.XPathRule.init(XPathRule.java:100)
    at net.sourceforge.pmd.lang.rule.XPathRule.getRuleChainVisits(XPathRule.java:85)
    at net.sourceforge.pmd.lang.rule.AbstractRule.usesRuleChain(AbstractRule.java:310)
    at net.sourceforge.pmd.lang.rule.AbstractDelegateRule.usesRuleChain(AbstractDelegateRule.java:195)
    at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.initialize(AbstractRuleChainVisitor.java:135)
    at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.visitAll(AbstractRuleChainVisitor.java:53)
    at net.sourceforge.pmd.RuleChain.apply(RuleChain.java:66)
    at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:122)
    at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:150)
    at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:80)
    at ch.acanda.eclipse.pmd.builder.Analyzer.runPMD(Analyzer.java:78)
    at ch.acanda.eclipse.pmd.builder.Analyzer.analyze(Analyzer.java:64)
    at ch.acanda.eclipse.pmd.builder.PMDBuilder.analyze(PMDBuilder.java:75)
    at ch.acanda.eclipse.pmd.builder.PMDBuilder$ResourceVisitor.visit(PMDBuilder.java:99)
    at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:126)
    at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:85)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
    at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:127)
    at org.eclipse.core.internal.resources.Resource.accept(Resource.java:95)
    at org.eclipse.core.internal.resources.Resource.accept(Resource.java:52)
    at org.eclipse.core.internal.resources.Resource.accept(Resource.java:124)
    at org.eclipse.core.internal.resources.Resource.accept(Resource.java:108)
    at ch.acanda.eclipse.pmd.builder.PMDBuilder.fullBuild(PMDBuilder.java:62)
    at ch.acanda.eclipse.pmd.builder.PMDBuilder.build(PMDBuilder.java:48)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:299)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:302)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:358)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:381)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: java.lang.ClassNotFoundException: net.sf.saxon.trans.XPathException cannot be found by ch.acanda.eclipse.pmd.core_1.1.0.201408102041
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:336)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:328)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 44 more

Eclipse Data:

eclipse.buildId=3.6.1.201408080429-CI-B2031403-e44
java.version=1.8.0_05
java.vendor=Oracle Corporation
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
Framework arguments:  -product org.springsource.sts.ide -keyring /Users/Minearo/.eclipse_keyring -showlocation
Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.springsource.sts.ide -keyring /Users/Minearo/.eclipse_keyring -showlocation

XML parsing problem in Eclipse Oxygen

Running on Eclipse Oxygen.1A, I'm seeing entries like this in the Error Log:
Could not run PMD on file C:/source/workspaces/pmd-test/maven-experiments/target/surefire-reports/TEST-my.experiments.test.TestMyArrayList.xml
net.sourceforge.pmd.PMDException: Error while processing TEST-my.experiments.test.TestMyArrayList.xml
at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:103)
at ch.acanda.eclipse.pmd.builder.Analyzer.runPMD(Analyzer.java:79)
at ch.acanda.eclipse.pmd.builder.Analyzer.analyze(Analyzer.java:65)
at ch.acanda.eclipse.pmd.builder.PMDBuilder.analyze(PMDBuilder.java:79)
at ch.acanda.eclipse.pmd.builder.PMDBuilder$ResourceVisitor.visit(PMDBuilder.java:126)
at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:120)
at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:84)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:87)
at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:129)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:94)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:52)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:117)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:105)
at ch.acanda.eclipse.pmd.builder.PMDBuilder.fullBuild(PMDBuilder.java:65)
at ch.acanda.eclipse.pmd.builder.PMDBuilder.build(PMDBuilder.java:51)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:142)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:232)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
Caused by: java.lang.IllegalArgumentException: interface org.apache.xerces.dom.DeferredNode is not visible from class loader
at java.lang.reflect.Proxy$ProxyClassFactory.apply(Unknown Source)
at java.lang.reflect.Proxy$ProxyClassFactory.apply(Unknown Source)
at java.lang.reflect.WeakCache$Factory.get(Unknown Source)
at java.lang.reflect.WeakCache.get(Unknown Source)
at java.lang.reflect.Proxy.getProxyClass0(Unknown Source)
at java.lang.reflect.Proxy.newProxyInstance(Unknown Source)
at net.sourceforge.pmd.lang.xml.ast.XmlParser.createProxy(XmlParser.java:88)
at net.sourceforge.pmd.lang.xml.ast.XmlParser.parse(XmlParser.java:71)
at net.sourceforge.pmd.lang.xml.XmlParser.parse(XmlParser.java:36)
at net.sourceforge.pmd.SourceCodeProcessor.parse(SourceCodeProcessor.java:113)
at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:175)
at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:97)
... 29 more

Remote ruleset: rules caching/refresh frequency?

In case of remote ruleset, does this plugin cache the downloaded PMD rules locally?

If so, for what duration, and what is the cache refresh frequency?

Or is it a one-time download of the rules? (I don't think this is the case as per docs)

The location is not a valid URI for Workspace type

I get "The location is not a valid URI" when I try to add a workspace relative rule set.

Spring Tool Suite
Version: 3.5.1.RELEASE
Build Id: 201405030657
Platform: Eclipse Kepler SR2 (4.3.2)

eclipse-pmd
1.0.0.201406040523
ch.acanda.eclipse.pmd.feature.feature.group

Steps to reproduce:

  • Project > Properties > PMD
    • Enable PMD for this project
    • Add...
      • Workspace, Next >
        • Name: My Rule Set
        • Location: [Browse...] parent/pmd-ruleset.xml

The only thing of note I can think of for my case is that the project I'm trying to enable PMD on is a Maven module nested inside of the parent project that contains the rule set file (i.e. the Hierachical project layout). Both projects are imported into Eclipse.

Handling exclude/include-pattern in ruleset files

I switch to this plugin instead of the official one because it's lighter but also because it seems to handle multiple ruleset files.

The thing is that I use multiple rulseset files to include/exclude specific packages. Could you handle those parameters ?

NoClassDefFoundError with version 1.12 in Eclipse Photon

I updated the plugin to the last available version (1.12.0.201804292018) in an Eclipse Photon installation (4.8.0.I20180417-2000) and started seeing the following error whenever I save a file:

eclipse.buildId=4.8.0.I20180417-2000
java.version=1.8.0_102
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=pt_BR
Command-line arguments: -os win32 -ws win32 -arch x86_64 -data file:/C:/Work/workspace/***/

This is a continuation of log file C:\Work\workspace***.metadata.bak_1.log
Created Time: 2018-05-10 14:24:34.289

ch.acanda.eclipse.pmd.core
Error
Thu May 10 14:51:29 BRT 2018
Errors running builder 'PMD Builder' on project '***'.

java.lang.NoClassDefFoundError: com/google/common/cache/RemovalCause
at com.google.common.cache.LocalCache$Segment.expireEntries(LocalCache.java:2744)
at com.google.common.cache.LocalCache$Segment.tryExpireEntries(LocalCache.java:2730)
at com.google.common.cache.LocalCache$Segment.getLiveValue(LocalCache.java:2872)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2197)
at com.google.common.cache.LocalCache.get(LocalCache.java:4154)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4158)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5147)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:5153)
at ch.acanda.eclipse.pmd.cache.RuleSetsCache.getRuleSets(RuleSetsCache.java:132)
at ch.acanda.eclipse.pmd.builder.PMDBuilder.analyze(PMDBuilder.java:78)
at ch.acanda.eclipse.pmd.builder.PMDBuilder$DeltaVisitor.visit(PMDBuilder.java:103)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:64)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:74)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:74)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:74)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:74)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:74)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:74)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:74)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:74)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:74)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:48)
at ch.acanda.eclipse.pmd.builder.PMDBuilder.incrementalBuild(PMDBuilder.java:72)
at ch.acanda.eclipse.pmd.builder.PMDBuilder.build(PMDBuilder.java:57)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:795)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:216)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:259)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:312)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:315)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:367)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:388)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:142)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:232)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:60)

Diff to pmd/pmd-eclipse-plugin

Hoi (Salut?),

Upon searching around where to [file some bug](for https://sourceforge.net/p/pmd/bugs/1503/) in the "PMD Eclipse plugin", I just realized that there are two different ones, this VS https://github.com/pmd/pmd-eclipse-plugin! I would not have thought that this world is big enough for two people writing separate Eclipse plugins for a code quality tool ... ;-)

Would you perhaps like to add section to your README and/or the homepage to outline how this one differs from pmd/pmd-eclipse-plugin ?

Specifically, do you happen to have CPD integration, with a Builder? As far as I could see pmd/pmd-eclipse-plugin does not (one seems to have to explicitly right-click PMD > Find Suspect Code And Paste with it, whereas a native on Save CPD validation be cool, of course. (I realize the possible performance impact, because it would have to look at more than just the changed resource?)

BTW: Do you know about https://github.com/m2e-code-quality/m2e-code-quality ? Perhaps you'd like to contribute eclipse-pmd support to that? Note also m2e-code-quality/m2e-code-quality#93.

Full disclosure: I'm trying to understand if https://github.com/vorburger/opendaylight-eclipse-setup would be best served by switching from pmd/pmd-eclipse-plugin to eclipse-pmd ... ;-)

Grüssli,
M.

Cannot use apex rules

In Eclipse, if I try and use PMD on a Salesforce project it needs me to add a rule set. In my ruleset.xml file, if I have a single entry like this, it loads fine.

< rule ref="category/java/codestyle.xml/AbstractNaming" />

BUT, if I put in a rule from the Apex page, it says that my ruleset.xml file is invalid

< rule ref="category/apex/codestyle.xml/WhileLoopsMustUseBraces" />

This is a basic ruleset.xml file. What am I doing wrong here?

Eclipse Luna throws Error: Plug-in "ch.acanda.eclipse.pmd.core" was unable to instantiate class "ch.acanda.eclipse.pmd.builder.PMDBuilder".

Using Eclipse Marketplace, the "eclipse-pmd" plugin is installed.

The PMD is activated in a project however it throws an exception like below:

Message:
Plug-in "ch.acanda.eclipse.pmd.core" was unable to instantiate class "ch.acanda.eclipse.pmd.builder.PMDBuilder".

Exception Stack Trace:
java.lang.NoClassDefFoundError: Could not initialize class ch.acanda.eclipse.pmd.builder.PMDBuilder
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at java.lang.Class.newInstance0(Class.java:372)
    at java.lang.Class.newInstance(Class.java:325)
    at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:184)
    at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
    at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
    at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
    at org.eclipse.core.internal.events.BuildManager.instantiateBuilder(BuildManager.java:907)
    at org.eclipse.core.internal.events.BuildManager.initializeBuilder(BuildManager.java:860)
    at org.eclipse.core.internal.events.BuildManager.getBuilder(BuildManager.java:545)
    at org.eclipse.core.internal.events.BuildManager.getBuilder(BuildManager.java:574)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:244)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:299)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:302)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:358)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:381)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

PMD should not analyze derived files

Often the code generated by tools if far from being clean code. Analyzing such code generates a lot of PMD warnings. In one of my projects, I have a directory of java files generated by a Corba compiler: those files are analyzed by PMD, which reports nearly 500 warnings.

Eclipse has, in the properties of a source directory, some attributes which should set by a developer to give some hints to code analyzers:

  • Resource/derived, which indicates that the directory contains generated code;
  • Java compiler/ignore optional compile, which tells to the compiler that no warning should be emitted for the classes in this directory.

Could it be possible to use these attributes to tell to PMD to not analyze the generated classes ?

Analyzer throws NPE when trying to analyze a file without extension

The analizer throws a NullPointerException when it tries to analyze a file without a file name extension.

java.lang.NullPointerException
at ch.acanda.eclipse.pmd.builder.Analyzer.analyze(Analyzer.java:64)
at ch.acanda.eclipse.pmd.builder.PMDBuilder.analyze(PMDBuilder.java:70)
at ch.acanda.eclipse.pmd.builder.PMDBuilder$ResourceVisitor.visit(PMDBuilder.java:94)
at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:106)
at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:65)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:127)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:75)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:104)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:88)
at ch.acanda.eclipse.pmd.builder.PMDBuilder.fullBuild(PMDBuilder.java:57)
at ch.acanda.eclipse.pmd.builder.PMDBuilder.build(PMDBuilder.java:43)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

BundleException when stopping PMD plug-in

A BundleException is thrown when Eclipse is closed and the PMD plug-in is stopped. This only happens when none of the images from PMDPluginImages were used.

org.osgi.framework.BundleException: Exception in ch.acanda.eclipse.pmd.PMDPlugin.stop() of bundle ch.acanda.eclipse.pmd.core.
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.stop(BundleContextImpl.java:791)
    at org.eclipse.osgi.framework.internal.core.BundleHost.stopWorker(BundleHost.java:510)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.suspend(AbstractBundle.java:565)
    at org.eclipse.osgi.framework.internal.core.Framework.suspendBundle(Framework.java:1161)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.decFWSL(StartLevelManager.java:595)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:257)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.shutdown(StartLevelManager.java:215)
    at org.eclipse.osgi.framework.internal.core.InternalSystemBundle.suspend(InternalSystemBundle.java:284)
    at org.eclipse.osgi.framework.internal.core.Framework.shutdown(Framework.java:691)
    at org.eclipse.osgi.framework.internal.core.Framework.close(Framework.java:598)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.shutdown(EclipseStarter.java:390)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:198)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: java.lang.ExceptionInInitializerError
    at ch.acanda.eclipse.pmd.PMDPlugin.stop(PMDPlugin.java:39)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:771)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.stop(BundleContextImpl.java:764)
    ... 19 more
Caused by: java.lang.NullPointerException
    at org.eclipse.jface.resource.JFaceResources.getResources(JFaceResources.java:207)
    at org.eclipse.jface.resource.JFaceResources.getResources(JFaceResources.java:232)
    at ch.acanda.eclipse.pmd.ui.util.PMDPluginImages.<clinit>(PMDPluginImages.java:33)
    ... 23 more
Root exception:
java.lang.ExceptionInInitializerError
    at ch.acanda.eclipse.pmd.PMDPlugin.stop(PMDPlugin.java:39)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:771)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.stop(BundleContextImpl.java:764)
    at org.eclipse.osgi.framework.internal.core.BundleHost.stopWorker(BundleHost.java:510)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.suspend(AbstractBundle.java:565)
    at org.eclipse.osgi.framework.internal.core.Framework.suspendBundle(Framework.java:1161)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.decFWSL(StartLevelManager.java:595)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:257)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.shutdown(StartLevelManager.java:215)
    at org.eclipse.osgi.framework.internal.core.InternalSystemBundle.suspend(InternalSystemBundle.java:284)
    at org.eclipse.osgi.framework.internal.core.Framework.shutdown(Framework.java:691)
    at org.eclipse.osgi.framework.internal.core.Framework.close(Framework.java:598)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.shutdown(EclipseStarter.java:390)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:198)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: java.lang.NullPointerException
    at org.eclipse.jface.resource.JFaceResources.getResources(JFaceResources.java:207)
    at org.eclipse.jface.resource.JFaceResources.getResources(JFaceResources.java:232)
    at ch.acanda.eclipse.pmd.ui.util.PMDPluginImages.<clinit>(PMDPluginImages.java:33)
    ... 23 more

'PMD' properties page is not shown

I've installed eclipse-pmd 0.7 on a fresh installation of Eclipse Kepler. The installation of the Plug-in is successful. However, no 'PMD' page is visible in the project properties dialog.

I've installed Eclipse Kepler for Java Developers (Linux 32bit) running on Ubuntu 12.04.

There is no error logged in the Eclipse error log.

CommentRequired rule broken after annonymous inner classes

Hi,

we are using the latest eclipse-pmd plugin (0.9) with a pmd 5.1 ruleset. If we have an annnonymous inner class like the following code extract, :

/** {@inheritDoc} */
    @Override
    public List<String> getNamespaces() throws RuntimeException {
...
        new FileFilter() {
            /** {@inheritDoc} */
            @Override
            public boolean accept(FileName dir, String fileName) {
                return fileName.endsWith(PROPS_FILE_ENDING);
            }
        };
...
    }

the rule will be always marked as PMD Problem. Even subsequent methods in the class with valid javaDoc will be marked as PMD Problem.
Removing the annonymous inner class resolves this issue.

Looks like a Bug in the plugin.

Add option for marking violations with high enough priority as errors

Starting from a workspace scope configurable PMD rule priority, the Eclipse marker should be error instead of warning. (Use case: At my current employer SVN will block commits with violations with priority <= 2. Hence, developers should see them as errors in Eclipse. I guess this isn't an uncommon practice, and right now this is why they still stick with the other messy PMD plugin.)

java.lang.NoClassDefFoundError: org/apache/commons/lang3/builder/ToStringBuilder

I'm getting the following when I try to enable the PMD nature on one of the projects in my multi-module maven project:

!MESSAGE Errors occurred during the build.
!SUBENTRY 1 ch.acanda.eclipse.pmd.core 4 75 2014-07-10 11:57:53.887
!MESSAGE Errors running builder 'PMD Builder' on project 'batch'.
!STACK 0
java.lang.NoClassDefFoundError: org/apache/commons/lang3/builder/ToStringBuilder
        at net.sourceforge.pmd.lang.vm.ast.ASTDirective.toString(ASTDirective.java:87)
        at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.indexNode(AbstractRuleChainVisitor.java:110)
        at net.sourceforge.pmd.lang.vm.rule.VmRuleChainVisitor.access$000(VmRuleChainVisitor.java:19)
        at net.sourceforge.pmd.lang.vm.rule.VmRuleChainVisitor$1.visit(VmRuleChainVisitor.java:28)
        at net.sourceforge.pmd.lang.vm.ast.VmParserVisitorAdapter.visit(VmParserVisitorAdapter.java:66)
        at net.sourceforge.pmd.lang.vm.ast.ASTDirective.jjtAccept(ASTDirective.java:60)
        at net.sourceforge.pmd.lang.vm.ast.AbstractVmNode.childrenAccept(AbstractVmNode.java:136)
        at net.sourceforge.pmd.lang.vm.ast.VmParserVisitorAdapter.visit(VmParserVisitorAdapter.java:7)
        at net.sourceforge.pmd.lang.vm.rule.VmRuleChainVisitor$1.visit(VmRuleChainVisitor.java:29)
        at net.sourceforge.pmd.lang.vm.ast.VmParserVisitorAdapter.visit(VmParserVisitorAdapter.java:13)
        at net.sourceforge.pmd.lang.vm.rule.VmRuleChainVisitor.indexNodes(VmRuleChainVisitor.java:34)
        at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.visitAll(AbstractRuleChainVisitor.java:59)
        at net.sourceforge.pmd.RuleChain.apply(RuleChain.java:66)
        at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:122)
        at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:150)
        at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:80)
        at ch.acanda.eclipse.pmd.builder.Analyzer.analyze(Analyzer.java:72)
        at ch.acanda.eclipse.pmd.builder.PMDBuilder.analyze(PMDBuilder.java:75)
        at ch.acanda.eclipse.pmd.builder.PMDBuilder$ResourceVisitor.visit(PMDBuilder.java:99)
        at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:126)
        at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:85)
        at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
        at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
        at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
        at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
        at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
        at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:127)
        at org.eclipse.core.internal.resources.Resource.accept(Resource.java:95)
        at org.eclipse.core.internal.resources.Resource.accept(Resource.java:52)
        at org.eclipse.core.internal.resources.Resource.accept(Resource.java:124)
        at org.eclipse.core.internal.resources.Resource.accept(Resource.java:108)
        at ch.acanda.eclipse.pmd.builder.PMDBuilder.fullBuild(PMDBuilder.java:62)
        at ch.acanda.eclipse.pmd.builder.PMDBuilder.build(PMDBuilder.java:48)
        at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:733)
        at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
        at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
        at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
        at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:299)
        at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
        at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:302)
        at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:358)
        at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:381)
        at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
        at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

I enabled the PMD nature on a smaller "common" module without issue. I can run mvn pmd:pmd on the project in question without issue as well. My Maven configuration is as follows:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pmd-plugin</artifactId>
    <version>${pmd.maven.plugin.version}</version>
    <configuration>
        <targetJdk>${target.jdk}</targetJdk>
        <rulesets>
            <ruleset>file://${basedir}/../my-pmd.xml</ruleset>
        </rulesets>
        <includeTests>true</includeTests>
        <verbose>true</verbose>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>net.sourceforge.pmd</groupId>
            <artifactId>pmd</artifactId>
            <version>${pmd.version}</version>
        </dependency>
    </dependencies>
</plugin>

My pmd.maven.plugin.version = 3.1, and pmd.version = 5.1.1. I'm referencing the same rule set file in Maven as I am in my eclipse-pmd configuration.

Zipped update site

Hello,

I work in a company where the firewall is not very permissive, so when I try to install or to update eclipse-pmd, I got error messages...
Could it be possible to have an update site zip so we could use it to install eclipse-pmd ?

Project in workspace option

It would be nice to be able to add a rule set pointing on a file included in a different project from the same workspace.

The use case is to have a basic Eclipse project containing all the configuration files of a team (checktyle, formatter, code template, pmd, etc). It is better to use this approach then refering to a hardcoded file system path. You can also put this project in a VCS.

Rules sets not selected on import

When you enable PMD on a project and check a rule set to use, if you remove the project from the workspace and re-import it, the rule set previously selected isn't anymore.

An entry in the project should keep track of selected rule sets. This way, new developpers on a project won't forget to activate PMD on a project and will follow the team rule set.

Build hangs on project with SQL files

I'm trying to enable the PMD nature on a Maven module project that contains 540 .sql files and 290 .java files. When I do this Building workspace hangs at 43% on "Setting classpath containers: Invoking 'PMD Builder' on '/db'." The Eclipse process has the CPU pegged at 700+% (4 cores, hyperthreaded, so 800% is the max). After running for over an hour the build eventually fails having run out of "Java heap space" (-Xmx1536m -XX:MaxPermSize=512m). After the failure I can remove the PMD nature from the project in question and restart Eclipse.

I took occasional stack dumps while it was running, and a single ever-present stack for PLSQLParser stood out:

"Worker-111" #596 prio=5 os_prio=31 tid=0x000000010096d800 nid=0xfbab runnable [0x000000012db31000]
   java.lang.Thread.State: RUNNABLE
    at java.lang.Throwable.fillInStackTrace(Native Method)
    at java.lang.Throwable.fillInStackTrace(Throwable.java:783)
    - locked <0x00000007a296da60> (a java.io.IOException)
    at java.lang.Throwable.<init>(Throwable.java:265)
    at java.lang.Exception.<init>(Exception.java:66)
    at java.io.IOException.<init>(IOException.java:58)
    at java.io.BufferedReader.ensureOpen(BufferedReader.java:122)
    at java.io.BufferedReader.read(BufferedReader.java:278)
    - locked <0x000000077afee790> (a java.io.InputStreamReader)
    at net.sourceforge.pmd.lang.ast.SimpleCharStream.FillBuff(SimpleCharStream.java:114)
    at net.sourceforge.pmd.lang.ast.SimpleCharStream.readChar(SimpleCharStream.java:196)
    at net.sourceforge.pmd.lang.ast.SimpleCharStream.BeginToken(SimpleCharStream.java:136)
    at net.sourceforge.pmd.lang.plsql.ast.PLSQLParserTokenManager.getNextToken(PLSQLParserTokenManager.java:4347)
    at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.getNextToken(PLSQLParser.java:39826)
    at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Skip2NextTerminator(PLSQLParser.java:9001)
    at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.SqlStatement(PLSQLParser.java:9250)
    at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.UnlabelledStatement(PLSQLParser.java:9355)
    at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Statement(PLSQLParser.java:9974)
    at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.View(PLSQLParser.java:22036)
    at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Input(PLSQLParser.java:182)
    at net.sourceforge.pmd.lang.plsql.PLSQLParser.parse(PLSQLParser.java:52)
    at net.sourceforge.pmd.SourceCodeProcessor.parse(SourceCodeProcessor.java:95)
    at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:142)
    at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:80)
    at ch.acanda.eclipse.pmd.builder.Analyzer.analyze(Analyzer.java:72)
    at ch.acanda.eclipse.pmd.builder.PMDBuilder.analyze(PMDBuilder.java:75)
    at ch.acanda.eclipse.pmd.builder.PMDBuilder$ResourceVisitor.visit(PMDBuilder.java:99)
    at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:126)
    at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:85)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
    at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
    at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:127)
    at org.eclipse.core.internal.resources.Resource.accept(Resource.java:95)
    at org.eclipse.core.internal.resources.Resource.accept(Resource.java:52)
    at org.eclipse.core.internal.resources.Resource.accept(Resource.java:124)
    at org.eclipse.core.internal.resources.Resource.accept(Resource.java:108)
    at ch.acanda.eclipse.pmd.builder.PMDBuilder.fullBuild(PMDBuilder.java:62)
    at ch.acanda.eclipse.pmd.builder.PMDBuilder.build(PMDBuilder.java:48)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:733)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:299)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:302)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:358)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:381)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

Assuming I've specified the patterns correctly my rule set excludes all but .java files, and I don't reference any of the "rulesets/plsql/*" rule sets:

<?xml version="1.0" encoding="UTF-8" ?>
<ruleset name="etpruleset" 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>My Ruleset</description>

    <exclude-pattern>**/*</exclude-pattern>
    <include-pattern>**/*.java</include-pattern>

    <rule ref="rulesets/java/basic.xml" />
[...]

When I run mvn pmd:pmd on this project it completes without issue in a few seconds.

Incorrect calculation of marker start position

The start position of a marker is not calculated correctly when a line contains spaces and tabs.

In public class A↦extends Object { } (↦ represents a tab) the marker will cover tends instead of Object.

New releases

Hi,

Great Plugin. I saw that the last release was at the end of 2015 with PMD 5.4.1.
But in the git history you updated to newer PMD versions.
Is there any reason why you don't do any releases anymore?

Cheers,
Lukas

Release 1.9

The 1.9 release of eclipse-pmd is long overdue. If you want to help test the new version (@lukedirtwalker, @sratz), here is what you can do.

Install eclipse-pmd from the update site http://www.acanda.ch/eclipse-pmd/beta/1.9 (Help > Install New Software... > paste the URL into "Work with" > select everything from eclipse-pmd > Finish).

Now all you have to do is use the plugin for a week to see if you run into any problems. If eclipse-pmd runs into an unexpected problem it will show a message box with a short error message. Also keep an eye on the view "Error Log". This is where you can see eclipse-pmd logging errors, warnings and info messages.

Open an new issue if you find something that is not working. Add a comment to this issue if you didn't encounter any problems after a week.

Thank you very much for your help!

Feature Request: Provide ability to define exclude pattern

It would be nice, if I can configure per project multiple exclude pattern for files and directories, which should not be checked by PMD.

For example in one of my projects I have a source directory with generated source with the name src/main/src-gen. I want PMD to not check this directory.

The exclude pattern configuration could be stored in the .eclipse-pmd file

pmd can not find my enum class (configure auxclasspath)

i write a custom rule to ensure enum equals use "==", so first of all ,i have to identify which class is enum in my project. i use "name.getType().isEnum() " to do it. but is not effective.

the reason maybe The class not loaded. so i want to asking , pmd has a auxclasspath configuration, how do i configure in my project.

thank you

Eclipse PDT. Cannot change PMD nature of project <projectName>

I can't enable and use PMD for my php project in Eclipse PDT.

Error StackTrace is attached.

My ruleset.xml file:

<?xml version="1.0"?>
<ruleset name="Braces"
    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>
	The Braces ruleset contains rules regarding the use and placement of braces.
	</description> 
	<rule name="IfStmtsMustUseBraces" language="php"
		message="The Braces ruleset contains rules regarding the use and placement of braces."
		class="net.sourceforge.pmd.lang.rule.XPathRule">
		<description>
		Avoid using if 123 statements without using braces to surround the code
		 block. If the code formatting or indentation is lost then it becomes difficult 
		to separate the code being controlled from the rest.
		</description>
		<priority>3</priority> 
		<properties>
			<property name="xpath">
				<value>
<![CDATA[
//IfStatement[count(*) < 3][not(Statement/Block)]
]]>
				</value>
			</property>
		</properties>
		
		<example>
<![CDATA[
class Foo {

	public function test(){
		if(bool==1)
			x++;

		if (bool==1){
			x++;
		}
	}

}
]]>
		</example>
		
	</rule>
	<rule name="WhileLoopsMustUseBraces"
		language="php"
		since="0.7"
		message="Avoid using 'while' statements without curly braces"
		class="net.sourceforge.pmd.lang.rule.XPathRule"
		externalInfoUrl="">
		<description>
		Avoid using 'while' statements without using braces to surround the code 
		block. If the code formatting or indentation is lost then it becomes difficult
		to separate the code being controlled from the rest.
		</description>
		<priority>3</priority>
		<properties>
			<property name="xpath">
				<value>
<![CDATA[
//WhileStatement[not(Statement/Block)]
]]>
				</value>
			</property>
		</properties>
		<example>
<![CDATA[
while (true)	// not recommended
      x++;
      
while (true) {	// preferred approach
      x++;
}
]]>
		</example>
		</rule>
</ruleset>
[stacktrace.txt](https://github.com/pmd/pmd/files/816944/stacktrace.txt)

Session Data

eclipse.buildId=4.6.2.M20161124-1400
java.version=1.8.0_91
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments:  -product org.eclipse.epp.package.php.product -product org.eclipse.epp.package.php.product
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.php.product -data file:/C:/Users/veaceslav/workspace2/ -product org.eclipse.epp.package.php.product

BUG: Rule.start() is not called before Rule.apply()

I've written a couple of rules that perform some setup and statistics/teardown in their start() and end() methods, respectively.

When I wrote an Eclipse Fragment to integrate them with the Acanda PMD-Plugin, I noted that neiter start() nor end() is called before calling Rule.apply() (as promised by the Rule interface).

Please compare the code in Acanda here (calling runPMD of the Acanda Plugin's Analyzer) with the comparable code piece here (PMD's MonoThreadProcessor performing analysis).

The MonoThreadProcessor calls rs.start(ctx) and rs.end(ctx) when running an analysis. This should also be peformed by the Acanda plugin.

The rule set configuration at the given location is invalid

even on default ruleset

<?xml version="1.0"?>
<ruleset name="Custom ruleset"
    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 checks my code for bad stuff
  </description>
</ruleset>

i get The rule set configuration at the given location is invalid message when trying to add the ruleset
screen shot 2017-01-03 at 7 35 30 pm

Improve ruleset feedback

AddRuleSetConfigurationModel.validateLocation() gags all exceptions when parsing the ruleset and simply displays the static message "The rule set configuration at the given location is invalid". It would be helpful if it gave some indication of what the problem was.

Add context menu to reanalyze after rule set file changes

It would be nice to have a context menu such as "PMD > Check Code with PMD" that picks up changes to active rule set files and reanalyzes. For prior art see "Checkstyle > Check Code with Checkstyle" and "Find Bugs > Find Bugs".

It would be great if this supported multiple selections to analyze several projects at once. A nice-to-have would be for it to work at the package/folder and file levels, again supporting multiple selections.

Looking ahead a "PMD > Configure" that shortcuts to the PMD properties page would be another use for a PMD context menu.

An error occurred while automatically activating bundle ch.acanda.eclipse.pmd.core

Submitted by @rsandidfc in another issue:

I've just installed PMD for the first time, and on launching Eclipse am immediately presented with:

Errors occurred during the build.
Error instantiating builder 'ch.acanda.eclipse.pmd.builder.PMDBuilder'.
Plug-in ch.acanda.eclipse.pmd.core was unable to load class ch.acanda.eclipse.pmd.builder.PMDBuilder.
An error occurred while automatically activating bundle ch.acanda.eclipse.pmd.core (1671).
Plug-in ch.acanda.eclipse.pmd.core was unable to load class ch.acanda.eclipse.pmd.builder.PMDBuilder.
An error occurred while automatically activating bundle ch.acanda.eclipse.pmd.core (1671).

I'm running Mars on Win2k8
Version: Mars.2 Release (4.5.2)
Build id: 20160218-0600
eclipse-pmd-1.8.0-201512061933
PMD for Eclipse 4.0.8.v20151204-2156

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.