Menu

Pmd custom rule based on java class

John
2016-05-21
2018-04-01
  • John

    John - 2016-05-21

    Hi all, i have a quick question on the pmd rule designer. From the pmd rule desginer itself, there is an option availabe for for developers to insert a new xml java rule. The xml java rule would be based on an existing java class. Take for instance

    <?xml version="1.0"?>
    <ruleset
    name="myrules"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../etc/
    ruleset_xml_schema.xml">
    <description>
    The ‘myrules’ ruleset contains my rules. Aptly named!
    </description>
    <rule name="EmptyIfStmt"
    message="Avoid empty 'if' statements"
    class="net.sourceforge.pmd.rules.EmptyIf">
    <description>
    Avoid empty 'if' statements
    </description>
    <priority>3</priority>
    <example>
    <![CDATA[
    if (foo == 0) {
    // why bother checking up on foo?
    }
    ]]>
    </example>
    </rule>
    </ruleset>
    

    From the xml file above, we can see that this xml rule file is referencing from a existing java class, namely "net.sourceforge.pmd.rules.EmptyIf". My question is this, where should I store this java class at? If i were to store "EmptyIf.java" in a folder named "net.sourceforge.pmd.rules" which is located on the desktop, would pmd be able to find this java class when I call the EmptyIf rule? Furthermore, do i have to compile this java class?

    Thank you all

     
  • Luv Srivastava

    Luv Srivastava - 2016-11-07

    Could anyone give idea of create custom rule with java using eclipse ide luna

     
  • Andreas Dangel

    Andreas Dangel - 2016-11-26

    Hi Luv,
    did you see the general documentation about it? How to write a rule

     
  • Swapnali

    Swapnali - 2018-04-01

    HI All,
    I am trying to create Xpath rule for Apex.
    I checked the existing Apex xpath rule, it has implementation Class: net.sourceforge.pmd.lang.apex.rule.ApexXPathRule
    While creating new Xpath rule, I am not getting option to choose implementation Class, it automatically takes net.sourceforge.pmd.lang.rule.XPathRule path.
    So my new rule is not getting fired for apex class.
    Please assist.

    Regards,
    Swapnali

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.