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

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


The following commit(s) were added to refs/heads/master by this push:
     new 09be846  [MPLUGIN-394] Respect input encoding (#73)
09be846 is described below

commit 09be846da8dbcec846ad38be4bfa76d9b6c59329
Author: Sebastian Kühn <d...@sebastiankuehn.de>
AuthorDate: Sun Feb 27 12:19:02 2022 +0100

    [MPLUGIN-394] Respect input encoding (#73)
    
    * [MPLUGIN-394] Respect input encoding
    
    PluginReport didn't specify an encoding while reading the
    Plugin-Descriptor. This causes the fallback to the plattform encoding
    and ignores the (user specified) input encoding.
    
    This commits adds an integration test to reproduce the error and fixes
    it by using the input encoding for the creation of the used Reader.
    
    The integration tests forces the plattform encoding to CP1252 (Western
    European charset used in Windows) while the source (input) and output
    encoding is UTF-8.
    The source file contains non-ASCII characters which have a different
    representation in both encodings.
    
    * [MPLUGIN-394] use XmlStreamReader to detect encoding
    
    Uses a XmlStreamRead to detect encoding instead of using the configured
    Encoding.
    
    Co-authored-by: Hervé Boutemy <hbout...@apache.org>
    
    Co-authored-by: Hervé Boutemy <hbout...@apache.org>
---
 .../mplugin-394_report-encoding/invoker.properties | 18 +++++
 .../src/it/mplugin-394_report-encoding/pom.xml     | 79 ++++++++++++++++++++++
 .../src/main/java/test/MyMojo.java                 | 50 ++++++++++++++
 .../it/mplugin-394_report-encoding/verify.groovy   | 25 +++++++
 .../apache/maven/plugin/plugin/PluginReport.java   | 14 ++--
 5 files changed, 180 insertions(+), 6 deletions(-)

diff --git 
a/maven-plugin-plugin/src/it/mplugin-394_report-encoding/invoker.properties 
b/maven-plugin-plugin/src/it/mplugin-394_report-encoding/invoker.properties
new file mode 100644
index 0000000..9397c3b
--- /dev/null
+++ b/maven-plugin-plugin/src/it/mplugin-394_report-encoding/invoker.properties
@@ -0,0 +1,18 @@
+# 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 = -Dfile.encoding=CP1252 plugin:report
diff --git a/maven-plugin-plugin/src/it/mplugin-394_report-encoding/pom.xml 
b/maven-plugin-plugin/src/it/mplugin-394_report-encoding/pom.xml
new file mode 100644
index 0000000..bf4fdd6
--- /dev/null
+++ b/maven-plugin-plugin/src/it/mplugin-394_report-encoding/pom.xml
@@ -0,0 +1,79 @@
+<?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.its.plugin</groupId>
+  <artifactId>report-encoding</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>maven-plugin</packaging>
+
+  <name>Maven Integration Test :: Report Encoding</name>
+  <description>
+    Tests correct usage of configured encoding for reports
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <project.report.outputEncoding>UTF-8</project.report.outputEncoding>
+    <maven.compiler.source>1.8</maven.compiler.source>
+    <maven.compiler.target>1.8</maven.compiler.target>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>@mavenVersion@</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+      <version>3.0.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugin-tools</groupId>
+      <artifactId>maven-plugin-annotations</artifactId>
+      <version>@project.version@</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>3.8.0</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-plugin-plugin</artifactId>
+        <version>@project.version@</version>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git 
a/maven-plugin-plugin/src/it/mplugin-394_report-encoding/src/main/java/test/MyMojo.java
 
b/maven-plugin-plugin/src/it/mplugin-394_report-encoding/src/main/java/test/MyMojo.java
new file mode 100644
index 0000000..9041f19
--- /dev/null
+++ 
b/maven-plugin-plugin/src/it/mplugin-394_report-encoding/src/main/java/test/MyMojo.java
@@ -0,0 +1,50 @@
+package test;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+/**
+ * Mojo-Description with some non-ASCII characters: €àáâãäåæòóôõöø
+ * <p>
+ * This file is encoded with UTF-8 and Maven is configured with UTF-8 for 
source
+ * files and UTF-8 as output encoding for the site.  Therefore we expect the
+ * generated site to contain all characters from above, even if the system
+ * encoding is not UTF-8.
+ */
+@Mojo( name= "test" )
+public class MyMojo
+    extends AbstractMojo
+{
+
+    /**
+     * Parameter-Description with some non-ASCII characters: ÈÉÊË€
+     */
+    @Parameter
+    private String testParam;
+
+
+    public void execute()
+    {
+    }
+
+}
diff --git 
a/maven-plugin-plugin/src/it/mplugin-394_report-encoding/verify.groovy 
b/maven-plugin-plugin/src/it/mplugin-394_report-encoding/verify.groovy
new file mode 100644
index 0000000..f769922
--- /dev/null
+++ b/maven-plugin-plugin/src/it/mplugin-394_report-encoding/verify.groovy
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+generated = new File( basedir, 
"target/generated-site/xdoc/test-mojo.xml").getText("UTF-8")
+
+assert generated.contains("Mojo-Description with some non-ASCII characters: 
€àáâãäåæòóôõöø")
+assert generated.contains("Parameter-Description with some non-ASCII 
characters: ÈÉÊË€")
+
+return true;
diff --git 
a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
 
b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
index cb2eee9..641d6ad 100644
--- 
a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
+++ 
b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
@@ -20,8 +20,9 @@ package org.apache.maven.plugin.plugin;
  */
 
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
@@ -60,6 +61,7 @@ import org.apache.maven.tools.plugin.util.PluginUtils;
 import org.codehaus.plexus.component.repository.ComponentDependency;
 import org.codehaus.plexus.configuration.PlexusConfigurationException;
 import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 
 /**
@@ -270,12 +272,12 @@ public class PluginReport
         throws MavenReportException
     {
         PluginDescriptorBuilder builder = getPluginDescriptorBuilder();
-        
-        try
+
+        try ( Reader input = new XmlStreamReader( new FileInputStream( 
pluginXmlFile ) ) )
         {
-            return builder.build( new FileReader( pluginXmlFile ) );
+            return builder.build( input );
         }
-        catch ( FileNotFoundException | PlexusConfigurationException e )
+        catch ( IOException | PlexusConfigurationException e )
         {
             getLog().debug( "Failed to read " + pluginXmlFile + ", fall back 
to mojoScanner" );
         }

Reply via email to