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 2017/12/18 19:14:38 UTC
[maven-pmd-plugin] branch master updated (2051d09 -> 8ea1ca9)
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 2051d09 [MPMD-248] cpd-check goal leaks file handle
new 4712a94 [MPMD-244] Maven PMD plugin fails but no reason is given for the failure
new f9c4942 [MPMD-246] Output details of processing errors
new a4ec983 [MPMD-246] Output details of processing errors
new fb7511f [MPMD-246] Output details of processing errors
new 8ea1ca9 [MPMD-244] Maven PMD plugin fails but no reason is given for the failure
The 5 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 | 7 +
.../invoker.properties | 1 -
.../logging-disabled}/pom.xml | 12 +-
.../src/main/java/BrokenFile.java | 0
.../logging-enabled}/pom.xml | 12 +-
.../logging-enabled}/src/main/java/BrokenFile.java | 0
.../pom.xml | 11 +-
.../verify.groovy | 6 +-
.../maven/plugins/pmd/AbstractPmdReport.java | 34 +++++
.../org/apache/maven/plugins/pmd/CpdReport.java | 2 +
.../maven/plugins/pmd/PmdCollectingRenderer.java | 11 +-
.../org/apache/maven/plugins/pmd/PmdReport.java | 22 ++-
.../maven/plugins/pmd/PmdReportGenerator.java | 168 ++++++++++++++++-----
src/main/resources/pmd-report.properties | 3 +
src/main/resources/pmd-report_de.properties | 3 +
.../apache/maven/plugins/pmd/PmdReportTest.java | 86 ++++++++++-
...d-processing-error-no-report-plugin-config.xml} | 3 +-
...=> pmd-processing-error-skip-plugin-config.xml} | 2 +-
18 files changed, 317 insertions(+), 66 deletions(-)
copy src/it/{MPMD-219-pmd-processing-error => MPMD-244-logging}/invoker.properties (96%)
copy src/it/{MPMD-219-pmd-processing-error => MPMD-244-logging/logging-disabled}/pom.xml (83%)
copy src/it/{MPMD-219-pmd-processing-error => MPMD-244-logging/logging-disabled}/src/main/java/BrokenFile.java (100%)
copy src/it/{MPMD-219-pmd-processing-error => MPMD-244-logging/logging-enabled}/pom.xml (83%)
copy src/it/{MPMD-219-pmd-processing-error => MPMD-244-logging/logging-enabled}/src/main/java/BrokenFile.java (100%)
copy src/it/{MPMD-234-analysis-cache => MPMD-244-logging}/pom.xml (85%)
copy src/it/{MPMD-219-pmd-processing-error => MPMD-244-logging}/verify.groovy (62%)
copy src/test/resources/unit/processing-error/{pmd-processing-error-plugin-config.xml => pmd-processing-error-no-report-plugin-config.xml} (94%)
copy src/test/resources/unit/processing-error/{pmd-processing-error-plugin-config.xml => pmd-processing-error-skip-plugin-config.xml} (97%)
--
To stop receiving notification emails like this one, please contact
['"commits@maven.apache.org" <co...@maven.apache.org>'].
[maven-pmd-plugin] 01/05: [MPMD-244] Maven PMD plugin fails but no
reason is given for the failure
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 4712a949be2018c739ee7bc890cc91b1cedfb4a8
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Mon Dec 18 19:53:58 2017 +0100
[MPMD-244] Maven PMD plugin fails but no reason is given for the failure
Added new parameter "showPmdLog", which helps in analyzing issues
within PMD. This integrates the PMD log into the maven log.
---
pom.xml | 7 +++
src/it/MPMD-244-logging/invoker.properties | 19 +++++++
src/it/MPMD-244-logging/logging-disabled/pom.xml | 61 ++++++++++++++++++++++
.../logging-disabled/src/main/java/BrokenFile.java | 26 +++++++++
src/it/MPMD-244-logging/logging-enabled/pom.xml | 61 ++++++++++++++++++++++
.../logging-enabled/src/main/java/BrokenFile.java | 26 +++++++++
src/it/MPMD-244-logging/pom.xml | 42 +++++++++++++++
src/it/MPMD-244-logging/verify.groovy | 26 +++++++++
.../maven/plugins/pmd/AbstractPmdReport.java | 34 ++++++++++++
.../org/apache/maven/plugins/pmd/CpdReport.java | 2 +
.../org/apache/maven/plugins/pmd/PmdReport.java | 2 +
11 files changed, 306 insertions(+)
diff --git a/pom.xml b/pom.xml
index 499a099..2813959 100644
--- a/pom.xml
+++ b/pom.xml
@@ -142,6 +142,13 @@ under the License.
<version>${pmdVersion}</version>
</dependency>
+ <!-- Support logging of PMD through slf4j. See also MPMD-244 -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jul-to-slf4j</artifactId>
+ <version>1.7.25</version>
+ </dependency>
+
<!-- doxia -->
<dependency>
<groupId>org.apache.maven.doxia</groupId>
diff --git a/src/it/MPMD-244-logging/invoker.properties b/src/it/MPMD-244-logging/invoker.properties
new file mode 100644
index 0000000..1e595ef
--- /dev/null
+++ b/src/it/MPMD-244-logging/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+
diff --git a/src/it/MPMD-244-logging/logging-disabled/pom.xml b/src/it/MPMD-244-logging/logging-disabled/pom.xml
new file mode 100644
index 0000000..46f0e2b
--- /dev/null
+++ b/src/it/MPMD-244-logging/logging-disabled/pom.xml
@@ -0,0 +1,61 @@
+<?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>
+
+ <parent>
+ <groupId>org.apache.maven.plugins.pmd.its</groupId>
+ <artifactId>MPMD-244-logging</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>MPMD-244-logging-disabled</artifactId>
+
+ <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>
+ <showPmdLog>false</showPmdLog>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>test-compile</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/MPMD-244-logging/logging-disabled/src/main/java/BrokenFile.java b/src/it/MPMD-244-logging/logging-disabled/src/main/java/BrokenFile.java
new file mode 100644
index 0000000..1c5335a
--- /dev/null
+++ b/src/it/MPMD-244-logging/logging-disabled/src/main/java/BrokenFile.java
@@ -0,0 +1,26 @@
+/*
+ * 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-244-logging/logging-enabled/pom.xml b/src/it/MPMD-244-logging/logging-enabled/pom.xml
new file mode 100644
index 0000000..355992c
--- /dev/null
+++ b/src/it/MPMD-244-logging/logging-enabled/pom.xml
@@ -0,0 +1,61 @@
+<?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>
+
+ <parent>
+ <groupId>org.apache.maven.plugins.pmd.its</groupId>
+ <artifactId>MPMD-244-logging</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>MPMD-244-logging-enabled</artifactId>
+
+ <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>
+ <showPmdLog>true</showPmdLog>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>test-compile</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/MPMD-244-logging/logging-enabled/src/main/java/BrokenFile.java b/src/it/MPMD-244-logging/logging-enabled/src/main/java/BrokenFile.java
new file mode 100644
index 0000000..1c5335a
--- /dev/null
+++ b/src/it/MPMD-244-logging/logging-enabled/src/main/java/BrokenFile.java
@@ -0,0 +1,26 @@
+/*
+ * 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-244-logging/pom.xml b/src/it/MPMD-244-logging/pom.xml
new file mode 100644
index 0000000..6d9d3c1
--- /dev/null
+++ b/src/it/MPMD-244-logging/pom.xml
@@ -0,0 +1,42 @@
+<?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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.pmd.its</groupId>
+ <artifactId>MPMD-244-logging</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <description>
+ Verify PMDs log output is present
+ </description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <modules>
+ <module>logging-disabled</module>
+ <module>logging-enabled</module>
+ </modules>
+</project>
diff --git a/src/it/MPMD-244-logging/verify.groovy b/src/it/MPMD-244-logging/verify.groovy
new file mode 100644
index 0000000..f213605
--- /dev/null
+++ b/src/it/MPMD-244-logging/verify.groovy
@@ -0,0 +1,26 @@
+/*
+ * 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( "Error while parsing" )
+String currentDir = basedir.getCanonicalPath()
+assert buildLog.text.contains( "net.sourceforge.pmd.PMDException: Error while parsing ${currentDir}/logging-enabled/src/main/java/BrokenFile.java" )
+assert ! buildLog.text.contains( "net.sourceforge.pmd.PMDException: Error while parsing ${currentDir}/logging-disabled/src/main/java/BrokenFile.java" )
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 67a7761..ec2b056 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java
@@ -29,6 +29,9 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.logging.SimpleFormatter;
import net.sourceforge.pmd.PMD;
@@ -42,6 +45,7 @@ import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.PathTool;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
+import org.slf4j.bridge.SLF4JBridgeHandler;
/**
* Base class for the PMD reports.
@@ -215,6 +219,17 @@ public abstract class AbstractPmdReport
@Parameter( property = "pmd.excludeFromFailureFile", defaultValue = "" )
protected String excludeFromFailureFile;
+ /**
+ * Redirect PMD log into maven log out.
+ * When enabled, the PMD log output is redirected to maven, so that
+ * it is visible in the console together with all the other log output.
+ * Also, if maven is started with the debug flag (<code>-X</code> or <code>--debug</code>),
+ * the PMD logger is also configured for debug.
+ *
+ * @since 3.9.0
+ */
+ @Parameter( defaultValue = "true", property = "pmd.showPmdLog" )
+ protected boolean showPmdLog = true;
/** The files that are being analyzed. */
protected Map<File, PmdFileInfo> filesToProcess;
@@ -535,6 +550,25 @@ public abstract class AbstractPmdReport
return ( outputEncoding != null ) ? outputEncoding : ReaderFactory.UTF_8;
}
+ protected void setupPmdLogging()
+ {
+ if ( !showPmdLog )
+ {
+ return;
+ }
+
+ Logger logger = Logger.getLogger( "net.sourceforge.pmd" );
+
+ 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 );
+ getLog().debug( "Configured jul-to-slf4j bridge for " + logger.getName() );
+ }
+
static String getPmdVersion()
{
try
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 92b9766..e943b24 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java
@@ -230,6 +230,8 @@ public class CpdReport
return;
}
+ setupPmdLogging();
+
Properties p = new Properties();
if ( ignoreLiterals )
{
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 9db12c4..0351988 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
@@ -320,6 +320,8 @@ public class PmdReport
private void executePmd()
throws MavenReportException
{
+ setupPmdLogging();
+
if ( renderer != null )
{
// PMD has already been run
--
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <co...@maven.apache.org>.
[maven-pmd-plugin] 02/05: [MPMD-246] Output details of processing
errors
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 f9c4942d2a49441b13bc5df83c632bad78fcb73f
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Fri Dec 15 19:57:09 2017 +0100
[MPMD-246] Output details of processing errors
Output detail error message when debug logging is enabled.
In any case, add the processing errors to the xml report.
---
.../maven/plugins/pmd/PmdCollectingRenderer.java | 11 ++++-
.../org/apache/maven/plugins/pmd/PmdReport.java | 4 +-
.../apache/maven/plugins/pmd/PmdReportTest.java | 31 ++++++++++++++
.../pmd-processing-error-skip-plugin-config.xml | 49 ++++++++++++++++++++++
4 files changed, 92 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/pmd/PmdCollectingRenderer.java b/src/main/java/org/apache/maven/plugins/pmd/PmdCollectingRenderer.java
index 9402639..e55b779 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/PmdCollectingRenderer.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/PmdCollectingRenderer.java
@@ -104,14 +104,19 @@ public class PmdCollectingRenderer extends AbstractRenderer
/**
* Gets the errors as a single string. Each error is in its own line.
+ * @param withDetails if <code>true</code> then add the error details additionally (contains e.g. the stacktrace)
* @return the errors as string
*/
- public String getErrorsAsString()
+ public String getErrorsAsString( boolean withDetails )
{
List<String> errorsAsString = new ArrayList<>( errors.size() );
for ( ProcessingError error : errors )
{
errorsAsString.add( error.getFile() + ": " + error.getMsg() );
+ if ( withDetails )
+ {
+ errorsAsString.add( error.getDetail() );
+ }
}
return StringUtils.join( errorsAsString.toArray(), System.getProperty( "line.separator" ) );
}
@@ -127,6 +132,10 @@ public class PmdCollectingRenderer extends AbstractRenderer
{
report.addRuleViolation( v );
}
+ for ( ProcessingError e : errors )
+ {
+ report.addError( e );
+ }
return report;
}
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 0351988..9b63b9d 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
@@ -422,11 +422,11 @@ public class PmdReport
if ( !skipPmdError )
{
getLog().error( "PMD processing errors:" );
- getLog().error( renderer.getErrorsAsString() );
+ getLog().error( renderer.getErrorsAsString( getLog().isDebugEnabled() ) );
throw new MavenReportException( "Found " + renderer.getErrors().size() + " PMD processing errors" );
}
getLog().warn( "There are " + renderer.getErrors().size() + " PMD processing errors:" );
- getLog().warn( renderer.getErrorsAsString() );
+ getLog().warn( renderer.getErrorsAsString( getLog().isDebugEnabled() ) );
}
removeExcludedViolations( renderer.getViolations() );
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 2ac342a..ee3bd1e 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
@@ -20,9 +20,11 @@ package org.apache.maven.plugins.pmd;
*/
import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
+import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.URL;
import java.nio.charset.StandardCharsets;
@@ -467,6 +469,35 @@ public class PmdReportTest
}
}
+ public void testPMDProcessingErrorWithDetailsSkipped()
+ throws Exception
+ {
+ File testPom = new File( getBasedir(),
+ "src/test/resources/unit/processing-error/pmd-processing-error-skip-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( new File( getBasedir(), "target/test/unit/parse-error/target/pmd.xml" ) );
+
+ assertTrue( str.contains( "Error while parsing" ) );
+ assertTrue( 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-skip-plugin-config.xml b/src/test/resources/unit/processing-error/pmd-processing-error-skip-plugin-config.xml
new file mode 100644
index 0000000..faa30c1
--- /dev/null
+++ b/src/test/resources/unit/processing-error/pmd-processing-error-skip-plugin-config.xml
@@ -0,0 +1,49 @@
+<!--
+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>
+ <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" <co...@maven.apache.org>.
[maven-pmd-plugin] 04/05: [MPMD-246] Output details of processing
errors
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 fb7511f5f36b38d30b1f4cce58bb914d56d1ad4d
Author: Andreas Dangel <ad...@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 bfc149c..20b2e5e 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 )
@@ -507,7 +519,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 614c58f..9fa5891 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
@@ -505,6 +505,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" <co...@maven.apache.org>.
[maven-pmd-plugin] 03/05: [MPMD-246] Output details of processing
errors
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 a4ec98393cf1a8db3dcfffc9cfa623481fd7ba83
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Fri Dec 15 19:57:35 2017 +0100
[MPMD-246] Output details of processing errors
Render processing errors in HTML report
---
.../org/apache/maven/plugins/pmd/PmdReport.java | 1 +
.../maven/plugins/pmd/PmdReportGenerator.java | 168 ++++++++++++++++-----
src/main/resources/pmd-report.properties | 3 +
src/main/resources/pmd-report_de.properties | 3 +
.../apache/maven/plugins/pmd/PmdReportTest.java | 23 ++-
5 files changed, 151 insertions(+), 47 deletions(-)
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 9b63b9d..bfc149c 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java
@@ -507,6 +507,7 @@ public class PmdReport
PmdReportGenerator doxiaRenderer = new PmdReportGenerator( getLog(), sink, getBundle( locale ), aggregate );
doxiaRenderer.setFiles( filesToProcess );
doxiaRenderer.setViolations( renderer.getViolations() );
+ doxiaRenderer.setProcessingErrors( renderer.getErrors() );
try
{
diff --git a/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java b/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java
index 54fa04f..152064a 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReportGenerator.java
@@ -29,13 +29,15 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
-
-import net.sourceforge.pmd.RuleViolation;
+import java.util.Set;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.util.StringUtils;
+import net.sourceforge.pmd.Report.ProcessingError;
+import net.sourceforge.pmd.RuleViolation;
+
/**
* Render the PMD violations into Doxia events.
*
@@ -52,7 +54,9 @@ public class PmdReportGenerator
private ResourceBundle bundle;
- private HashSet<RuleViolation> violations = new HashSet<>();
+ private Set<RuleViolation> violations = new HashSet<>();
+
+ private List<ProcessingError> processingErrors = new ArrayList<>();
private boolean aggregate;
@@ -86,6 +90,16 @@ public class PmdReportGenerator
return new ArrayList<>( violations );
}
+ public void setProcessingErrors( Collection<ProcessingError> errors )
+ {
+ this.processingErrors = new ArrayList<>( errors );
+ }
+
+ public List<ProcessingError> getProcessingErrors()
+ {
+ return processingErrors;
+ }
+
// public List<Metric> getMetrics()
// {
// return metrics;
@@ -96,26 +110,46 @@ public class PmdReportGenerator
// this.metrics = metrics;
// }
- private void startFileSection( String currentFilename, PmdFileInfo fileInfo )
+ private String shortenFilename( String filename, PmdFileInfo fileInfo )
{
- sink.section2();
- sink.sectionTitle2();
-
- // prepare the filename
- this.currentFilename = currentFilename;
+ String result = filename;
if ( fileInfo != null && fileInfo.getSourceDirectory() != null )
{
- this.currentFilename =
- StringUtils.substring( currentFilename, fileInfo.getSourceDirectory().getAbsolutePath().length() + 1 );
+ result =
+ StringUtils.substring( result, fileInfo.getSourceDirectory().getAbsolutePath().length() + 1 );
}
- this.currentFilename = StringUtils.replace( this.currentFilename, "\\", "/" );
+ result = StringUtils.replace( result, "\\", "/" );
- String title = this.currentFilename;
if ( aggregate && fileInfo != null && fileInfo.getProject() != null )
{
- title = fileInfo.getProject().getName() + " - " + this.currentFilename;
+ result = fileInfo.getProject().getName() + " - " + result;
}
- sink.text( title );
+
+ return result;
+ }
+
+ private PmdFileInfo determineFileInfo( String filename ) throws IOException
+ {
+ File canonicalFilename = new File( filename ).getCanonicalFile();
+ PmdFileInfo fileInfo = files.get( canonicalFilename );
+ if ( fileInfo == null )
+ {
+ log.warn( "Couldn't determine PmdFileInfo for file " + filename + " (canonical: " + canonicalFilename
+ + "). XRef links won't be available." );
+ }
+
+ return fileInfo;
+ }
+
+ private void startFileSection( String currentFilename, PmdFileInfo fileInfo )
+ {
+ sink.section2();
+ sink.sectionTitle2();
+
+ // prepare the filename
+ this.currentFilename = shortenFilename( currentFilename, fileInfo );
+
+ sink.text( this.currentFilename );
sink.sectionTitle2_();
sink.table();
@@ -162,8 +196,15 @@ public class PmdReportGenerator
private void processViolations()
throws IOException
{
+ sink.section1();
+ sink.sectionTitle1();
+ sink.text( bundle.getString( "report.pmd.files" ) );
+ sink.sectionTitle1_();
+
+ // TODO files summary
+
fileCount = files.size();
- ArrayList<RuleViolation> violations2 = new ArrayList<>( violations );
+ List<RuleViolation> violations2 = new ArrayList<>( violations );
Collections.sort( violations2, new Comparator<RuleViolation>()
{
/** {@inheritDoc} */
@@ -186,13 +227,7 @@ public class PmdReportGenerator
for ( RuleViolation ruleViolation : violations2 )
{
String currentFn = ruleViolation.getFilename();
- File canonicalFilename = new File( currentFn ).getCanonicalFile();
- PmdFileInfo fileInfo = files.get( canonicalFilename );
- if ( fileInfo == null )
- {
- log.warn( "Couldn't determine PmdFileInfo for file " + currentFn + " (canonical: " + canonicalFilename
- + "). XRef links won't be available." );
- }
+ PmdFileInfo fileInfo = determineFileInfo( currentFn );
if ( !currentFn.equalsIgnoreCase( previousFilename ) && fileSectionStarted )
{
@@ -214,6 +249,15 @@ public class PmdReportGenerator
{
endFileSection();
}
+
+ if ( fileCount == 0 )
+ {
+ sink.paragraph();
+ sink.text( bundle.getString( "report.pmd.noProblems" ) );
+ sink.paragraph_();
+ }
+
+ sink.section1_();
}
private void outputLineLink( int line, PmdFileInfo fileInfo )
@@ -235,6 +279,63 @@ public class PmdReportGenerator
}
}
+ private void processProcessingErrors() throws IOException
+ {
+ // sort the problem by filename first, since PMD is executed multi-threaded
+ // and might reports the results unsorted
+ Collections.sort( processingErrors, new Comparator<ProcessingError>()
+ {
+ @Override
+ public int compare( ProcessingError e1, ProcessingError e2 )
+ {
+ return e1.getFile().compareTo( e2.getFile() );
+ }
+ } );
+
+ sink.section1();
+ sink.sectionTitle1();
+ sink.text( bundle.getString( "report.pmd.processingErrors.title" ) );
+ sink.sectionTitle1_();
+
+ sink.table();
+ sink.tableRow();
+ sink.tableHeaderCell();
+ sink.text( bundle.getString( "report.pmd.processingErrors.column.filename" ) );
+ sink.tableHeaderCell_();
+ sink.tableHeaderCell();
+ sink.text( bundle.getString( "report.pmd.processingErrors.column.problem" ) );
+ sink.tableHeaderCell_();
+ sink.tableRow_();
+
+ for ( ProcessingError error : processingErrors )
+ {
+ processSingleProcessingError( error );
+ }
+
+ sink.table_();
+
+ sink.section1_();
+ }
+
+ private void processSingleProcessingError( ProcessingError error ) throws IOException
+ {
+ String filename = error.getFile();
+ PmdFileInfo fileInfo = determineFileInfo( filename );
+ filename = shortenFilename( filename, fileInfo );
+
+ sink.tableRow();
+ sink.tableCell();
+ sink.text( filename );
+ sink.tableCell_();
+ sink.tableCell();
+ sink.text( error.getMsg() );
+ sink.verbatim( null );
+ sink.rawText( error.getDetail() );
+ sink.verbatim_();
+ sink.tableCell_();
+ sink.tableRow_();
+ }
+
public void beginDocument()
{
sink.head();
@@ -261,13 +362,6 @@ public class PmdReportGenerator
sink.section1_();
// TODO overall summary
-
- sink.section1();
- sink.sectionTitle1();
- sink.text( bundle.getString( "report.pmd.files" ) );
- sink.sectionTitle1_();
-
- // TODO files summary
}
/*
@@ -288,20 +382,16 @@ public class PmdReportGenerator
throws IOException
{
processViolations();
+
+ if ( !processingErrors.isEmpty() )
+ {
+ processProcessingErrors();
+ }
}
public void endDocument()
throws IOException
{
- if ( fileCount == 0 )
- {
- sink.paragraph();
- sink.text( bundle.getString( "report.pmd.noProblems" ) );
- sink.paragraph_();
- }
-
- sink.section1_();
-
// The Metrics report useless with the current PMD metrics impl.
// For instance, run the coupling ruleset and you will get a boatload
// of excessive imports metrics, none of which is really any use.
diff --git a/src/main/resources/pmd-report.properties b/src/main/resources/pmd-report.properties
index 798c806..031ceef 100644
--- a/src/main/resources/pmd-report.properties
+++ b/src/main/resources/pmd-report.properties
@@ -23,3 +23,6 @@ report.pmd.column.line=Line
report.pmd.pmdlink=The following document contains the results of
report.pmd.files=Files
report.pmd.noProblems=PMD found no problems in your source code.
+report.pmd.processingErrors.title=Processing Errors
+report.pmd.processingErrors.column.filename=Filename
+report.pmd.processingErrors.column.problem=Problem
diff --git a/src/main/resources/pmd-report_de.properties b/src/main/resources/pmd-report_de.properties
index 71bb460..36a7cd7 100644
--- a/src/main/resources/pmd-report_de.properties
+++ b/src/main/resources/pmd-report_de.properties
@@ -23,3 +23,6 @@ report.pmd.column.line=Zeile
report.pmd.pmdlink=Dieses Dokument enth\u00e4lt die Ergebnisse von
report.pmd.files=Dateien
report.pmd.noProblems=PMD hat keine Probleme in dem Quellcode gefunden.
+report.pmd.processingErrors.title=Verarbeitungsprobleme
+report.pmd.processingErrors.column.filename=Datei
+report.pmd.processingErrors.column.problem=Problem
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 ee3bd1e..614c58f 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
@@ -81,7 +81,7 @@ public class PmdReportTest
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
// check if there's a link to the JXR files
- String str = readFile( new File( getBasedir(), "target/test/unit/default-configuration/target/site/pmd.html" ) );
+ String str = readFile( generatedFile );
assertTrue( str.contains( "/xref/def/configuration/App.html#L31" ) );
@@ -202,7 +202,7 @@ public class PmdReportTest
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
// check if there's a link to the JXR files
- String str = readFile( new File( getBasedir(), "target/test/unit/default-configuration/target/site/pmd.html" ) );
+ String str = readFile( generatedFile );
assertTrue( str.contains( "/xref/def/configuration/App.html#L31" ) );
@@ -244,11 +244,10 @@ public class PmdReportTest
generatedFile = new File( getBasedir(), "target/test/unit/custom-configuration/target/site/pmd.html" );
renderer( mojo, generatedFile );
- renderer( mojo, generatedFile );
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
// check if custom ruleset was applied
- String str = readFile( new File( getBasedir(), "target/test/unit/custom-configuration/target/site/pmd.html" ) );
+ String str = readFile( generatedFile );
assertTrue( lowerCaseContains( str, "Avoid using if statements without curly braces" ) );
// Must be false as IfElseStmtsMustUseBraces is excluded!
@@ -309,7 +308,7 @@ public class PmdReportTest
// verify the generated files do exist, even if there are no violations
File generatedFile = new File( getBasedir(), "target/test/unit/empty-report/target/site/pmd.html" );
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
- String str = readFile( new File( getBasedir(), "target/test/unit/empty-report/target/site/pmd.html" ) );
+ String str = readFile( generatedFile );
assertFalse( lowerCaseContains( str, "Hello.java" ) );
}
@@ -368,6 +367,7 @@ public class PmdReportTest
{
str.append( ' ' );
str.append( line );
+ str.append( '\n' );
}
return str.toString();
}
@@ -411,7 +411,7 @@ public class PmdReportTest
File generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/pmd.xml" );
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
- String str = readFile( new File( getBasedir(), "target/test/unit/default-configuration/target/pmd.xml" ) );
+ String str = readFile( generatedFile );
// check that there is no violation reported for "unusedVar2" - as it is suppressed
assertFalse( str.contains( "Avoid unused private fields such as 'unusedVar2'." ) );
@@ -487,9 +487,16 @@ public class PmdReportTest
File generatedFile = new File( getBasedir(), "target/test/unit/parse-error/target/pmd.xml" );
assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
- String str = readFile( new File( getBasedir(), "target/test/unit/parse-error/target/pmd.xml" ) );
-
+ 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 also be in the HTML report
assertTrue( str.contains( "ParseException: Encountered \"\" at line 23, column 5." ) );
} finally {
--
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <co...@maven.apache.org>.
[maven-pmd-plugin] 05/05: [MPMD-244] Maven PMD plugin fails but no
reason is given for the failure
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 8ea1ca954d32740a464e1285efa458d44898235c
Author: Andreas Dangel <ad...@apache.org>
AuthorDate: Mon Dec 18 20:11:44 2017 +0100
[MPMD-244] Maven PMD plugin fails but no reason is given for the failure
Fix integration test
---
src/it/MPMD-244-logging/verify.groovy | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/it/MPMD-244-logging/verify.groovy b/src/it/MPMD-244-logging/verify.groovy
index f213605..1e906a6 100644
--- a/src/it/MPMD-244-logging/verify.groovy
+++ b/src/it/MPMD-244-logging/verify.groovy
@@ -22,5 +22,7 @@ assert buildLog.exists()
assert buildLog.text.contains( "PMD processing errors" )
assert buildLog.text.contains( "Error while parsing" )
String currentDir = basedir.getCanonicalPath()
-assert buildLog.text.contains( "net.sourceforge.pmd.PMDException: Error while parsing ${currentDir}/logging-enabled/src/main/java/BrokenFile.java" )
-assert ! buildLog.text.contains( "net.sourceforge.pmd.PMDException: Error while parsing ${currentDir}/logging-disabled/src/main/java/BrokenFile.java" )
+// 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 ${currentDir}/logging-disabled/src/main/java/BrokenFile.java" )
+// 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 ${currentDir}/logging-enabled/src/main/java/BrokenFile.java" )
--
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <co...@maven.apache.org>.