o Restored compat with Maven 2.x regarding order of mojo parameters

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@800767 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-04 13:01:35 +00:00
parent f3d89b4d5b
commit 82e64d3049
1 changed files with 55 additions and 45 deletions

View File

@ -258,6 +258,11 @@ public class DefaultLifecycleExecutor
if ( !forkedExecutions.isEmpty() ) if ( !forkedExecutions.isEmpty() )
{ {
if ( logger.isDebugEnabled() )
{
logger.debug( "Forking execution for " + mojoExecution.getMojoDescriptor().getId() );
}
executionProject = project.clone(); executionProject = project.clone();
session.setCurrentProject( executionProject ); session.setCurrentProject( executionProject );
@ -272,6 +277,11 @@ public class DefaultLifecycleExecutor
{ {
session.setCurrentProject( project ); session.setCurrentProject( project );
} }
if ( logger.isDebugEnabled() )
{
logger.debug( "Completed forked execution for " + mojoExecution.getMojoDescriptor().getId() );
}
} }
project.setExecutionProject( executionProject ); project.setExecutionProject( executionProject );
@ -335,6 +345,8 @@ public class DefaultLifecycleExecutor
populateMojoExecutionConfiguration( project, mojoExecution, populateMojoExecutionConfiguration( project, mojoExecution,
MojoExecution.Source.CLI.equals( mojoExecution.getSource() ) ); MojoExecution.Source.CLI.equals( mojoExecution.getSource() ) );
extractMojoConfiguration( mojoExecution );
calculateForkedExecutions( mojoExecution, session, project, new HashSet<MojoDescriptor>() ); calculateForkedExecutions( mojoExecution, session, project, new HashSet<MojoDescriptor>() );
collectDependencyResolutionScopes( requiredDependencyResolutionScopes, mojoExecution ); collectDependencyResolutionScopes( requiredDependencyResolutionScopes, mojoExecution );
@ -621,12 +633,11 @@ public class DefaultLifecycleExecutor
{ {
for ( MojoExecution forkedExecution : forkedExecutions ) for ( MojoExecution forkedExecution : forkedExecutions )
{ {
Xpp3Dom executionConfiguration = forkedExecution.getConfiguration(); Xpp3Dom forkedConfiguration = forkedExecution.getConfiguration();
Xpp3Dom mergedConfiguration = forkedConfiguration = Xpp3Dom.mergeXpp3Dom( phaseConfiguration, forkedConfiguration );
Xpp3Dom.mergeXpp3Dom( phaseConfiguration, executionConfiguration );
forkedExecution.setConfiguration( mergedConfiguration ); forkedExecution.setConfiguration( forkedConfiguration );
} }
} }
} }
@ -637,6 +648,8 @@ public class DefaultLifecycleExecutor
{ {
for ( MojoExecution forkedExecution : forkedExecutions ) for ( MojoExecution forkedExecution : forkedExecutions )
{ {
extractMojoConfiguration( forkedExecution );
calculateForkedExecutions( forkedExecution, session, project, alreadyForkedExecutions ); calculateForkedExecutions( forkedExecution, session, project, alreadyForkedExecutions );
mojoExecution.addForkedExecution( forkedExecution ); mojoExecution.addForkedExecution( forkedExecution );
@ -657,6 +670,8 @@ public class DefaultLifecycleExecutor
populateMojoExecutionConfiguration( project, forkedExecution, true ); populateMojoExecutionConfiguration( project, forkedExecution, true );
extractMojoConfiguration( forkedExecution );
calculateForkedExecutions( forkedExecution, session, project, alreadyForkedExecutions ); calculateForkedExecutions( forkedExecution, session, project, alreadyForkedExecutions );
mojoExecution.addForkedExecution( forkedExecution ); mojoExecution.addForkedExecution( forkedExecution );
@ -690,7 +705,7 @@ public class DefaultLifecycleExecutor
{ {
Xpp3Dom executionConfiguration = (Xpp3Dom) e.getConfiguration(); Xpp3Dom executionConfiguration = (Xpp3Dom) e.getConfiguration();
Xpp3Dom mojoConfiguration = extractMojoConfiguration( executionConfiguration, mojoDescriptor ); Xpp3Dom mojoConfiguration = new Xpp3Dom( executionConfiguration );
mojoConfiguration = Xpp3Dom.mergeXpp3Dom( mojoExecution.getConfiguration(), mojoConfiguration ); mojoConfiguration = Xpp3Dom.mergeXpp3Dom( mojoExecution.getConfiguration(), mojoConfiguration );
@ -722,7 +737,7 @@ public class DefaultLifecycleExecutor
if ( plugin != null && plugin.getConfiguration() != null ) if ( plugin != null && plugin.getConfiguration() != null )
{ {
Xpp3Dom pluginConfiguration = (Xpp3Dom) plugin.getConfiguration(); Xpp3Dom pluginConfiguration = (Xpp3Dom) plugin.getConfiguration();
pluginConfiguration = extractMojoConfiguration( pluginConfiguration, mojoDescriptor ); pluginConfiguration = new Xpp3Dom( pluginConfiguration );
mojoConfiguration = Xpp3Dom.mergeXpp3Dom( pluginConfiguration, defaultConfiguration, Boolean.TRUE ); mojoConfiguration = Xpp3Dom.mergeXpp3Dom( pluginConfiguration, defaultConfiguration, Boolean.TRUE );
} }
@ -732,6 +747,15 @@ public class DefaultLifecycleExecutor
} }
} }
private void extractMojoConfiguration( MojoExecution mojoExecution )
{
Xpp3Dom configuration = mojoExecution.getConfiguration();
configuration = extractMojoConfiguration( configuration, mojoExecution.getMojoDescriptor() );
mojoExecution.setConfiguration( configuration );
}
/** /**
* Extracts the configuration for a single mojo from the specified execution configuration by discarding any * Extracts the configuration for a single mojo from the specified execution configuration by discarding any
* non-applicable parameters. This is necessary because a plugin execution can have multiple goals with different * non-applicable parameters. This is necessary because a plugin execution can have multiple goals with different
@ -739,58 +763,44 @@ public class DefaultLifecycleExecutor
* underlying configurator will error out when trying to configure a mojo parameter that is specified in the * underlying configurator will error out when trying to configure a mojo parameter that is specified in the
* configuration but not present in the mojo instance. * configuration but not present in the mojo instance.
* *
* @param executionConfiguration The configuration from the plugin execution, must not be {@code null}. * @param executionConfiguration The configuration from the plugin execution, may be {@code null}.
* @param mojoDescriptor The descriptor for the mojo being configured, must not be {@code null}. * @param mojoDescriptor The descriptor for the mojo being configured, must not be {@code null}.
* @return The configuration for the mojo, never {@code null}. * @return The configuration for the mojo, never {@code null}.
*/ */
private Xpp3Dom extractMojoConfiguration( Xpp3Dom executionConfiguration, MojoDescriptor mojoDescriptor ) private Xpp3Dom extractMojoConfiguration( Xpp3Dom executionConfiguration, MojoDescriptor mojoDescriptor )
{ {
Xpp3Dom mojoConfiguration = new Xpp3Dom( executionConfiguration.getName() ); Xpp3Dom mojoConfiguration = null;
Map<String, Parameter> mojoParameters = mojoDescriptor.getParameterMap(); if ( executionConfiguration != null )
Map<String, String> aliases = new HashMap<String, String>();
if ( mojoDescriptor.getParameters() != null )
{ {
for ( Parameter parameter : mojoDescriptor.getParameters() ) mojoConfiguration = new Xpp3Dom( executionConfiguration.getName() );
if ( mojoDescriptor.getParameters() != null )
{ {
String alias = parameter.getAlias(); for ( Parameter parameter : mojoDescriptor.getParameters() )
if ( StringUtils.isNotEmpty( alias ) )
{ {
aliases.put( alias, parameter.getName() ); Xpp3Dom parameterConfiguration = executionConfiguration.getChild( parameter.getName() );
if ( parameterConfiguration == null )
{
parameterConfiguration = executionConfiguration.getChild( parameter.getAlias() );
}
if ( parameterConfiguration != null )
{
parameterConfiguration = new Xpp3Dom( parameterConfiguration, parameter.getName() );
if ( StringUtils.isNotEmpty( parameter.getImplementation() ) )
{
parameterConfiguration.setAttribute( "implementation", parameter.getImplementation() );
}
mojoConfiguration.addChild( parameterConfiguration );
}
} }
} }
} }
for ( int i = 0; i < executionConfiguration.getChildCount(); i++ )
{
Xpp3Dom executionDom = executionConfiguration.getChild( i );
String paramName = executionDom.getName();
Xpp3Dom mojoDom;
if ( mojoParameters.containsKey( paramName ) )
{
mojoDom = new Xpp3Dom( executionDom );
}
else if ( aliases.containsKey( paramName ) )
{
mojoDom = new Xpp3Dom( executionDom, aliases.get( paramName ) );
}
else
{
continue;
}
String implementation = mojoParameters.get( mojoDom.getName() ).getImplementation();
if ( StringUtils.isNotEmpty( implementation ) )
{
mojoDom.setAttribute( "implementation", implementation );
}
mojoConfiguration.addChild( mojoDom );
}
return mojoConfiguration; return mojoConfiguration;
} }