in maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java [639:736]
private Mojo getConfiguredMojo( MavenSession session,
Xpp3Dom dom,
MavenProject project,
boolean report,
MojoExecution mojoExecution )
throws PluginConfigurationException, ArtifactNotFoundException, PluginManagerException,
ArtifactResolutionException
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
PlexusContainer pluginContainer = getPluginContainer( pluginDescriptor );
// if this is the first time this plugin has been used, the plugin's container will only
// contain the plugin's artifact in isolation; we need to finish resolving the plugin's
// dependencies, and add them to the container.
ensurePluginContainerIsComplete( pluginDescriptor, pluginContainer, project, session );
Mojo plugin;
try
{
plugin = (Mojo) pluginContainer.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() );
if ( report && !( plugin instanceof MavenReport ) )
{
// TODO: the mojoDescriptor should actually capture this information so we don't get this far
return null;
}
}
catch ( ComponentLookupException e )
{
Throwable cause = e.getCause();
while ( cause != null && !( cause instanceof NoClassDefFoundError ) )
{
cause = cause.getCause();
}
if ( cause != null && ( cause instanceof NoClassDefFoundError ) )
{
throw new PluginManagerException( "Unable to load the mojo '" + mojoDescriptor.getRoleHint()
+ "' in the plugin '" + pluginDescriptor.getPluginLookupKey() + "'. A required class is missing: "
+ cause.getMessage(), e );
}
throw new PluginManagerException( "Unable to find the mojo '" + mojoDescriptor.getGoal()
+ "' (or one of its required components) in the plugin '" + pluginDescriptor.getPluginLookupKey() + "'", e );
}
catch ( NoClassDefFoundError e )
{
throw new PluginManagerException( "Unable to load the mojo '" + mojoDescriptor.getRoleHint()
+ "' in the plugin '" + pluginDescriptor.getPluginLookupKey() + "'. A required class is missing: "
+ e.getMessage(), e );
}
if ( plugin instanceof ContextEnabled )
{
Map pluginContext = session.getPluginContext( pluginDescriptor, project );
( (ContextEnabled) plugin ).setPluginContext( pluginContext );
}
plugin.setLog( mojoLogger );
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( session, mojoExecution,
pathTranslator,
getLogger(),
project,
session.getExecutionProperties() );
PlexusConfiguration extractedMojoConfiguration =
extractMojoConfiguration( mergedConfiguration, mojoDescriptor );
checkRequiredParameters( mojoDescriptor, extractedMojoConfiguration, expressionEvaluator );
populatePluginFields( plugin, mojoDescriptor, extractedMojoConfiguration, pluginContainer,
expressionEvaluator );
return plugin;
}