You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ad...@apache.org on 2023/05/19 17:30:24 UTC
[maven-pmd-plugin] 10/10: REPLACE ME - Make m-pmd-p forward compatible for upcoming changes
This is an automated email from the ASF dual-hosted git repository.
adangel pushed a commit to branch pmd7
in repository https://gitbox.apache.org/repos/asf/maven-pmd-plugin.git
commit 54ba1665f56583c8098cca1af188faa5cfcf5e20
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Fri May 19 19:29:27 2023 +0200
REPLACE ME - Make m-pmd-p forward compatible for upcoming changes
in RuleViolation.getFilename() -> RuleViolation.getFileId()->getFileName()
Refs https://github.com/pmd/pmd/pull/4425
---
.../maven/plugins/pmd/ExcludeViolationsFromFile.java | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/pmd/ExcludeViolationsFromFile.java b/src/main/java/org/apache/maven/plugins/pmd/ExcludeViolationsFromFile.java
index 38919a4..55c9a98 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/ExcludeViolationsFromFile.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/ExcludeViolationsFromFile.java
@@ -84,8 +84,23 @@ public class ExcludeViolationsFromFile implements ExcludeFromFile<Violation> {
* @return <code>true</code> if the violation should be excluded, <code>false</code> otherwise.
*/
public boolean isExcludedFromFailure(final RuleViolation errorDetail) {
- final String className =
- extractClassName(errorDetail.getPackageName(), errorDetail.getClassName(), errorDetail.getFilename());
+ // Forward compatible change for https://github.com/pmd/pmd/pull/4425
+ String fileName;
+ try {
+ fileName = errorDetail.getFilename();
+ } catch (NoSuchMethodError e) {
+ try {
+ // fileName = errorDetail.getFileId().getFileName();
+ Object fileId = errorDetail.getClass().getMethod("getFileId").invoke(errorDetail);
+ java.lang.reflect.Method getFileName = fileId.getClass().getMethod("getFileName");
+ getFileName.setAccessible(true);
+ fileName = (String) getFileName.invoke(fileId);
+ } catch (ReflectiveOperationException e2) {
+ e2.addSuppressed(e);
+ throw new RuntimeException(e2);
+ }
+ }
+ final String className = extractClassName(errorDetail.getPackageName(), errorDetail.getClassName(), fileName);
return isExcludedFromFailure(className, errorDetail.getRule().getName());
}