fixing formats at top of file (may be other formatting changes...)

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@574387 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2007-09-10 22:20:31 +00:00
parent 3bc1f858e1
commit b1159725a5
1 changed files with 291 additions and 184 deletions

View File

@ -165,16 +165,17 @@ public class DefaultPluginManager
public PluginDescriptor verifyPlugin( Plugin plugin, public PluginDescriptor verifyPlugin( Plugin plugin,
MavenProject project, MavenProject project,
MavenSession session ) MavenSession session )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException, throws ArtifactResolutionException, PluginVersionResolutionException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException, ArtifactNotFoundException, InvalidVersionSpecificationException, InvalidPluginException,
PluginVersionNotFoundException PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException
{ {
// TODO: this should be possibly outside // TODO: this should be possibly outside
// All version-resolution logic has been moved to DefaultPluginVersionManager. // All version-resolution logic has been moved to DefaultPluginVersionManager.
if ( plugin.getVersion() == null ) if ( plugin.getVersion() == null )
{ {
getLogger().debug( "Resolving version for plugin: " + plugin.getKey() ); getLogger().debug( "Resolving version for plugin: " + plugin.getKey() );
String version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(), String version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(),
plugin.getArtifactId(),
project, session ); project, session );
plugin.setVersion( version ); plugin.setVersion( version );
} }
@ -185,18 +186,21 @@ public class DefaultPluginManager
private PluginDescriptor verifyVersionedPlugin( Plugin plugin, private PluginDescriptor verifyVersionedPlugin( Plugin plugin,
MavenProject project, MavenProject project,
MavenSession session ) MavenSession session )
throws PluginVersionResolutionException, ArtifactNotFoundException, ArtifactResolutionException, throws PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException ArtifactResolutionException, InvalidVersionSpecificationException, InvalidPluginException,
PluginManagerException, PluginNotFoundException
{ {
ArtifactRepository localRepository = session.getLocalRepository(); ArtifactRepository localRepository = session.getLocalRepository();
return verifyVersionedPlugin( plugin, project, localRepository ); return verifyVersionedPlugin( plugin, project, localRepository );
} }
private PluginDescriptor verifyVersionedPlugin( Plugin plugin, MavenProject project, private PluginDescriptor verifyVersionedPlugin( Plugin plugin,
MavenProject project,
ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws PluginVersionResolutionException, ArtifactNotFoundException, ArtifactResolutionException, throws PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException ArtifactResolutionException, InvalidVersionSpecificationException, InvalidPluginException,
PluginManagerException, PluginNotFoundException
{ {
getLogger().debug( "In verifyVersionedPlugin for: " + plugin.getKey() ); getLogger().debug( "In verifyVersionedPlugin for: " + plugin.getKey() );
@ -219,18 +223,23 @@ public class DefaultPluginManager
checkRequiredMavenVersion( plugin, localRepository, remoteRepositories ); checkRequiredMavenVersion( plugin, localRepository, remoteRepositories );
Artifact pluginArtifact = Artifact pluginArtifact = artifactFactory.createPluginArtifact(
artifactFactory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), versionRange ); plugin.getGroupId(),
plugin.getArtifactId(),
versionRange );
pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact ); pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
artifactResolver.resolve( pluginArtifact, project.getPluginArtifactRepositories(), localRepository ); artifactResolver.resolve( pluginArtifact, project.getPluginArtifactRepositories(),
localRepository );
addPlugin( plugin, pluginArtifact, project, localRepository ); addPlugin( plugin, pluginArtifact, project, localRepository );
} }
else else
{ {
getLogger().debug( "Skipping resolution for Maven built-in plugin: " + plugin.getKey() ); getLogger().debug(
"Skipping resolution for Maven built-in plugin: "
+ plugin.getKey() );
PluginDescriptor pd = pluginCollector.getPluginDescriptor( plugin ); PluginDescriptor pd = pluginCollector.getPluginDescriptor( plugin );
pd.setClassRealm( container.getContainerRealm() ); pd.setClassRealm( container.getContainerRealm() );
@ -250,8 +259,8 @@ public class DefaultPluginManager
{ {
throw new PluginNotFoundException( e ); throw new PluginNotFoundException( e );
} }
else if ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() ) && else if ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() )
version.equals( e.getVersion() ) && "maven-plugin".equals( e.getType() ) ) && version.equals( e.getVersion() ) && "maven-plugin".equals( e.getType() ) )
{ {
throw new PluginNotFoundException( e ); throw new PluginNotFoundException( e );
} }
@ -277,26 +286,32 @@ public class DefaultPluginManager
{ {
try try
{ {
Artifact artifact = artifactFactory.createProjectArtifact( plugin.getGroupId(), plugin.getArtifactId(), Artifact artifact = artifactFactory.createProjectArtifact( plugin.getGroupId(),
plugin.getArtifactId(),
plugin.getVersion() ); plugin.getVersion() );
MavenProject project = MavenProject project = mavenProjectBuilder.buildFromRepository( artifact,
mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository, false ); remoteRepositories,
localRepository, false );
// if we don't have the required Maven version, then ignore an update // if we don't have the required Maven version, then ignore an update
if ( ( project.getPrerequisites() != null ) && ( project.getPrerequisites().getMaven() != null ) ) if ( ( project.getPrerequisites() != null )
&& ( project.getPrerequisites().getMaven() != null ) )
{ {
DefaultArtifactVersion requiredVersion = DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion(
new DefaultArtifactVersion( project.getPrerequisites().getMaven() ); project.getPrerequisites()
.getMaven() );
if ( runtimeInformation.getApplicationVersion().compareTo( requiredVersion ) < 0 ) if ( runtimeInformation.getApplicationVersion().compareTo( requiredVersion ) < 0 )
{ {
throw new PluginVersionResolutionException( plugin.getGroupId(), plugin.getArtifactId(), throw new PluginVersionResolutionException( plugin.getGroupId(),
"Plugin requires Maven version " + requiredVersion ); plugin.getArtifactId(),
"Plugin requires Maven version "
+ requiredVersion );
} }
} }
} }
catch ( ProjectBuildingException e ) catch ( ProjectBuildingException e )
{ {
throw new InvalidPluginException( throw new InvalidPluginException( "Unable to build project for plugin '"
"Unable to build project for plugin '" + plugin.getKey() + "': " + e.getMessage(), e ); + plugin.getKey() + "': " + e.getMessage(), e );
} }
} }
@ -304,7 +319,8 @@ public class DefaultPluginManager
Artifact pluginArtifact, Artifact pluginArtifact,
MavenProject project, MavenProject project,
ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws ArtifactNotFoundException, ArtifactResolutionException, PluginManagerException, InvalidPluginException throws ArtifactNotFoundException, ArtifactResolutionException, PluginManagerException,
InvalidPluginException
{ {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Get the dependencies for the Plugin // Get the dependencies for the Plugin
@ -329,7 +345,8 @@ public class DefaultPluginManager
Artifact pluginArtifact, Artifact pluginArtifact,
MavenProject project, MavenProject project,
MavenSession session ) MavenSession session )
throws ArtifactNotFoundException, ArtifactResolutionException, PluginManagerException, InvalidPluginException throws ArtifactNotFoundException, ArtifactResolutionException, PluginManagerException,
InvalidPluginException
{ {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Get the dependencies for the Plugin // Get the dependencies for the Plugin
@ -345,13 +362,18 @@ public class DefaultPluginManager
projectPlugin = plugin; projectPlugin = plugin;
} }
Set artifacts = getPluginArtifacts( pluginArtifact, projectPlugin, project, session.getLocalRepository() ); Set artifacts = getPluginArtifacts( pluginArtifact, projectPlugin, project,
session.getLocalRepository() );
addPlugin( plugin, projectPlugin, pluginArtifact, artifacts ); addPlugin( plugin, projectPlugin, pluginArtifact, artifacts );
} }
private void addPlugin( Plugin plugin, Plugin projectPlugin, Artifact pluginArtifact, Set artifacts ) private void addPlugin( Plugin plugin,
throws ArtifactNotFoundException, ArtifactResolutionException, PluginManagerException, InvalidPluginException Plugin projectPlugin,
Artifact pluginArtifact,
Set artifacts )
throws ArtifactNotFoundException, ArtifactResolutionException, PluginManagerException,
InvalidPluginException
{ {
// TODO When/if we go to project-level plugin instances (like for plugin-level deps in the // TODO When/if we go to project-level plugin instances (like for plugin-level deps in the
// POM), we need to undo this somehow. // POM), we need to undo this somehow.
@ -359,7 +381,9 @@ public class DefaultPluginManager
if ( ( pluginRealm != null ) && ( pluginRealm != container.getContainerRealm() ) ) if ( ( pluginRealm != null ) && ( pluginRealm != container.getContainerRealm() ) )
{ {
getLogger().debug( "Realm already exists for: " + projectPlugin.getKey() + ". Skipping addition..." ); getLogger().debug(
"Realm already exists for: " + projectPlugin.getKey()
+ ". Skipping addition..." );
// we've already discovered this plugin, and configured it, so skip it this time. // we've already discovered this plugin, and configured it, so skip it this time.
return; return;
@ -390,30 +414,37 @@ public class DefaultPluginManager
// adding for MNG-3012 to try to work around problems with Xpp3Dom (from plexus-utils) // adding for MNG-3012 to try to work around problems with Xpp3Dom (from plexus-utils)
// spawning a ClassCastException when a mojo calls plugin.getConfiguration() from maven-model... // spawning a ClassCastException when a mojo calls plugin.getConfiguration() from maven-model...
componentRealm.importFrom( componentRealm.getParentRealm().getId(), Xpp3Dom.class.getName() ); componentRealm.importFrom( componentRealm.getParentRealm().getId(),
componentRealm.importFrom( componentRealm.getParentRealm().getId(), "org.codehaus.plexus.util.xml.pull" ); Xpp3Dom.class.getName() );
componentRealm.importFrom( componentRealm.getParentRealm().getId(),
"org.codehaus.plexus.util.xml.pull" );
} }
catch ( PlexusContainerException e ) catch ( PlexusContainerException e )
{ {
throw new PluginManagerException( "Failed to create realm for plugin '" + projectPlugin + ".", e ); throw new PluginManagerException( "Failed to create realm for plugin '" + projectPlugin
+ ".", e );
} }
catch ( NoSuchRealmException e ) catch ( NoSuchRealmException e )
{ {
throw new PluginManagerException( "Failed to import Xpp3Dom from parent realm for plugin: '" + projectPlugin + ".", e ); throw new PluginManagerException(
"Failed to import Xpp3Dom from parent realm for plugin: '"
+ projectPlugin + ".", e );
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// The PluginCollector will now know about the plugin we are trying to load // The PluginCollector will now know about the plugin we are trying to load
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
getLogger().debug( "Checking for plugin descriptor for: " + plugin.getKey() + " in collector: " + pluginCollector ); getLogger().debug(
"Checking for plugin descriptor for: " + plugin.getKey()
+ " in collector: " + pluginCollector );
PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( projectPlugin ); PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( projectPlugin );
if ( pluginDescriptor == null ) if ( pluginDescriptor == null )
{ {
throw new IllegalStateException( throw new IllegalStateException( "The PluginDescriptor for the plugin "
"The PluginDescriptor for the plugin " + projectPlugin.getKey() + " was not found" ); + projectPlugin.getKey() + " was not found" );
} }
pluginDescriptor.setPluginArtifact( pluginArtifact ); pluginDescriptor.setPluginArtifact( pluginArtifact );
@ -432,7 +463,9 @@ public class DefaultPluginManager
pluginDescriptor.setClassRealm( componentRealm ); pluginDescriptor.setClassRealm( componentRealm );
} }
private Set getPluginArtifacts( Artifact pluginArtifact, Plugin plugin, MavenProject project, private Set getPluginArtifacts( Artifact pluginArtifact,
Plugin plugin,
MavenProject project,
ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws InvalidPluginException, ArtifactNotFoundException, ArtifactResolutionException throws InvalidPluginException, ArtifactNotFoundException, ArtifactResolutionException
{ {
@ -441,25 +474,35 @@ public class DefaultPluginManager
try try
{ {
projectPluginDependencies = MavenMetadataSource.createArtifacts( artifactFactory, plugin.getDependencies(), null, projectPluginDependencies = MavenMetadataSource.createArtifacts(
coreArtifactFilterManager.getCoreArtifactFilter(), project ); artifactFactory,
plugin.getDependencies(),
null,
coreArtifactFilterManager.getCoreArtifactFilter(),
project );
} }
catch ( InvalidDependencyVersionException e ) catch ( InvalidDependencyVersionException e )
{ {
throw new InvalidPluginException( "Plugin '" + plugin + "' is invalid: " + e.getMessage(), e ); throw new InvalidPluginException( "Plugin '" + plugin + "' is invalid: "
+ e.getMessage(), e );
} }
ResolutionGroup resolutionGroup; ResolutionGroup resolutionGroup;
try try
{ {
resolutionGroup = artifactMetadataSource.retrieve( pluginArtifact, localRepository, resolutionGroup = artifactMetadataSource.retrieve(
pluginArtifact,
localRepository,
project.getPluginArtifactRepositories() ); project.getPluginArtifactRepositories() );
} }
catch ( ArtifactMetadataRetrievalException e ) catch ( ArtifactMetadataRetrievalException e )
{ {
throw new ArtifactResolutionException( "Unable to download metadata from repository for plugin '" + throw new ArtifactResolutionException(
pluginArtifact.getId() + "': " + e.getMessage(), pluginArtifact, e ); "Unable to download metadata from repository for plugin '"
+ pluginArtifact.getId() + "': "
+ e.getMessage(),
pluginArtifact, e );
} }
checkPlexusUtils( resolutionGroup, artifactFactory ); checkPlexusUtils( resolutionGroup, artifactFactory );
@ -478,9 +521,12 @@ public class DefaultPluginManager
repositories.addAll( project.getRemoteArtifactRepositories() ); repositories.addAll( project.getRemoteArtifactRepositories() );
ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencies, pluginArtifact, ArtifactResolutionResult result = artifactResolver.resolveTransitively(
dependencies,
pluginArtifact,
Collections.EMPTY_MAP, Collections.EMPTY_MAP,
localRepository, repositories, localRepository,
repositories,
artifactMetadataSource, artifactMetadataSource,
coreArtifactFilterManager.getArtifactFilter() ); coreArtifactFilterManager.getArtifactFilter() );
@ -496,7 +542,10 @@ public class DefaultPluginManager
} }
} }
getLogger().debug( "Using the following artifacts for classpath of: " + pluginArtifact.getId() + ":\n\n" + resolved.toString().replace( ',', '\n' ) ); getLogger().debug(
"Using the following artifacts for classpath of: "
+ pluginArtifact.getId() + ":\n\n"
+ resolved.toString().replace( ',', '\n' ) );
return resolved; return resolved;
} }
@ -508,8 +557,9 @@ public class DefaultPluginManager
public void executeMojo( MavenProject project, public void executeMojo( MavenProject project,
MojoExecution mojoExecution, MojoExecution mojoExecution,
MavenSession session ) MavenSession session )
throws ArtifactResolutionException, MojoExecutionException, MojoFailureException, ArtifactNotFoundException, throws ArtifactResolutionException, MojoExecutionException, MojoFailureException,
InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException ArtifactNotFoundException, InvalidDependencyVersionException, PluginManagerException,
PluginConfigurationException
{ {
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
@ -517,15 +567,19 @@ public class DefaultPluginManager
// anything that wants to execute a mojo. // anything that wants to execute a mojo.
if ( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem() ) if ( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem() )
{ {
throw new MojoExecutionException( "Cannot execute mojo: " + mojoDescriptor.getGoal() + throw new MojoExecutionException(
". It requires a project with an existing pom.xml, but the build is not using one." ); "Cannot execute mojo: "
+ mojoDescriptor.getGoal()
+ ". It requires a project with an existing pom.xml, but the build is not using one." );
} }
if ( mojoDescriptor.isOnlineRequired() && session.getSettings().isOffline() ) if ( mojoDescriptor.isOnlineRequired() && session.getSettings().isOffline() )
{ {
// TODO: Should we error out, or simply warn and skip?? // TODO: Should we error out, or simply warn and skip??
throw new MojoExecutionException( "Mojo: " + mojoDescriptor.getGoal() + throw new MojoExecutionException(
" requires online mode for execution. Maven is currently offline." ); "Mojo: "
+ mojoDescriptor.getGoal()
+ " requires online mode for execution. Maven is currently offline." );
} }
if ( mojoDescriptor.isDependencyResolutionRequired() != null ) if ( mojoDescriptor.isDependencyResolutionRequired() != null )
@ -546,7 +600,8 @@ public class DefaultPluginManager
MavenProject p = (MavenProject) i.next(); MavenProject p = (MavenProject) i.next();
resolveTransitiveDependencies( session, artifactResolver, resolveTransitiveDependencies( session, artifactResolver,
mojoDescriptor.isDependencyResolutionRequired(), artifactFactory, p ); mojoDescriptor.isDependencyResolutionRequired(),
artifactFactory, p );
} }
downloadDependencies( project, session, artifactResolver ); downloadDependencies( project, session, artifactResolver );
@ -638,7 +693,8 @@ public class DefaultPluginManager
{ {
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
PluginDescriptor descriptor = mojoDescriptor.getPluginDescriptor(); PluginDescriptor descriptor = mojoDescriptor.getPluginDescriptor();
Xpp3Dom dom = project.getReportConfiguration( descriptor.getGroupId(), descriptor.getArtifactId(), Xpp3Dom dom = project.getReportConfiguration( descriptor.getGroupId(),
descriptor.getArtifactId(),
mojoExecution.getExecutionId() ); mojoExecution.getExecutionId() );
if ( mojoExecution.getConfiguration() != null ) if ( mojoExecution.getConfiguration() != null )
{ {
@ -651,16 +707,18 @@ public class DefaultPluginManager
public PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, public PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin,
MavenProject project, MavenProject project,
MavenSession session ) MavenSession session )
throws PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException, throws PluginVersionResolutionException, ArtifactResolutionException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException, ArtifactNotFoundException, InvalidVersionSpecificationException, InvalidPluginException,
PluginVersionNotFoundException PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException
{ {
String version = reportPlugin.getVersion(); String version = reportPlugin.getVersion();
if ( version == null ) if ( version == null )
{ {
version = pluginVersionManager.resolveReportPluginVersion( reportPlugin.getGroupId(), version = pluginVersionManager.resolveReportPluginVersion(
reportPlugin.getArtifactId(), project, session ); reportPlugin.getGroupId(),
reportPlugin.getArtifactId(),
project, session );
reportPlugin.setVersion( version ); reportPlugin.setVersion( version );
} }
@ -705,13 +763,18 @@ public class DefaultPluginManager
{ {
ClassRealm oldRealm = container.setLookupRealm( realm ); ClassRealm oldRealm = container.setLookupRealm( realm );
getLogger().debug( "Looking up mojo " + mojoDescriptor.getRoleHint() + " in realm " + realm.getId() + " - descRealmId=" + mojoDescriptor.getRealmId() ); getLogger().debug(
"Looking up mojo " + mojoDescriptor.getRoleHint() + " in realm "
+ realm.getId() + " - descRealmId="
+ mojoDescriptor.getRealmId() );
plugin = (Mojo) container.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint(), realm ); plugin = (Mojo) container.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint(), realm );
if ( plugin != null ) if ( plugin != null )
{ {
getLogger().debug( "Looked up - " + plugin + " - " + plugin.getClass().getClassLoader() ); getLogger().debug(
"Looked up - " + plugin + " - "
+ plugin.getClass().getClassLoader() );
} }
else else
{ {
@ -722,13 +785,19 @@ public class DefaultPluginManager
} }
else else
{ {
getLogger().info( "Looking up mojo " + mojoDescriptor.getRoleHint() + " in default realm " + container.getLookupRealm() + " - descRealmId=" + mojoDescriptor.getRealmId() ); getLogger().info(
"Looking up mojo " + mojoDescriptor.getRoleHint()
+ " in default realm "
+ container.getLookupRealm() + " - descRealmId="
+ mojoDescriptor.getRealmId() );
plugin = (Mojo) container.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() ); plugin = (Mojo) container.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() );
if ( plugin != null ) if ( plugin != null )
{ {
getLogger().info( "Looked up - " + plugin + " - " + plugin.getClass().getClassLoader() ); getLogger().info(
"Looked up - " + plugin + " - "
+ plugin.getClass().getClassLoader() );
} }
else else
{ {
@ -737,8 +806,6 @@ public class DefaultPluginManager
} }
if ( report && !( plugin instanceof MavenReport ) ) if ( report && !( plugin instanceof MavenReport ) )
{ {
// TODO: the mojoDescriptor should actually capture this information so we don't get this far // TODO: the mojoDescriptor should actually capture this information so we don't get this far
@ -747,8 +814,9 @@ public class DefaultPluginManager
} }
catch ( ComponentLookupException e ) catch ( ComponentLookupException e )
{ {
throw new PluginManagerException( "Unable to find the mojo '" + mojoDescriptor.getRoleHint() + throw new PluginManagerException( "Unable to find the mojo '"
"' in the plugin '" + pluginDescriptor.getPluginLookupKey() + "'", e ); + mojoDescriptor.getRoleHint() + "' in the plugin '"
+ pluginDescriptor.getPluginLookupKey() + "'", e );
} }
if ( plugin instanceof ContextEnabled ) if ( plugin instanceof ContextEnabled )
@ -764,7 +832,6 @@ public class DefaultPluginManager
plugin.setLog( mojoLogger ); plugin.setLog( mojoLogger );
XmlPlexusConfiguration pomConfiguration; XmlPlexusConfiguration pomConfiguration;
if ( dom == null ) if ( dom == null )
@ -780,7 +847,8 @@ public class DefaultPluginManager
// override in the POM. // override in the POM.
validatePomConfiguration( mojoDescriptor, pomConfiguration ); validatePomConfiguration( mojoDescriptor, pomConfiguration );
PlexusConfiguration mergedConfiguration = mergeMojoConfiguration( pomConfiguration, mojoDescriptor ); PlexusConfiguration mergedConfiguration = mergeMojoConfiguration( pomConfiguration,
mojoDescriptor );
// TODO: plexus changes to make this more like the component descriptor so this can be used instead // TODO: plexus changes to make this more like the component descriptor so this can be used instead
// PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration, // PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration,
@ -794,16 +862,22 @@ public class DefaultPluginManager
ctx = new LifecycleExecutionContext( project ); ctx = new LifecycleExecutionContext( project );
} }
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, mojoExecution, pathTranslator, ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(
ctx, getLogger(), session,
mojoExecution,
pathTranslator,
ctx,
getLogger(),
session.getExecutionProperties() ); session.getExecutionProperties() );
PlexusConfiguration extractedMojoConfiguration = PlexusConfiguration extractedMojoConfiguration = extractMojoConfiguration(
extractMojoConfiguration( mergedConfiguration, mojoDescriptor ); mergedConfiguration,
mojoDescriptor );
checkRequiredParameters( mojoDescriptor, extractedMojoConfiguration, expressionEvaluator ); checkRequiredParameters( mojoDescriptor, extractedMojoConfiguration, expressionEvaluator );
populatePluginFields( plugin, mojoDescriptor, extractedMojoConfiguration, container, expressionEvaluator ); populatePluginFields( plugin, mojoDescriptor, extractedMojoConfiguration, container,
expressionEvaluator );
return plugin; return plugin;
} }
@ -831,8 +905,11 @@ public class DefaultPluginManager
// ideally, this would be elevated above the true debug output, but below the default INFO 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 // [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. // removed - shouldn't need DEBUG to diagnose a problem most of the time.
getLogger().debug( "*** WARNING: Configuration \'" + child.getName() + "\' is not used in goal \'" + getLogger().debug(
mojoDescriptor.getFullGoalName() + "; this may indicate a typo... ***" ); "*** WARNING: Configuration \'" + child.getName()
+ "\' is not used in goal \'"
+ mojoDescriptor.getFullGoalName()
+ "; this may indicate a typo... ***" );
} }
} }
@ -897,11 +974,13 @@ public class DefaultPluginManager
} }
catch ( ExpressionEvaluationException e ) catch ( ExpressionEvaluationException e )
{ {
throw new PluginConfigurationException( goal.getPluginDescriptor(), e.getMessage(), e ); throw new PluginConfigurationException( goal.getPluginDescriptor(),
e.getMessage(), e );
} }
// only mark as invalid if there are no child nodes // only mark as invalid if there are no child nodes
if ( ( fieldValue == null ) && ( ( value == null ) || ( value.getChildCount() == 0 ) ) ) if ( ( fieldValue == null )
&& ( ( value == null ) || ( value.getChildCount() == 0 ) ) )
{ {
parameter.setExpression( expression ); parameter.setExpression( expression );
invalidParameters.add( parameter ); invalidParameters.add( parameter );
@ -946,12 +1025,12 @@ public class DefaultPluginManager
// Make sure the parameter is either editable/configurable, or else is NOT specified in the POM // Make sure the parameter is either editable/configurable, or else is NOT specified in the POM
if ( !parameter.isEditable() ) if ( !parameter.isEditable() )
{ {
StringBuffer errorMessage = new StringBuffer() StringBuffer errorMessage = new StringBuffer().append( "ERROR: Cannot override read-only parameter: " );
.append( "ERROR: Cannot override read-only parameter: " );
errorMessage.append( key ); errorMessage.append( key );
errorMessage.append( " in goal: " ).append( goal.getFullGoalName() ); errorMessage.append( " in goal: " ).append( goal.getFullGoalName() );
throw new PluginConfigurationException( goal.getPluginDescriptor(), errorMessage.toString() ); throw new PluginConfigurationException( goal.getPluginDescriptor(),
errorMessage.toString() );
} }
String deprecated = parameter.getDeprecated(); String deprecated = parameter.getDeprecated();
@ -1009,7 +1088,8 @@ public class DefaultPluginManager
{ {
pomConfig = buildTopDownMergedConfiguration( pomConfig, mojoConfig ); pomConfig = buildTopDownMergedConfiguration( pomConfig, mojoConfig );
if ( StringUtils.isNotEmpty( pomConfig.getValue( null ) ) || ( pomConfig.getChildCount() > 0 ) ) if ( StringUtils.isNotEmpty( pomConfig.getValue( null ) )
|| ( pomConfig.getChildCount() > 0 ) )
{ {
toAdd = pomConfig; toAdd = pomConfig;
} }
@ -1022,12 +1102,15 @@ public class DefaultPluginManager
if ( toAdd != null ) if ( toAdd != null )
{ {
if ( ( implementation != null ) && ( toAdd.getAttribute( "implementation", null ) == null ) ) if ( ( implementation != null )
&& ( toAdd.getAttribute( "implementation", null ) == null ) )
{ {
XmlPlexusConfiguration implementationConf = new XmlPlexusConfiguration( paramName ); XmlPlexusConfiguration implementationConf = new XmlPlexusConfiguration(
paramName );
implementationConf.setAttribute( "implementation", parameter.getImplementation() ); implementationConf.setAttribute( "implementation",
parameter.getImplementation() );
toAdd = buildTopDownMergedConfiguration( toAdd, implementationConf ); toAdd = buildTopDownMergedConfiguration( toAdd, implementationConf );
} }
@ -1082,7 +1165,8 @@ public class DefaultPluginManager
for ( int i = 0; i < children.length; i++ ) for ( int i = 0; i < children.length; i++ )
{ {
PlexusConfiguration childDom = children[i]; PlexusConfiguration childDom = children[i];
PlexusConfiguration childRec = recessive == null ? null : recessive.getChild( childDom.getName(), false ); PlexusConfiguration childRec = recessive == null ? null
: recessive.getChild( childDom.getName(), false );
if ( childRec != null ) if ( childRec != null )
{ {
@ -1142,12 +1226,16 @@ public class DefaultPluginManager
// so that this meethod could entirely be handled by a plexus lookup? // so that this meethod could entirely be handled by a plexus lookup?
if ( StringUtils.isNotEmpty( configuratorId ) ) if ( StringUtils.isNotEmpty( configuratorId ) )
{ {
configurator = configurator = (ComponentConfigurator) pluginContainer.lookup(
(ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE, configuratorId, pluginRealm ); ComponentConfigurator.ROLE,
configuratorId,
pluginRealm );
} }
else else
{ {
configurator = (ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE, "basic", pluginRealm ); configurator = (ComponentConfigurator) pluginContainer.lookup(
ComponentConfigurator.ROLE,
"basic", pluginRealm );
} }
ConfigurationListener listener = new DebugConfigurationListener( getLogger() ); ConfigurationListener listener = new DebugConfigurationListener( getLogger() );
@ -1155,18 +1243,22 @@ public class DefaultPluginManager
getLogger().debug( "Configuring mojo '" + mojoDescriptor.getId() + "' -->" ); getLogger().debug( "Configuring mojo '" + mojoDescriptor.getId() + "' -->" );
// This needs to be able to use methods // This needs to be able to use methods
configurator.configureComponent( plugin, configuration, expressionEvaluator, pluginRealm, listener ); configurator.configureComponent( plugin, configuration, expressionEvaluator,
pluginRealm, listener );
getLogger().debug( "-- end configuration --" ); getLogger().debug( "-- end configuration --" );
} }
catch ( ComponentConfigurationException e ) catch ( ComponentConfigurationException e )
{ {
throw new PluginConfigurationException( mojoDescriptor.getPluginDescriptor(), throw new PluginConfigurationException(
"Unable to parse the created DOM for plugin configuration", e ); mojoDescriptor.getPluginDescriptor(),
"Unable to parse the created DOM for plugin configuration",
e );
} }
catch ( ComponentLookupException e ) catch ( ComponentLookupException e )
{ {
throw new PluginConfigurationException( mojoDescriptor.getPluginDescriptor(), throw new PluginConfigurationException(
mojoDescriptor.getPluginDescriptor(),
"Unable to retrieve component configurator for plugin configuration", "Unable to retrieve component configurator for plugin configuration",
e ); e );
} }
@ -1226,13 +1318,16 @@ public class DefaultPluginManager
String scope, String scope,
ArtifactFactory artifactFactory, ArtifactFactory artifactFactory,
MavenProject project ) MavenProject project )
throws ArtifactResolutionException, ArtifactNotFoundException, InvalidDependencyVersionException throws ArtifactResolutionException, ArtifactNotFoundException,
InvalidDependencyVersionException
{ {
ArtifactFilter filter = new ScopeArtifactFilter( scope ); ArtifactFilter filter = new ScopeArtifactFilter( scope );
// TODO: such a call in MavenMetadataSource too - packaging not really the intention of type // TODO: such a call in MavenMetadataSource too - packaging not really the intention of type
Artifact artifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(), Artifact artifact = artifactFactory.createBuildArtifact( project.getGroupId(),
project.getVersion(), project.getPackaging() ); project.getArtifactId(),
project.getVersion(),
project.getPackaging() );
// TODO: we don't need to resolve over and over again, as long as we are sure that the parameters are the same // TODO: we don't need to resolve over and over again, as long as we are sure that the parameters are the same
// check this with yourkit as a hot spot. // check this with yourkit as a hot spot.
@ -1241,12 +1336,14 @@ public class DefaultPluginManager
{ {
project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) ); project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
} }
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(), ArtifactResolutionResult result = artifactResolver.resolveTransitively(
project.getDependencyArtifacts(),
artifact, artifact,
Collections.EMPTY_MAP, Collections.EMPTY_MAP,
context.getLocalRepository(), context.getLocalRepository(),
project.getRemoteArtifactRepositories(), project.getRemoteArtifactRepositories(),
artifactMetadataSource, filter ); artifactMetadataSource,
filter );
project.setArtifacts( result.getArtifacts() ); project.setArtifacts( result.getArtifacts() );
} }
@ -1271,21 +1368,26 @@ public class DefaultPluginManager
} }
} }
public Object getPluginComponent( Plugin plugin, String role, String roleHint ) public Object getPluginComponent( Plugin plugin,
String role,
String roleHint )
throws PluginManagerException, ComponentLookupException throws PluginManagerException, ComponentLookupException
{ {
ClassRealm pluginRealm = pluginCollector.getPluginDescriptor( plugin ).getClassRealm(); ClassRealm pluginRealm = pluginCollector.getPluginDescriptor( plugin ).getClassRealm();
if ( pluginRealm == null ) if ( pluginRealm == null )
{ {
getLogger().warn( "getPluginComponent(" + plugin + ", " + role + "): descriptor is missing classRealm" ); getLogger().warn(
"getPluginComponent(" + plugin + ", " + role
+ "): descriptor is missing classRealm" );
pluginRealm = container.getLookupRealm(); pluginRealm = container.getLookupRealm();
} }
return container.lookup( role, roleHint, pluginRealm ); return container.lookup( role, roleHint, pluginRealm );
} }
public Map getPluginComponents( Plugin plugin, String role ) public Map getPluginComponents( Plugin plugin,
String role )
throws ComponentLookupException, PluginManagerException throws ComponentLookupException, PluginManagerException
{ {
getLogger().debug( "Looking for plugin realm: " + plugin + " using: " + pluginCollector ); getLogger().debug( "Looking for plugin realm: " + plugin + " using: " + pluginCollector );
@ -1294,14 +1396,17 @@ public class DefaultPluginManager
if ( pluginRealm == null ) if ( pluginRealm == null )
{ {
getLogger().warn( "getPluginComponent(" + plugin + ", " + role + "): descriptor is missing classRealm" ); getLogger().warn(
"getPluginComponent(" + plugin + ", " + role
+ "): descriptor is missing classRealm" );
pluginRealm = container.getLookupRealm(); pluginRealm = container.getLookupRealm();
} }
return container.lookupMap( role, pluginRealm ); return container.lookupMap( role, pluginRealm );
} }
public static void checkPlexusUtils( ResolutionGroup resolutionGroup, ArtifactFactory artifactFactory ) public static void checkPlexusUtils( ResolutionGroup resolutionGroup,
ArtifactFactory artifactFactory )
{ {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// If the plugin already declares a dependency on plexus-utils then we're all // If the plugin already declares a dependency on plexus-utils then we're all
@ -1330,8 +1435,8 @@ public class DefaultPluginManager
{ {
Artifact a = (Artifact) i.next(); Artifact a = (Artifact) i.next();
if ( a.getArtifactId().equals( "plexus-utils" ) && if ( a.getArtifactId().equals( "plexus-utils" )
vr.containsVersion( new DefaultArtifactVersion( a.getVersion() ) ) ) && vr.containsVersion( new DefaultArtifactVersion( a.getVersion() ) ) )
{ {
plexusUtilsPresent = true; plexusUtilsPresent = true;
@ -1345,7 +1450,9 @@ public class DefaultPluginManager
// version to the latest version we know that works as of the 2.0.6 release. We set the scope to runtime // version to the latest version we know that works as of the 2.0.6 release. We set the scope to runtime
// as this is what's implicitly happening in 2.0.6. // as this is what's implicitly happening in 2.0.6.
resolutionGroup.getArtifacts().add( artifactFactory.createArtifact( "org.codehaus.plexus", resolutionGroup.getArtifacts()
.add(
artifactFactory.createArtifact( "org.codehaus.plexus",
"plexus-utils", "1.1", "plexus-utils", "1.1",
Artifact.SCOPE_RUNTIME, "jar" ) ); Artifact.SCOPE_RUNTIME, "jar" ) );
} }