2

I would like to add a new rule related to DMLStatements in for loops.

What i have thought

  • I could create a class with "AvoidDmlStatementsInLoopsRule" class code
  • then convert it into .jar and finally copy .jar into "eclipse\plugins\com.villagechief.pmd.eclipse_1.2.3.v201108241738\libs" folder.

  • For that i found a Java class in below url.

"https://pmd.github.io/pmd-5.5.0/pmd-apex/xref/net/sourceforge/pmd/lang/apex/rule/performance/AvoidDmlStatementsInLoopsRule.html"

I'm completely blocked here, what to do next.

  • I'm trying to save the class "AvoidDmlStatementsInLoopsRule" in eclipse, but it's importing some packages like
  • "package net.sourceforge.pmd.lang.apex.rule.performance;

    import net.sourceforge.pmd.lang.ast.AbstractNode;

    import net.sourceforge.pmd.lang.ast.Node;"

  • I have downloaded above folder structure from "https://sourceforge.net/projects/pmd/files/".

How to made them available for the "AvoidDmlStatementsInLoopsRule" class.

Am i in the right direction or any other process to be followed instead?

4
4

As the original contributor of the PMD Apex language module all I can add here is to clarify a common misunderstanding that is the root for many confusion here on StackExchange:

There are two PMD tools out there:

  1. The original Open-Source PMD - the well-known open-source code analyzer that support many languages and can be extended and improved by the community.

  2. The **Closed-source ApexPMD(a.k.a CodeScan) - a paid PMD clone by an Australian company called VillageChief. ApexPMD uses PMD under the hood.

Which on should you use?

As the original contributor of the Apex module to PMD I might be biased, but I think in the long run developers will definitely profit from going with a flexible open source solution. Why?

  • Features: There might be no feature-parity between PMD and ApexPMD right now but the more developer and companies jump on the #CleanApex bandwagon the more contributions we will see. No small company can then compete with that velocity.

  • Integrations/Tooling: Since my initial contribution many tooling providers integrated PMD into their products. Let me just name a few. Salesforce IDEs like Illuminated Cloud, The WelkinsSuite, Force.com IDE. Github and Bitbucket integrators like CodeClimate and Codacy.

  • Salesforce.com favors Open-Source: Salesforce.com is actively supporting my work on PMD for Apex. They donated a parser and added features to Apex that make life easier for us writing PMD rules. There are even plans to make the PMD Eclipse plugin part of their Force.com IDE 2.

Become part of the community at https://github.com/pmd/pmd/issues. :-)

1
  • 1
    'The **Closed-source ApexPMD(a.k.a CodeScan) - a paid PMD clone by an Australian company called VillageChief. ApexPMD uses PMD under the hood.' - I think this is a really interesting point. By leveraging your Apex module with PMD, companies can save thousands a year vs using CodeScan. May 11 '18 at 8:40
2

1.You need to have maven configured on your machine to build the package.
Build PMD and test your new rule
https://github.com/Up2Go/codeclimate-apexmetrics/wiki/build-pmd-and-test-your-new-rule

  1. Add a new rule for Apex PMD following link has detail explanation about how to create PMD Rule.
    https://github.com/Up2Go/codeclimate-apexmetrics/wiki/add-a-new-rule-for-apex-pmd
  2. You can create PMD rule using two options (which I am aware of)
    i. X-PATH ii. JAVA Code
    For X-Path:
    You can also use PMD Designer GO To>> PMD Folder that you have downloaded >> BIN>> execute designer.bat file using command prompt
    following window will get opend and you can design your rule using Xpath query by traversing through nodes.
    enter image description here
  3. How to setup Development Environment
    https://github.com/Up2Go/codeclimate-apexmetrics/wiki/setup-development-environment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.