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/06/01 09:24:19 UTC

[maven-pmd-plugin] branch pmd7 updated (01e30a6 -> 6582e15)

This is an automated email from the ASF dual-hosted git repository.

adangel pushed a change to branch pmd7
in repository https://gitbox.apache.org/repos/asf/maven-pmd-plugin.git


 discard 01e30a6  Remove deprecated usages
 discard 72969c7  Finish logging implementation (fix it MPMD-244-logging)
 discard 5c98926  Separate integration test for MPMD-246
 discard 54ba166  REPLACE ME - Make m-pmd-p forward compatible for upcoming changes
 discard 98ad5f5  Fix it MPMD-258-multiple-executions
 discard bc86b2a  Fix integration tests
 discard c6cda16  Fix deprecate rule reference
 discard 91271db  Fix integration test MPMD-243-excludeFromFailureFile
 discard c34bd81  Improve logging integration
 discard 6b23e06  Fix integration tests
 discard a067e89  Add separate testcase to detect deprecated rules
 discard 9bce28e  Clarify unit tests
 discard a9fb72a  Upgrade to PMD 7.0.0-rc2
     add 5a21037  Use proper scope for method
     add 01310e6  [MPMD-371] Using two ruleset files with same name in different directories (#127)
     add 3dcc10d  (doc) Update releasenotes.md [skip ci]
     new fb1411d  Upgrade to PMD 7.0.0-rc2
     new f5152d9  Clarify unit tests
     new 966cc11  Add separate testcase to detect deprecated rules
     new f00dbf2  Fix integration tests
     new a8ebc44  Improve logging integration
     new a70a97b  Fix integration test MPMD-243-excludeFromFailureFile
     new e9112d5  Fix deprecate rule reference
     new c6c013b  Fix integration tests
     new c439592  Fix it MPMD-258-multiple-executions
     new 6d0a00e  Separate integration test for MPMD-246
     new db1275c  Finish logging implementation (fix it MPMD-244-logging)
     new 67dd07a  Remove deprecated usages
     new 6582e15  Upgrade to PMD 7.0.0-rc3

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (01e30a6)
            \
             N -- N -- N   refs/heads/pmd7 (6582e15)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 13 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            |  2 +-
 src/it/MPMD-219-pmd-processing-error/verify.groovy |  2 +-
 .../MPMD-296-rulesetsTargetDirectory/verify.groovy |  6 +-
 src/it/MPMD-323-multi-module-basedir/verify.groovy |  4 +-
 src/it/multi-module/verify.bsh                     |  4 +-
 .../plugins/pmd/ExcludeViolationsFromFile.java     | 20 +------
 .../org/apache/maven/plugins/pmd/PmdReport.java    | 10 ++--
 .../maven/plugins/pmd/PmdReportRenderer.java       |  2 +-
 .../apache/maven/plugins/pmd/exec/PmdExecutor.java |  2 +-
 src/site/markdown/releasenotes.md                  |  1 +
 .../apache/maven/plugins/pmd/PmdReportTest.java    | 67 ++++++++++++----------
 11 files changed, 57 insertions(+), 63 deletions(-)


[maven-pmd-plugin] 06/13: Fix integration test MPMD-243-excludeFromFailureFile

Posted by ad...@apache.org.
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 a70a97b2d33469d3030ac8b221d2ab12b8316853
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Fri Jun 10 11:23:58 2022 +0200

    Fix integration test MPMD-243-excludeFromFailureFile
---
 src/it/MPMD-243-excludeFromFailureFile/invoker.properties | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/it/MPMD-243-excludeFromFailureFile/invoker.properties b/src/it/MPMD-243-excludeFromFailureFile/invoker.properties
index 1e595ef..c630e55 100644
--- a/src/it/MPMD-243-excludeFromFailureFile/invoker.properties
+++ b/src/it/MPMD-243-excludeFromFailureFile/invoker.properties
@@ -15,5 +15,5 @@
 # specific language governing permissions and limitations
 # under the License.
 
-invoker.goals = clean pmd:check
+invoker.goals = clean verify
 invoker.maven.version = 3+


[maven-pmd-plugin] 05/13: Improve logging integration

Posted by ad...@apache.org.
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 a8ebc44dc9aa57b6699e5e2f3fdbea7ec869fda1
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Fri Jun 10 11:11:01 2022 +0200

    Improve logging integration
---
 src/it/MPMD-244-logging/invoker.properties               |  1 +
 src/it/MPMD-244-logging/verify.groovy                    | 16 +++++++++++++++-
 .../java/org/apache/maven/plugins/pmd/exec/Executor.java | 13 +++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/it/MPMD-244-logging/invoker.properties b/src/it/MPMD-244-logging/invoker.properties
index d57dce3..38b6d74 100644
--- a/src/it/MPMD-244-logging/invoker.properties
+++ b/src/it/MPMD-244-logging/invoker.properties
@@ -16,5 +16,6 @@
 # under the License.
 
 invoker.goals = clean pmd:check
+invoker.goals.2 = pmd:check --projects logging-enabled --log-file build2.log
 invoker.maven.version = 3.1.0+
 invoker.debug = true
diff --git a/src/it/MPMD-244-logging/verify.groovy b/src/it/MPMD-244-logging/verify.groovy
index e561fb8..daa1091 100644
--- a/src/it/MPMD-244-logging/verify.groovy
+++ b/src/it/MPMD-244-logging/verify.groovy
@@ -27,5 +27,19 @@ String enabledPath = new File( basedir, 'logging-enabled/src/main/java/BrokenFil
 
 // logging disabled: the pmd exception is only output through the processing error reporting (since MPMD-246)
 assert 1 == buildLog.text.count( "${disabledPath}: ParseException: Encountered" )
+
+// TODO: with PMD 7, the parse exception is not logged through PMD's logging anymore, it is only added as a processing error
+// in the report. is this correct?
 // logging enabled: the pmd exception is output twice: through the processing error reporting (since MPMD-246) and through PMD's own logging
-assert 2 == buildLog.text.count( "${enabledPath}: ParseException: Encountered" )
+// assert 2 == buildLog.text.count( "${enabledPath}: ParseException: Encountered" )
+assert 1 == buildLog.text.count( "${enabledPath}: ParseException: Encountered" )
+
+// logging disabled module is executed first, which disables the logging
+// even when logging-enabled is executed afterwards in the same JVM, the logger are not reinitialized
+// everywhere, so logging is most likely still disabled.
+assert 0 == buildLog.text.count( "[DEBUG] Rules loaded from" )
+
+// only in the second invoker run, when only logging-enabled is executed, the logs from PMD are visible
+File build2Log = new File( basedir, 'build2.log' )
+assert build2Log.exists()
+assert 1 == build2Log.text.count( "[DEBUG] Rules loaded from" )
diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/Executor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/Executor.java
index d8f902c..6bcf115 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/exec/Executor.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/exec/Executor.java
@@ -52,6 +52,19 @@ abstract class Executor {
     private java.util.logging.Logger julLogger;
 
     protected void setupPmdLogging(boolean showPmdLog, String logLevel) {
+
+        // TODO: enabling/disabling the log doesn't work reliably, because
+        // the log level is cached at each logger and the logger instances
+        // are usually static.
+        if (!showPmdLog) {
+            System.setProperty("org.slf4j.simpleLogger.log.net.sourceforge.pmd", "off");
+        } else {
+            System.clearProperty("org.slf4j.simpleLogger.log.net.sourceforge.pmd");
+        }
+        ILoggerFactory slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
+        Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration(slf4jLoggerFactory);
+        slf4jConfiguration.activate();
+
         if (!showPmdLog) {
             return;
         }


[maven-pmd-plugin] 03/13: Add separate testcase to detect deprecated rules

Posted by ad...@apache.org.
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 966cc11b39cc0ed0d754b27b3b4e274836cdac86
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Fri Jun 10 11:42:49 2022 +0200

    Add separate testcase to detect deprecated rules
---
 .../org/apache/maven/plugins/pmd/RuleSetTest.java  | 56 ++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/src/test/java/org/apache/maven/plugins/pmd/RuleSetTest.java b/src/test/java/org/apache/maven/plugins/pmd/RuleSetTest.java
new file mode 100644
index 0000000..04a449e
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/pmd/RuleSetTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.pmd;
+
+import net.sourceforge.pmd.PMDConfiguration;
+import net.sourceforge.pmd.RuleSetLoader;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+
+public class RuleSetTest {
+
+    private RuleSetLoader ruleSetLoader =
+            RuleSetLoader.fromPmdConfig(new PMDConfiguration()).warnDeprecated(true);
+
+    @Before
+    public void setUp() {
+        CapturingPrintStream.init(true);
+    }
+
+    @Test
+    public void testDefaultRuleset() {
+        ruleSetLoader.loadFromResource("rulesets/java/maven-pmd-plugin-default.xml");
+        assertNoDeprecatedRules(CapturingPrintStream.getOutput());
+    }
+
+    @Test
+    public void testMavenRuleset() {
+        ruleSetLoader.loadFromResource("rulesets/maven.xml");
+        assertNoDeprecatedRules(CapturingPrintStream.getOutput());
+    }
+
+    private void assertNoDeprecatedRules(String output) {
+        // there must be no warnings (like deprecated rules) in the log output
+        assertFalse(output.contains("deprecated Rule name"));
+        assertFalse(output.contains("Discontinue using Rule name"));
+        assertFalse(output.contains("is referenced multiple times"));
+    }
+}


[maven-pmd-plugin] 10/13: Separate integration test for MPMD-246

Posted by ad...@apache.org.
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 6d0a00ed01d2c520c22cd5ce5ec23820df20cf14
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Fri May 19 20:39:19 2023 +0200

    Separate integration test for MPMD-246
---
 .../MPMD-246-processing-errors/invoker.properties  | 19 +++++++++
 src/it/MPMD-246-processing-errors/pom.xml          | 48 ++++++++++++++++++++++
 .../src/main/java/BrokenFile.java                  | 23 +++++++++++
 src/it/MPMD-246-processing-errors/verify.groovy    | 28 +++++++++++++
 4 files changed, 118 insertions(+)

diff --git a/src/it/MPMD-246-processing-errors/invoker.properties b/src/it/MPMD-246-processing-errors/invoker.properties
new file mode 100644
index 0000000..ea9f79e
--- /dev/null
+++ b/src/it/MPMD-246-processing-errors/invoker.properties
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals = clean pmd:check
+invoker.maven.version = 3.1.0+
diff --git a/src/it/MPMD-246-processing-errors/pom.xml b/src/it/MPMD-246-processing-errors/pom.xml
new file mode 100644
index 0000000..be1cd2b
--- /dev/null
+++ b/src/it/MPMD-246-processing-errors/pom.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.pmd.its</groupId>
+  <artifactId>MPMD-246-processing-errors</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>@project.groupId@</groupId>
+        <artifactId>@project.artifactId@</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <skipPmdError>true</skipPmdError>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/MPMD-246-processing-errors/src/main/java/BrokenFile.java b/src/it/MPMD-246-processing-errors/src/main/java/BrokenFile.java
new file mode 100644
index 0000000..7ea0203
--- /dev/null
+++ b/src/it/MPMD-246-processing-errors/src/main/java/BrokenFile.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class BrokenFile {
+    // This file has a parse error, so PMD will fail to parse it
+    broken!!
+}
diff --git a/src/it/MPMD-246-processing-errors/verify.groovy b/src/it/MPMD-246-processing-errors/verify.groovy
new file mode 100644
index 0000000..10de06a
--- /dev/null
+++ b/src/it/MPMD-246-processing-errors/verify.groovy
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+File buildLog = new File( basedir, 'build.log' )
+assert buildLog.exists()
+assert buildLog.text.contains( "PMD processing errors" )
+assert buildLog.text.contains( "ParseException" )
+
+String brokenFilePath = new File( basedir, 'src/main/java/BrokenFile.java' ).getCanonicalPath()
+
+// processing error should be logged through maven-pmd-plugin, since "skipPmdError=true" (MPMD-246)
+assert 1 == buildLog.text.count( "${brokenFilePath}: ParseException: Parse exception in file" )


[maven-pmd-plugin] 02/13: Clarify unit tests

Posted by ad...@apache.org.
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 f5152d9920d466acd7606dc629eb5e9a1f2b1af8
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Fri May 19 16:47:21 2023 +0200

    Clarify unit tests
---
 .../apache/maven/plugins/pmd/CpdReportTest.java    |  8 ++--
 .../apache/maven/plugins/pmd/PmdReportTest.java    | 18 +++----
 .../def/configuration/App.java                     | 56 ++++++++--------------
 .../def/configuration/App2.java                    | 11 ++---
 .../def/configuration/AppSample.java               | 42 ++++++----------
 5 files changed, 53 insertions(+), 82 deletions(-)

diff --git a/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java b/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java
index ac49a29..7af5b80 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java
@@ -64,8 +64,8 @@ public class CpdReportTest extends AbstractPmdReportTestCase {
         String str = readFile(generatedReport);
         assertTrue(lowerCaseContains(str, "AppSample.java"));
         assertTrue(lowerCaseContains(str, "App.java"));
-        assertTrue(lowerCaseContains(str, "public String dup( String str )"));
-        assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring( i, i + 1);"));
+        assertTrue(lowerCaseContains(str, "public String dup(String str)"));
+        assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring(i, i + 1);"));
 
         // the version should be logged
         String output = CapturingPrintStream.getOutput();
@@ -171,8 +171,8 @@ public class CpdReportTest extends AbstractPmdReportTestCase {
         String str = readFile(generatedFile);
         assertTrue(lowerCaseContains(str, "AppSample.java"));
         assertTrue(lowerCaseContains(str, "App.java"));
-        assertTrue(lowerCaseContains(str, "public String dup( String str )"));
-        assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring( i, i + 1);"));
+        assertTrue(lowerCaseContains(str, "public String dup(String str)"));
+        assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring(i, i + 1);"));
     }
 
     /**
diff --git a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
index aa897f6..0d344ab 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
@@ -73,9 +73,10 @@ public class PmdReportTest extends AbstractPmdReportTestCase {
         // check if there's a link to the JXR files
         String str = readFile(generatedReport);
 
-        assertTrue(str.contains("/xref/def/configuration/App.html#L31"));
-
-        assertTrue(str.contains("/xref/def/configuration/AppSample.html#L45"));
+        // PMD: UnusedPrivateField (Prio 3)
+        assertTrue(str.contains("/xref/def/configuration/App.html#L29"));
+        // PMD: UnusedFormalParameter (Prio 3) and UnusedPrivateMethod (Prio 3)
+        assertTrue(str.contains("/xref/def/configuration/AppSample.html#L42"));
 
         // check if there's a priority column
         assertTrue(str.contains("<th>Priority</th>"));
@@ -251,9 +252,10 @@ public class PmdReportTest extends AbstractPmdReportTestCase {
         // check if there's a link to the JXR files
         String str = readFile(generatedReport);
 
-        assertTrue(str.contains("/xref/def/configuration/App.html#L31"));
-
-        assertTrue(str.contains("/xref/def/configuration/AppSample.html#L45"));
+        // PMD: UnusedPrivateField (Prio 3)
+        assertTrue(str.contains("/xref/def/configuration/App.html#L29"));
+        // PMD: UnusedFormalParameter (Prio 3) and UnusedPrivateMethod (Prio 3)
+        assertTrue(str.contains("/xref/def/configuration/AppSample.html#L42"));
 
         mockServer.stop();
     }
@@ -452,7 +454,7 @@ public class PmdReportTest extends AbstractPmdReportTestCase {
         // check if there's a link to the JXR files
         str = readFile(generatedReport);
 
-        assertTrue(str.contains("/xref/def/configuration/AppSample.html#L27"));
+        assertTrue(str.contains("/xref/def/configuration/AppSample.html#L25")); // PMD: UnusedPrivateField (Prio 3)
         // suppressed violation
         assertTrue(str.contains("Avoid unused private fields such as 'unusedVar2'."));
     }
@@ -477,7 +479,7 @@ public class PmdReportTest extends AbstractPmdReportTestCase {
         // check if there's a link to the JXR files
         str = readFile(generatedReport);
 
-        assertTrue(str.contains("/xref/def/configuration/AppSample.html#L27"));
+        assertTrue(str.contains("/xref/def/configuration/AppSample.html#L25")); // PMD: UnusedPrivateField (Prio 3)
         // suppressed violations are not rendered
         assertFalse(str.contains("Avoid unused private fields such as 'unusedVar2'."));
     }
diff --git a/src/test/resources/unit/default-configuration/def/configuration/App.java b/src/test/resources/unit/default-configuration/def/configuration/App.java
index da53df0..3441a0c 100644
--- a/src/test/resources/unit/default-configuration/def/configuration/App.java
+++ b/src/test/resources/unit/default-configuration/def/configuration/App.java
@@ -1,5 +1,3 @@
-package def.configuration;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -18,17 +16,17 @@ package def.configuration;
  * specific language governing permissions and limitations
  * under the License.
  */
+package def.configuration;
 
 /**
  * This is a sample class used for testing
  *
  * @author Maria Odea Ching
  */
-public class App
-{
+public class App  {
     protected String unusedVar1;
 
-    private int unusedVar2; //SUPPRESSME test for the suppressMarker property
+    private int unusedVar2; //SUPPRESSME test for the suppressMarker property - PMD: UnusedPrivateField (Prio 3)
 
     String unusedvar3;
 
@@ -37,9 +35,8 @@ public class App
      *
      * @param args  an array of strings that contains the arguments
      */
-    public static void main( String[] args )
-    {
-        System.out.println( "Sample Application." );
+    public static void main(String[] args) {
+        System.out.println("Sample Application.");
     }
 
     /**
@@ -47,15 +44,10 @@ public class App
      *
      * @param str   the value to be displayed
      */
-    protected void sampleMethod( String str )
-    {
-        try
-        {
-            System.out.println( str );
-        }
-        catch ( Exception e )
-        {
-
+    protected void sampleMethod(String str) {
+        try {
+            System.out.println(str);
+        } catch ( Exception e ) { // PMD: EmptyCatchBlock (Prio 3)
         }
     }
 
@@ -65,35 +57,27 @@ public class App
      * @param unusedParam1
      * @param unusedParam2
      */
-    public void testMethod( String unusedParam1, String unusedParam2)
-    {
+    public void testMethod(String unusedParam1, String unusedParam2) {
         System.out.println( "Test method" );
     }
 
 
-    public String dup( String str )
-    {
+    public String dup(String str) {
         String tmp = "";
 
-        for( int i = 0; i < str.length(); i++ )
-        {
-            if ( i != ( str.length() -1 ) )
-            {
-                tmp = tmp + str.substring( i, i + 1);
-            }
-            else
-            {
-                tmp = tmp + str.substring( i );
+        for (int i = 0; i < str.length(); i++) {
+            if (i != ((str.length() - 1))) { // PMD: UselessParentheses (Prio 4)
+                tmp = tmp + str.substring(i, i + 1);
+            } else {
+                tmp = tmp + str.substring(i);
             }
         }
 
-        if ("".equals( tmp ))
-        {
-                tmp = "EMPTY";
+        if ("".equals(tmp)) {
+            tmp = "EMPTY";
         }
 
-        System.out.println( "The value of tmp is " + tmp );
+        System.out.println("The value of tmp is " + tmp);
         return tmp;
     }
-
-}
\ No newline at end of file
+}
diff --git a/src/test/resources/unit/default-configuration/def/configuration/App2.java b/src/test/resources/unit/default-configuration/def/configuration/App2.java
index 6054a2e..49b38fc 100644
--- a/src/test/resources/unit/default-configuration/def/configuration/App2.java
+++ b/src/test/resources/unit/default-configuration/def/configuration/App2.java
@@ -1,4 +1,3 @@
-package def.configuration;
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -17,16 +16,14 @@ package def.configuration;
  * specific language governing permissions and limitations
  * under the License.
  */
+package def.configuration;
+
+import java.io.File; // PMD: UnnecessaryImport (Prio 4)
 
-//trigger unused import
-import java.io.File;
 /**
  * This is a sample class used for testing
  *
  * @author Maria Odea Ching
  */
-public class App2
-{
-
-  
+public class App2 {
 }
diff --git a/src/test/resources/unit/default-configuration/def/configuration/AppSample.java b/src/test/resources/unit/default-configuration/def/configuration/AppSample.java
index 201bf19..c4b8316 100644
--- a/src/test/resources/unit/default-configuration/def/configuration/AppSample.java
+++ b/src/test/resources/unit/default-configuration/def/configuration/AppSample.java
@@ -1,5 +1,3 @@
-package def.configuration;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -18,21 +16,20 @@ package def.configuration;
  * specific language governing permissions and limitations
  * under the License.
  */
+package def.configuration;
 
 /**
  * @author Maria Odea Ching
  */
-public class AppSample
-{
-    private String unusedVar = "UNUSED";
+public class AppSample {
+    private String unusedVar = "UNUSED"; // PMD: UnusedPrivateField (Prio 3)
 
     /**
      * The main method
      *
      * @param args  an array of strings that contains the arguments
      */
-    public static void main( String[] args )
-    {
+    public static void main(String[] args) {
         System.out.println( "Another Sample Application" );
     }
 
@@ -42,36 +39,27 @@ public class AppSample
      * @param notUsedParam
      * @return a blank String
      */
-    private String unusedMethod( String notUsedParam )
-    {
-        System.out.println( "This is just a test." );
-
+    private String unusedMethod(String notUsedParam) { // PMD: UnusedFormalParameter (Prio 3) and UnusedPrivateMethod (Prio 3)
+        System.out.println("This is just a test.");
         return "";
     }
 
-    public String dup( String str )
-    {
+    public String dup(String str) {
         String tmp = "";
 
-        for( int i = 0; i < str.length(); i++ )
-        {
-            if ( i != ( str.length() -1 ) )
-            {
-                tmp = tmp + str.substring( i, i + 1);
-            }
-            else
-            {
-                tmp = tmp + str.substring( i );
+        for (int i = 0; i < str.length(); i++) {
+            if (i != ((str.length() - 1))) { // PMD: UselessParentheses (Prio 4)
+                tmp = tmp + str.substring(i, i + 1);
+            } else {
+                tmp = tmp + str.substring(i);
             }
         }
 
-        if ("".equals( tmp ))
-        {
+        if ("".equals(tmp)) {
                 tmp = "EMPTY";
         }
 
-        System.out.println( "The value of tmp is " + tmp );
+        System.out.println("The value of tmp is " + tmp);
         return tmp;
     }
-
-}
\ No newline at end of file
+}


[maven-pmd-plugin] 01/13: Upgrade to PMD 7.0.0-rc2

Posted by ad...@apache.org.
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 fb1411deb70a2af16aeae0fad7e867615d9cedcb
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Thu Jun 9 18:50:10 2022 +0200

    Upgrade to PMD 7.0.0-rc2
---
 pom.xml                                            |  4 +-
 .../org/apache/maven/plugins/pmd/CpdReport.java    | 13 -------
 .../apache/maven/plugins/pmd/exec/CpdExecutor.java | 40 +++++++------------
 .../maven/plugins/pmd/exec/CpdReportFilter.java    | 45 ++++++++++++++++++++++
 .../apache/maven/plugins/pmd/exec/PmdExecutor.java |  2 +-
 .../apache/maven/plugins/pmd/PmdReportTest.java    | 20 ++++++----
 6 files changed, 74 insertions(+), 50 deletions(-)

diff --git a/pom.xml b/pom.xml
index be8acfb..b945e06 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@ under the License.
   </parent>
 
   <artifactId>maven-pmd-plugin</artifactId>
-  <version>3.21.1-SNAPSHOT</version>
+  <version>3.21.1-pmd-7-SNAPSHOT</version>
   <packaging>maven-plugin</packaging>
 
   <name>Apache Maven PMD Plugin</name>
@@ -83,7 +83,7 @@ under the License.
   <properties>
     <mavenVersion>3.2.5</mavenVersion>
     <javaVersion>8</javaVersion>
-    <pmdVersion>6.55.0</pmdVersion>
+    <pmdVersion>7.0.0-rc2</pmdVersion>
     <slf4jVersion>1.7.36</slf4jVersion>
     <aetherVersion>1.0.0.v20140518</aetherVersion>
     <doxiaVersion>1.12.0</doxiaVersion>
diff --git a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java
index c01fdbc..45660e0 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java
@@ -24,7 +24,6 @@ import java.util.Locale;
 import java.util.Properties;
 
 import net.sourceforge.pmd.cpd.JavaTokenizer;
-import net.sourceforge.pmd.cpd.renderer.CPDRenderer;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
@@ -229,16 +228,4 @@ public class CpdReport extends AbstractPmdReport {
     public String getOutputName() {
         return "cpd";
     }
-
-    /**
-     * Create and return the correct renderer for the output type.
-     *
-     * @return the renderer based on the configured output
-     * @throws org.apache.maven.reporting.MavenReportException if no renderer found for the output type
-     * @deprecated Use {@link CpdExecutor#createRenderer(String, String)} instead.
-     */
-    @Deprecated
-    public CPDRenderer createRenderer() throws MavenReportException {
-        return CpdExecutor.createRenderer(format, getOutputEncoding());
-    }
 }
diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java
index 43ba3c0..4f0a25f 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java
@@ -26,23 +26,20 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
 import java.util.Objects;
 
 import net.sourceforge.pmd.cpd.CPD;
 import net.sourceforge.pmd.cpd.CPDConfiguration;
+import net.sourceforge.pmd.cpd.CPDReport;
 import net.sourceforge.pmd.cpd.CSVRenderer;
 import net.sourceforge.pmd.cpd.EcmascriptLanguage;
 import net.sourceforge.pmd.cpd.JSPLanguage;
 import net.sourceforge.pmd.cpd.JavaLanguage;
 import net.sourceforge.pmd.cpd.Language;
 import net.sourceforge.pmd.cpd.LanguageFactory;
-import net.sourceforge.pmd.cpd.Match;
 import net.sourceforge.pmd.cpd.SimpleRenderer;
 import net.sourceforge.pmd.cpd.XMLRenderer;
-import net.sourceforge.pmd.cpd.renderer.CPDRenderer;
+import net.sourceforge.pmd.cpd.renderer.CPDReportRenderer;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.pmd.ExcludeDuplicationsFromFile;
 import org.apache.maven.reporting.MavenReportException;
@@ -207,7 +204,7 @@ public class CpdExecutor extends Executor {
         }
     }
 
-    private File writeReport(CPD cpd, CPDRenderer r, String extension) throws MavenReportException {
+    private File writeReport(CPD cpd, CPDReportRenderer r, String extension) throws MavenReportException {
         if (r == null) {
             return null;
         }
@@ -216,7 +213,7 @@ public class CpdExecutor extends Executor {
         targetDir.mkdirs();
         File targetFile = new File(targetDir, "cpd." + extension);
         try (Writer writer = new OutputStreamWriter(new FileOutputStream(targetFile), request.getOutputEncoding())) {
-            r.render(filterMatches(cpd.getMatches()), writer);
+            r.render(filterMatches(cpd.toReport()), writer);
             writer.flush();
         } catch (IOException ioe) {
             throw new MavenReportException(ioe.getMessage(), ioe);
@@ -225,7 +222,7 @@ public class CpdExecutor extends Executor {
     }
 
     private void writeFormattedReport(CPD cpd) throws MavenReportException {
-        CPDRenderer r = createRenderer(request.getFormat(), request.getOutputEncoding());
+        CPDReportRenderer r = createRenderer(request.getFormat(), request.getOutputEncoding());
         writeReport(cpd, r, request.getFormat());
     }
 
@@ -235,8 +232,8 @@ public class CpdExecutor extends Executor {
      * @return the renderer based on the configured output
      * @throws org.apache.maven.reporting.MavenReportException if no renderer found for the output type
      */
-    public static CPDRenderer createRenderer(String format, String outputEncoding) throws MavenReportException {
-        CPDRenderer renderer = null;
+    public static CPDReportRenderer createRenderer(String format, String outputEncoding) throws MavenReportException {
+        CPDReportRenderer renderer = null;
         if ("xml".equals(format)) {
             renderer = new XMLRenderer(outputEncoding);
         } else if ("csv".equals(format)) {
@@ -245,7 +242,8 @@ public class CpdExecutor extends Executor {
             renderer = new SimpleRenderer();
         } else if (!"".equals(format) && !"none".equals(format)) {
             try {
-                renderer = (CPDRenderer) Class.forName(format).getConstructor().newInstance();
+                renderer = (CPDReportRenderer)
+                        Class.forName(format).getConstructor().newInstance();
             } catch (Exception e) {
                 throw new MavenReportException(
                         "Can't find CPD custom format " + format + ": "
@@ -257,22 +255,12 @@ public class CpdExecutor extends Executor {
         return renderer;
     }
 
-    private Iterator<Match> filterMatches(Iterator<Match> matches) {
+    private CPDReport filterMatches(CPDReport report) {
         LOG.debug("Filtering duplications. Using " + excludeDuplicationsFromFile.countExclusions()
                 + " configured exclusions.");
-
-        List<Match> filteredMatches = new ArrayList<>();
-        int excludedDuplications = 0;
-        while (matches.hasNext()) {
-            Match match = matches.next();
-            if (excludeDuplicationsFromFile.isExcludedFromFailure(match)) {
-                excludedDuplications++;
-            } else {
-                filteredMatches.add(match);
-            }
-        }
-
-        LOG.debug("Excluded " + excludedDuplications + " duplications.");
-        return filteredMatches.iterator();
+        CpdReportFilter filter = new CpdReportFilter(excludeDuplicationsFromFile);
+        CPDReport filteredReport = report.filterMatches(filter);
+        LOG.debug("Excluded " + filter.getExcludedDuplications() + " duplications.");
+        return filteredReport;
     }
 }
diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdReportFilter.java b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdReportFilter.java
new file mode 100644
index 0000000..1a7c961
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdReportFilter.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.pmd.exec;
+
+import net.sourceforge.pmd.cpd.Match;
+import net.sourceforge.pmd.util.Predicate;
+import org.apache.maven.plugins.pmd.ExcludeDuplicationsFromFile;
+
+class CpdReportFilter implements Predicate<Match> {
+    private final ExcludeDuplicationsFromFile excludeDuplicationsFromFile;
+    private int excludedDuplications = 0;
+
+    CpdReportFilter(ExcludeDuplicationsFromFile excludeDuplicationsFromFile) {
+        this.excludeDuplicationsFromFile = excludeDuplicationsFromFile;
+    }
+
+    @Override
+    public boolean test(Match match) {
+        if (excludeDuplicationsFromFile.isExcludedFromFailure(match)) {
+            excludedDuplications++;
+            return false;
+        }
+        return true;
+    }
+
+    int getExcludedDuplications() {
+        return excludedDuplications;
+    }
+}
diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java
index 8e96bf4..ad0a5d3 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java
@@ -30,6 +30,7 @@ import java.io.Writer;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
+import java.util.function.Predicate;
 
 import net.sourceforge.pmd.PMDConfiguration;
 import net.sourceforge.pmd.PmdAnalysis;
@@ -50,7 +51,6 @@ import net.sourceforge.pmd.renderers.HTMLRenderer;
 import net.sourceforge.pmd.renderers.Renderer;
 import net.sourceforge.pmd.renderers.TextRenderer;
 import net.sourceforge.pmd.renderers.XMLRenderer;
-import net.sourceforge.pmd.util.Predicate;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.pmd.ExcludeViolationsFromFile;
 import org.apache.maven.reporting.MavenReportException;
diff --git a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
index e3f4b3e..aa897f6 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
@@ -446,7 +446,8 @@ public class PmdReportTest extends AbstractPmdReportTestCase {
         // check that there is no violation reported for "unusedVar2" - as it is suppressed
         assertFalse(str.contains("Avoid unused private fields such as 'unusedVar2'.\n </violation>"));
         // but it appears as suppressed
-        assertTrue(str.contains("suppressiontype=\"nopmd\" msg=\"Avoid unused private fields such as 'unusedVar2'.\""));
+        assertTrue(
+                str.contains("suppressiontype=\"//nopmd\" msg=\"Avoid unused private fields such as 'unusedVar2'.\""));
 
         // check if there's a link to the JXR files
         str = readFile(generatedReport);
@@ -470,7 +471,8 @@ public class PmdReportTest extends AbstractPmdReportTestCase {
         // check that there is no violation reported for "unusedVar2" - as it is suppressed
         assertFalse(str.contains("Avoid unused private fields such as 'unusedVar2'.\n </violation>"));
         // but it appears as suppressed
-        assertTrue(str.contains("suppressiontype=\"nopmd\" msg=\"Avoid unused private fields such as 'unusedVar2'.\""));
+        assertTrue(
+                str.contains("suppressiontype=\"//nopmd\" msg=\"Avoid unused private fields such as 'unusedVar2'.\""));
 
         // check if there's a link to the JXR files
         str = readFile(generatedReport);
@@ -534,13 +536,14 @@ public class PmdReportTest extends AbstractPmdReportTestCase {
         File generatedFile = new File(getBasedir(), "target/test/unit/parse-error/target/pmd.xml");
         assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
         String str = readFile(generatedFile);
-        assertTrue(str.contains("Error while parsing"));
         // The parse exception must be in the XML report
-        assertTrue(str.contains("ParseException: Encountered \"\" at line 23, column 5."));
+        assertTrue(str.contains("ParseException:"));
+        assertTrue(str.contains("Encountered  at line 23, column 5."));
 
         str = readFile(generatedReport);
         // The parse exception must also be in the HTML report
-        assertTrue(str.contains("ParseException: Encountered \"\" at line 23, column 5."));
+        assertTrue(str.contains("ParseException:"));
+        assertTrue(str.contains("Encountered  at line 23, column 5."));
     }
 
     public void testPMDProcessingErrorWithDetailsNoReport() throws Exception {
@@ -554,13 +557,14 @@ public class PmdReportTest extends AbstractPmdReportTestCase {
         File generatedFile = new File(getBasedir(), "target/test/unit/parse-error/target/pmd.xml");
         assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
         String str = readFile(generatedFile);
-        assertTrue(str.contains("Error while parsing"));
         // The parse exception must be in the XML report
-        assertTrue(str.contains("ParseException: Encountered \"\" at line 23, column 5."));
+        assertTrue(str.contains("ParseException:"));
+        assertTrue(str.contains("Encountered  at line 23, column 5."));
 
         str = readFile(generatedReport);
         // The parse exception must NOT be in the HTML report, since reportProcessingErrors is false
-        assertFalse(str.contains("ParseException: Encountered \"\" at line 23, column 5."));
+        assertFalse(str.contains("ParseException:"));
+        assertFalse(str.contains("Encountered  at line 23, column 5."));
     }
 
     public void testPMDExcludeRootsShouldExcludeSubdirectories() throws Exception {


[maven-pmd-plugin] 11/13: Finish logging implementation (fix it MPMD-244-logging)

Posted by ad...@apache.org.
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 db1275c8c7497a7321d142bf5490c6d74ce21504
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Sat May 20 10:30:55 2023 +0200

    Finish logging implementation (fix it MPMD-244-logging)
---
 src/it/MPMD-244-logging/invoker.properties         |  1 -
 src/it/MPMD-244-logging/logging-disabled/pom.xml   |  9 ---
 .../src/main/java/App.java}                        |  7 +--
 src/it/MPMD-244-logging/logging-enabled/pom.xml    |  9 ---
 .../src/main/java/App.java}                        |  7 +--
 src/it/MPMD-244-logging/verify.groovy              | 26 +--------
 .../maven/plugins/pmd/AbstractPmdReport.java       | 15 ++++-
 .../apache/maven/plugins/pmd/exec/Executor.java    | 65 +++++++---------------
 .../apache/maven/plugins/pmd/exec/PmdRequest.java  |  2 +-
 9 files changed, 39 insertions(+), 102 deletions(-)

diff --git a/src/it/MPMD-244-logging/invoker.properties b/src/it/MPMD-244-logging/invoker.properties
index 38b6d74..d57dce3 100644
--- a/src/it/MPMD-244-logging/invoker.properties
+++ b/src/it/MPMD-244-logging/invoker.properties
@@ -16,6 +16,5 @@
 # under the License.
 
 invoker.goals = clean pmd:check
-invoker.goals.2 = pmd:check --projects logging-enabled --log-file build2.log
 invoker.maven.version = 3.1.0+
 invoker.debug = true
diff --git a/src/it/MPMD-244-logging/logging-disabled/pom.xml b/src/it/MPMD-244-logging/logging-disabled/pom.xml
index 46f0e2b..429d707 100644
--- a/src/it/MPMD-244-logging/logging-disabled/pom.xml
+++ b/src/it/MPMD-244-logging/logging-disabled/pom.xml
@@ -44,17 +44,8 @@ under the License.
         <artifactId>@project.artifactId@</artifactId>
         <version>@project.version@</version>
         <configuration>
-          <skipPmdError>true</skipPmdError>
           <showPmdLog>false</showPmdLog>
         </configuration>
-        <executions>
-          <execution>
-            <phase>test-compile</phase>
-            <goals>
-              <goal>check</goal>
-            </goals>
-          </execution>
-        </executions>
       </plugin>
     </plugins>
   </build>
diff --git a/src/it/MPMD-244-logging/logging-enabled/src/main/java/BrokenFile.java b/src/it/MPMD-244-logging/logging-disabled/src/main/java/App.java
similarity index 88%
rename from src/it/MPMD-244-logging/logging-enabled/src/main/java/BrokenFile.java
rename to src/it/MPMD-244-logging/logging-disabled/src/main/java/App.java
index 1c5335a..64889d2 100644
--- a/src/it/MPMD-244-logging/logging-enabled/src/main/java/BrokenFile.java
+++ b/src/it/MPMD-244-logging/logging-disabled/src/main/java/App.java
@@ -17,10 +17,5 @@
  * under the License.
  */
 
-public class BrokenFile
-{
-
-    // This file has a parse error, so PMD will fail to parse it
-    broken!!
-
+public class App {
 }
diff --git a/src/it/MPMD-244-logging/logging-enabled/pom.xml b/src/it/MPMD-244-logging/logging-enabled/pom.xml
index 355992c..a7fe73b 100644
--- a/src/it/MPMD-244-logging/logging-enabled/pom.xml
+++ b/src/it/MPMD-244-logging/logging-enabled/pom.xml
@@ -44,17 +44,8 @@ under the License.
         <artifactId>@project.artifactId@</artifactId>
         <version>@project.version@</version>
         <configuration>
-          <skipPmdError>true</skipPmdError>
           <showPmdLog>true</showPmdLog>
         </configuration>
-        <executions>
-          <execution>
-            <phase>test-compile</phase>
-            <goals>
-              <goal>check</goal>
-            </goals>
-          </execution>
-        </executions>
       </plugin>
     </plugins>
   </build>
diff --git a/src/it/MPMD-244-logging/logging-disabled/src/main/java/BrokenFile.java b/src/it/MPMD-244-logging/logging-enabled/src/main/java/App.java
similarity index 88%
rename from src/it/MPMD-244-logging/logging-disabled/src/main/java/BrokenFile.java
rename to src/it/MPMD-244-logging/logging-enabled/src/main/java/App.java
index 1c5335a..64889d2 100644
--- a/src/it/MPMD-244-logging/logging-disabled/src/main/java/BrokenFile.java
+++ b/src/it/MPMD-244-logging/logging-enabled/src/main/java/App.java
@@ -17,10 +17,5 @@
  * under the License.
  */
 
-public class BrokenFile
-{
-
-    // This file has a parse error, so PMD will fail to parse it
-    broken!!
-
+public class App {
 }
diff --git a/src/it/MPMD-244-logging/verify.groovy b/src/it/MPMD-244-logging/verify.groovy
index b3d0d7e..7360fd0 100644
--- a/src/it/MPMD-244-logging/verify.groovy
+++ b/src/it/MPMD-244-logging/verify.groovy
@@ -19,27 +19,7 @@
 
 File buildLog = new File( basedir, 'build.log' )
 assert buildLog.exists()
-assert buildLog.text.contains( "PMD processing errors" )
-assert buildLog.text.contains( "ParseException" )
 
-String disabledPath = new File( basedir, 'logging-disabled/src/main/java/BrokenFile.java' ).getCanonicalPath()
-String enabledPath = new File( basedir, 'logging-enabled/src/main/java/BrokenFile.java' ).getCanonicalPath()
-
-// logging disabled: the pmd exception is only output through the processing error reporting (since MPMD-246)
-assert 1 == buildLog.text.count( "${disabledPath}: ParseException: Parse exception in file" )
-
-// TODO: with PMD 7, the parse exception is not logged through PMD's logging anymore, it is only added as a processing error
-// in the report. is this correct?
-// logging enabled: the pmd exception is output twice: through the processing error reporting (since MPMD-246) and through PMD's own logging
-// assert 2 == buildLog.text.count( "${enabledPath}: ParseException: Parse exception in file" )
-assert 1 == buildLog.text.count( "${enabledPath}: ParseException: Parse exception in file" )
-
-// logging disabled module is executed first, which disables the logging
-// even when logging-enabled is executed afterwards in the same JVM, the logger are not reinitialized
-// everywhere, so logging is most likely still disabled.
-assert 0 == buildLog.text.count( "[DEBUG] Rules loaded from" )
-
-// only in the second invoker run, when only logging-enabled is executed, the logs from PMD are visible
-File build2Log = new File( basedir, 'build2.log' )
-assert build2Log.exists()
-assert 1 == build2Log.text.count( "[DEBUG] Rules loaded from" )
+// build.log contains the logging from the two PMD executions
+// only one execution has logging enabled, so we expect only one log output
+assert 1 == buildLog.text.count( "[DEBUG] Rules loaded from" )
diff --git a/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java b/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java
index d44028f..ff6ff90 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java
@@ -49,6 +49,8 @@ import org.apache.maven.toolchain.ToolchainManager;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.PathTool;
 import org.codehaus.plexus.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Base class for the PMD reports.
@@ -484,8 +486,17 @@ public abstract class AbstractPmdReport extends AbstractMavenReport {
             logLevel = System.getProperty("maven.logging.root.level");
         }
         if (logLevel == null) {
-            // TODO: logback level
-            logLevel = "info";
+            Logger rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+            if (rootLogger.isErrorEnabled()) {
+                logLevel = "error";
+            }
+            if (rootLogger.isInfoEnabled() || rootLogger.isWarnEnabled()) {
+                logLevel = "info";
+            }
+            if (rootLogger.isTraceEnabled() || rootLogger.isDebugEnabled()) {
+                logLevel = "debug";
+            }
+            logLevel = "info"; // default
         }
         return logLevel;
     }
diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/Executor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/Executor.java
index 6bcf115..6ef13f2 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/exec/Executor.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/exec/Executor.java
@@ -29,77 +29,52 @@ import java.net.URL;
 import java.net.URLClassLoader;
 import java.net.URLDecoder;
 import java.nio.charset.StandardCharsets;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.SimpleFormatter;
 
+import net.sourceforge.pmd.internal.Slf4jSimpleConfiguration;
 import org.apache.maven.cli.logging.Slf4jConfiguration;
 import org.apache.maven.cli.logging.Slf4jConfigurationFactory;
 import org.codehaus.plexus.logging.console.ConsoleLogger;
 import org.slf4j.ILoggerFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.slf4j.bridge.SLF4JBridgeHandler;
 
 abstract class Executor {
     private static final Logger LOG = LoggerFactory.getLogger(Executor.class);
 
     /**
-     * This holds a strong reference in case we configured the logger to
-     * redirect to slf4j. See {@link #showPmdLog}. Without a strong reference,
-     * the logger might be garbage collected and the redirect to slf4j is gone.
+     * Configures the appropriate log levels for PMD or disables
+     * PMD logging.
+     *
+     * @param showPmdLog whether the PMD logs should appear in the maven log output
+     * @param logLevel the maven log level, e.g. "info" or "debug".
      */
-    private java.util.logging.Logger julLogger;
-
     protected void setupPmdLogging(boolean showPmdLog, String logLevel) {
-
-        // TODO: enabling/disabling the log doesn't work reliably, because
-        // the log level is cached at each logger and the logger instances
-        // are usually static.
         if (!showPmdLog) {
             System.setProperty("org.slf4j.simpleLogger.log.net.sourceforge.pmd", "off");
         } else {
             System.clearProperty("org.slf4j.simpleLogger.log.net.sourceforge.pmd");
         }
-        ILoggerFactory slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
-        Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration(slf4jLoggerFactory);
-        slf4jConfiguration.activate();
-
-        if (!showPmdLog) {
-            return;
-        }
 
-        java.util.logging.Logger logger = java.util.logging.Logger.getLogger("net.sourceforge.pmd");
-
-        boolean slf4jBridgeAlreadyAdded = false;
-        for (Handler handler : logger.getHandlers()) {
-            if (handler instanceof SLF4JBridgeHandler) {
-                slf4jBridgeAlreadyAdded = true;
-                break;
-            }
-        }
-
-        if (slf4jBridgeAlreadyAdded) {
-            return;
-        }
-
-        SLF4JBridgeHandler handler = new SLF4JBridgeHandler();
-        SimpleFormatter formatter = new SimpleFormatter();
-        handler.setFormatter(formatter);
-        logger.setUseParentHandlers(false);
-        logger.addHandler(handler);
-        handler.setLevel(Level.ALL);
-        logger.setLevel(Level.ALL);
-        julLogger = logger;
-        julLogger.fine("Configured jul-to-slf4j bridge for " + logger.getName());
+        // When slf4j-simple is in use, the log level is cached at each logger and the logger
+        // instances are usually static. So they don't see any configuration changes at runtime
+        // normally. This call will go through each logger and reinitialize these with the
+        // freshly determined log level from the configuration.
+        // Note: This only works for slf4j-simple.
+        Slf4jSimpleConfiguration.reconfigureDefaultLogLevel(null);
     }
 
+    /**
+     * Initializes the maven logging system. This is only needed when toolchain is in use. In that
+     * case we fork a new Java process to run PMD.
+     *
+     * @param logLevel the desired log level, e.g. "debug" or "info".
+     */
     protected void setupLogLevel(String logLevel) {
         ILoggerFactory slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
         Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration(slf4jLoggerFactory);
-        if ("debug".equals(logLevel)) {
+        if ("debug".equalsIgnoreCase(logLevel)) {
             slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.DEBUG);
-        } else if ("info".equals(logLevel)) {
+        } else if ("info".equalsIgnoreCase(logLevel)) {
             slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.INFO);
         } else {
             slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.ERROR);
diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdRequest.java b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdRequest.java
index d1a8099..150eef6 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdRequest.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdRequest.java
@@ -215,7 +215,7 @@ public class PmdRequest implements Serializable {
     }
 
     public boolean isDebugEnabled() {
-        return "debug".equals(logLevel);
+        return "debug".equalsIgnoreCase(logLevel);
     }
 
     public boolean isSkipPmdError() {


[maven-pmd-plugin] 13/13: Upgrade to PMD 7.0.0-rc3

Posted by ad...@apache.org.
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 6582e159135a31b582eb02fa1e25d78de2d8858c
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Thu Jun 1 10:36:25 2023 +0200

    Upgrade to PMD 7.0.0-rc3
---
 pom.xml                                                           | 2 +-
 src/it/MPMD-219-pmd-processing-error/verify.groovy                | 2 +-
 .../org/apache/maven/plugins/pmd/ExcludeViolationsFromFile.java   | 7 +++++--
 src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java  | 2 +-
 src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java     | 8 ++++----
 5 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/pom.xml b/pom.xml
index b945e06..e1c0f14 100644
--- a/pom.xml
+++ b/pom.xml
@@ -83,7 +83,7 @@ under the License.
   <properties>
     <mavenVersion>3.2.5</mavenVersion>
     <javaVersion>8</javaVersion>
-    <pmdVersion>7.0.0-rc2</pmdVersion>
+    <pmdVersion>7.0.0-rc3</pmdVersion>
     <slf4jVersion>1.7.36</slf4jVersion>
     <aetherVersion>1.0.0.v20140518</aetherVersion>
     <doxiaVersion>1.12.0</doxiaVersion>
diff --git a/src/it/MPMD-219-pmd-processing-error/verify.groovy b/src/it/MPMD-219-pmd-processing-error/verify.groovy
index b9212f2..6e74b57 100644
--- a/src/it/MPMD-219-pmd-processing-error/verify.groovy
+++ b/src/it/MPMD-219-pmd-processing-error/verify.groovy
@@ -20,5 +20,5 @@
 File buildLog = new File( basedir, 'build.log' )
 assert buildLog.exists()
 assert buildLog.text.contains( "PMD processing errors" )
-assert buildLog.text.contains( "BrokenFile.java: ParseException: Parse exception in file")
+assert buildLog.text.contains( "BrokenFile.java: ParseException: Parse exception in file" )
 assert buildLog.text.contains( "Encountered" )
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..e207e4e 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,11 @@ 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());
+        final Map<String, String> additionalInfo = errorDetail.getAdditionalInfo();
+        final String className = extractClassName(
+                additionalInfo.get(RuleViolation.PACKAGE_NAME),
+                additionalInfo.get(RuleViolation.CLASS_NAME),
+                errorDetail.getFileId().getAbsolutePath());
         return isExcludedFromFailure(className, errorDetail.getRule().getName());
     }
 
diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java
index 55f069b..807259d 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java
@@ -259,7 +259,7 @@ public class PmdExecutor extends Executor {
     private String getErrorsAsString(List<Report.ProcessingError> errors, boolean withDetails) {
         List<String> errorsAsString = new ArrayList<>(errors.size());
         for (Report.ProcessingError error : errors) {
-            errorsAsString.add(error.getFile() + ": " + error.getMsg());
+            errorsAsString.add(error.getFileId().getAbsolutePath() + ": " + error.getMsg());
             if (withDetails) {
                 errorsAsString.add(error.getDetail());
             }
diff --git a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
index 0d344ab..84cbaf4 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
@@ -540,12 +540,12 @@ public class PmdReportTest extends AbstractPmdReportTestCase {
         String str = readFile(generatedFile);
         // The parse exception must be in the XML report
         assertTrue(str.contains("ParseException:"));
-        assertTrue(str.contains("Encountered  at line 23, column 5."));
+        assertTrue(str.contains("at line 23, column 5: Encountered"));
 
         str = readFile(generatedReport);
         // The parse exception must also be in the HTML report
         assertTrue(str.contains("ParseException:"));
-        assertTrue(str.contains("Encountered  at line 23, column 5."));
+        assertTrue(str.contains("at line 23, column 5: Encountered"));
     }
 
     public void testPMDProcessingErrorWithDetailsNoReport() throws Exception {
@@ -561,12 +561,12 @@ public class PmdReportTest extends AbstractPmdReportTestCase {
         String str = readFile(generatedFile);
         // The parse exception must be in the XML report
         assertTrue(str.contains("ParseException:"));
-        assertTrue(str.contains("Encountered  at line 23, column 5."));
+        assertTrue(str.contains("at line 23, column 5: Encountered"));
 
         str = readFile(generatedReport);
         // The parse exception must NOT be in the HTML report, since reportProcessingErrors is false
         assertFalse(str.contains("ParseException:"));
-        assertFalse(str.contains("Encountered  at line 23, column 5."));
+        assertFalse(str.contains("at line 23, column 5: Encountered"));
     }
 
     public void testPMDExcludeRootsShouldExcludeSubdirectories() throws Exception {


[maven-pmd-plugin] 04/13: Fix integration tests

Posted by ad...@apache.org.
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 f00dbf2418ee3089fccddbf86f571842a982b2e7
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Fri Jun 10 09:03:20 2022 +0200

    Fix integration tests
---
 src/it/MPMD-219-pmd-processing-error/verify.groovy        | 3 +--
 src/it/MPMD-243-excludeFromFailureFile/config/ruleset.xml | 2 +-
 src/it/MPMD-244-logging/verify.groovy                     | 6 +++---
 src/it/MPMD-304-toolchain-support/verify.groovy           | 4 ++--
 src/it/mpmd-138/verify.groovy                             | 2 +-
 5 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/it/MPMD-219-pmd-processing-error/verify.groovy b/src/it/MPMD-219-pmd-processing-error/verify.groovy
index 0656c50..9cf76cc 100644
--- a/src/it/MPMD-219-pmd-processing-error/verify.groovy
+++ b/src/it/MPMD-219-pmd-processing-error/verify.groovy
@@ -20,5 +20,4 @@
 File buildLog = new File( basedir, 'build.log' )
 assert buildLog.exists()
 assert buildLog.text.contains( "PMD processing errors" )
-assert buildLog.text.contains( "Error while parsing" )
-assert buildLog.text.contains( "BrokenFile.java" )
+assert buildLog.text.contains( "BrokenFile.java: ParseException: Encountered" )
diff --git a/src/it/MPMD-243-excludeFromFailureFile/config/ruleset.xml b/src/it/MPMD-243-excludeFromFailureFile/config/ruleset.xml
index c337933..47daac1 100644
--- a/src/it/MPMD-243-excludeFromFailureFile/config/ruleset.xml
+++ b/src/it/MPMD-243-excludeFromFailureFile/config/ruleset.xml
@@ -26,5 +26,5 @@ under the License.
     MPMD-243
   </description>
 
-  <rule ref="rulesets/java/imports.xml/TooManyStaticImports"/>
+  <rule ref="category/java/codestyle.xml/TooManyStaticImports"/>
 </ruleset>
diff --git a/src/it/MPMD-244-logging/verify.groovy b/src/it/MPMD-244-logging/verify.groovy
index 459b2b9..e561fb8 100644
--- a/src/it/MPMD-244-logging/verify.groovy
+++ b/src/it/MPMD-244-logging/verify.groovy
@@ -20,12 +20,12 @@
 File buildLog = new File( basedir, 'build.log' )
 assert buildLog.exists()
 assert buildLog.text.contains( "PMD processing errors" )
-assert buildLog.text.contains( "Error while parsing" )
+assert buildLog.text.contains( "ParseException" )
 
 String disabledPath = new File( basedir, 'logging-disabled/src/main/java/BrokenFile.java' ).getCanonicalPath()
 String enabledPath = new File( basedir, 'logging-enabled/src/main/java/BrokenFile.java' ).getCanonicalPath()
 
 // logging disabled: the pmd exception is only output through the processing error reporting (since MPMD-246)
-assert 1 == buildLog.text.count( "net.sourceforge.pmd.PMDException: Error while parsing ${disabledPath}" )
+assert 1 == buildLog.text.count( "${disabledPath}: ParseException: Encountered" )
 // logging enabled: the pmd exception is output twice: through the processing error reporting (since MPMD-246) and through PMD's own logging
-assert 2 == buildLog.text.count( "net.sourceforge.pmd.PMDException: Error while parsing ${enabledPath}" )
+assert 2 == buildLog.text.count( "${enabledPath}: ParseException: Encountered" )
diff --git a/src/it/MPMD-304-toolchain-support/verify.groovy b/src/it/MPMD-304-toolchain-support/verify.groovy
index 7370225..21aa349 100644
--- a/src/it/MPMD-304-toolchain-support/verify.groovy
+++ b/src/it/MPMD-304-toolchain-support/verify.groovy
@@ -29,8 +29,8 @@ assert buildLog.text.contains( '[INFO] You have 1 CPD duplication' )
 
 File pmdReport = new File( basedir, 'target/pmd.xml' )
 assert pmdReport.exists()
-assert pmdReport.text.contains( '<violation beginline="24" endline="24" begincolumn="29" endcolumn="34" rule="ExtendsObject"' )
-assert pmdReport.text.contains( '<violation beginline="36" endline="36" begincolumn="9" endcolumn="31" rule="DontCallThreadRun"' )
+assert pmdReport.text.contains( '<violation beginline="24" endline="24" begincolumn="29" endcolumn="35" rule="ExtendsObject"' )
+assert pmdReport.text.contains( '<violation beginline="36" endline="36" begincolumn="9" endcolumn="32" rule="DontCallThreadRun"' )
 
 File pmdSite = new File( basedir, 'target/site/pmd.html' )
 assert pmdSite.exists()
diff --git a/src/it/mpmd-138/verify.groovy b/src/it/mpmd-138/verify.groovy
index 0a3a32b..2f6d345 100644
--- a/src/it/mpmd-138/verify.groovy
+++ b/src/it/mpmd-138/verify.groovy
@@ -23,7 +23,7 @@ assert buildLog.exists()
 
 // Module 1
 assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:27 Rule:UnnecessarySemicolon Priority:3 Unnecessary semicolon')
-assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:28 Rule:UnnecessaryReturn Priority:3 Avoid unnecessary return statements')
+assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:28 Rule:UnnecessaryReturn Priority:3 Unnecessary return statement')
 assert 1 == buildLog.getText().count('[INFO] You have 2 PMD violations. For more details see:')
 
 // Module 2


[maven-pmd-plugin] 07/13: Fix deprecate rule reference

Posted by ad...@apache.org.
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 e9112d5be2a65663e3cc1bc6e37d9b5e72db056b
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Fri Jun 10 11:59:21 2022 +0200

    Fix deprecate rule reference
---
 src/it/MPMD-89-232-typeresolution/src/main/pmd/ruleset.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/it/MPMD-89-232-typeresolution/src/main/pmd/ruleset.xml b/src/it/MPMD-89-232-typeresolution/src/main/pmd/ruleset.xml
index fcd6bc4..05c8abd 100644
--- a/src/it/MPMD-89-232-typeresolution/src/main/pmd/ruleset.xml
+++ b/src/it/MPMD-89-232-typeresolution/src/main/pmd/ruleset.xml
@@ -24,5 +24,5 @@ under the License.
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
     <description>Custom Ruleset for test case MPMD-89 and MPMP-232</description>
-  <rule ref="rulesets/java/junit.xml/TestClassWithoutTestCases"/>
+  <rule ref="category/java/errorprone.xml/TestClassWithoutTestCases"/>
 </ruleset>


[maven-pmd-plugin] 08/13: Fix integration tests

Posted by ad...@apache.org.
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 c6c013bd7da1567afa1a1b94cccb833ffad3b16b
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Tue Jan 17 19:26:54 2023 +0100

    Fix integration tests
---
 src/it/MPMD-219-pmd-processing-error/verify.groovy | 3 ++-
 src/it/MPMD-244-logging/verify.groovy              | 6 +++---
 src/it/MPMD-268-deprecated-rules/verify.groovy     | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/it/MPMD-219-pmd-processing-error/verify.groovy b/src/it/MPMD-219-pmd-processing-error/verify.groovy
index 9cf76cc..b9212f2 100644
--- a/src/it/MPMD-219-pmd-processing-error/verify.groovy
+++ b/src/it/MPMD-219-pmd-processing-error/verify.groovy
@@ -20,4 +20,5 @@
 File buildLog = new File( basedir, 'build.log' )
 assert buildLog.exists()
 assert buildLog.text.contains( "PMD processing errors" )
-assert buildLog.text.contains( "BrokenFile.java: ParseException: Encountered" )
+assert buildLog.text.contains( "BrokenFile.java: ParseException: Parse exception in file")
+assert buildLog.text.contains( "Encountered" )
diff --git a/src/it/MPMD-244-logging/verify.groovy b/src/it/MPMD-244-logging/verify.groovy
index daa1091..b3d0d7e 100644
--- a/src/it/MPMD-244-logging/verify.groovy
+++ b/src/it/MPMD-244-logging/verify.groovy
@@ -26,13 +26,13 @@ String disabledPath = new File( basedir, 'logging-disabled/src/main/java/BrokenF
 String enabledPath = new File( basedir, 'logging-enabled/src/main/java/BrokenFile.java' ).getCanonicalPath()
 
 // logging disabled: the pmd exception is only output through the processing error reporting (since MPMD-246)
-assert 1 == buildLog.text.count( "${disabledPath}: ParseException: Encountered" )
+assert 1 == buildLog.text.count( "${disabledPath}: ParseException: Parse exception in file" )
 
 // TODO: with PMD 7, the parse exception is not logged through PMD's logging anymore, it is only added as a processing error
 // in the report. is this correct?
 // logging enabled: the pmd exception is output twice: through the processing error reporting (since MPMD-246) and through PMD's own logging
-// assert 2 == buildLog.text.count( "${enabledPath}: ParseException: Encountered" )
-assert 1 == buildLog.text.count( "${enabledPath}: ParseException: Encountered" )
+// assert 2 == buildLog.text.count( "${enabledPath}: ParseException: Parse exception in file" )
+assert 1 == buildLog.text.count( "${enabledPath}: ParseException: Parse exception in file" )
 
 // logging disabled module is executed first, which disables the logging
 // even when logging-enabled is executed afterwards in the same JVM, the logger are not reinitialized
diff --git a/src/it/MPMD-268-deprecated-rules/verify.groovy b/src/it/MPMD-268-deprecated-rules/verify.groovy
index 009a5dd..5c41672 100644
--- a/src/it/MPMD-268-deprecated-rules/verify.groovy
+++ b/src/it/MPMD-268-deprecated-rules/verify.groovy
@@ -19,4 +19,4 @@
 
 File buildLog = new File( basedir, 'build.log' )
 assert buildLog.exists()
-assert buildLog.text.contains( "[WARNING] Use Rule name category/java/codestyle.xml/ControlStatementBraces instead of the deprecated" )
+assert buildLog.text.contains( "Use Rule name category/java/codestyle.xml/ControlStatementBraces instead of the deprecated" )


[maven-pmd-plugin] 12/13: Remove deprecated usages

Posted by ad...@apache.org.
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 67dd07a831e573d141a8cc48707587f98fe94c90
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Sat May 20 10:46:12 2023 +0200

    Remove deprecated usages
---
 .../java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java    |  7 ++-----
 .../java/org/apache/maven/plugins/pmd/exec/ExecutorTest.java   | 10 ++++++----
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java
index ad0a5d3..55f069b 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java
@@ -155,8 +155,8 @@ public class PmdExecutor extends Executor {
 
         PMDConfiguration configuration = new PMDConfiguration();
         LanguageVersion languageVersion = null;
-        Language language = LanguageRegistry.findLanguageByTerseName(
-                request.getLanguage() != null ? request.getLanguage() : "java");
+        Language language =
+                LanguageRegistry.PMD.getLanguageById(request.getLanguage() != null ? request.getLanguage() : "java");
         if (language == null) {
             throw new MavenReportException("Unsupported language: " + request.getLanguage());
         }
@@ -189,9 +189,6 @@ public class PmdExecutor extends Executor {
 
         configuration.setRuleSets(request.getRulesets());
         configuration.setMinimumPriority(RulePriority.valueOf(request.getMinimumPriority()));
-        if (request.getBenchmarkOutputLocation() != null) {
-            configuration.setBenchmark(true);
-        }
         List<File> files = request.getFiles();
 
         Report report = null;
diff --git a/src/test/java/org/apache/maven/plugins/pmd/exec/ExecutorTest.java b/src/test/java/org/apache/maven/plugins/pmd/exec/ExecutorTest.java
index fadd719..67f48e1 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/exec/ExecutorTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/exec/ExecutorTest.java
@@ -23,11 +23,13 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
 import org.apache.commons.lang3.SystemUtils;
+import org.junit.Test;
 
-public class ExecutorTest extends TestCase {
+import static org.junit.Assert.assertEquals;
+
+public class ExecutorTest {
+    @Test
     public void testBuildClasspath() throws MalformedURLException {
         String basename = "home/test/dir with space/mylib.jar";
         String pathname = new File("/", basename).getPath();
@@ -39,6 +41,6 @@ public class ExecutorTest extends TestCase {
 
         StringBuilder classpath = new StringBuilder();
         Executor.buildClasspath(classpath, mockedClassLoader);
-        Assert.assertEquals(pathname + File.pathSeparator, classpath.toString());
+        assertEquals(pathname + File.pathSeparator, classpath.toString());
     }
 }


[maven-pmd-plugin] 09/13: Fix it MPMD-258-multiple-executions

Posted by ad...@apache.org.
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 c439592f64bacbdc5564663c6cabecadf419edd7
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Fri May 19 18:43:35 2023 +0200

    Fix it MPMD-258-multiple-executions
    
    The logging "Analysis cache created" or "Analysis cache updated" is only logged in debug mode.
---
 src/it/MPMD-258-multiple-executions/invoker.properties | 2 +-
 src/it/MPMD-258-multiple-executions/verify.groovy      | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/it/MPMD-258-multiple-executions/invoker.properties b/src/it/MPMD-258-multiple-executions/invoker.properties
index 02b72c7..ea3955e 100644
--- a/src/it/MPMD-258-multiple-executions/invoker.properties
+++ b/src/it/MPMD-258-multiple-executions/invoker.properties
@@ -15,5 +15,5 @@
 # specific language governing permissions and limitations
 # under the License.
 
-invoker.goals = clean compile pmd:pmd
+invoker.goals = -X clean compile pmd:pmd
 invoker.maven.version = 3.1.0+
diff --git a/src/it/MPMD-258-multiple-executions/verify.groovy b/src/it/MPMD-258-multiple-executions/verify.groovy
index b6622b1..1925c67 100644
--- a/src/it/MPMD-258-multiple-executions/verify.groovy
+++ b/src/it/MPMD-258-multiple-executions/verify.groovy
@@ -21,7 +21,9 @@ File buildLog = new File( basedir, 'build.log' )
 assert buildLog.exists()
 
 // we have 2 modules and for each module this should be output once
+// note: this is only logged in debug mode by net.sourceforge.pmd.cache.FileAnalysisCache
 assert 2 == buildLog.text.count( "Analysis cache created" )
 
 // since we are running clean pmd:pmd, the cache is always created, never updated
+// note: this is only logged in debug mode by net.sourceforge.pmd.cache.FileAnalysisCache
 assert 0 == buildLog.text.count( "Analysis cache updated" )