MPLUGINTESTING-32 fixed incorrect configuration merge order
Signed-off-by: Igor Fedorenko <ifedorenko@apache.org>
diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java
index a1c7a66..3de20a3 100644
--- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java
+++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java
@@ -374,7 +374,7 @@
{
configuration = new Xpp3Dom( "configuration" );
}
- configuration = Xpp3Dom.mergeXpp3Dom( execution.getConfiguration(), configuration );
+ configuration = Xpp3Dom.mergeXpp3Dom( configuration, execution.getConfiguration() );
PlexusConfiguration pluginConfiguration = new XmlPlexusConfiguration( configuration );
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
new file mode 100644
index 0000000..a1436fe
--- /dev/null
+++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojo.java
@@ -0,0 +1,41 @@
+package org.apache.maven.plugin.testing;
+
+/*
+ * 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 org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+public class ParametersMojo
+ extends AbstractMojo
+{
+ public String plain;
+
+ public String withProperty;
+
+ public String withDefault;
+
+ public String withPropertyAndDefault;
+
+ public void execute()
+ throws MojoExecutionException, MojoFailureException
+ {
+ }
+}
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
new file mode 100644
index 0000000..3f36d8a
--- /dev/null
+++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ParametersMojoTest.java
@@ -0,0 +1,108 @@
+package org.apache.maven.plugin.testing;
+
+/*
+ * 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;
+
+import org.apache.maven.execution.DefaultMavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.apache.maven.plugin.testing.ParametersMojo;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.project.ProjectBuildingRequest;
+
+public class ParametersMojoTest
+ extends AbstractMojoTestCase
+{
+ public void testDefault()
+ throws Exception
+ {
+ MavenProject project = readMavenProject( new File( "src/test/projects/default" ) );
+
+ ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo( project, "parameters" );
+
+ assertNull( mojo.plain );
+ assertNull( mojo.withProperty );
+ assertEquals( "default", mojo.withDefault );
+ assertEquals( "default", mojo.withPropertyAndDefault );
+ }
+
+ public void testExplicit()
+ throws Exception
+ {
+ MavenProject project = readMavenProject( new File( "src/test/projects/explicit" ) );
+
+ ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo( project, "parameters" );
+
+ assertEquals( "explicitValue", mojo.plain );
+ assertEquals( "explicitWithPropertyValue", mojo.withProperty );
+ assertEquals( "explicitWithDefaultValue", mojo.withDefault );
+ assertEquals( "explicitWithPropertyAndDefaultValue", mojo.withPropertyAndDefault );
+ }
+
+ public void testDefaultWithProperty()
+ throws Exception
+ {
+ MavenProject project = readMavenProject( new File( "src/test/projects/default" ) );
+ MavenSession session = newMavenSession( project );
+ MojoExecution execution = newMojoExecution( "parameters" );
+
+ session.getUserProperties().put( "property", "propertyValue" );
+ ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo( session, execution );
+
+ assertNull( mojo.plain );
+ assertEquals( "propertyValue", mojo.withProperty );
+ assertEquals( "default", mojo.withDefault );
+ assertEquals( "propertyValue", mojo.withPropertyAndDefault );
+ }
+
+ public void testExplicitWithProperty()
+ throws Exception
+ {
+ MavenProject project = readMavenProject( new File( "src/test/projects/explicit" ) );
+ MavenSession session = newMavenSession( project );
+ MojoExecution execution = newMojoExecution( "parameters" );
+
+ session.getUserProperties().put( "property", "propertyValue" );
+ ParametersMojo mojo = (ParametersMojo) lookupConfiguredMojo( session, execution );
+
+ assertEquals( "explicitValue", mojo.plain );
+ assertEquals( "explicitWithPropertyValue", mojo.withProperty );
+ assertEquals( "explicitWithDefaultValue", mojo.withDefault );
+ assertEquals( "explicitWithPropertyAndDefaultValue", mojo.withPropertyAndDefault );
+ }
+
+ protected MavenProject readMavenProject( File basedir )
+ throws ProjectBuildingException, Exception
+ {
+ File pom = new File( basedir, "pom.xml" );
+ MavenExecutionRequest request = new DefaultMavenExecutionRequest();
+ request.setBaseDirectory( basedir );
+ ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
+ MavenProject project = lookup( ProjectBuilder.class ).build( pom, configuration ).getProject();
+ assertNotNull( project );
+ return project;
+ }
+
+}
diff --git a/maven-plugin-testing-harness/src/test/projects/default/pom.xml b/maven-plugin-testing-harness/src/test/projects/default/pom.xml
new file mode 100644
index 0000000..e0dc4b3
--- /dev/null
+++ b/maven-plugin-testing-harness/src/test/projects/default/pom.xml
@@ -0,0 +1,48 @@
+<?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>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/maven-plugin-testing-harness/src/test/projects/explicit/pom.xml b/maven-plugin-testing-harness/src/test/projects/explicit/pom.xml
new file mode 100644
index 0000000..06628e9
--- /dev/null
+++ b/maven-plugin-testing-harness/src/test/projects/explicit/pom.xml
@@ -0,0 +1,54 @@
+<?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>
+ <plain>explicitValue</plain>
+ <withProperty>explicitWithPropertyValue</withProperty>
+ <withDefault>explicitWithDefaultValue</withDefault>
+ <withPropertyAndDefault>explicitWithPropertyAndDefaultValue</withPropertyAndDefault>
+ </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
new file mode 100644
index 0000000..d442272
--- /dev/null
+++ b/maven-plugin-testing-harness/src/test/resources/META-INF/maven/plugin.xml
@@ -0,0 +1,84 @@
+<?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.
+-->
+
+<plugin>
+ <name>test-plugin</name>
+ <description></description>
+ <groupId>test</groupId>
+ <artifactId>test-plugin</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <goalPrefix>test</goalPrefix>
+ <isolatedRealm>false</isolatedRealm>
+ <inheritedByDefault>true</inheritedByDefault>
+ <mojos>
+ <mojo>
+ <goal>parameters</goal>
+ <requiresDirectInvocation>false</requiresDirectInvocation>
+ <requiresProject>true</requiresProject>
+ <requiresReports>false</requiresReports>
+ <aggregator>false</aggregator>
+ <requiresOnline>false</requiresOnline>
+ <inheritedByDefault>true</inheritedByDefault>
+ <implementation>org.apache.maven.plugin.testing.ParametersMojo</implementation>
+ <language>java</language>
+ <instantiationStrategy>per-lookup</instantiationStrategy>
+ <executionStrategy>once-per-session</executionStrategy>
+ <threadSafe>false</threadSafe>
+ <parameters>
+ <parameter>
+ <name>plain</name>
+ <type>java.lang.String</type>
+ <required>false</required>
+ <editable>true</editable>
+ <description></description>
+ </parameter>
+ <parameter>
+ <name>withDefault</name>
+ <type>java.lang.String</type>
+ <required>false</required>
+ <editable>true</editable>
+ <description></description>
+ </parameter>
+ <parameter>
+ <name>withProperty</name>
+ <type>java.lang.String</type>
+ <required>false</required>
+ <editable>true</editable>
+ <description></description>
+ </parameter>
+ <parameter>
+ <name>withPropertyAndDefault</name>
+ <type>java.lang.String</type>
+ <required>false</required>
+ <editable>true</editable>
+ <description></description>
+ </parameter>
+ </parameters>
+ <configuration>
+ <withDefault implementation="java.lang.String" default-value="default"/>
+ <withProperty implementation="java.lang.String">${property}</withProperty>
+ <withPropertyAndDefault implementation="java.lang.String" default-value="default">${property}</withPropertyAndDefault>
+ </configuration>
+ </mojo>
+ </mojos>
+ <dependencies/>
+</plugin>
\ No newline at end of file