o Fixed order of inherited plugins

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@785644 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-06-17 15:00:06 +00:00
parent 8d6f2f1139
commit 3843481a3b
6 changed files with 314 additions and 78 deletions

View File

@ -1608,6 +1608,20 @@ public class PomConstructionTest
assertEquals( "child-mailing-list", pom.getValue( "mailingLists[1]/name" ) );
}
public void testPluginInheritanceOrder()
throws Exception
{
PomTestWrapper pom = buildPom( "plugin-inheritance-order/child" );
assertEquals( "maven-it-plugin-log-file", pom.getValue( "build/plugins[1]/artifactId" ) );
assertEquals( "maven-it-plugin-expression", pom.getValue( "build/plugins[2]/artifactId" ) );
assertEquals( "maven-it-plugin-configuration", pom.getValue( "build/plugins[3]/artifactId" ) );
assertEquals( "maven-it-plugin-log-file", pom.getValue( "reporting/plugins[1]/artifactId" ) );
assertEquals( "maven-it-plugin-expression", pom.getValue( "reporting/plugins[2]/artifactId" ) );
assertEquals( "maven-it-plugin-configuration", pom.getValue( "reporting/plugins[3]/artifactId" ) );
}
private void assertPathSuffixEquals( String expected, Object actual )
{
String a = actual.toString();

View File

@ -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>
<parent>
<groupId>org.apache.maven.its.mng3808</groupId>
<artifactId>test</artifactId>
<version>0.1</version>
</parent>
<artifactId>child</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-configuration</artifactId>
<version>2.1-SNAPSHOT</version>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-configuration</artifactId>
<version>2.1-SNAPSHOT</version>
</plugin>
</plugins>
</reporting>
</project>

View File

@ -0,0 +1,68 @@
<?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>org.apache.maven.its.mng3808</groupId>
<artifactId>test</artifactId>
<version>0.1</version>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-3808</name>
<description>
Test the reports are executeed in the order given in the POM.
</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-log-file</artifactId>
<version>2.1-SNAPSHOT</version>
</plugin>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-expression</artifactId>
<version>2.1-SNAPSHOT</version>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-log-file</artifactId>
<version>2.1-SNAPSHOT</version>
</plugin>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-expression</artifactId>
<version>2.1-SNAPSHOT</version>
</plugin>
</plugins>
</reporting>
<modules>
<module>child</module>
</modules>
</project>

View File

@ -19,11 +19,19 @@ package org.apache.maven.model.inheritance;
* under the License.
*/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginContainer;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.merge.MavenModelMerger;
import org.codehaus.plexus.component.annotations.Component;
@ -37,7 +45,7 @@ public class DefaultInheritanceAssembler
implements InheritanceAssembler
{
private MavenModelMerger merger = new MavenModelMerger();
private InheritanceModelMerger merger = new InheritanceModelMerger();
public void assembleModelInheritance( Model child, Model parent, ModelBuildingRequest request )
{
@ -97,4 +105,94 @@ public class DefaultInheritanceAssembler
return adjustment;
}
private static class InheritanceModelMerger
extends MavenModelMerger
{
@Override
protected void mergePluginContainer_Plugins( PluginContainer target, PluginContainer source,
boolean sourceDominant, Map<Object, Object> context )
{
List<Plugin> src = source.getPlugins();
if ( !src.isEmpty() )
{
List<Plugin> tgt = target.getPlugins();
Map<Object, Plugin> merged = new LinkedHashMap<Object, Plugin>( ( src.size() + tgt.size() ) * 2 );
for ( Iterator<Plugin> it = src.iterator(); it.hasNext(); )
{
Plugin element = it.next();
Object key = getPluginKey( element );
if ( element.isInherited() )
{
// NOTE: Enforce recursive merge to trigger merging/inheritance logic for executions as well
Plugin plugin = new Plugin();
plugin.setGroupId( element.getGroupId() );
plugin.setArtifactId( element.getArtifactId() );
mergePlugin( plugin, element, sourceDominant, context );
merged.put( key, plugin );
}
}
for ( Iterator<Plugin> it = tgt.iterator(); it.hasNext(); )
{
Plugin element = it.next();
Object key = getPluginKey( element );
Plugin existing = merged.get( key );
if ( existing != null )
{
mergePlugin( element, existing, sourceDominant, context );
}
merged.put( key, element );
}
target.setPlugins( new ArrayList<Plugin>( merged.values() ) );
}
}
@Override
protected void mergeReporting_Plugins( Reporting target, Reporting source, boolean sourceDominant,
Map<Object, Object> context )
{
List<ReportPlugin> src = source.getPlugins();
if ( !src.isEmpty() )
{
List<ReportPlugin> tgt = target.getPlugins();
Map<Object, ReportPlugin> merged =
new LinkedHashMap<Object, ReportPlugin>( ( src.size() + tgt.size() ) * 2 );
for ( Iterator<ReportPlugin> it = src.iterator(); it.hasNext(); )
{
ReportPlugin element = it.next();
Object key = getReportPluginKey( element );
if ( element.isInherited() )
{
// NOTE: Enforce recursive merge to trigger merging/inheritance logic for executions as well
ReportPlugin plugin = new ReportPlugin();
plugin.setGroupId( element.getGroupId() );
plugin.setArtifactId( element.getArtifactId() );
mergeReportPlugin( plugin, element, sourceDominant, context );
merged.put( key, plugin );
}
}
for ( Iterator<ReportPlugin> it = tgt.iterator(); it.hasNext(); )
{
ReportPlugin element = it.next();
Object key = getReportPluginKey( element );
ReportPlugin existing = merged.get( key );
if ( existing != null )
{
mergeReportPlugin( element, existing, sourceDominant, context );
}
merged.put( key, element );
}
target.setPlugins( new ArrayList<ReportPlugin>( merged.values() ) );
}
}
}
}

View File

@ -44,11 +44,9 @@ import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBase;
import org.apache.maven.model.Organization;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginContainer;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.ReportSet;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Repository;
import org.apache.maven.model.RepositoryBase;
import org.apache.maven.model.Scm;
@ -452,81 +450,6 @@ public class MavenModelMerger
}
}
@Override
protected void mergePluginContainer_Plugins( PluginContainer target, PluginContainer source,
boolean sourceDominant, Map<Object, Object> context )
{
List<Plugin> src = source.getPlugins();
if ( !src.isEmpty() )
{
List<Plugin> tgt = target.getPlugins();
Map<Object, Plugin> merged = new LinkedHashMap<Object, Plugin>( ( src.size() + tgt.size() ) * 2 );
for ( Iterator<Plugin> it = tgt.iterator(); it.hasNext(); )
{
Plugin element = it.next();
Object key = getPluginKey( element );
merged.put( key, element );
}
for ( Iterator<Plugin> it = src.iterator(); it.hasNext(); )
{
Plugin element = it.next();
Object key = getPluginKey( element );
Plugin existing = merged.get( key );
if ( existing == null )
{
// NOTE: Enforce recursive merge to trigger merging/inheritance logic for executions as well
existing = new Plugin();
existing.setGroupId( element.getGroupId() );
existing.setArtifactId( element.getArtifactId() );
merged.put( key, existing );
}
mergePlugin( existing, element, sourceDominant, context );
}
target.setPlugins( new ArrayList<Plugin>( merged.values() ) );
}
}
@Override
protected void mergeReporting_Plugins( Reporting target, Reporting source, boolean sourceDominant,
Map<Object, Object> context )
{
List<ReportPlugin> src = source.getPlugins();
if ( !src.isEmpty() )
{
List<ReportPlugin> tgt = target.getPlugins();
Map<Object, ReportPlugin> merged =
new LinkedHashMap<Object, ReportPlugin>( ( src.size() + tgt.size() ) * 2 );
for ( Iterator<ReportPlugin> it = tgt.iterator(); it.hasNext(); )
{
ReportPlugin element = it.next();
Object key = getReportPluginKey( element );
merged.put( key, element );
}
for ( Iterator<ReportPlugin> it = src.iterator(); it.hasNext(); )
{
ReportPlugin element = it.next();
Object key = getReportPluginKey( element );
ReportPlugin existing = merged.get( key );
if ( existing == null )
{
// NOTE: Enforce recursive merge to trigger merging/inheritance logic for executions as well
existing = new ReportPlugin();
existing.setGroupId( element.getGroupId() );
existing.setArtifactId( element.getArtifactId() );
merged.put( key, existing );
}
mergeReportPlugin( existing, element, sourceDominant, context );
}
target.setPlugins( new ArrayList<ReportPlugin>( merged.values() ) );
}
}
@Override
protected void mergePlugin_Executions( Plugin target, Plugin source, boolean sourceDominant,
Map<Object, Object> context )

View File

@ -19,14 +19,23 @@ package org.apache.maven.model.profile;
* under the License.
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.maven.model.Build;
import org.apache.maven.model.BuildBase;
import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBase;
import org.apache.maven.model.ModelBuildingRequest;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginContainer;
import org.apache.maven.model.Profile;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.merge.MavenModelMerger;
import org.codehaus.plexus.component.annotations.Component;
@ -73,6 +82,79 @@ public class DefaultProfileInjector
mergeBuildBase( target, source, true, Collections.emptyMap() );
}
@Override
protected void mergePluginContainer_Plugins( PluginContainer target, PluginContainer source,
boolean sourceDominant, Map<Object, Object> context )
{
List<Plugin> src = source.getPlugins();
if ( !src.isEmpty() )
{
List<Plugin> tgt = target.getPlugins();
Map<Object, Plugin> merged = new LinkedHashMap<Object, Plugin>( ( src.size() + tgt.size() ) * 2 );
for ( Iterator<Plugin> it = tgt.iterator(); it.hasNext(); )
{
Plugin element = it.next();
Object key = getPluginKey( element );
merged.put( key, element );
}
for ( Iterator<Plugin> it = src.iterator(); it.hasNext(); )
{
Plugin element = it.next();
Object key = getPluginKey( element );
Plugin existing = merged.get( key );
if ( existing == null )
{
merged.put( key, element );
}
else
{
mergePlugin( existing, element, sourceDominant, context );
}
}
target.setPlugins( new ArrayList<Plugin>( merged.values() ) );
}
}
@Override
protected void mergeReporting_Plugins( Reporting target, Reporting source, boolean sourceDominant,
Map<Object, Object> context )
{
List<ReportPlugin> src = source.getPlugins();
if ( !src.isEmpty() )
{
List<ReportPlugin> tgt = target.getPlugins();
Map<Object, ReportPlugin> merged =
new LinkedHashMap<Object, ReportPlugin>( ( src.size() + tgt.size() ) * 2 );
for ( Iterator<ReportPlugin> it = tgt.iterator(); it.hasNext(); )
{
ReportPlugin element = it.next();
Object key = getReportPluginKey( element );
merged.put( key, element );
}
for ( Iterator<ReportPlugin> it = src.iterator(); it.hasNext(); )
{
ReportPlugin element = it.next();
Object key = getReportPluginKey( element );
ReportPlugin existing = merged.get( key );
if ( existing == null )
{
merged.put( key, element );
}
else
{
mergeReportPlugin( existing, element, sourceDominant, context );
}
}
target.setPlugins( new ArrayList<ReportPlugin>( merged.values() ) );
}
}
}
}