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 2020/10/24 14:05:20 UTC

[maven-pmd-plugin] branch master updated (563654b -> bd5b017)

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

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


    from 563654b  [MPMD-307] - NPE when using custom rule
     new 5048ab8  [MPMD-302] - Upgrade to PMD 6.29.0
     new bd5b017  Fix integration test MPMD-165

The 2 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-165/src/main/java/test/MyClass.java    |  2 +-
 .../apache/maven/plugins/pmd/exec/PmdResult.java   | 62 +++++++++++++++++++++-
 .../apt/examples/upgrading-PMD-at-runtime.apt.vm   |  2 +-
 4 files changed, 64 insertions(+), 4 deletions(-)


[maven-pmd-plugin] 01/02: [MPMD-302] - Upgrade to PMD 6.29.0

Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5048ab82bd92fa6526eba922d059f1a646b30cc6
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Sat Oct 24 14:37:19 2020 +0200

    [MPMD-302] - Upgrade to PMD 6.29.0
---
 pom.xml                                               | 2 +-
 src/site/apt/examples/upgrading-PMD-at-runtime.apt.vm | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 8444dfe..7943ff3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -89,7 +89,7 @@ under the License.
     <doxiaVersion>1.9.1</doxiaVersion>
     <doxiaSitetoolsVersion>1.9.2</doxiaSitetoolsVersion>
     <javaVersion>7</javaVersion><!-- Because PMD 5.4+ requires Java 7 -->
-    <pmdVersion>6.28.0</pmdVersion>
+    <pmdVersion>6.29.0</pmdVersion>
     <sitePluginVersion>3.7.1</sitePluginVersion>
     <projectInfoReportsPluginVersion>3.0.0</projectInfoReportsPluginVersion>
     <project.build.outputTimestamp>2020-04-07T21:04:00Z</project.build.outputTimestamp>
diff --git a/src/site/apt/examples/upgrading-PMD-at-runtime.apt.vm b/src/site/apt/examples/upgrading-PMD-at-runtime.apt.vm
index 1e20228..7c343b2 100644
--- a/src/site/apt/examples/upgrading-PMD-at-runtime.apt.vm
+++ b/src/site/apt/examples/upgrading-PMD-at-runtime.apt.vm
@@ -88,7 +88,7 @@ Upgrading PMD at Runtime
 *--------------------------------------------------------------------------------*--------------------------------------------------*
 | <<maven-pmd-plugin>>                                                           | <<PMD>>                                          |
 *--------------------------------------------------------------------------------*--------------------------------------------------*
-| {{{https://maven.apache.org/plugins-archives/maven-pmd-plugin-3.14.0/}3.14.0}} | {{{https://pmd.github.io/pmd-6.28.0/}6.28.0}}    |
+| {{{https://maven.apache.org/plugins-archives/maven-pmd-plugin-3.14.0/}3.14.0}} | {{{https://pmd.github.io/pmd-6.29.0/}6.29.0}}    |
 *--------------------------------------------------------------------------------*--------------------------------------------------*
 | {{{https://maven.apache.org/plugins-archives/maven-pmd-plugin-3.13.0/}3.13.0}} | {{{https://pmd.github.io/pmd-6.21.0/}6.21.0}}    |
 *--------------------------------------------------------------------------------*--------------------------------------------------*


[maven-pmd-plugin] 02/02: Fix integration test MPMD-165

Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit bd5b0173532a23caa12ae3751ac87a9cf870e7df
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Sat Oct 24 15:50:14 2020 +0200

    Fix integration test MPMD-165
---
 src/it/MPMD-165/src/main/java/test/MyClass.java    |  2 +-
 .../apache/maven/plugins/pmd/exec/PmdResult.java   | 62 +++++++++++++++++++++-
 2 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/src/it/MPMD-165/src/main/java/test/MyClass.java b/src/it/MPMD-165/src/main/java/test/MyClass.java
index 5e8d6f1..6c4c05c 100644
--- a/src/it/MPMD-165/src/main/java/test/MyClass.java
+++ b/src/it/MPMD-165/src/main/java/test/MyClass.java
@@ -24,7 +24,7 @@ public class MyClass
 
     public static void main( String[] args )
     {
-        return;
+        return; // This is a UnnecessaryReturn violation
     }
 
 }
diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdResult.java b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdResult.java
index 504f633..93645d7 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdResult.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdResult.java
@@ -21,6 +21,8 @@ package org.apache.maven.plugins.pmd.exec;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FilterReader;
+import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.util.ArrayList;
@@ -60,7 +62,8 @@ public class PmdResult
 
     private void loadResult( File pmdFile, String encoding ) throws MavenReportException
     {
-        try ( Reader reader1 = new InputStreamReader( new FileInputStream( pmdFile ), encoding ) )
+        try ( Reader reader1 = new BomFilter( encoding, new InputStreamReader(
+                new FileInputStream( pmdFile ), encoding ) ) )
         {
             PmdXpp3Reader reader = new PmdXpp3Reader();
             PmdErrorDetail details = reader.read( reader1, false );
@@ -82,6 +85,63 @@ public class PmdResult
         }
     }
 
+    // Note: This seems to be a bug in PMD's XMLRenderer. The BOM is rendered multiple times.
+    // once at the beginning of the file, which is Ok, but also in the middle of the file.
+    // This filter just skips all BOMs if the encoding is not UTF-8
+    private static class BomFilter extends FilterReader
+    {
+        private static final char BOM = '\uFEFF';
+        private final boolean filter;
+
+        BomFilter( String encoding, Reader in )
+        {
+            super( in );
+            filter = !"UTF-8".equalsIgnoreCase( encoding );
+        }
+
+        @Override
+        public int read() throws IOException
+        {
+            int c = super.read();
+
+            if ( !filter )
+            {
+                return c;
+            }
+
+            while ( c != -1 && c == BOM )
+            {
+                c = super.read();
+            }
+            return c;
+        }
+
+        @Override
+        public int read( char[] cbuf, int off, int len ) throws IOException
+        {
+            int count = super.read( cbuf, off, len );
+
+            if ( !filter )
+            {
+                return count;
+            }
+
+            if ( count != -1 )
+            {
+                for ( int i = off; i < off + count; i++ )
+                {
+                    if ( cbuf[i] == BOM )
+                    {
+                        // shift the content one char to the left
+                        System.arraycopy( cbuf, i + 1, cbuf, i, off + count - 1 - i );
+                        count--;
+                    }
+                }
+            }
+            return count;
+        }
+    }
+
     public Collection<Violation> getViolations()
     {
         return violations;