Resolving: MNG-674

o Added it0049 to prevent further regressions. ;)


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@231393 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-08-11 04:38:46 +00:00
parent 309f26b810
commit 3c53a1305d
7 changed files with 138 additions and 4 deletions

View File

@ -59,7 +59,7 @@ public class CoreItMojo
private File basedirAlignmentDirectory;
/**
* @parameter
* @parameter alias="pluginFile"
*/
private String pluginItem = "foo";

View File

@ -134,6 +134,10 @@ it0046: Test fail-never reactor behavior. Forces an exception to be thrown in
it0047: Test the use case for having a compile time dependency be transitive: when you extend a class you need its
dependencies at compile time.
it0048: Test profile overrides of values specified in the pom.
it0049: Test parameter alias usage.
-------------------------------------------------------------------------------
- generated sources

View File

@ -1,3 +1,5 @@
it0049
it0048
it0047
it0046
it0045

View File

@ -0,0 +1 @@
target/touchFile.txt

View File

@ -0,0 +1 @@
core-it:touch

View File

@ -0,0 +1,28 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.it</groupId>
<artifactId>maven-it0049</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-core-it-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<pluginFile>touchFile.txt</pluginFile>
</configuration>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>plugin-snapshots</id>
<name>Plugin Snapshots</name>
<url>http://snapshots.maven.codehaus.org/maven2/plugins</url>
</pluginRepository>
</pluginRepositories>
</project>

View File

@ -490,7 +490,7 @@ public class DefaultPluginManager
plugin.setLog( mojoLogger );
PlexusConfiguration pomConfiguration;
XmlPlexusConfiguration pomConfiguration;
if ( dom == null )
{
pomConfiguration = new XmlPlexusConfiguration( "configuration" );
@ -504,8 +504,7 @@ public class DefaultPluginManager
// override in the POM.
validatePomConfiguration( mojoDescriptor, pomConfiguration );
PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration, mojoDescriptor
.getMojoConfiguration() );
PlexusConfiguration mergedConfiguration = mergeMojoConfiguration( pomConfiguration, mojoDescriptor );
// TODO: plexus changes to make this more like the component descriptor so this can be used instead
// PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration,
@ -829,6 +828,105 @@ public class DefaultPluginManager
}
}
}
private PlexusConfiguration mergeMojoConfiguration( XmlPlexusConfiguration fromPom, MojoDescriptor mojoDescriptor )
{
XmlPlexusConfiguration result = new XmlPlexusConfiguration( fromPom.getName() );
result.setValue( fromPom.getValue( null ) );
PlexusConfiguration fromMojo = mojoDescriptor.getMojoConfiguration();
for ( Iterator it = mojoDescriptor.getParameters().iterator(); it.hasNext(); )
{
Parameter parameter = (Parameter) it.next();
String paramName = parameter.getName();
String alias = parameter.getAlias();
PlexusConfiguration pomConfig = fromPom.getChild( paramName );
PlexusConfiguration aliased = null;
if ( alias != null )
{
aliased = fromPom.getChild( alias );
}
PlexusConfiguration mojoConfig = fromMojo.getChild( paramName, false );
// first we'll merge configurations from the aliased and real params.
// TODO: Is this the right thing to do?
if ( aliased != null )
{
if ( pomConfig == null )
{
pomConfig = new XmlPlexusConfiguration( paramName );
}
pomConfig = buildTopDownMergedConfiguration( pomConfig, aliased );
}
if ( pomConfig != null )
{
pomConfig = buildTopDownMergedConfiguration( pomConfig, mojoConfig );
// if ( StringUtils.isEmpty( pomConfig.getValue( null ) ) && pomConfig.getChildCount() == 0 )
// {
// // if we still can't find a value for this parameter, set to ${paramName}
// result.setValue( "${" + pomConfig.getName() + "}" );
// }
result.addChild( pomConfig );
}
else if ( mojoConfig != null )
{
result.addChild( copyConfiguration( mojoConfig ) );
}
}
return result;
}
private XmlPlexusConfiguration buildTopDownMergedConfiguration( PlexusConfiguration dominant, PlexusConfiguration recessive )
{
XmlPlexusConfiguration result = new XmlPlexusConfiguration( dominant.getName() );
String value = dominant.getValue( null );
if ( StringUtils.isEmpty( value ) && recessive != null )
{
value = recessive.getValue( null );
}
if ( StringUtils.isNotEmpty( value ) )
{
result.setValue( value );
}
String[] attributeNames = dominant.getAttributeNames();
for ( int i = 0; i < attributeNames.length; i++ )
{
String attributeValue = dominant.getAttribute( attributeNames[i], null );
result.setAttribute( attributeNames[i], attributeValue );
}
if ( recessive != null )
{
attributeNames = recessive.getAttributeNames();
for ( int i = 0; i < attributeNames.length; i++ )
{
String attributeValue = recessive.getAttribute( attributeNames[i], null );
result.setAttribute( attributeNames[i], attributeValue );
}
mergeConfiguration( result, recessive );
}
return result;
}
private PlexusConfiguration mergeConfiguration( PlexusConfiguration dominant, PlexusConfiguration configuration )
{