You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gb...@apache.org on 2016/11/17 12:28:06 UTC

maven-archetype git commit: [ARCHETYPE-513] Files in excludePatterns having a default filtered extension are still included

Repository: maven-archetype
Updated Branches:
  refs/heads/master 4a59126c6 -> 44e7ed632


[ARCHETYPE-513] Files in excludePatterns having a default filtered
extension are still included

If a file having a default filtered extensions was present in a manually
excluded pattern, it still ended up in the generated archetype. The fix
is to propagate the excludePattern to the creation of the archetype
files in (FilesetArchetypeCreator#createArchetypeFiles).

Project: http://git-wip-us.apache.org/repos/asf/maven-archetype/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-archetype/commit/44e7ed63
Tree: http://git-wip-us.apache.org/repos/asf/maven-archetype/tree/44e7ed63
Diff: http://git-wip-us.apache.org/repos/asf/maven-archetype/diff/44e7ed63

Branch: refs/heads/master
Commit: 44e7ed6329320ae6b009bf3415b0e615770a110e
Parents: 4a59126
Author: Guillaume Bou� <gb...@apache.org>
Authored: Thu Nov 17 13:27:58 2016 +0100
Committer: Guillaume Bou� <gb...@apache.org>
Committed: Thu Nov 17 13:27:58 2016 +0100

----------------------------------------------------------------------
 .../creator/FilesetArchetypeCreator.java        | 18 ++++++--
 .../archetype.properties                        |  1 +
 .../invoker.properties                          |  1 +
 .../pom.xml                                     | 30 +++++++++++++
 .../src/main/resources/file.txt                 |  0
 .../src/main/resources/file.xml                 |  0
 .../src/main/resources/toexclude/file.txt       |  0
 .../src/main/resources/toexclude/file.xml       |  0
 .../src/main/toexclude/file.txt                 |  0
 .../src/main/toexclude/file.xml                 |  0
 .../src/toexclude/file.txt                      |  0
 .../src/toexclude/file.xml                      |  0
 .../toexclude/file.txt                          |  0
 .../toexclude/file.xml                          |  0
 .../verify.bsh                                  | 46 ++++++++++++++++++++
 .../creator/DefaultArchetypeCreatorTest.java    | 12 +++++
 .../projects/exclude-patterns-2/.sonar/file.txt |  0
 .../archetype.properties.sample                 |  9 ++++
 .../exclude-patterns-2/folder/.sonar/file.txt   |  0
 .../projects/exclude-patterns-2/folder/file.txt |  0
 .../projects/exclude-patterns-2/pom.xml.sample  | 34 +++++++++++++++
 21 files changed, 147 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java
----------------------------------------------------------------------
diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java b/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java
index 6af535f..22465fd 100644
--- a/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java
+++ b/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java
@@ -211,7 +211,7 @@ public class FilesetArchetypeCreator
             archetypeDescriptor.setFileSets( filesets );
 
             createArchetypeFiles( reverseProperties, filesets, packageName, basedir, archetypeFilesDirectory,
-                                  defaultEncoding );
+                                  defaultEncoding, excludePatterns );
             getLogger().debug( "Created files for " + archetypeDescriptor.getName() );
 
             setParentArtifactId( reverseProperties, configurationProperties.getProperty( Constants.ARTIFACT_ID ) );
@@ -805,6 +805,14 @@ public class FilesetArchetypeCreator
         return result;
     }
 
+    private List<String> addLists( List<String> list, List<String> other )
+    {
+        List<String> result = new ArrayList<String>( list.size() + other.size() );
+        result.addAll( list );
+        result.addAll( other );
+        return result;
+    }
+
     private void copyFiles( File basedir, File archetypeFilesDirectory, String directory, List<String> fileSetResources,
                             boolean packaged, String packageName )
         throws IOException
@@ -832,7 +840,8 @@ public class FilesetArchetypeCreator
     }
 
     private void createArchetypeFiles( Properties reverseProperties, List<FileSet> fileSets, String packageName,
-                                       File basedir, File archetypeFilesDirectory, String defaultEncoding )
+                                       File basedir, File archetypeFilesDirectory, String defaultEncoding,
+                                       List<String> excludePatterns )
         throws IOException
     {
         getLogger().debug( "Creating Archetype/Module files from " + basedir + " to " + archetypeFilesDirectory );
@@ -843,7 +852,8 @@ public class FilesetArchetypeCreator
             scanner.setBasedir( basedir );
             scanner.setIncludes( (String[]) concatenateToList( fileSet.getIncludes(), fileSet.getDirectory() ).toArray(
                 new String[fileSet.getIncludes().size()] ) );
-            scanner.setExcludes( (String[]) fileSet.getExcludes().toArray( new String[fileSet.getExcludes().size()] ) );
+            scanner.setExcludes( (String[]) addLists( fileSet.getExcludes(), excludePatterns ).toArray(
+                new String[fileSet.getExcludes().size()] ) );
             scanner.addDefaultExcludes();
             getLogger().debug( "Using fileset " + fileSet );
             scanner.scan();
@@ -1059,7 +1069,7 @@ public class FilesetArchetypeCreator
         archetypeDescriptor.setFileSets( filesets );
 
         createArchetypeFiles( reverseProperties, filesets, packageName, basedir, archetypeFilesDirectory,
-                              defaultEncoding );
+                              defaultEncoding, excludePatterns );
         getLogger().debug( "Created files for module " + archetypeDescriptor.getName() );
 
         String parentArtifactId = reverseProperties.getProperty( Constants.PARENT_ARTIFACT_ID );

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/archetype.properties
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/archetype.properties b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/archetype.properties
new file mode 100644
index 0000000..19f85bb
--- /dev/null
+++ b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/archetype.properties
@@ -0,0 +1 @@
+excludePatterns=**/toexclude/**
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/invoker.properties
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/invoker.properties b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/invoker.properties
new file mode 100644
index 0000000..dac2cd9
--- /dev/null
+++ b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/invoker.properties
@@ -0,0 +1 @@
+invoker.goals = clean org.apache.maven.plugins:maven-archetype-plugin:${project.version}:create-from-project -Darchetype.properties=archetype.properties

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/pom.xml
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/pom.xml b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/pom.xml
new file mode 100644
index 0000000..7a173a0
--- /dev/null
+++ b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/pom.xml
@@ -0,0 +1,30 @@
+<!--
+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.plugins.archetype.its</groupId>
+  <artifactId>create-from-project</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <name>archetype:create-from-project It</name>
+</project>

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/file.txt
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/file.txt b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/file.txt
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/file.xml
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/file.xml b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/file.xml
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/toexclude/file.txt
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/toexclude/file.txt b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/toexclude/file.txt
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/toexclude/file.xml
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/toexclude/file.xml b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/toexclude/file.xml
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/toexclude/file.txt
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/toexclude/file.txt b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/toexclude/file.txt
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/toexclude/file.xml
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/toexclude/file.xml b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/toexclude/file.xml
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/toexclude/file.txt
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/toexclude/file.txt b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/toexclude/file.txt
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/toexclude/file.xml
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/toexclude/file.xml b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/toexclude/file.xml
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/toexclude/file.txt
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/toexclude/file.txt b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/toexclude/file.txt
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/toexclude/file.xml
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/toexclude/file.xml b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/toexclude/file.xml
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/verify.bsh
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/verify.bsh b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/verify.bsh
new file mode 100644
index 0000000..1021842
--- /dev/null
+++ b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/verify.bsh
@@ -0,0 +1,46 @@
+
+/*
+ * 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 java.io.*;
+
+File archetype = new File( basedir, "target/generated-sources/archetype/src/main/resources/archetype-resources/" );
+
+// ARCHETYPE-513
+String[] excluded = new String[] { "/", "src/", "src/main/", "src/main/resources/" };
+for ( String exclude : excluded )
+{
+    File app = new File( archetype, exclude + "toexclude" );
+    if ( app.exists() )
+    {
+        throw new Exception( app + " folder exists when it should have been excluded." );
+    }
+}
+
+String[] included = new String[] { "file.txt", "file.xml" };
+for ( String include : included )
+{
+    File app = new File( archetype, "src/main/resources/" + include );
+    if ( !app.isFile() )
+    {
+        throw new Exception( app + " file does not exist when it should have been included." );
+    }
+}
+
+return true;

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorTest.java
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorTest.java b/archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorTest.java
index 8e18b68..c011498 100644
--- a/archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorTest.java
+++ b/archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorTest.java
@@ -168,6 +168,18 @@ public class DefaultArchetypeCreatorTest
         assertExists(template1);
     }
 
+    public void testExcludePatternsContainingFilesSameExtension()
+        throws Exception
+    {
+        String project = "exclude-patterns-2";
+
+        createFilesetArchetype( project );
+
+        assertNotExists( getTemplateFile( project, ".sonar/file.txt" ) );
+        assertNotExists( getTemplateFile( project, "folder/.sonar/file.txt" ) );
+        assertExists( getTemplateFile( project, "folder/file.txt" ) );
+    }
+
     public void testIncludeFileWithNoExtension()
                     throws Exception
     {

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/.sonar/file.txt
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/.sonar/file.txt b/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/.sonar/file.txt
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/archetype.properties.sample
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/archetype.properties.sample b/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/archetype.properties.sample
new file mode 100644
index 0000000..562743a
--- /dev/null
+++ b/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/archetype.properties.sample
@@ -0,0 +1,9 @@
+archetype.groupId=org.codehaus.mojo.archetypes
+archetype.artifactId=maven-archetype-test
+archetype.version=1.0
+groupId=org.apache.maven.archetype.test
+artifactId=change-file-with-property
+version=1.0-SNAPSHOT
+package=archetype
+someProperty=App
+excludePatterns=**/.sonar/**

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/folder/.sonar/file.txt
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/folder/.sonar/file.txt b/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/folder/.sonar/file.txt
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/folder/file.txt
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/folder/file.txt b/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/folder/file.txt
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/44e7ed63/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/pom.xml.sample
----------------------------------------------------------------------
diff --git a/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/pom.xml.sample b/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/pom.xml.sample
new file mode 100644
index 0000000..4c59ea2
--- /dev/null
+++ b/archetype-testing/archetype-final/src/test/resources/projects/exclude-patterns-2/pom.xml.sample
@@ -0,0 +1,34 @@
+<?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.archetype.test</groupId>
+    <artifactId>exclude-patterns</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <name>Maven archetype Test ExcludePatterns Property</name>
+    <packaging>pom</packaging>
+
+</project>