[MNG-4035] - Removing plugin manager changes. This is breaking tycho build and also causes a hefty performance hit. Using mixins is over-generalizing this solution. Only need to cleanup config merging.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@745040 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-02-17 13:13:49 +00:00
parent 55fe596230
commit 759769900d
1 changed files with 375 additions and 37 deletions

View File

@ -557,13 +557,52 @@ public class DefaultPluginManager
downloadDependencies( project, session, artifactResolver ); downloadDependencies( project, session, artifactResolver );
} }
// String goalName = mojoDescriptor.getFullGoalName();
Mojo mojo = null;
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
Xpp3Dom dom = mojoExecution.getConfiguration();
if ( dom != null )
{
try
{
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties(
session.getProjectBuilderConfiguration().getExecutionProperties(),
PomInterpolatorTag.EXECUTION_PROPERTIES.name()));
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getUserProperties(),
PomInterpolatorTag.USER_PROPERTIES.name()));
String interpolatedDom =
Interpolator.interpolateXmlString( String.valueOf( dom ), interpolatorProperties );
dom = Xpp3DomBuilder.build( new StringReader( interpolatedDom ) );
}
catch ( XmlPullParserException e )
{
throw new PluginManagerException(
mojoDescriptor,
project,
"Failed to calculate concrete state for configuration of: "
+ mojoDescriptor.getHumanReadableKey(),
e );
}
catch ( IOException e )
{
throw new PluginManagerException(
mojoDescriptor,
project,
"Failed to calculate concrete state for configuration of: "
+ mojoDescriptor.getHumanReadableKey(),
e );
}
}
// Event monitoring. // Event monitoring.
String event = MavenEvents.MOJO_EXECUTION; String event = MavenEvents.MOJO_EXECUTION;
EventDispatcher dispatcher = session.getEventDispatcher(); EventDispatcher dispatcher = session.getEventDispatcher();
String goalName = mojoDescriptor.getFullGoalName();
String goalExecId = goalName; String goalExecId = goalName;
if ( mojoExecution.getExecutionId() != null ) if ( mojoExecution.getExecutionId() != null )
{ {
@ -576,12 +615,9 @@ public class DefaultPluginManager
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
List realmActions = new ArrayList(); List realmActions = new ArrayList();
Mojo mojo = null;
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
try try
{ {
mojo = getConfiguredMojo( session, project, false, mojoExecution, realmActions ); mojo = getConfiguredMojo( session, dom, project, false, mojoExecution, realmActions );
dispatcher.dispatchStart( event, goalExecId ); dispatcher.dispatchStart( event, goalExecId );
@ -712,7 +748,7 @@ public class DefaultPluginManager
MavenSession session ) MavenSession session )
throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException, throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException,
ArtifactResolutionException ArtifactResolutionException
{ /* {
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
PluginDescriptor descriptor = mojoDescriptor.getPluginDescriptor(); PluginDescriptor descriptor = mojoDescriptor.getPluginDescriptor();
Xpp3Dom dom = project.getReportConfiguration( descriptor.getGroupId(), Xpp3Dom dom = project.getReportConfiguration( descriptor.getGroupId(),
@ -722,8 +758,8 @@ public class DefaultPluginManager
{ {
dom = Xpp3Dom.mergeXpp3Dom( dom, mojoExecution.getConfiguration() ); dom = Xpp3Dom.mergeXpp3Dom( dom, mojoExecution.getConfiguration() );
} }
*/
return (MavenReport) getConfiguredMojo( session, project, true, mojoExecution, new ArrayList() ); return (MavenReport) getConfiguredMojo( session, dom, project, true, mojoExecution, new ArrayList() );
} }
public PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, public PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin,
@ -755,6 +791,7 @@ public class DefaultPluginManager
} }
private Mojo getConfiguredMojo( MavenSession session, private Mojo getConfiguredMojo( MavenSession session,
Xpp3Dom dom,
MavenProject project, MavenProject project,
boolean report, boolean report,
MojoExecution mojoExecution, MojoExecution mojoExecution,
@ -840,6 +877,28 @@ public class DefaultPluginManager
mojo.setLog( new DefaultLog( getLogger() ) ); mojo.setLog( new DefaultLog( getLogger() ) );
XmlPlexusConfiguration pomConfiguration;
if ( dom == null )
{
pomConfiguration = new XmlPlexusConfiguration( "configuration" );
}
else
{
pomConfiguration = new XmlPlexusConfiguration( dom );
}
// Validate against non-editable (@readonly) parameters, to make sure users aren't trying to
// override in the POM.
validatePomConfiguration( mojoDescriptor, pomConfiguration );
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,
// mojoDescriptor.getConfiguration() );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(
session, session,
mojoExecution, mojoExecution,
@ -847,38 +906,16 @@ public class DefaultPluginManager
getLogger(), getLogger(),
session.getExecutionProperties() ); session.getExecutionProperties() );
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>(); PlexusConfiguration extractedMojoConfiguration = extractMojoConfiguration(
mergedConfiguration,
mojoDescriptor );
interpolatorProperties.addAll(InterpolatorProperty.toInterpolatorProperties(session.getProjectBuilderConfiguration().getExecutionProperties(), checkDeprecatedParameters( mojoDescriptor, pomConfiguration );
PomInterpolatorTag.EXECUTION_PROPERTIES.name()));
interpolatorProperties.addAll(InterpolatorProperty.toInterpolatorProperties(session.getProjectBuilderConfiguration().getUserProperties(), checkRequiredParameters( mojoDescriptor, extractedMojoConfiguration, expressionEvaluator );
PomInterpolatorTag.USER_PROPERTIES.name()));
Plugin plugin = null; populatePluginFields( mojo, mojoDescriptor, extractedMojoConfiguration, expressionEvaluator );
try {
plugin = pluginRepository.findPluginById(pluginDescriptor.getId(), mojoDescriptor.getId());
} catch (Exception e) {
e.printStackTrace();
}
PlexusConfiguration mojoConfiguration = null;
try {
mojoConfiguration = ((Mixer) projectBuilder).mixPluginAndReturnConfig(plugin, mojoExecution.getConfiguration(), project.getModel(),
interpolatorProperties);
} catch (Exception e) {
e.printStackTrace();
}
if(mojoConfiguration == null)
{
mojoConfiguration = new XmlPlexusConfiguration( "configuration" );
}
checkRequiredParameters( mojoDescriptor, mojoConfiguration, expressionEvaluator );
populatePluginFields( mojo, mojoDescriptor, mojoConfiguration, expressionEvaluator );
return mojo; return mojo;
} finally { } finally {
@ -886,6 +923,63 @@ public class DefaultPluginManager
} }
} }
private void checkDeprecatedParameters( MojoDescriptor mojoDescriptor,
PlexusConfiguration extractedMojoConfiguration )
{
if ( ( extractedMojoConfiguration == null ) || ( extractedMojoConfiguration.getChildCount() < 1 ) )
{
return;
}
List parameters = mojoDescriptor.getParameters();
if ( ( parameters != null ) && !parameters.isEmpty() )
{
for ( Iterator it = parameters.iterator(); it.hasNext(); )
{
Parameter param = (Parameter) it.next();
if ( param.getDeprecated() != null )
{
boolean warnOfDeprecation = false;
PlexusConfiguration child = extractedMojoConfiguration.getChild( param.getName() );
try
{
if ( ( child != null ) && ( child.getValue() != null ) )
{
warnOfDeprecation = true;
}
else if ( param.getAlias() != null)
{
child = extractedMojoConfiguration.getChild( param.getAlias() );
if ( ( child != null ) && ( child.getValue() != null ) )
{
warnOfDeprecation = true;
}
}
}
catch ( PlexusConfigurationException e )
{
// forget it, this is just for deprecation checking, after all...
}
if ( warnOfDeprecation )
{
StringBuffer buffer = new StringBuffer();
buffer.append( "In mojo: " ).append( mojoDescriptor.getGoal() ).append( ", parameter: " ).append( param.getName() );
if ( param.getAlias() != null )
{
buffer.append( " (alias: " ).append( param.getAlias() ).append( ")" );
}
buffer.append( " is deprecated:" ).append( "\n\n" ).append( param.getDeprecated() ).append( "\n" );
getLogger().warn( buffer.toString() );
}
}
}
}
}
private void setDescriptorClassAndArtifactInfo( PluginDescriptor pluginDescriptor, private void setDescriptorClassAndArtifactInfo( PluginDescriptor pluginDescriptor,
MavenProject project, MavenProject project,
@ -928,6 +1022,40 @@ public class DefaultPluginManager
pluginDescriptor.setArtifacts( realmManager.getPluginArtifacts( plugin ) ); pluginDescriptor.setArtifacts( realmManager.getPluginArtifacts( plugin ) );
} }
private PlexusConfiguration extractMojoConfiguration( PlexusConfiguration mergedConfiguration,
MojoDescriptor mojoDescriptor )
{
Map parameterMap = mojoDescriptor.getParameterMap();
PlexusConfiguration[] mergedChildren = mergedConfiguration.getChildren();
XmlPlexusConfiguration extractedConfiguration = new XmlPlexusConfiguration( "configuration" );
for ( int i = 0; i < mergedChildren.length; i++ )
{
PlexusConfiguration child = mergedChildren[i];
if ( parameterMap.containsKey( child.getName() ) )
{
extractedConfiguration.addChild( copyConfiguration( child ) );
}
else
{
// TODO: I defy anyone to find these messages in the '-X' output! Do we need a new log level?
// ideally, this would be elevated above the true debug output, but below the default INFO level...
// [BP] (2004-07-18): need to understand the context more but would prefer this could be either WARN or
// removed - shouldn't need DEBUG to diagnose a problem most of the time.
getLogger().debug(
"*** WARNING: Configuration \'" + child.getName()
+ "\' is not used in goal \'"
+ mojoDescriptor.getFullGoalName()
+ "; this may indicate a typo... ***" );
}
}
return extractedConfiguration;
}
private void checkRequiredParameters( MojoDescriptor goal, private void checkRequiredParameters( MojoDescriptor goal,
PlexusConfiguration configuration, PlexusConfiguration configuration,
ExpressionEvaluator expressionEvaluator ) ExpressionEvaluator expressionEvaluator )
@ -952,6 +1080,7 @@ public class DefaultPluginManager
{ {
// the key for the configuration map we're building. // the key for the configuration map we're building.
String key = parameter.getName(); String key = parameter.getName();
Object fieldValue = null; Object fieldValue = null;
String expression = null; String expression = null;
PlexusConfiguration value = configuration.getChild( key, false ); PlexusConfiguration value = configuration.getChild( key, false );
@ -1005,6 +1134,215 @@ public class DefaultPluginManager
} }
} }
private void validatePomConfiguration( MojoDescriptor goal,
PlexusConfiguration pomConfiguration )
throws PluginConfigurationException
{
List parameters = goal.getParameters();
if ( parameters == null )
{
return;
}
for ( int i = 0; i < parameters.size(); i++ )
{
Parameter parameter = (Parameter) parameters.get( i );
// the key for the configuration map we're building.
String key = parameter.getName();
PlexusConfiguration value = pomConfiguration.getChild( key, false );
if ( ( value == null ) && StringUtils.isNotEmpty( parameter.getAlias() ) )
{
key = parameter.getAlias();
value = pomConfiguration.getChild( key, false );
}
if ( value != null )
{
// Make sure the parameter is either editable/configurable, or else is NOT specified in the POM
if ( !parameter.isEditable() )
{
StringBuffer errorMessage = new StringBuffer().append( "ERROR: Cannot override read-only parameter: " );
errorMessage.append( key );
errorMessage.append( " in goal: " ).append( goal.getFullGoalName() );
throw new PluginConfigurationException( goal.getPluginDescriptor(),
errorMessage.toString() );
}
String deprecated = parameter.getDeprecated();
if ( StringUtils.isNotEmpty( deprecated ) )
{
getLogger().warn( "DEPRECATED [" + parameter.getName() + "]: " + deprecated );
}
}
}
}
private PlexusConfiguration mergeMojoConfiguration( XmlPlexusConfiguration fromPom,
MojoDescriptor mojoDescriptor )
{
XmlPlexusConfiguration result = new XmlPlexusConfiguration( fromPom.getName() );
result.setValue( fromPom.getValue( null ) );
if ( mojoDescriptor.getParameters() != 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();
String implementation = parameter.getImplementation();
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 );
}
PlexusConfiguration toAdd = null;
if ( pomConfig != null )
{
pomConfig = buildTopDownMergedConfiguration( pomConfig, mojoConfig );
if ( StringUtils.isNotEmpty( pomConfig.getValue( null ) )
|| ( pomConfig.getChildCount() > 0 ) )
{
toAdd = pomConfig;
}
}
if ( ( toAdd == null ) && ( mojoConfig != null ) )
{
toAdd = copyConfiguration( mojoConfig );
}
if ( toAdd != null )
{
if ( ( implementation != null )
&& ( toAdd.getAttribute( "implementation", null ) == null ) )
{
XmlPlexusConfiguration implementationConf = new XmlPlexusConfiguration(
paramName );
implementationConf.setAttribute( "implementation",
parameter.getImplementation() );
toAdd = buildTopDownMergedConfiguration( toAdd, implementationConf );
}
result.addChild( toAdd );
}
}
}
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 );
// TODO: recessive seems to be dominant here?
result.setAttribute( attributeNames[i], attributeValue );
}
}
PlexusConfiguration[] children = dominant.getChildren();
for ( int i = 0; i < children.length; i++ )
{
PlexusConfiguration childDom = children[i];
PlexusConfiguration childRec = recessive == null ? null
: recessive.getChild( childDom.getName(), false );
if ( childRec != null )
{
result.addChild( buildTopDownMergedConfiguration( childDom, childRec ) );
}
else
{ // FIXME: copy, or use reference?
result.addChild( copyConfiguration( childDom ) );
}
}
return result;
}
public static PlexusConfiguration copyConfiguration( PlexusConfiguration src )
{
// TODO: shouldn't be necessary
XmlPlexusConfiguration dom = new XmlPlexusConfiguration( src.getName() );
dom.setValue( src.getValue( null ) );
String[] attributeNames = src.getAttributeNames();
for ( int i = 0; i < attributeNames.length; i++ )
{
String attributeName = attributeNames[i];
dom.setAttribute( attributeName, src.getAttribute( attributeName, null ) );
}
PlexusConfiguration[] children = src.getChildren();
for ( int i = 0; i < children.length; i++ )
{
dom.addChild( copyConfiguration( children[i] ) );
}
return dom;
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Mojo Parameter Handling // Mojo Parameter Handling
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------