Various bug fixes to model building.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@756975 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-03-21 17:36:34 +00:00
parent cdf874b056
commit 609077e2b4
8 changed files with 60 additions and 137 deletions

View File

@ -26,6 +26,9 @@ import org.apache.maven.model.Model;
public class ModuleProcessor public class ModuleProcessor
extends BaseProcessor extends BaseProcessor
{ {
/**
* No parent
*/
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized ) public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{ {
super.process( parent, child, target, isChildMostSpecialized ); super.process( parent, child, target, isChildMostSpecialized );

View File

@ -40,7 +40,7 @@ public class PluginProcessor
return; return;
} }
else if ( parent == null && child != null ) else if ( parent == null && child != null )
{//Plugin targetPlugin = new Plugin(); {
boolean isAdd = true; boolean isAdd = true;
Plugin targetPlugin = find((Plugin) child, t); Plugin targetPlugin = find((Plugin) child, t);
@ -58,8 +58,6 @@ public class PluginProcessor
} }
else if ( parent != null && child == null ) else if ( parent != null && child == null )
{ {
//Plugin targetPlugin = new Plugin();
boolean isAdd = true; boolean isAdd = true;
Plugin targetPlugin = find((Plugin) parent, t); Plugin targetPlugin = find((Plugin) parent, t);
if(targetPlugin == null) if(targetPlugin == null)
@ -231,16 +229,18 @@ public class PluginProcessor
target.setPhase( source.getPhase() ); target.setPhase( source.getPhase() );
} }
List<String> goals = new ArrayList<String>(target.getGoals()); List<String> targetGoals = new ArrayList<String>(target.getGoals());
List<String> setGoals = new ArrayList<String>();
for(String goal : source.getGoals()) for(String goal : source.getGoals())
{ {
if(!goals.contains( goal )) if(targetGoals.contains( goal ))
{ {
goals.add( goal ); targetGoals.remove( goal );
} }
} }
target.setGoals( goals ); setGoals.addAll( source.getGoals() );
setGoals.addAll( targetGoals );
target.setGoals( setGoals );
if(source.getConfiguration() != null) if(source.getConfiguration() != null)
{ {

View File

@ -43,7 +43,7 @@ public class PluginsManagementProcessor extends BaseProcessor
for(Plugin depMng : pluginManagement) for(Plugin depMng : pluginManagement)
{ {
for(Plugin targetDep : targetPlugin) for(Plugin targetDep : targetPlugin)
{ { //PluginManagement is first in ordering
if(match(depMng, targetDep)) if(match(depMng, targetDep))
{ {
copy(depMng, targetDep ); copy(depMng, targetDep );
@ -83,22 +83,26 @@ public class PluginsManagementProcessor extends BaseProcessor
target.setVersion( source.getVersion() ); target.setVersion( source.getVersion() );
} }
List<PluginExecution> executions = new ArrayList<PluginExecution>();
for( PluginExecution pe : source.getExecutions()) for( PluginExecution pe : source.getExecutions())
{ {
PluginExecution idMatch = contains(pe, target.getExecutions()); PluginExecution idMatch = contains(pe, target.getExecutions());
if(idMatch != null)//Join if(idMatch != null)//Join
{ {
copyPluginExecution(pe, idMatch); copyPluginExecution(pe, idMatch);
target.getExecutions().remove( idMatch );
executions.add( idMatch );
} }
else else
{ {
PluginExecution targetPe = new PluginExecution(); PluginExecution targetPe = new PluginExecution();
copyPluginExecution(pe, targetPe); copyPluginExecution(pe, targetPe);
target.addExecution( targetPe ); executions.add( targetPe );
}
} }
} executions.addAll( target.getExecutions() );
target.setExecutions( executions );
DependenciesProcessor proc = new DependenciesProcessor(); DependenciesProcessor proc = new DependenciesProcessor();
if(target.getDependencies().isEmpty()) if(target.getDependencies().isEmpty())
@ -116,17 +120,14 @@ public class PluginsManagementProcessor extends BaseProcessor
//TODO: Not copying //TODO: Not copying
if(target.getConfiguration() != null) if(target.getConfiguration() != null)
{ {
target.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) source.getConfiguration(), (Xpp3Dom) target.getConfiguration() )); target.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) target.getConfiguration(), (Xpp3Dom) source.getConfiguration() ));
} }
else else
{ {
target.setConfiguration( source.getConfiguration() ); target.setConfiguration( source.getConfiguration() );
} }
} }
// p2.setConfiguration( configuration ) merge nodes
//Goals
target.setExtensions(source.isExtensions()); target.setExtensions(source.isExtensions());
} }
@ -172,76 +173,17 @@ public class PluginsManagementProcessor extends BaseProcessor
} }
target.setGoals( goals ); target.setGoals( goals );
if(source.getConfiguration() != null)
{
if(target.getConfiguration() != null) if(target.getConfiguration() != null)
{ {
target.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) source.getConfiguration(), (Xpp3Dom) target.getConfiguration() )); //Target is dominant
target.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) target.getConfiguration(), (Xpp3Dom) source.getConfiguration() ));
} }
else else
{ {
target.setConfiguration( source.getConfiguration() ); target.setConfiguration( source.getConfiguration() );
} }
} }
/*
private static void copy(Plugin p1, Plugin p2)
{
if(p2.getArtifactId() == null)
{
p2.setArtifactId( p1.getArtifactId() );
} }
if(p2.getGroupId() == null)
{
p2.setGroupId( p1.getGroupId() );
}
if(p2.getInherited() == null)
{
p2.setInherited( p1.getInherited() );
}
if(p2.getVersion() == null)
{
p2.setVersion( p1.getVersion() );
}
for( PluginExecution pe : p1.getExecutions())
{
PluginExecution p = new PluginExecution();
p.setId( pe.getId() );
p.setInherited( pe.getInherited() );
p.setPhase( pe.getPhase() );
p.setGoals( new ArrayList<String>(pe.getGoals()) );
p2.addExecution( p );
}
// if(p2.getDependencies().isEmpty())
// {
DependenciesProcessor proc = new DependenciesProcessor();
proc.process( new ArrayList<Dependency>(), new ArrayList<Dependency>(p1.getDependencies()), p2.getDependencies(), false );
// }
// else
// {
// DependenciesProcessor proc = new DependenciesProcessor();
// proc.process( new ArrayList<Dependency>(p1.getDependencies()), new ArrayList<Dependency>(), p2.getDependencies(), false );
// }
if(p1.getConfiguration() != null)
{
//TODO: Not copying
if(p2.getConfiguration() != null)
{
p2.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) p1.getConfiguration(), (Xpp3Dom) p2.getConfiguration() ));
}
else
{
p2.setConfiguration( p1.getConfiguration() );
}
}
// p2.setConfiguration( configuration ) merge nodes
//Goals
p2.setExtensions(p1.isExtensions());
}
*/
} }

View File

@ -40,7 +40,6 @@ public class PluginsProcessor
p = (List<Plugin>) parent; p = (List<Plugin>) parent;
} }
// Model t = (Model) target;
List<Plugin> plugins = (List<Plugin>) target; List<Plugin> plugins = (List<Plugin>) target;
PluginProcessor processor = new PluginProcessor(); PluginProcessor processor = new PluginProcessor();
@ -92,18 +91,6 @@ public class PluginsProcessor
private static boolean match( Plugin d1, Plugin d2 ) private static boolean match( Plugin d1, Plugin d2 )
{ {
return getId( d1 ).equals( getId( d2 )); return getId( d1 ).equals( getId( d2 ));
/*
if ( getId( d1 ).equals( getId( d2 ) ) )
{
if(d1.getVersion() == null || d2.getVersion() == null)
{
return true;
}
return ( d1.getVersion() == null ? "" : d1.getVersion() ).equals( d2.getVersion() == null ? ""
: d2.getVersion() );
}
return false;
*/
} }
private static String getId( Plugin d ) private static String getId( Plugin d )

View File

@ -1,4 +1,4 @@
package org.apache.maven.project.processor; package org.apache.maven.project.processor;
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
@ -35,8 +35,6 @@ public class ProfilesModuleProcessor
Model p = (Model) parent; Model p = (Model) parent;
List<String> modules = new ArrayList<String>(); List<String> modules = new ArrayList<String>();
for ( String module : c.getModules() ) for ( String module : c.getModules() )
{ {
if(!modules.contains( module )) if(!modules.contains( module ))

View File

@ -32,16 +32,18 @@ public class PropertiesProcessor
Model t = (Model) target, c = (Model) child, p = (Model) parent; Model t = (Model) target, c = (Model) child, p = (Model) parent;
Properties properties = new Properties(); Properties properties = new Properties();
if ( p != null && p.getProperties() != null )
{
properties.putAll( p.getProperties() );
}
if ( c.getProperties() != null ) if ( c.getProperties() != null )
{ {
properties.putAll( c.getProperties() ); properties.putAll( c.getProperties() );
} }
if ( p != null && p.getProperties() != null )
{
properties.putAll( p.getProperties() );
}
if ( !properties.isEmpty() ) if ( !properties.isEmpty() )
{ {
t.setProperties( properties ); t.setProperties( properties );

View File

@ -122,7 +122,6 @@ public class PomConstructionTest
} }
/*MNG-3900*/ /*MNG-3900*/
/*F:
public void testProfilePropertiesInterpolation() public void testProfilePropertiesInterpolation()
throws Exception throws Exception
{ {
@ -131,7 +130,7 @@ public class PomConstructionTest
assertEquals("PASSED", pom.getValue("properties[1]/test")); assertEquals("PASSED", pom.getValue("properties[1]/test"));
assertEquals("PASSED", pom.getValue("properties[1]/property")); assertEquals("PASSED", pom.getValue("properties[1]/property"));
} }
*/
// Some better conventions for the test poms needs to be created and each of these tests // Some better conventions for the test poms needs to be created and each of these tests
// that represent a verification of a specification item needs to be a couple lines at most. // that represent a verification of a specification item needs to be a couple lines at most.
@ -303,6 +302,7 @@ public class PomConstructionTest
throws Exception throws Exception
{ {
PomTestWrapper pom = buildPom( "single-configuration-inheritance" ); PomTestWrapper pom = buildPom( "single-configuration-inheritance" );
System.out.println(pom.getDomainModel().asString());
assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules" ) ).size() ); assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules" ) ).size() );
assertEquals("2.0.6", pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules[1]/requireMavenVersion[1]/version" ) ); assertEquals("2.0.6", pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules[1]/requireMavenVersion[1]/version" ) );
assertEquals("[2.0.6,)", pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules[2]/requireMavenVersion[1]/version" ) ); assertEquals("[2.0.6,)", pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules[2]/requireMavenVersion[1]/version" ) );
@ -325,15 +325,6 @@ public class PomConstructionTest
assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules[1]/bannedDependencies" ) ).size() ); assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules[1]/bannedDependencies" ) ).size() );
} }
/** MNG-
public void testFoo()
throws Exception
{
PomTestWrapper pom = buildPom( "foo/sub" );
//System.out.println(pom.getDomainModel().asString());
}
*/
/** MNG-3985 */ /** MNG-3985 */
public void testMultipleRepositories() public void testMultipleRepositories()
throws Exception throws Exception
@ -434,7 +425,7 @@ public class PomConstructionTest
assertEquals( "<?xml version='1.0'?>Tom&Jerry", pom.getValue( "properties/xmlTest" ) ); assertEquals( "<?xml version='1.0'?>Tom&Jerry", pom.getValue( "properties/xmlTest" ) );
} }
/* FIXME: cf. MNG-3925 /* FIXME: cf. MNG-3925 */
public void testOrderOfMergedPluginExecutionsWithoutPluginManagement() public void testOrderOfMergedPluginExecutionsWithoutPluginManagement()
throws Exception throws Exception
{ {
@ -452,6 +443,7 @@ public class PomConstructionTest
throws Exception throws Exception
{ {
PomTestWrapper pom = buildPom( "merged-plugin-exec-order/w-plugin-mngt/sub" ); PomTestWrapper pom = buildPom( "merged-plugin-exec-order/w-plugin-mngt/sub" );
System.out.println(pom.getDomainModel().asString());
assertEquals( 5, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() ); assertEquals( 5, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
assertEquals( "parent-1", pom.getValue( "build/plugins[1]/executions[1]/goals[1]" ) ); assertEquals( "parent-1", pom.getValue( "build/plugins[1]/executions[1]/goals[1]" ) );
assertEquals( "parent-2", pom.getValue( "build/plugins[1]/executions[2]/goals[1]" ) ); assertEquals( "parent-2", pom.getValue( "build/plugins[1]/executions[2]/goals[1]" ) );
@ -471,12 +463,11 @@ public class PomConstructionTest
} }
/* MNG-3937*/ /* MNG-3937*/
/* FIX - REGRESSION*/
/*
public void testOrderOfMergedPluginExecutionGoalsWithoutPluginManagement() public void testOrderOfMergedPluginExecutionGoalsWithoutPluginManagement()
throws Exception throws Exception
{ {
PomTestWrapper pom = buildPom( "merged-plugin-exec-goals-order/wo-plugin-mngt/sub" ); PomTestWrapper pom = buildPom( "merged-plugin-exec-goals-order/wo-plugin-mngt/sub" );
System.out.println(pom.getDomainModel().asString());
assertEquals( 5, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/goals" ) ).size() ); assertEquals( 5, ( (List<?>) pom.getValue( "build/plugins[1]/executions[1]/goals" ) ).size() );
assertEquals( "child-a", pom.getValue( "build/plugins[1]/executions[1]/goals[1]" ) ); assertEquals( "child-a", pom.getValue( "build/plugins[1]/executions[1]/goals[1]" ) );
assertEquals( "merged", pom.getValue( "build/plugins[1]/executions[1]/goals[2]" ) ); assertEquals( "merged", pom.getValue( "build/plugins[1]/executions[1]/goals[2]" ) );
@ -484,7 +475,7 @@ public class PomConstructionTest
assertEquals( "parent-b", pom.getValue( "build/plugins[1]/executions[1]/goals[4]" ) ); assertEquals( "parent-b", pom.getValue( "build/plugins[1]/executions[1]/goals[4]" ) );
assertEquals( "parent-a", pom.getValue( "build/plugins[1]/executions[1]/goals[5]" ) ); assertEquals( "parent-a", pom.getValue( "build/plugins[1]/executions[1]/goals[5]" ) );
} }
*/
public void testOrderOfMergedPluginExecutionGoalsWithPluginManagement() public void testOrderOfMergedPluginExecutionGoalsWithPluginManagement()
throws Exception throws Exception
{ {
@ -497,7 +488,7 @@ public class PomConstructionTest
assertEquals( "parent-a", pom.getValue( "build/plugins[1]/executions[1]/goals[5]" ) ); assertEquals( "parent-a", pom.getValue( "build/plugins[1]/executions[1]/goals[5]" ) );
} }
//*/ //*/
/* FIX - REGRESSION*/
public void testOverridingOfInheritedPluginExecutionsWithoutPluginManagement() public void testOverridingOfInheritedPluginExecutionsWithoutPluginManagement()
throws Exception throws Exception
{ {
@ -629,7 +620,7 @@ public class PomConstructionTest
assertEquals( "PASSED", pom.getValue( "properties/property" + index ) ); assertEquals( "PASSED", pom.getValue( "properties/property" + index ) );
} }
} }
/*F: /*
public void testInterpolationOfLegacyExpressionsThatDontIncludeTheProjectPrefix() public void testInterpolationOfLegacyExpressionsThatDontIncludeTheProjectPrefix()
throws Exception throws Exception
{ {
@ -751,26 +742,27 @@ public class PomConstructionTest
} }
//*/ //*/
/* FIXME: cf. MNG-3836 /* FIXME: cf. MNG-3836*/
public void testMergeOfInheritedPluginConfiguration() public void testMergeOfInheritedPluginConfiguration()
throws Exception throws Exception
{ {
PomTestWrapper pom = buildPom( "plugin-config-merging/child" ); PomTestWrapper pom = buildPom( "plugin-config-merging/child" );
System.out.println(pom.getDomainModel().asString());
String prefix = "build/plugins[1]/configuration/"; String prefix = "build/plugins[1]/configuration/";
assertEquals( "PASSED", pom.getValue( prefix + "propertiesFile" ) ); assertEquals( "PASSED", pom.getValue( prefix + "propertiesFile" ) );
assertEquals( "PASSED", pom.getValue( prefix + "parent" ) ); assertEquals( "PASSED", pom.getValue( prefix + "parent" ) );
assertEquals( "PASSED-1", pom.getValue( prefix + "stringParams/stringParam[1]" ) ); assertEquals( "PASSED-1", pom.getValue( prefix + "stringParams/stringParam[1]" ) );
assertEquals( "PASSED-2", pom.getValue( prefix + "stringParams/stringParam[2]" ) ); assertEquals( "PASSED-3", pom.getValue( prefix + "stringParams/stringParam[2]" ) );
assertEquals( "PASSED-3", pom.getValue( prefix + "stringParams/stringParam[3]" ) ); assertEquals( "PASSED-2", pom.getValue( prefix + "stringParams/stringParam[3]" ) );
assertEquals( "PASSED-4", pom.getValue( prefix + "stringParams/stringParam[4]" ) ); assertEquals( "PASSED-4", pom.getValue( prefix + "stringParams/stringParam[4]" ) );
assertEquals( "PASSED-1", pom.getValue( prefix + "listParam/listParam[1]" ) ); assertEquals( "PASSED-1", pom.getValue( prefix + "listParam/listParam[1]" ) );
assertEquals( "PASSED-2", pom.getValue( prefix + "listParam/listParam[2]" ) ); assertEquals( "PASSED-3", pom.getValue( prefix + "listParam/listParam[2]" ) );
assertEquals( "PASSED-3", pom.getValue( prefix + "listParam/listParam[3]" ) ); assertEquals( "PASSED-2", pom.getValue( prefix + "listParam/listParam[3]" ) );
assertEquals( "PASSED-4", pom.getValue( prefix + "listParam/listParam[4]" ) ); assertEquals( "PASSED-4", pom.getValue( prefix + "listParam/listParam[4]" ) );
} }
//*/ //*/
/* FIXME: cf. MNG-2591 /* FIXME: cf. MNG-2591*/
public void testAppendOfInheritedPluginConfiguration() public void testAppendOfInheritedPluginConfiguration()
throws Exception throws Exception
{ {

View File

@ -19,8 +19,7 @@
<project> <project>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng3900 <groupId>org.apache.maven.its.mng3900 </groupId>
</groupId>
<artifactId>test</artifactId> <artifactId>test</artifactId>
<version>0.1</version> <version>0.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>