[MNG-1703] <pluginManagement><dependencies> is not propagated to child POMs

Submitted by: Edwin Punzalan


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@379365 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2006-02-21 06:15:33 +00:00
parent bf4764c73a
commit b68c84b86d
2 changed files with 57 additions and 13 deletions

View File

@ -53,6 +53,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.HashMap;
public final class ModelUtils public final class ModelUtils
{ {
@ -208,6 +209,8 @@ public final class ModelUtils
child.setConfiguration( childConfiguration ); child.setConfiguration( childConfiguration );
child.setDependencies( mergeDependencyList( child.getDependencies(), parent.getDependencies() ) );
// from here to the end of the method is dealing with merging of the <executions/> section. // from here to the end of the method is dealing with merging of the <executions/> section.
String parentInherited = parent.getInherited(); String parentInherited = parent.getInherited();
@ -1000,4 +1003,30 @@ public final class ModelUtils
} }
} }
} }
public static List mergeDependencyList( List child, List parent )
{
Map depsMap = new HashMap();
if ( parent != null )
{
for ( Iterator it = parent.iterator(); it.hasNext(); )
{
Dependency dependency = (Dependency) it.next();
depsMap.put( dependency.getManagementKey(), dependency );
}
}
if ( child != null )
{
for ( Iterator it = child.iterator(); it.hasNext(); )
{
Dependency dependency = (Dependency) it.next();
depsMap.put( dependency.getManagementKey(), dependency );
}
}
return new ArrayList( depsMap.values() );
}
} }

View File

@ -5,6 +5,9 @@ import junit.framework.TestCase;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginContainer; import org.apache.maven.model.PluginContainer;
import org.apache.maven.model.PluginExecution; import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.Dependency;
import java.util.Collections;
/* /*
* Copyright 2001-2005 The Apache Software Foundation. * Copyright 2001-2005 The Apache Software Foundation.
@ -180,6 +183,13 @@ public class ModelUtilsTest
parent.addExecution( parentExecution1 ); parent.addExecution( parentExecution1 );
parent.addExecution( parentExecution2 ); parent.addExecution( parentExecution2 );
// this block verifies MNG-1703
Dependency dep = new Dependency();
dep.setGroupId( "depGroupId" );
dep.setArtifactId( "depArtifactId" );
dep.setVersion( "depVersion" );
parent.setDependencies( Collections.singletonList( dep ) );
Plugin child = new Plugin(); Plugin child = new Plugin();
child.setArtifactId( "testArtifact" ); child.setArtifactId( "testArtifact" );
child.setGroupId( "testGroup" ); child.setGroupId( "testGroup" );
@ -200,5 +210,10 @@ public class ModelUtilsTest
assertSame(parentExecution2, child.getExecutions().get(1)); assertSame(parentExecution2, child.getExecutions().get(1));
assertSame(childExecution1, child.getExecutions().get(2)); assertSame(childExecution1, child.getExecutions().get(2));
assertSame(childExecution2, child.getExecutions().get(3)); assertSame(childExecution2, child.getExecutions().get(3));
// this block prevents MNG-1703
assertEquals( 1, child.getDependencies().size() );
Dependency dep2 = (Dependency) child.getDependencies().get( 0 );
assertEquals( dep.getManagementKey(), dep2.getManagementKey() );
} }
} }