Always filter the output file name always.
authorpetar.tahchiev <paranoiabla@gmail.com>
Tue, 28 Mar 2017 08:59:06 +0000 (11:59 +0300)
committerpetar.tahchiev <paranoiabla@gmail.com>
Tue, 28 Mar 2017 08:59:06 +0000 (11:59 +0300)
The filenames were only processed for filtering if resources in the folder
were filtered. However if a folder contains both filtered and not-filtered
resources then the folders are duplicated (see ARCHETYPE-524).

With this change we filter the filenames always - making the resulting files
reside in the same folder always.

archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java
archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorIT.java
archetype-testing/archetype-final/src/test/resources/projects/create-6/archetype.properties.sample [new file with mode: 0644]
archetype-testing/archetype-final/src/test/resources/projects/create-6/pom.xml.sample [new file with mode: 0644]
archetype-testing/archetype-final/src/test/resources/projects/create-6/src/main/webapp/resources/create-6/a.gif [new file with mode: 0644]
archetype-testing/archetype-final/src/test/resources/projects/create-6/src/main/webapp/resources/create-6/a.jsp [new file with mode: 0644]

index 85b1359..f884cb4 100644 (file)
@@ -786,7 +786,7 @@ public class FilesetArchetypeCreator
     }
 
     private void copyFiles( File basedir, File archetypeFilesDirectory, String directory, List<String> fileSetResources,
-                            boolean packaged, String packageName )
+                            boolean packaged, String packageName, Properties reverseProperties )
         throws IOException
     {
         String packageAsDirectory = StringUtils.replace( packageName, ".", File.separator );
@@ -801,7 +801,11 @@ public class FilesetArchetypeCreator
             getLogger().debug( "InputFileName:" + inputFileName );
             getLogger().debug( "OutputFileName:" + outputFileName );
 
-            File outputFile = new File( archetypeFilesDirectory, outputFileName );
+            reverseProperties.remove( "archetype.languages" );
+
+            String reversedOutputFilename = getReversedFilename( outputFileName, reverseProperties );
+
+            File outputFile = new File( archetypeFilesDirectory, reversedOutputFilename );
 
             File inputFile = new File( basedir, inputFileName );
 
@@ -842,7 +846,7 @@ public class FilesetArchetypeCreator
             else
             {
                 copyFiles( basedir, archetypeFilesDirectory, fileSet.getDirectory(), fileSetResources,
-                           fileSet.isPackaged(), packageName );
+                           fileSet.isPackaged(), packageName, reverseProperties );
                 getLogger().debug( "Copied " + fileSet.getDirectory() + " files" );
             }
         }
index 58f9b81..5009392 100644 (file)
@@ -431,6 +431,22 @@ public class DefaultArchetypeCreatorIT
         File template = getTemplateFile( project, "dummy.file" );
         assertExists( template );
     }
+
+    /**
+     * A test-case for ARCHETYPE-524
+     *
+     * @throws Exception
+     */
+    public void testCreateFilesetArchetype6()
+                    throws Exception
+    {
+        String project = "create-6";
+
+        createFilesetArchetype( project );
+
+        assertExists( getTemplateFile( project, "src/main/webapp/resources/__artifactId__/a.jsp" ) );
+        assertExists( getTemplateFile( project, "src/main/webapp/resources/__artifactId__/a.gif" ) );
+    }
     
     protected void tearDown()
         throws Exception
diff --git a/archetype-testing/archetype-final/src/test/resources/projects/create-6/archetype.properties.sample b/archetype-testing/archetype-final/src/test/resources/projects/create-6/archetype.properties.sample
new file mode 100644 (file)
index 0000000..3bce41a
--- /dev/null
@@ -0,0 +1,20 @@
+# 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.
+groupId=com.test
+artifactId=create-6
+archetype.groupId=archetypes
+archetype.version=1.0
diff --git a/archetype-testing/archetype-final/src/test/resources/projects/create-6/pom.xml.sample b/archetype-testing/archetype-final/src/test/resources/projects/create-6/pom.xml.sample
new file mode 100644 (file)
index 0000000..9a2165a
--- /dev/null
@@ -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>test-create-6</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <name>Maven archetype Test create-6</name>
+    <packaging>war</packaging>
+
+</project>
diff --git a/archetype-testing/archetype-final/src/test/resources/projects/create-6/src/main/webapp/resources/create-6/a.gif b/archetype-testing/archetype-final/src/test/resources/projects/create-6/src/main/webapp/resources/create-6/a.gif
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/archetype-testing/archetype-final/src/test/resources/projects/create-6/src/main/webapp/resources/create-6/a.jsp b/archetype-testing/archetype-final/src/test/resources/projects/create-6/src/main/webapp/resources/create-6/a.jsp
new file mode 100644 (file)
index 0000000..e5ba937
--- /dev/null
@@ -0,0 +1,23 @@
+<!--
+  ~ 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.
+  -->
+<html>
+<body>
+<h2>Hello World!</h2>
+</body>
+</html>