[MSHARED-497] Allow copying of defaultExcludes like .gitignore etc.
 o The setupScanner method excluded by default all extensions which
   is not allways a good idea. There are edge cases where it would
   be helpful to change this behaviour. This now possible by introducing
   addDefaultExcludes which can be turned off.


git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1733872 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
index 90ce4c9..5199e64 100644
--- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
@@ -167,7 +167,7 @@
                                 : resource.getIncludes().toString() );
 
                 // @formatter:on
-                getLogger().debug( debugMessage.toString() );
+                getLogger().info( debugMessage.toString() );
             }
 
             String targetPath = resource.getTargetPath();
@@ -197,10 +197,10 @@
 
             boolean ignoreDelta = !outputExists || buildContext.hasDelta( mavenResourcesExecution.getFileFilters() )
                 || buildContext.hasDelta( getRelativeOutputDirectory( mavenResourcesExecution ) );
-            getLogger().debug( "ignoreDelta " + ignoreDelta );
+            getLogger().info( "ignoreDelta " + ignoreDelta );
             Scanner scanner = buildContext.newScanner( resourceDirectory, ignoreDelta );
 
-            setupScanner( resource, scanner );
+            setupScanner( resource, scanner, mavenResourcesExecution.isAddDefaultExcludes() );
 
             scanner.scan();
 
@@ -227,6 +227,7 @@
             for ( String name : includedFiles )
             {
 
+                getLogger().info( "Copying file " + name );
                 File source = new File( resourceDirectory, name );
 
                 File destinationFile = getDestinationFile( outputDirectory, targetPath, name, mavenResourcesExecution );
@@ -244,7 +245,7 @@
 
             scanner = buildContext.newDeleteScanner( resourceDirectory );
 
-            setupScanner( resource, scanner );
+            setupScanner( resource, scanner, mavenResourcesExecution.isAddDefaultExcludes() );
 
             scanner.scan();
 
@@ -292,7 +293,7 @@
         return destinationFile;
     }
 
-    private String[] setupScanner( Resource resource, Scanner scanner )
+    private String[] setupScanner( Resource resource, Scanner scanner, boolean addDefaultExcludes )
     {
         String[] includes = null;
         if ( resource.getIncludes() != null && !resource.getIncludes().isEmpty() )
@@ -312,7 +313,10 @@
             scanner.setExcludes( excludes );
         }
 
-        scanner.addDefaultExcludes();
+        if ( addDefaultExcludes )
+        {
+            scanner.addDefaultExcludes();
+        }
         return includes;
     }
 
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesExecution.java b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesExecution.java
index a43425b..ed22cf7 100644
--- a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesExecution.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesExecution.java
@@ -58,6 +58,35 @@
     private String encoding;
 
     /**
+     * By default files like {@code .gitignore}, {@code .cvsignore} etc. are
+     * excluded which means they will not being copied.
+     * If you need them for a particular reason you can do that by  
+     * settings this to {@code false}. This means
+     * all files like the following will be copied.
+     * <ul>
+     * <li>Misc: &#42;&#42;/&#42;~, &#42;&#42;/#&#42;#, &#42;&#42;/.#&#42;, &#42;&#42;/%&#42;%, &#42;&#42;/._&#42; </li>
+     * <li>CVS: &#42;&#42;/CVS, &#42;&#42;/CVS/&#42;&#42;, &#42;&#42;/.cvsignore</li>
+     * <li>RCS: &#42;&#42;/RCS, &#42;&#42;/RCS/&#42;&#42;</li>
+     * <li>SCCS: &#42;&#42;/SCCS, &#42;&#42;/SCCS/&#42;&#42;</li>
+     * <li>VSSercer: &#42;&#42;/vssver.scc</li>
+     * <li>MKS: &#42;&#42;/project.pj</li>
+     * <li>SVN: &#42;&#42;/.svn, &#42;&#42;/.svn/&#42;&#42;</li>
+     * <li>GNU: &#42;&#42;/.arch-ids, &#42;&#42;/.arch-ids/&#42;&#42;</li>
+     * <li>Bazaar: &#42;&#42;/.bzr, &#42;&#42;/.bzr/&#42;&#42;</li>
+     * <li>SurroundSCM: &#42;&#42;/.MySCMServerInfo</li>
+     * <li>Mac: &#42;&#42;/.DS_Store</li>
+     * <li>Serena Dimension: &#42;&#42;/.metadata, &#42;&#42;/.metadata/&#42;&#42;</li>
+     * <li>Mercurial: &#42;&#42;/.hg, &#42;&#42;/.hg/&#42;&#42;</li>
+     * <li>GIT: &#42;&#42;/.git, &#42;&#42;/.gitignore, &#42;&#42;/.gitattributes, &#42;&#42;/.git/&#42;&#42;</li>
+     * <li>Bitkeeper: &#42;&#42;/BitKeeper, &#42;&#42;/BitKeeper/&#42;&#42;, &#42;&#42;/ChangeSet, &#42;&#42;/ChangeSet/&#42;&#42;</li>
+     * <li>Darcs: &#42;&#42;/_darcs, &#42;&#42;/_darcs/&#42;&#42;, &#42;&#42;/.darcsrepo, &#42;&#42;/.darcsrepo/&#42;&#42;&#42;&#42;/-darcs-backup&#42;, &#42;&#42;/.darcs-temp-mail
+     * </ul>
+     * 
+     * @since 3.1.0
+     */
+    private boolean addDefaultExcludes = true;
+
+    /**
      * Overwrite existing files even if the destination files are newer. <code>false</code> by default.
      *
      * @since 1.0-beta-2
@@ -87,7 +116,8 @@
     }
 
     /**
-     * As we use a Maven project <code>useDefaultFilterWrappers</code> will be set to <code>true</code>.
+     * As we use a Maven project <code>useDefaultFilterWrappers</code> will be set to <code>true</code>. The
+     * {@code useDefaultExcludes} is set to {@code true}.
      *
      * @param resources The list of resources.
      * @param outputDirectory The output directory.
@@ -107,6 +137,7 @@
         this.outputDirectory = outputDirectory;
         this.nonFilteredFileExtensions = nonFilteredFileExtensions;
         this.useDefaultFilterWrappers = true;
+        this.addDefaultExcludes = true;
         this.resourcesBaseDirectory = mavenProject.getBasedir();
     }
 
@@ -288,6 +319,22 @@
     }
 
     /**
+     * @return add the default excludes.
+     */
+    public boolean isAddDefaultExcludes()
+    {
+        return addDefaultExcludes;
+    }
+
+    /**
+     * @param addDefaultExcludes {@link #addDefaultExcludes}
+     */
+    public void setAddDefaultExcludes( boolean addDefaultExcludes )
+    {
+        this.addDefaultExcludes = addDefaultExcludes;
+    }
+
+    /**
      * Overwrite existing files even if the destination files are newer.
      *
      * @return {@link #overwrite}
@@ -372,6 +419,7 @@
         mre.setResources( copyList( mre.getResources() ) );
         mre.setResourcesBaseDirectory( mre.getResourcesBaseDirectory() );
         mre.setUseDefaultFilterWrappers( mre.isUseDefaultFilterWrappers() );
+        mre.setAddDefaultExcludes( mre.isAddDefaultExcludes() );
         mre.setSupportMultiLineFiltering( mre.isSupportMultiLineFiltering() );
         return mre;
     }
diff --git a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
index 51e40b4..31662e7 100644
--- a/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
+++ b/src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
@@ -694,6 +694,70 @@
         }
     }
 
+    public void testShouldReturnGitIgnoreFiles()
+        throws Exception
+    {
+        File outputDirectory = new File( getBasedir(), "target/testGitIgnoreFile" );
+        File baseDir = new File( "c:\\foo\\bar" );
+        StubMavenProject mavenProject = new StubMavenProject( baseDir );
+        mavenProject.setVersion( "1.0" );
+        mavenProject.setGroupId( "org.apache" );
+        mavenProject.setName( "test project" );
+
+        MavenResourcesFiltering mavenResourcesFiltering = lookup( MavenResourcesFiltering.class );
+
+        List<Resource> resources = new ArrayList<Resource>();
+        resources.add( new Resource()
+        {
+            {
+                setDirectory( getBasedir() + "/src/test/units-files/include-git-files" );
+                setIncludes( Arrays.asList( "**/*" ) );
+            }
+        } );
+        MavenResourcesExecution mavenResourcesExecution =
+            new MavenResourcesExecution( resources, outputDirectory, mavenProject, "UTF-8",
+                                         Collections.<String>emptyList(), Collections.<String>emptyList(),
+                                         new StubMavenSession() );
+        mavenResourcesExecution.setIncludeEmptyDirs( true );
+        mavenResourcesExecution.setAddDefaultExcludes( false );
+        mavenResourcesFiltering.filterResources( mavenResourcesExecution );
+
+        File[] childs = outputDirectory.listFiles();
+        assertNotNull( childs );
+        assertEquals( 3, childs.length );
+
+        for ( File file : childs )
+        {
+            if ( file.getName().endsWith( "dir1" ) || file.getName().endsWith( "empty-directory" )
+                || file.getName().endsWith( "empty-directory-child" ) )
+            {
+                if ( file.getName().endsWith( "dir1" ) )
+                {
+                    assertEquals( 1, file.list().length );
+                    assertTrue( file.listFiles()[0].getName().endsWith( "foo.txt" ) );
+                }
+                if ( file.getName().endsWith( "empty-directory" ) )
+                {
+
+                    assertEquals( 1, file.list().length );
+                    assertTrue ( file.listFiles()[0].getName().endsWith( ".gitignore" ) );
+                }
+                if ( file.getName().endsWith( "empty-directory-child" ) )
+                {
+                    assertEquals( 1, file.list().length );
+                    assertTrue( file.listFiles()[0].isDirectory() );
+                    assertEquals( 1, file.listFiles()[0].listFiles().length );
+                  
+                    assertTrue( file.listFiles()[0].listFiles()[0].getName().endsWith( ".gitignore" ) );
+                }
+            }
+            else
+            {
+                fail( "unknow child file found " + file.getName() );
+            }
+        }
+    }
+
     /**
      * unit test for MSHARED-81 : https://issues.apache.org/jira/browse/MSHARED-81
      */
diff --git a/src/test/units-files/include-git-files/dir1/foo.txt b/src/test/units-files/include-git-files/dir1/foo.txt
new file mode 100644
index 0000000..4ae1a11
--- /dev/null
+++ b/src/test/units-files/include-git-files/dir1/foo.txt
@@ -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.
+
+foo.
\ No newline at end of file
diff --git a/src/test/units-files/include-git-files/empty-directory-child/empty-child/.gitignore b/src/test/units-files/include-git-files/empty-directory-child/empty-child/.gitignore
new file mode 100644
index 0000000..695fc81
--- /dev/null
+++ b/src/test/units-files/include-git-files/empty-directory-child/empty-child/.gitignore
@@ -0,0 +1 @@
+# just here to make the directory non-empty
diff --git a/src/test/units-files/include-git-files/empty-directory/.gitignore b/src/test/units-files/include-git-files/empty-directory/.gitignore
new file mode 100644
index 0000000..695fc81
--- /dev/null
+++ b/src/test/units-files/include-git-files/empty-directory/.gitignore
@@ -0,0 +1 @@
+# just here to make the directory non-empty