Skip to content

Commit 5bb51f3

Browse files
authored
Update PMD to 6.22.0 (#380)
Updates PMD from 6.7.0 to 6.22.0 For release notes see: * https://pmd.github.io/latest/pmd_release_notes.html * https://pmd.github.io/latest/pmd_release_notes_old.html After going through all those many changes, updating to the newer version results in: * Support for newer Java versions * Fixes for false positives/negatives * More rules we could use such as [UseDiamondOperator](https://pmd.github.io/latest/pmd_rules_java_codestyle.html#usediamondoperator) * Deprecations of several PMD classes in preparation for PMD 7.0.0 where they will be removed (builders have been introduced and APIs have become less specific to Java) I've fixed the deprecations impacting SAT: * UseSLF4JLoggerRule now uses the generic API methods instead of the deprecated Java specific methods * The [UnsynchronizedStaticDateFormatter](https://pmd.github.io/latest/pmd_rules_java_multithreading.html#unsynchronizedstaticdateformatter) rule has been deprecated in favor of the [UnsynchronizedStaticFormatter](https://pmd.github.io/latest/pmd_rules_java_multithreading.html#unsynchronizedstaticformatter) which would cause the following warnings during execution: [WARNING] Discontinue using Rule name category/java/multithreading.xml/UnsynchronizedStaticDateFormatter as it is scheduled for removal from PMD. PMD 7.0.0 will remove support for this Rule. Signed-off-by: Wouter Born <github@maindrain.net>
1 parent ccc28ab commit 5bb51f3

5 files changed

Lines changed: 12 additions & 11 deletions

File tree

custom-checks/pmd/src/main/java/org/openhab/tools/analysis/pmd/UseSLF4JLoggerRule.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,20 @@ public Object visit(ASTImportDeclaration node, Object data) {
4747
String fullImportName = node.getImportedName();
4848
if (forbiddenLoggers.contains(fullImportName)) {
4949
addViolation(data, node);
50-
} else if ("org.slf4j.Logger".equals(fullImportName) || ("org.slf4j".equals(fullImportName) && node.isImportOnDemand())) {
50+
} else if ("org.slf4j.Logger".equals(fullImportName)
51+
|| ("org.slf4j".equals(fullImportName) && node.isImportOnDemand())) {
5152
isSlf4jPackageImported = true;
5253
}
5354
return super.visit(node, data);
5455
}
5556

5657
@Override
5758
public Object visit(ASTVariableDeclarator node, Object data) {
58-
ASTType typeNode = node.jjtGetParent().getFirstChildOfType(ASTType.class);
59-
Node reftypeNode = typeNode.jjtGetChild(0);
59+
ASTType typeNode = node.getParent().getFirstChildOfType(ASTType.class);
60+
Node reftypeNode = typeNode.getChild(0);
6061
if (reftypeNode instanceof ASTReferenceType) {
61-
ASTClassOrInterfaceType classOrInterfaceType = reftypeNode.getFirstChildOfType(ASTClassOrInterfaceType.class);
62+
ASTClassOrInterfaceType classOrInterfaceType = reftypeNode
63+
.getFirstChildOfType(ASTClassOrInterfaceType.class);
6264
if (classOrInterfaceType != null) {
6365
String className = classOrInterfaceType.getImage();
6466

@@ -74,9 +76,8 @@ private boolean isClassNameForbidden(String className) {
7476
if (forbiddenLoggers.contains(className)) {
7577
return true;
7678
}
77-
//If the classname is Logger but org.slf4j is not in the imports,
79+
// If the classname is Logger but org.slf4j is not in the imports,
7880
// that means the current Logger literal is not a sfl4j.Logger
7981
return LOGGER_LITERAL.equals(className) && !isSlf4jPackageImported;
8082
}
8183
}
82-

docs/maven-plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Parameters:
8686
| ------ | ------| -------- |
8787
| **pmdRuleset** | String | Relative path of the XML configuration to use. If not set the default ruleset file will be used |
8888
| **pmdFilter** | String | Relative path of a suppression.properties file that lists classes and rules to be excluded from failures. If not set no classes and no rules will be excluded |
89-
| **maven.pmd.version** | String | The version of the maven-pmd-plugin that will be used (Default value is **3.11.0**)|
89+
| **maven.pmd.version** | String | The version of the maven-pmd-plugin that will be used (Default value is **3.13.0**)|
9090
| **pmdPlugins** | List<Dependency> | A list with artifacts that contain additional checks for PMD |
9191

9292
### sat-plugin:checkstyle

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<commons.lang.version>2.6</commons.lang.version>
5050
<mockito.version>2.25.0</mockito.version>
5151
<maven.resources.version>2.4</maven.resources.version>
52-
<pmd.version>6.7.0</pmd.version>
52+
<pmd.version>6.22.0</pmd.version>
5353
<checkstyle.version>8.30</checkstyle.version>
5454
<spotbugs.version>4.0.1</spotbugs.version>
5555
<maven.core.version>3.6.0</maven.core.version>

sat-plugin/src/main/java/org/openhab/tools/analysis/tools/PmdChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class PmdChecker extends AbstractChecker {
6060
/**
6161
* The version of the maven-pmd-plugin that will be used
6262
*/
63-
@Parameter(property = "maven.pmd.version", defaultValue = "3.11.0")
63+
@Parameter(property = "maven.pmd.version", defaultValue = "3.13.0")
6464
private String mavenPmdVersion;
6565

6666
/**
@@ -69,7 +69,7 @@ public class PmdChecker extends AbstractChecker {
6969
@Parameter
7070
private List<Dependency> pmdPlugins = new ArrayList<>();
7171

72-
private static final String PMD_VERSION = "6.7.0";
72+
private static final String PMD_VERSION = "6.22.0";
7373
/**
7474
* Location of the properties files that contains configuration options for the maven-pmd-plugin
7575
*/

sat-plugin/src/main/resources/rulesets/pmd/rules.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<rule ref="category/java/multithreading.xml/NonThreadSafeSingleton">
7575
<priority>3</priority>
7676
</rule>
77-
<rule ref="category/java/multithreading.xml/UnsynchronizedStaticDateFormatter">
77+
<rule ref="category/java/multithreading.xml/UnsynchronizedStaticFormatter">
7878
<priority>3</priority>
7979
</rule>
8080

0 commit comments

Comments
 (0)