Skip to content

Commit

Permalink
Merge pull request #4804 from adangel:issue-4309-xpath-cleanups
Browse files Browse the repository at this point in the history
[core] XPath cleanups #4804
  • Loading branch information
adangel committed Feb 9, 2024
2 parents 7698b6a + f5c4aad commit 5931461
Show file tree
Hide file tree
Showing 87 changed files with 919 additions and 656 deletions.
1 change: 0 additions & 1 deletion docs/pages/pmd/userdocs/extending/defining_properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ with a backslash when needed.
```xml
<rule name="MyXpathRule" ...>
<properties>
<property name="version" value="2.0" />
<property name="intProp" type="List[Integer]" value="1,2,5" description="An IntegerMultiProperty." />
<property name="reportedIdentifiers" type="List[String]" value="foo,bar"
description="A StringMultiProperty." />
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/pmd/userdocs/extending/writing_rules_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ instead of mentioning the `ref` attribute, it mentions the `class` attribute,
with the implementation class of your rule.

* **For Java rules:** this is the concrete class extending AbstractRule (transitively)
* **For XPath rules:** this is `net.sourceforge.pmd.lang.rule.XPathRule`.
* **For XPath rules:** this is `net.sourceforge.pmd.lang.rule.xpath.XPathRule`.
* **For XPath rules analyzing XML-based languages:** this is `net.sourceforge.pmd.lang.xml.rule.DomXPathRule`.
See [XPath rules in XML](pmd_languages_xml.html#xpath-rules-in-xml) for more info.

Expand All @@ -128,7 +128,7 @@ Example for XPath rule:
<rule name="MyXPathRule"
language="java"
message="Violation!"
class="net.sourceforge.pmd.lang.rule.XPathRule">
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<description>
Description
</description>
Expand Down
3 changes: 2 additions & 1 deletion docs/pages/pmd/userdocs/extending/writing_xpath_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ with opt-in support for XPath 2.0.
See [the Saxonica documentation](https://www.saxonica.com/html/documentation/expressions/xpath31new.html)
for an introduction to new features in XPath 3.1.

The property `version` of {% jdoc core::lang.rule.XPathRule %} is deprecated and will be removed.
The property `version` of {% jdoc core::lang.rule.XPathRule %} is deprecated and
has been removed with PMD 7.


## DOM representation of ASTs
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/pmd/userdocs/extending/your_first_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ copy-paste into your ruleset XML. The resulting element looks like so:
<rule name="DontCallBossShort"
language="java"
message="Boss wants to talk to you."
class="net.sourceforge.pmd.lang.rule.XPathRule">
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<description>
TODO
</description>
Expand Down
8 changes: 5 additions & 3 deletions docs/pages/pmd/userdocs/migrating_to_pmd7.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ XPath 2.0 is available in PMD 6 already and can be used right away. PMD 7 will u
won't support XPath 1.0 anymore. The difference between XPath 2.0 and XPath 3.1 is not big, so your XPath 2.0
can be expected to work in PMD 7 without any further changes. So the migration path is to simply migrate to XPath 2.0.

After you have migrated your XPath rules to XPath 2.0, remove the "version" property, since that will be removed
with PMD 7. PMD 7 by default uses XPath 3.1.
See below [XPath](#xpath-migrating-from-10-to-20) for details.
After you have migrated your XPath rules to XPath 2.0, remove the "version" property, since that has been removed
with PMD 7. PMD 7 by default uses XPath 3.1. See below [XPath](#xpath-migrating-from-10-to-20) for details.

Then change the `class` attribute of your rule to `net.sourceforge.pmd.lang.rule.xpath.XPathRule` - because the
class {%jdoc core::lang.rule.xpath.XPathRule %} has been moved into subpackage {% jdoc_package core::lang.rule.xpath %}.

There are some general changes for AST nodes regarding the `@Image` attribute.
See below [General AST Changes to avoid @Image](#general-ast-changes-to-avoid-image).
Expand Down
8 changes: 8 additions & 0 deletions docs/pages/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ The rules have been moved into categories with PMD 6.
* [#3903](https://github.com/pmd/pmd/issues/3903): \[core] Consolidate `n.s.pmd.reporting` package
* [#3917](https://github.com/pmd/pmd/issues/3917): \[core] Consolidate `n.s.pmd.lang.rule` package
* [#4065](https://github.com/pmd/pmd/issues/4065): \[core] Rename TokenMgrError to LexException, Tokenizer to CpdLexer
* [#4309](https://github.com/pmd/pmd/issues/4309): \[core] Cleanups in XPath area
* [#4312](https://github.com/pmd/pmd/issues/4312): \[core] Remove unnecessary property `color` and system property `pmd.color` in `TextColorRenderer`
* [#4313](https://github.com/pmd/pmd/issues/4313): \[core] Remove support for &lt;lang&gt;-&lt;ruleset&gt; hyphen notation for ruleset references
* [#4314](https://github.com/pmd/pmd/issues/4314): \[core] Remove ruleset compatibility filter (RuleSetFactoryCompatibility) and CLI option `--no-ruleset-compatibility`
Expand Down Expand Up @@ -235,6 +236,11 @@ The rules have been moved into categories with PMD 6.
See [General AST Changes to avoid @Image]({{ baseurl }}pmd_userdocs_migrating_to_pmd7.html#general-ast-changes-to-avoid-image)
in the migration guide for details.

**XPath Rules**
* The property `version` was already deprecated and has finally been removed. Please don't define the version
property anymore in your custom XPath rules. By default, the latest XPath version will be used, which
is XPath 3.1.

**Moved classes/consolidated packages**

* pmd-core
Expand All @@ -252,6 +258,7 @@ in the migration guide for details.
* {%jdoc core::reporting.RuleViolation %}
* {%jdoc core::reporting.ViolationSuppressor %}
* {%jdoc core::reporting.ParametricRuleViolation %} (moved from `net.sourcceforge.pmd.lang.rule`)
* {%jdoc core::lang.rule.xpath.XPathRule %} has been moved into subpackage {% jdoc_package core::lang.rule.xpath %}.

**Internalized classes**

Expand Down Expand Up @@ -746,6 +753,7 @@ See also [Detailed Release Notes for PMD 7]({{ baseurl }}pmd_release_notes_pmd7.
* [#4204](https://github.com/pmd/pmd/issues/4204): \[core] Provide a CpdAnalysis class as a programmatic entry point into CPD
* [#4301](https://github.com/pmd/pmd/issues/4301): \[core] Remove deprecated property concrete classes
* [#4302](https://github.com/pmd/pmd/issues/4302): \[core] Migrate Property Framework API to Java 8
* [#4309](https://github.com/pmd/pmd/issues/4309): \[core] Cleanups in XPath area
* [#4312](https://github.com/pmd/pmd/issues/4312): \[core] Remove unnecessary property `color` and system property `pmd.color` in `TextColorRenderer`
* [#4313](https://github.com/pmd/pmd/issues/4313): \[core] Remove support for &lt;lang&gt;-&lt;ruleset&gt; hyphen notation for ruleset references
* [#4314](https://github.com/pmd/pmd/issues/4314): \[core] Remove ruleset compatibility filter (RuleSetFactoryCompatibility) and CLI option `--no-ruleset-compatibility`
Expand Down
5 changes: 2 additions & 3 deletions pmd-apex/src/main/resources/category/apex/bestpractices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private class TestRunAs {
since="6.13.0"
language="apex"
message="Apex test methods should have @isTest annotation."
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#apexunittestmethodshouldhaveistestannotation">
<description>
Apex test methods should have `@isTest` annotation instead of the `testMethod` keyword,
Expand All @@ -116,7 +116,6 @@ annotation for test classes and methods.
</description>
<priority>3</priority>
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value>
<![CDATA[
Expand Down Expand Up @@ -231,7 +230,7 @@ trigger Accounts on Account (before insert, before update, before delete, after
since="6.18.0"
language="apex"
message="Calls to System.debug should specify a logging level."
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#debugsshoulduselogginglevel">
<description>
The first parameter of System.debug, when using the signature with two parameters, is a LoggingLevel enum.
Expand Down
10 changes: 5 additions & 5 deletions pmd-apex/src/main/resources/category/apex/codestyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class fooClass { } // This will be reported unless you change the regex
language="apex"
since="5.6.0"
message="Avoid using 'if...else' statements without curly braces"
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#ifelsestmtsmustusebraces">
<description>
Avoid using if..else statements without using surrounding braces. If the code formatting
Expand Down Expand Up @@ -74,7 +74,7 @@ else
language="apex"
since="5.6.0"
message="Avoid using if statements without curly braces"
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#ifstmtsmustusebraces">
<description>
Avoid using if statements without using braces to surround the code block. If the code
Expand Down Expand Up @@ -156,7 +156,7 @@ public class Foo {
language="apex"
since="5.6.0"
message="Avoid using 'for' statements without curly braces"
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#forloopsmustusebraces">
<description>
Avoid using 'for' statements without using surrounding braces. If the code formatting or
Expand Down Expand Up @@ -270,7 +270,7 @@ public class Foo {
language="apex"
since="6.7.0"
message="Use one statement for each line, it enhances code readability."
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#onedeclarationperline">
<description>
Apex allows the use of several variables declaration of the same type on one line. However, it
Expand Down Expand Up @@ -338,7 +338,7 @@ public class Foo {
language="apex"
since="5.6.0"
message="Avoid using 'while' statements without curly braces"
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#whileloopsmustusebraces">
<description>
Avoid using 'while' statements without using braces to surround the code block. If the code
Expand Down
14 changes: 7 additions & 7 deletions pmd-apex/src/main/resources/category/apex/errorprone.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Foo {
language="apex"
since="6.0.0"
message="Avoid directly accessing Trigger.old and Trigger.new"
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#avoiddirectaccesstriggermap">
<description>
Avoid directly accessing Trigger.old and Trigger.new as it can lead to a bug. Triggers should be bulkified and iterate through the map to handle the actions for each item separately.
Expand Down Expand Up @@ -138,7 +138,7 @@ public without sharing class Foo {
language="apex"
since="6.0.0"
message="Avoid empty catch blocks"
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#emptycatchblock">
<description>
Empty Catch Block finds instances where an exception is caught, but nothing is done.
Expand Down Expand Up @@ -177,7 +177,7 @@ public void doSomething() {
language="apex"
since="6.0.0"
message="Avoid empty 'if' statements"
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#emptyifstmt">
<description>
Empty If Statement finds instances where a condition is checked but nothing is done about it.
Expand Down Expand Up @@ -210,7 +210,7 @@ public class Foo {
language="apex"
since="6.0.0"
message="Avoid empty block statements."
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#emptystatementblock">
<description>
Empty block statements serve no purpose and should be removed.
Expand Down Expand Up @@ -247,7 +247,7 @@ public class Foo {
language="apex"
since="6.0.0"
message="Avoid empty try or finally blocks"
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#emptytryorfinallyblock">
<description>
Avoid empty try or finally blocks - what's the point?
Expand Down Expand Up @@ -291,7 +291,7 @@ public class Foo {
language="apex"
since="6.0.0"
message="Avoid empty 'while' statements"
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#emptywhilestmt">
<description>
Empty While Statement finds all instances where a while statement does nothing.
Expand Down Expand Up @@ -445,7 +445,7 @@ public class Foo { // perfect, both methods provided
language="apex"
since="6.22.0"
message="Test methods must be in test classes"
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#testmethodsmustbeintestclasses">
<description>
Test methods marked as a testMethod or annotated with @IsTest,
Expand Down
6 changes: 2 additions & 4 deletions pmd-apex/src/main/resources/category/apex/performance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Rules that flag suboptimal code.
language="apex"
since="6.36.0"
message="Avoid debug statements since they impact on performance"
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_performance.html#avoiddebugstatements">
<description>
Debug statements contribute to longer transactions and consume Apex CPU time even when debug logs are not being captured.
Expand All @@ -24,7 +24,6 @@ For other valid use cases that the statement is in fact valid make use of the `@
</description>
<priority>3</priority>
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value>
<![CDATA[
Expand Down Expand Up @@ -141,7 +140,7 @@ public class Something {
language="apex"
since="6.40.0"
message="DescribeSObjectResult could be being loaded eagerly with all child relationships."
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_performance.html#eagerlyloadeddescribesobjectresult">
<description>
This rule finds `DescribeSObjectResult`s which could have been loaded eagerly via `SObjectType.getDescribe()`.
Expand Down Expand Up @@ -172,7 +171,6 @@ Properties:
<priority>3</priority>
<properties>
<property name="noDefault" type="Boolean" value="false" description="Do not allow SObjectDescribeOptions.DEFAULT option to ensure consistent results no matter where getDescribe is called"/>
<property name="version" value="2.0"/>
<property name="xpath">
<value>
<![CDATA[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import net.sourceforge.pmd.lang.apex.ast.ApexParserTestBase;
import net.sourceforge.pmd.lang.document.FileId;
import net.sourceforge.pmd.lang.rule.XPathRule;
import net.sourceforge.pmd.lang.rule.xpath.XPathRule;
import net.sourceforge.pmd.reporting.Report;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</description>

<rule name="ReportAllRootNodes" language="dummy" since="1.0" message="Violation from ReportAllRootNodes"
class="net.sourceforge.pmd.lang.rule.XPathRule"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/rules/test/TestRuleset3.xml#Ruleset3Rule1">
<description>Just for test</description>
<priority>3</priority>
Expand Down
2 changes: 1 addition & 1 deletion pmd-compat6/src/it/pmd-for-java/exception_ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<description/>
<rule name="ExceptionThrowingRule"
language="java"
class="net.sourceforge.pmd.lang.rule.XPathRule">
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<description>Use this rule to produce a processing error.</description>
<priority>3</priority>
<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.lang.rule;

public class XPathRule extends net.sourceforge.pmd.lang.rule.xpath.XPathRule {
}

0 comments on commit 5931461

Please sign in to comment.