diff --git a/maven-project/src/main/java/org/apache/maven/project/injection/DefaultProfileInjector.java b/maven-project/src/main/java/org/apache/maven/project/injection/DefaultProfileInjector.java index 2aaed88818..1d9d3e8514 100644 --- a/maven-project/src/main/java/org/apache/maven/project/injection/DefaultProfileInjector.java +++ b/maven-project/src/main/java/org/apache/maven/project/injection/DefaultProfileInjector.java @@ -154,7 +154,7 @@ public class DefaultProfileInjector if ( profilePlugin != null ) { - mergedPlugin = profilePlugin; + mergedPlugin = modelPlugin; injectPluginDefinition( profilePlugin, modelPlugin ); } diff --git a/maven-project/src/test/java/org/apache/maven/project/injection/DefaultProfileInjectorTest.java b/maven-project/src/test/java/org/apache/maven/project/injection/DefaultProfileInjectorTest.java index dc12f6e55a..461c7ea395 100644 --- a/maven-project/src/test/java/org/apache/maven/project/injection/DefaultProfileInjectorTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/injection/DefaultProfileInjectorTest.java @@ -5,6 +5,7 @@ import org.apache.maven.model.Build; import org.apache.maven.model.BuildBase; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; import org.apache.maven.model.Profile; import org.apache.maven.model.Repository; import org.codehaus.plexus.util.xml.Xpp3Dom; @@ -15,7 +16,7 @@ public class DefaultProfileInjectorTest extends TestCase { - public void testProfilePluginConfigurationShouldOverrideModelPluginConfiguration() + public void testProfilePluginConfigurationShouldOverrideCollidingModelPluginConfiguration() { Plugin mPlugin = new Plugin(); mPlugin.setGroupId( "test" ); @@ -25,8 +26,12 @@ public class DefaultProfileInjectorTest Xpp3Dom mConfigChild = new Xpp3Dom( "test" ); mConfigChild.setValue( "value" ); + Xpp3Dom mConfigChild2 = new Xpp3Dom( "test2" ); + mConfigChild2.setValue( "value2" ); + Xpp3Dom mConfig = new Xpp3Dom( "configuration" ); mConfig.addChild( mConfigChild ); + mConfig.addChild( mConfigChild2 ); mPlugin.setConfiguration( mConfig ); @@ -66,8 +71,87 @@ public class DefaultProfileInjectorTest Xpp3Dom rChild = rConfig.getChild( "test" ); assertEquals( "replacedValue", rChild.getValue() ); + + Xpp3Dom rChild2 = rConfig.getChild( "test2" ); + + assertEquals( "value2", rChild2.getValue() ); } + public void testModelConfigShouldPersistWhenPluginHasExecConfigs() + { + Plugin mPlugin = new Plugin(); + mPlugin.setGroupId( "test" ); + mPlugin.setArtifactId( "test-artifact" ); + mPlugin.setVersion( "1.0-SNAPSHOT" ); + + Xpp3Dom mConfigChild = new Xpp3Dom( "test" ); + mConfigChild.setValue( "value" ); + + Xpp3Dom mConfigChild2 = new Xpp3Dom( "test2" ); + mConfigChild2.setValue( "value2" ); + + Xpp3Dom mConfig = new Xpp3Dom( "configuration" ); + mConfig.addChild( mConfigChild ); + mConfig.addChild( mConfigChild2 ); + + mPlugin.setConfiguration( mConfig ); + + Build mBuild = new Build(); + mBuild.addPlugin( mPlugin ); + + Model model = new Model(); + model.setBuild( mBuild ); + + Plugin pPlugin = new Plugin(); + pPlugin.setGroupId( "test" ); + pPlugin.setArtifactId( "test-artifact" ); + pPlugin.setVersion( "1.0-SNAPSHOT" ); + + PluginExecution pExec = new PluginExecution(); + pExec.setId("profile-injected"); + + Xpp3Dom pConfigChild = new Xpp3Dom( "test" ); + pConfigChild.setValue( "replacedValue" ); + + Xpp3Dom pConfig = new Xpp3Dom( "configuration" ); + pConfig.addChild( pConfigChild ); + + pExec.setConfiguration( pConfig ); + + pPlugin.addExecution( pExec ); + + BuildBase pBuild = new BuildBase(); + pBuild.addPlugin( pPlugin ); + + Profile profile = new Profile(); + profile.setId( "testId" ); + + profile.setBuild( pBuild ); + + new DefaultProfileInjector().inject( profile, model ); + + Build rBuild = model.getBuild(); + Plugin rPlugin = (Plugin) rBuild.getPlugins().get( 0 ); + + PluginExecution rExec = (PluginExecution) rPlugin.getExecutionsAsMap().get( "profile-injected" ); + + assertNotNull( rExec ); + + Xpp3Dom rExecConfig = (Xpp3Dom) rExec.getConfiguration(); + + Xpp3Dom rChild = rExecConfig.getChild( "test" ); + + assertEquals( "replacedValue", rChild.getValue() ); + + Xpp3Dom rConfig = (Xpp3Dom) rPlugin.getConfiguration(); + + assertNotNull( rConfig ); + + Xpp3Dom rChild2 = rConfig.getChild( "test2" ); + + assertEquals( "value2", rChild2.getValue() ); + } + public void testProfileRepositoryShouldOverrideModelRepository() { Repository mRepository = new Repository();