[MCHANGELOG-110] use ${project.reporting.outputEncoding} as default value for "outputEncoding" parameter and default to UTF-8

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1242166 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/it/minimal-pom-output-encoding/pom.xml b/src/it/minimal-pom-output-encoding/pom.xml
index 9a9ef32..2faecd9 100644
--- a/src/it/minimal-pom-output-encoding/pom.xml
+++ b/src/it/minimal-pom-output-encoding/pom.xml
@@ -58,7 +58,7 @@
         <artifactId>maven-changelog-plugin</artifactId>
         <version>@pom.version@</version>
         <configuration>
-          <outputEncoding>UTF-8</outputEncoding>
+          <outputEncoding>ISO-8859-1</outputEncoding>
         </configuration>
       </plugin>
     </plugins>
diff --git a/src/it/minimal-pom-output-encoding/verify.bsh b/src/it/minimal-pom-output-encoding/verify.bsh
index 8682526..68c00f6 100644
--- a/src/it/minimal-pom-output-encoding/verify.bsh
+++ b/src/it/minimal-pom-output-encoding/verify.bsh
@@ -7,8 +7,8 @@
 {
     File outputXML = new File( basedir, "target/changelog.xml" );
     System.out.println( "Checking for existence of xml file: " + outputXML );
-    String content = FileUtils.fileRead( outputXML, "UTF-8" );
-    if ( content.indexOf( "encoding=\"UTF-8\"" ) < 0 )
+    String content = FileUtils.fileRead( outputXML, "ISO-8859-1" );
+    if ( content.indexOf( "encoding=\"ISO-8859-1\"" ) < 0 )
     {
         throw new IOException( "Wrong encoding attribute in content." );
     }
diff --git a/src/it/minimal-pom/verify.bsh b/src/it/minimal-pom/verify.bsh
index 68c00f6..8682526 100644
--- a/src/it/minimal-pom/verify.bsh
+++ b/src/it/minimal-pom/verify.bsh
@@ -7,8 +7,8 @@
 {
     File outputXML = new File( basedir, "target/changelog.xml" );
     System.out.println( "Checking for existence of xml file: " + outputXML );
-    String content = FileUtils.fileRead( outputXML, "ISO-8859-1" );
-    if ( content.indexOf( "encoding=\"ISO-8859-1\"" ) < 0 )
+    String content = FileUtils.fileRead( outputXML, "UTF-8" );
+    if ( content.indexOf( "encoding=\"UTF-8\"" ) < 0 )
     {
         throw new IOException( "Wrong encoding attribute in content." );
     }
diff --git a/src/it/project-reporting-output-encoding/pom.xml b/src/it/project-reporting-output-encoding/pom.xml
new file mode 100644
index 0000000..c3bb94c
--- /dev/null
+++ b/src/it/project-reporting-output-encoding/pom.xml
@@ -0,0 +1,64 @@
+<?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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.changelog</groupId>
+  <artifactId>project-reporting-output-encoding</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <url>http://maven.apache.org/</url>
+
+  <scm>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-changelog-plugin/</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-changelog-plugin/</developerConnection>
+    <url>http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changelog-plugin/</url>
+  </scm>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <project.reporting.outputEncoding>ISO-8859-1</project.reporting.outputEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-site-plugin</artifactId>
+        <version>@sitePluginVersion@</version>
+      </plugin>
+    </plugins>
+  </build>
+
+  <reporting>
+    <excludeDefaults>true</excludeDefaults>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-changelog-plugin</artifactId>
+        <version>@pom.version@</version>
+      </plugin>
+    </plugins>
+  </reporting>
+</project>
diff --git a/src/it/project-reporting-output-encoding/verify.bsh b/src/it/project-reporting-output-encoding/verify.bsh
new file mode 100644
index 0000000..68c00f6
--- /dev/null
+++ b/src/it/project-reporting-output-encoding/verify.bsh
@@ -0,0 +1,42 @@
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+import org.codehaus.plexus.util.FileUtils;
+
+try
+{
+    File outputXML = new File( basedir, "target/changelog.xml" );
+    System.out.println( "Checking for existence of xml file: " + outputXML );
+    String content = FileUtils.fileRead( outputXML, "ISO-8859-1" );
+    if ( content.indexOf( "encoding=\"ISO-8859-1\"" ) < 0 )
+    {
+        throw new IOException( "Wrong encoding attribute in content." );
+    }
+
+    File siteDir = new File( basedir, "target/site" );
+    System.out.println( "Checking for existence of site directory: " + siteDir );
+    if ( !siteDir.isDirectory() )
+    {
+        System.out.println( "FAILED" );
+        return false;
+    }
+
+    String[] reports = { "changelog", "dev-activity", "file-activity" };
+    for ( String report : reports )
+    {
+        File reportFile = new File( siteDir, report + ".html" );
+        System.out.println( "Checking for existence of report: " + reportFile );
+        if ( !reportFile.isFile() )
+        {
+            System.out.println( "FAILED" );
+            return false;
+        }
+    }
+}
+catch( Throwable t )
+{
+    t.printStackTrace();
+    return false;
+}
+
+return true;
diff --git a/src/main/java/org/apache/maven/plugin/changelog/ChangeLogReport.java b/src/main/java/org/apache/maven/plugin/changelog/ChangeLogReport.java
index 0ad5baa..2660c24 100644
--- a/src/main/java/org/apache/maven/plugin/changelog/ChangeLogReport.java
+++ b/src/main/java/org/apache/maven/plugin/changelog/ChangeLogReport.java
@@ -188,10 +188,9 @@
     private String commentFormat;
 
     /**
-     * Output encoding for the xml document
+     * The file encoding when writing non-HTML reports.
      *
-     * @parameter expression="${changelog.outputEncoding}" default-value="ISO-8859-1"
-     * @required
+     * @parameter expression="${changelog.outputEncoding}" default-value="${project.reporting.outputEncoding}"
      */
     private String outputEncoding;
 
@@ -524,12 +523,12 @@
             {
                 try
                 {
-                    //ReaderFactory.newReader( outputXML, outputEncoding );
+                    //ReaderFactory.newReader( outputXML, getOutputEncoding() );
                     //FileInputStream fIn = new FileInputStream( outputXML );
 
                     getLog().info( "Using existing changelog.xml..." );
 
-                    changelogList = ChangeLog.loadChangedSets( ReaderFactory.newReader( outputXML, outputEncoding ) );
+                    changelogList = ChangeLog.loadChangedSets( ReaderFactory.newReader( outputXML, getOutputEncoding() ) );
                 }
                 catch ( FileNotFoundException e )
                 {
@@ -580,7 +579,7 @@
     {
         StringBuffer changelogXml = new StringBuffer();
 
-        changelogXml.append( "<?xml version=\"1.0\" encoding=\"" ).append( outputEncoding ).append( "\"?>\n" );
+        changelogXml.append( "<?xml version=\"1.0\" encoding=\"" ).append( getOutputEncoding() ).append( "\"?>\n" );
         changelogXml.append( "<changelog>" );
 
         for ( Iterator sets = changelogList.iterator(); sets.hasNext(); )
@@ -588,7 +587,7 @@
             changelogXml.append( "\n  " );
 
             ChangeLogSet changelogSet = (ChangeLogSet) sets.next();
-            String changeset = changelogSet.toXML( outputEncoding );
+            String changeset = changelogSet.toXML( getOutputEncoding() );
 
             //remove xml header
             if ( changeset.startsWith( "<?xml" ) )
@@ -609,7 +608,7 @@
         //pw.flush();
         //pw.close();
         // MCHANGELOG-86
-        Writer writer = WriterFactory.newWriter( new BufferedOutputStream( new FileOutputStream( outputXML ) ), outputEncoding );
+        Writer writer = WriterFactory.newWriter( new BufferedOutputStream( new FileOutputStream( outputXML ) ), getOutputEncoding() );
         writer.write( changelogXml.toString() );
         writer.flush();
         writer.close();
@@ -1696,6 +1695,16 @@
         return outputDirectory.getAbsolutePath();
     }
 
+    /**
+     * Gets the effective reporting output files encoding.
+     *
+     * @return The effective reporting output file encoding, never <code>null</code>.
+     */
+    protected String getOutputEncoding()
+    {
+        return ( outputEncoding != null ) ? outputEncoding : ReaderFactory.UTF_8;
+    }
+
     /** {@inheritDoc} */
     protected Renderer getSiteRenderer()
     {