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

slachiewicz pushed a commit to branch maven-plugin-testing-3.x
in repository https://gitbox.apache.org/repos/asf/maven-plugin-testing.git


The following commit(s) were added to refs/heads/maven-plugin-testing-3.x by 
this push:
     new 2dc3ebf  Configure a parameter set by its alias under the parameter 
name
2dc3ebf is described below

commit 2dc3ebfc76f4358017bd84b24bca39ace160bce3
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sun Nov 8 02:30:54 2026 +0100

    Configure a parameter set by its alias under the parameter name
    
    finalizeConfig found the aliased element but kept its name, so the
    configurator looked for a field called like the alias and failed, while
    Maven renames it.
    
    Fixes #300
---
 .../maven/api/plugin/testing/MojoExtension.java    |  8 +++-
 .../maven/plugin/testing/ParametersMojo.java       | 10 +++++
 .../maven/plugin/testing/ParametersMojoTest.java   |  8 ++++
 .../src/test/projects/alias/pom.xml                | 51 ++++++++++++++++++++++
 .../src/test/resources/META-INF/maven/plugin.xml   |  8 ++++
 5 files changed, 83 insertions(+), 2 deletions(-)

diff --git 
a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java
 
b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java
index 434bcd2..010caef 100644
--- 
a/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java
+++ 
b/maven-plugin-testing-harness/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java
@@ -632,8 +632,12 @@ public class MojoExtension extends PlexusExtension 
implements ParameterResolver
             Xpp3Dom defaultConfiguration = 
MojoDescriptorCreator.convert(mojoDescriptor);
             for (Parameter parameter : mojoDescriptor.getParameters()) {
                 Xpp3Dom parameterConfiguration = 
config.getChild(parameter.getName());
-                if (parameterConfiguration == null) {
-                    parameterConfiguration = 
config.getChild(parameter.getAlias());
+                if (parameterConfiguration == null && parameter.getAlias() != 
null) {
+                    Xpp3Dom aliased = config.getChild(parameter.getAlias());
+                    if (aliased != null) {
+                        // configure the field under its name, as Maven does
+                        parameterConfiguration = new Xpp3Dom(aliased, 
parameter.getName());
+                    }
                 }
                 Xpp3Dom parameterDefaults = 
defaultConfiguration.getChild(parameter.getName());
                 parameterConfiguration = 
Xpp3Dom.mergeXpp3Dom(parameterConfiguration, parameterDefaults, Boolean.TRUE);
diff --git 
a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojo.java
 
b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojo.java
index 438b46f..ae1cd06 100644
--- 
a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojo.java
+++ 
b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojo.java
@@ -30,6 +30,8 @@ public class ParametersMojo extends AbstractMojo {
 
     private String withPropertyAndDefault;
 
+    private String withAlias;
+
     @Override
     public void execute() {
         getLog().info("Plain value = " + plain);
@@ -66,4 +68,12 @@ public class ParametersMojo extends AbstractMojo {
     public void setWithPropertyAndDefault(String withPropertyAndDefault) {
         this.withPropertyAndDefault = withPropertyAndDefault;
     }
+
+    public String getWithAlias() {
+        return withAlias;
+    }
+
+    public void setWithAlias(String withAlias) {
+        this.withAlias = withAlias;
+    }
 }
diff --git 
a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java
 
b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java
index a0bd5d4..451ce42 100644
--- 
a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java
+++ 
b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java
@@ -52,6 +52,8 @@ public class ParametersMojoTest {
 
     private static final String PROPERTY_POM_DIR = 
"src/test/projects/property/";
 
+    private static final String ALIAS_POM_DIR = "src/test/projects/alias/";
+
     @Inject
     private Log log;
 
@@ -75,6 +77,12 @@ public class ParametersMojoTest {
         assertDoesNotThrow(mojo::execute);
     }
 
+    @Test
+    @InjectMojo(goal = "test:test-plugin:0.0.1-SNAPSHOT:parameters", pom = 
ALIAS_POM_DIR + POM_DOT_XML_FILE)
+    void testAliasPom(ParametersMojo mojo) {
+        assertEquals("aliasValue", mojo.getWithAlias());
+    }
+
     @Test
     @InjectMojo(goal = "test:test-plugin:0.0.1-SNAPSHOT:parameters", pom = 
PROPERTY_POM_DIR + POM_DOT_XML_FILE)
     void testPropertyPom(ParametersMojo mojo) {
diff --git a/maven-plugin-testing-harness/src/test/projects/alias/pom.xml 
b/maven-plugin-testing-harness/src/test/projects/alias/pom.xml
new file mode 100644
index 0000000..6df8d21
--- /dev/null
+++ b/maven-plugin-testing-harness/src/test/projects/alias/pom.xml
@@ -0,0 +1,51 @@
+<?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>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>test</groupId>
+  <artifactId>test-test</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>test</groupId>
+        <artifactId>test-plugin</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+        <executions>
+          <execution>
+            <id>test</id>
+            <goals>
+              <goal>test</goal>
+            </goals>
+            <phase>compile</phase>
+          </execution>
+        </executions>
+        <configuration>
+          <aliased>aliasValue</aliased>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git 
a/maven-plugin-testing-harness/src/test/resources/META-INF/maven/plugin.xml 
b/maven-plugin-testing-harness/src/test/resources/META-INF/maven/plugin.xml
index c8d4ca8..a4c9d18 100644
--- a/maven-plugin-testing-harness/src/test/resources/META-INF/maven/plugin.xml
+++ b/maven-plugin-testing-harness/src/test/resources/META-INF/maven/plugin.xml
@@ -72,6 +72,14 @@ under the License.
           <editable>true</editable>
           <description></description>
         </parameter>
+        <parameter>
+          <name>withAlias</name>
+          <alias>aliased</alias>
+          <type>java.lang.String</type>
+          <required>false</required>
+          <editable>true</editable>
+          <description></description>
+        </parameter>
       </parameters>
       <configuration>
         <withDefault implementation="java.lang.String" 
default-value="default"/>

Reply via email to