Author: hboutemy
Date: Sun Sep 14 00:30:58 2014
New Revision: 1624794

URL: http://svn.apache.org/r1624794
Log:
[MSHARED-348] support reporting encoding configuration when used as goal

Modified:
    
maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java

Modified: 
maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java?rev=1624794&r1=1624793&r2=1624794&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
 (original)
+++ 
maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
 Sun Sep 14 00:30:58 2014
@@ -33,6 +33,7 @@ import org.apache.maven.plugins.annotati
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.shared.utils.io.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
 
 import java.io.File;
 import java.io.FileOutputStream;
@@ -79,6 +80,18 @@ public abstract class AbstractMavenRepor
     protected MavenProject project;
 
     /**
+     * Specifies the input encoding.
+     */
+    @Parameter( property = "encoding", defaultValue = 
"${project.build.sourceEncoding}", readonly = true )
+    private String inputEncoding;
+
+    /**
+     * Specifies the output encoding.
+     */
+    @Parameter( property = "outputEncoding", defaultValue = 
"${project.reporting.outputEncoding}", readonly = true )
+    private String outputEncoding;
+
+    /**
      * Doxia Site Renderer component.
      */
     @Component
@@ -93,21 +106,6 @@ public abstract class AbstractMavenRepor
     /** The current report output directory to use */
     private File reportOutputDirectory;
 
-    protected String getOutputDirectory()
-    {
-        return outputDirectory.getAbsolutePath();
-    }
-
-    protected MavenProject getProject()
-    {
-        return project;
-    }
-
-    protected Renderer getSiteRenderer()
-    {
-        return siteRenderer;
-    }
-
     /**
      * This method is called when the report generation is invoked directly as 
a standalone Mojo.
      *
@@ -149,7 +147,8 @@ public abstract class AbstractMavenRepor
                 outputDirectory.mkdirs();
 
                 writer =
-                    new OutputStreamWriter( new FileOutputStream( new File( 
outputDirectory, filename ) ), "UTF-8" );
+                    new OutputStreamWriter( new FileOutputStream( new File( 
outputDirectory, filename ) ),
+                                            getOutputEncoding() );
 
                 getSiteRenderer().generateDocument( writer, sink, siteContext 
);
 
@@ -187,8 +186,8 @@ public abstract class AbstractMavenRepor
     {
         Map<String, Object> templateProperties = new HashMap<String, Object>();
         templateProperties.put( "project", getProject() );
-        templateProperties.put( "inputEncoding", "UTF-8" );
-        templateProperties.put( "outputEncoding", "UTF-8" );
+        templateProperties.put( "inputEncoding", getInputEncoding() );
+        templateProperties.put( "outputEncoding", getOutputEncoding() );
         // Put any of the properties in directly into the Velocity context
         for ( Map.Entry<Object, Object> entry : 
getProject().getProperties().entrySet() )
         {
@@ -285,6 +284,41 @@ public abstract class AbstractMavenRepor
         this.outputDirectory = reportOutputDirectory;
     }
 
+    protected String getOutputDirectory()
+    {
+        return outputDirectory.getAbsolutePath();
+    }
+
+    protected MavenProject getProject()
+    {
+        return project;
+    }
+
+    protected Renderer getSiteRenderer()
+    {
+        return siteRenderer;
+    }
+
+    /**
+     * Gets the input files encoding.
+     *
+     * @return The input files encoding, never <code>null</code>.
+     */
+    protected String getInputEncoding()
+    {
+        return ( inputEncoding == null ) ? ReaderFactory.ISO_8859_1 : 
inputEncoding;
+    }
+
+    /**
+     * Gets the effective reporting output files encoding.
+     *
+     * @return The effective reporting output file encoding, never 
<code>null</code>.
+     */
+    protected String getOutputEncoding()
+    {
+        return ( outputEncoding == null ) ? ReaderFactory.UTF_8 : 
outputEncoding;
+    }
+
     /**
      * Actions when closing the report.
      */


Reply via email to