This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-archetype.git


The following commit(s) were added to refs/heads/master by this push:
     new 68b07413 Accept archetype.filteredExtensions in create-from-project
68b07413 is described below

commit 68b074136f52be22de30b8bd5e275e5527d33621
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sat Oct 31 17:45:49 2026 +0000

    Accept archetype.filteredExtensions in create-from-project
    
    The parameter was bound to the misspelled archetype.filteredExtentions, so 
the documented property had no effect. The old spelling stays as a deprecated 
parameter and is not to be removed: existing command lines and POM 
configurations use it.
---
 .../mojos/CreateArchetypeFromProjectMojo.java      | 24 ++++--
 .../mojos/CreateArchetypeFromProjectMojoTest.java  | 98 ++++++++++++++++++++++
 2 files changed, 117 insertions(+), 5 deletions(-)

diff --git 
a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojo.java
 
b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojo.java
index 8cd25922..f4f9d4a6 100644
--- 
a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojo.java
+++ 
b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojo.java
@@ -109,6 +109,16 @@ public class CreateArchetypeFromProjectMojo extends 
AbstractMojo {
     /**
      * File extensions which are checked for project's text files (vs binary 
files).
      */
+    @Parameter(property = "archetype.filteredExtensions")
+    private String archetypeFilteredExtensions;
+
+    /**
+     * Misspelled alias of <code>archetypeFilteredExtensions</code>, kept so 
that existing command lines
+     * and POM configurations keep working. 
<code>archetypeFilteredExtensions</code> wins when both are set.
+     *
+     * @deprecated use <code>archetypeFilteredExtensions</code> 
(<code>-Darchetype.filteredExtensions</code>)
+     */
+    @Deprecated
     @Parameter(property = "archetype.filteredExtentions")
     private String archetypeFilteredExtentions;
 
@@ -164,7 +174,7 @@ public class CreateArchetypeFromProjectMojo extends 
AbstractMojo {
      * <dt>version</dt><dd>The default version of the generated project.</dd>
      * <dt>excludePatterns</dt><dd>A comma-separated list of paths that will 
not be included in the resulting
      * archetype.</dd>
-     * <dt>archetype.filteredExtensions</dt><dd>See the filteredExensions 
parameter.</dd>
+     * <dt>archetype.filteredExtensions</dt><dd>See the 
archetypeFilteredExtensions parameter.</dd>
      * </dl>
      * <strong>Custom Properties</strong>
      * <p>
@@ -239,7 +249,8 @@ public class CreateArchetypeFromProjectMojo extends 
AbstractMojo {
             Properties properties = configurator.configureArchetypeCreation(
                     project, interactive, executionProperties, propertyFile, 
languages);
 
-            List<String> filtereds = 
getFilteredExtensions(archetypeFilteredExtentions, propertyFile);
+            List<String> filtereds =
+                    getFilteredExtensions(archetypeFilteredExtensions, 
archetypeFilteredExtentions, propertyFile);
 
             ArchetypeCreationRequest request = new ArchetypeCreationRequest()
                     .setDefaultEncoding(defaultEncoding)
@@ -282,12 +293,15 @@ public class CreateArchetypeFromProjectMojo extends 
AbstractMojo {
         }
     }
 
-    private List<String> getFilteredExtensions(String 
archetypeFilteredExtentions, File propertyFile)
+    List<String> getFilteredExtensions(String commandLineExtensions, String 
misspelledExtensions, File propertyFile)
             throws IOException {
         List<String> filteredExtensions = new ArrayList<>();
 
-        if (archetypeFilteredExtentions != null && 
!archetypeFilteredExtentions.isEmpty()) {
-            
filteredExtensions.addAll(Arrays.asList(StringUtils.split(archetypeFilteredExtentions,
 ",")));
+        String fromCommandLine = commandLineExtensions != null && 
!commandLineExtensions.isEmpty()
+                ? commandLineExtensions
+                : misspelledExtensions;
+        if (fromCommandLine != null && !fromCommandLine.isEmpty()) {
+            
filteredExtensions.addAll(Arrays.asList(StringUtils.split(fromCommandLine, 
",")));
 
             getLog().debug("Found in command line extensions = " + 
filteredExtensions);
         }
diff --git 
a/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojoTest.java
 
b/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojoTest.java
new file mode 100644
index 00000000..41e0541c
--- /dev/null
+++ 
b/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojoTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+package org.apache.maven.archetype.mojos;
+
+import java.io.File;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.maven.archetype.common.Constants;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class CreateArchetypeFromProjectMojoTest {
+
+    @TempDir
+    File dir;
+
+    private final CreateArchetypeFromProjectMojo mojo = new 
CreateArchetypeFromProjectMojo(null, null);
+
+    @Test
+    void documentedPropertyIsBoundToAParameter() throws Exception {
+        assertEquals("${archetype.filteredExtensions}", 
defaultExpression("archetypeFilteredExtensions"));
+    }
+
+    @Test
+    void misspelledPropertyIsStillBoundToAParameter() throws Exception {
+        assertEquals("${archetype.filteredExtentions}", 
defaultExpression("archetypeFilteredExtentions"));
+    }
+
+    @Test
+    void correctSpellingIsUsed() throws Exception {
+        assertEquals(Arrays.asList("java", "xml"), 
mojo.getFilteredExtensions("java,xml", null, null));
+    }
+
+    @Test
+    void misspelledSpellingIsUsed() throws Exception {
+        assertEquals(Arrays.asList("java", "xml"), 
mojo.getFilteredExtensions(null, "java,xml", null));
+    }
+
+    @Test
+    void correctSpellingWinsWhenBothAreSet() throws Exception {
+        assertEquals(Arrays.asList("java"), mojo.getFilteredExtensions("java", 
"xml", null));
+    }
+
+    @Test
+    void propertyFileIsUsedWhenNeitherIsSet() throws Exception {
+        File propertyFile = new File(dir, "archetype.properties");
+        Files.write(
+                propertyFile.toPath(),
+                (Constants.ARCHETYPE_FILTERED_EXTENSIONS + 
"=groovy").getBytes(StandardCharsets.UTF_8));
+
+        assertEquals(Arrays.asList("groovy"), mojo.getFilteredExtensions(null, 
null, propertyFile));
+    }
+
+    @Test
+    void defaultsAreUsedWhenNothingIsSet() throws Exception {
+        List<String> extensions = mojo.getFilteredExtensions(null, "", new 
File(dir, "missing.properties"));
+
+        assertEquals(Constants.DEFAULT_FILTERED_EXTENSIONS, extensions);
+    }
+
+    /** Reads the parameter's expression from the generated plugin descriptor, 
as Maven does at run time. */
+    private static String defaultExpression(String parameter) throws Exception 
{
+        try (InputStream in =
+                
CreateArchetypeFromProjectMojoTest.class.getResourceAsStream("/META-INF/maven/plugin.xml"))
 {
+            Xpp3Dom plugin = Xpp3DomBuilder.build(in, "UTF-8");
+            for (Xpp3Dom mojo : plugin.getChild("mojos").getChildren("mojo")) {
+                if 
("create-from-project".equals(mojo.getChild("goal").getValue())) {
+                    return 
mojo.getChild("configuration").getChild(parameter).getValue();
+                }
+            }
+        }
+        throw new AssertionError("create-from-project not found in 
plugin.xml");
+    }
+}

Reply via email to