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

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

commit e4be7da1cd940f6499fb2525e0aee87e31814b7e
Author: Andreas Dangel <adan...@apache.org>
AuthorDate: Fri Dec 15 19:58:08 2017 +0100

    [MPMD-246] Output details of processing errors
    
    Add new parameter "renderProcessingErrors"
---
 .../org/apache/maven/plugins/pmd/PmdReport.java    | 17 +++++++-
 .../apache/maven/plugins/pmd/PmdReportTest.java    | 36 ++++++++++++++++
 ...md-processing-error-no-report-plugin-config.xml | 50 ++++++++++++++++++++++
 3 files changed, 102 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java 
b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
index 4152070..ae2a96a 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
@@ -206,6 +206,18 @@ public class PmdReport
     private String analysisCacheLocation;
 
     /**
+     * Also render processing errors into the HTML report.
+     * Processing errors are problems, that PMD encountered while executing 
the rules.
+     * It can be parsing errors or exceptions during rule execution.
+     * Processing errors indicate a bug in PMD and the information provided 
help in
+     * reporting and fixing bugs in PMD.
+     *
+     * @since 3.9.0
+     */
+    @Parameter( property = "pmd.renderProcessingErrors", defaultValue = "true" 
)
+    private boolean renderProcessingErrors = true;
+
+    /**
      * {@inheritDoc}
      */
     public String getName( Locale locale )
@@ -505,7 +517,10 @@ public class PmdReport
         PmdReportGenerator doxiaRenderer = new PmdReportGenerator( getLog(), 
sink, getBundle( locale ), aggregate );
         doxiaRenderer.setFiles( filesToProcess );
         doxiaRenderer.setViolations( renderer.getViolations() );
-        doxiaRenderer.setProcessingErrors( renderer.getErrors() );
+        if ( renderProcessingErrors )
+        {
+            doxiaRenderer.setProcessingErrors( renderer.getErrors() );
+        }
 
         try
         {
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 9096c8c..0ba7bbc 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
@@ -494,6 +494,42 @@ public class PmdReportTest
         }
     }
 
+    public void testPMDProcessingErrorWithDetailsNoReport()
+            throws Exception
+    {
+        File testPom = new File( getBasedir(),
+                
"src/test/resources/unit/processing-error/pmd-processing-error-no-report-plugin-config.xml"
 );
+        PmdReport mojo = (PmdReport) lookupMojo( "pmd", testPom );
+
+        PrintStream originalOut = System.out;
+        ByteArrayOutputStream logging = new ByteArrayOutputStream();
+        System.setOut( new PrintStream( logging ) );
+
+        try {
+            mojo.execute();
+            String output = logging.toString();
+            assertTrue ( output.contains( "There are 1 PMD processing errors:" 
) );
+
+            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." ) );
+
+            generatedFile = new File( getBasedir(), 
"target/test/unit/default-configuration/target/site/pmd.html" );
+            renderer( mojo, generatedFile );
+            assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() 
) );
+            str = readFile( generatedFile );
+            // The parse exception must NOT be in the HTML report, since 
reportProcessingErrors is false
+            assertFalse( str.contains( "ParseException: Encountered \"\" at 
line 23, column 5." ) );
+
+        } finally {
+            System.setOut( originalOut );
+            System.out.println( logging.toString() );
+        }
+    }
+
     public void testPMDExcludeRootsShouldExcludeSubdirectories() throws 
Exception {
         File testPom = new File(getBasedir(), 
"src/test/resources/unit/exclude-roots/pmd-exclude-roots-plugin-config.xml");
         PmdReport mojo = (PmdReport) lookupMojo ("pmd", testPom);
diff --git 
a/src/test/resources/unit/processing-error/pmd-processing-error-no-report-plugin-config.xml
 
b/src/test/resources/unit/processing-error/pmd-processing-error-no-report-plugin-config.xml
new file mode 100644
index 0000000..77953cf
--- /dev/null
+++ 
b/src/test/resources/unit/processing-error/pmd-processing-error-no-report-plugin-config.xml
@@ -0,0 +1,50 @@
+<!--
+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>parse.error.configuration</groupId>
+  <artifactId>parse-error-configuration</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0-SNAPSHOT</version>
+  <inceptionYear>2006</inceptionYear>
+  <name>Maven PMD Plugin Parse Error Test</name>
+  <url>http://maven.apache.org</url>
+  <build>
+    <finalName>parse-error</finalName>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-pmd-plugin</artifactId>
+        <configuration>
+          <project 
implementation="org.apache.maven.plugins.pmd.stubs.DefaultConfigurationMavenProjectStub"/>
+          
<outputDirectory>${basedir}/target/test/unit/parse-error/target/site</outputDirectory>
+          
<targetDirectory>${basedir}/target/test/unit/parse-error/target</targetDirectory>
+          <format>xml</format>
+          <sourceEncoding>UTF-8</sourceEncoding>
+          <skipPmdError>true</skipPmdError>
+          <renderProcessingErrors>false</renderProcessingErrors>
+          <compileSourceRoots>
+            
<compileSourceRoot>${basedir}/src/test/resources/unit/processing-error/src</compileSourceRoot>
+          </compileSourceRoots>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

-- 
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <commits@maven.apache.org>.

Reply via email to