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 3972a7995964d31d92fc0db37b4c3aa1810a73e8 Author: Brad Flood <bfl...@keyholesoftware.com> AuthorDate: Thu Jan 18 10:25:41 2018 +0100 [MPMD-251] Invalid report XML is generated with includeXmlInSite=true Submitted by: Brad Flood <bfl...@keyholesoftware.com> Closes apache/maven-plugins#127 --- .../org/apache/maven/plugins/pmd/PmdReport.java | 1 + .../apache/maven/plugins/pmd/PmdReportTest.java | 27 +++++++++- ...md-report-include-xml-in-site-plugin-config.xml | 62 ++++++++++++++++++++++ 3 files changed, 89 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 e5a193d..fe39380 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java @@ -596,6 +596,7 @@ public class PmdReport r.start(); r.renderFileReport( report ); r.end(); + writer.flush(); if ( includeXmlInSite ) { 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 9fa5891..e108f96 100644 --- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java +++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java @@ -350,6 +350,31 @@ public class PmdReportTest } /** + * verify the pmd.xml file is included in the site when requested. + * @throws Exception + */ + public void testIncludeXmlInSite() + throws Exception + { + File testPom = new File( getBasedir(), "src/test/resources/unit/default-configuration/pmd-report-include-xml-in-site-plugin-config.xml" ); + PmdReport mojo = (PmdReport) lookupMojo( "pmd", testPom ); + mojo.execute(); + + File generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/site/pmd.html" ); + assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) ); + // verify the pmd file is included in site + File generatedXmlFile = new File( getBasedir(), "target/test/unit/default-configuration/target/site/pmd.xml" ); + assertTrue( FileUtils.fileExists( generatedXmlFile.getAbsolutePath() ) ); + + String pmdXmlTarget = readFile( new File( getBasedir(), "target/test/unit/default-configuration/target/pmd.xml" ) ); + assertTrue( pmdXmlTarget.contains( "</pmd>" ) ); + + // check that pmd.xml file has the closing element + String pmdXml = readFile( new File( getBasedir(), "target/test/unit/default-configuration/target/site/pmd.xml" ) ); + assertTrue( pmdXml.contains( "</pmd>" ) ); + } + + /** * Read the contents of the specified file object into a string * * @param file the file to be read @@ -374,7 +399,7 @@ public class PmdReportTest } /** - * Verify the correct working of the localtionTemp method + * Verify the correct working of the locationTemp method * * @throws Exception */ diff --git a/src/test/resources/unit/default-configuration/pmd-report-include-xml-in-site-plugin-config.xml b/src/test/resources/unit/default-configuration/pmd-report-include-xml-in-site-plugin-config.xml new file mode 100644 index 0000000..dc0e98d --- /dev/null +++ b/src/test/resources/unit/default-configuration/pmd-report-include-xml-in-site-plugin-config.xml @@ -0,0 +1,62 @@ +<!-- +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>def.configuration</groupId> + <artifactId>default-configuration</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <inceptionYear>2006</inceptionYear> + <name>Maven PMD Plugin Default Configuration Test</name> + <url>http://maven.apache.org</url> + <build> + <finalName>default-configuration</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/default-configuration/target/site</outputDirectory> + <targetDirectory>${basedir}/target/test/unit/default-configuration/target</targetDirectory> + <format>xml</format> + <sourceEncoding>UTF-8</sourceEncoding> + <includeXmlInSite>true</includeXmlInSite> + + </configuration> + <dependencies> + <dependency> + <groupId>pmd</groupId> + <artifactId>pmd</artifactId> + <version>3.6</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> + <reporting> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jxr-plugin</artifactId> + </plugin> + </plugins> + </reporting> +</project> -- To stop receiving notification emails like this one, please contact "commits@maven.apache.org" <commits@maven.apache.org>.