Author: bentmann
Date: Sat May  3 06:38:49 2008
New Revision: 653078

URL: http://svn.apache.org/viewvc?rev=653078&view=rev
Log:
[MRESOURCES-57] use ${project.build.sourceEncoding} as default value for 
"encoding" parameter

o Reverted default encoding to platform encoding 
(http://www.nabble.com/-POLL--Default-Value-for-File-Encoding-td16958386.html)


Modified:
    
maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java

Modified: 
maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java?rev=653078&r1=653077&r2=653078&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java
 Sat May  3 06:38:49 2008
@@ -27,11 +27,13 @@
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.InterpolationFilterReader;
 import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
 import java.io.IOException;
 import java.io.Reader;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
@@ -52,7 +54,7 @@
 {
 
     /**
-     * The character encoding scheme to be applied.
+     * The character encoding scheme to be applied when filtering resources.
      *
      * @parameter expression="${encoding}" 
default-value="${project.build.sourceEncoding}"
      */
@@ -95,16 +97,6 @@
      */
     private List filters;
 
-    /**
-     * Gets the source file encoding.
-     *
-     * @return The source file encoding, never <code>null</code>.
-     */
-    protected String getEncoding()
-    {
-        return ( encoding == null ) ? ReaderFactory.ISO_8859_1 : encoding;
-    }
-
     public void execute()
         throws MojoExecutionException
     {
@@ -116,7 +108,12 @@
     {
         initializeFiltering();
 
-        getLog().info( "Using " + getEncoding() + " encoding to copy filtered 
resources." );
+        if ( StringUtils.isEmpty( encoding ) && isFilteringEnabled( resources 
) )
+        {
+            getLog().warn(
+                           "File encoding has not been set, using platform 
encoding " + ReaderFactory.FILE_ENCODING
+                               + ", i.e. build is platform dependent!" );
+        }
 
         for ( Iterator i = resources.iterator(); i.hasNext(); )
         {
@@ -168,8 +165,8 @@
 
             List includedFiles = Arrays.asList( scanner.getIncludedFiles() );
 
-            getLog().info( "Copying " + includedFiles.size() + " resource"
-                + ( includedFiles.size() > 1 ? "s" : "" )
+            getLog().info( "Copying " + ( resource.isFiltering() ? "and 
filtering " : "")
+                + includedFiles.size() + " resource" + ( includedFiles.size() 
!= 1 ? "s" : "" )
                 + ( targetPath == null ? "" : " to " + targetPath ) );
 
             for ( Iterator j = includedFiles.iterator(); j.hasNext(); )
@@ -204,6 +201,28 @@
         }
     }
 
+    /**
+     * Determines whether filtering has been enabled for any resource.
+     * 
+     * @param resources The set of resources to check for filtering, may be 
<code>null</code>.
+     * @return <code>true</code> if at least one resource uses filtering, 
<code>false</code> otherwise.
+     */
+    private boolean isFilteringEnabled( Collection resources )
+    {
+        if ( resources != null )
+        {
+            for ( Iterator i = resources.iterator(); i.hasNext(); )
+            {
+                Resource resource = (Resource) i.next();
+                if ( resource.isFiltering() )
+                {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
     private void initializeFiltering()
         throws MojoExecutionException
     {
@@ -269,6 +288,6 @@
                     }
             };
         }
-        FileUtils.copyFile(from, to, getEncoding(), wrappers);
+        FileUtils.copyFile(from, to, encoding, wrappers);
     }
 }


Reply via email to