o more separation of plugins from reporting

o more sequencing of plugin resolution and execution


git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@757109 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-03-22 00:13:42 +00:00
parent 0f70fd4a0f
commit 66d06cee8a
4 changed files with 96 additions and 122 deletions

View File

@ -86,7 +86,7 @@ public class MavenSession
this.eventDispatcher = Eventdispatcher;
}
public Map getPluginContext( PluginDescriptor pluginDescriptor, MavenProject project )
public Map<String,Object> getPluginContext( PluginDescriptor pluginDescriptor, MavenProject project )
{
if ( reactorManager == null )
{

View File

@ -69,7 +69,7 @@ public class ReactorManager
}
}
public Map getPluginContext( PluginDescriptor plugin, MavenProject project )
public Map<String,Object> getPluginContext( PluginDescriptor plugin, MavenProject project )
{
Map pluginContextsByKey = (Map) pluginContextsByProjectAndPluginKey.get( project.getId() );

View File

@ -241,7 +241,7 @@ public class DefaultLifecycleExecutor
session.setCurrentProject( rootProject );
// only call once, with the top-level project (assumed to be provided as a parameter)...
for ( Iterator goalIterator = segment.getTasks().iterator(); goalIterator.hasNext(); )
for ( Iterator<String> goalIterator = segment.getTasks().iterator(); goalIterator.hasNext(); )
{
String task = (String) goalIterator.next();
@ -1217,6 +1217,8 @@ public class DefaultLifecycleExecutor
return goals;
}
// all this logic should go to the plugin manager
MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project )
throws LifecycleExecutionException
{
@ -1392,7 +1394,7 @@ public class DefaultLifecycleExecutor
tasks.add( task );
}
List getTasks()
List<String> getTasks()
{
return tasks;
}

View File

@ -158,13 +158,19 @@ public class DefaultPluginManager
return getByPrefix( prefix, session.getPluginGroups(), project.getRemoteArtifactRepositories(), session.getLocalRepository() );
}
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, MavenSession session )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException, InvalidPluginException, PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException
public PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, MavenSession session )
throws PluginLoaderException
{
if ( plugin.getGroupId() == null )
{
plugin.setGroupId( PluginDescriptor.getDefaultPluginGroupId() );
}
try
{
String pluginVersion = plugin.getVersion();
// TODO: this should be possibly outside
// All version-resolution logic has been moved to DefaultPluginVersionManager.
logger.debug( "Resolving plugin: " + plugin.getKey() + " with version: " + pluginVersion );
if ( ( pluginVersion == null ) || Artifact.LATEST_VERSION.equals( pluginVersion ) || Artifact.RELEASE_VERSION.equals( pluginVersion ) )
@ -178,49 +184,41 @@ public class DefaultPluginManager
logger.debug( "Resolved to version: " + pluginVersion );
}
return verifyVersionedPlugin( plugin, project, session );
}
System.out.println( "XXXXXXXXXXXXXXXXXXXXXXX " + plugin.getArtifactId() + ":" + plugin.getVersion() );
private PluginDescriptor verifyVersionedPlugin( Plugin plugin, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, ArtifactNotFoundException, ArtifactResolutionException, InvalidPluginException, PluginManagerException, PluginNotFoundException
{
logger.debug( "In verifyVersionedPlugin for: " + plugin.getKey() );
// TODO: this might result in an artifact "RELEASE" being resolved continuously
// FIXME: need to find out how a plugin gets marked as 'installed'
// and no ChildContainer exists. The check for that below fixes
// the 'Can't find plexus container for plugin: xxx' error.
try
{
addPlugin( plugin, project, session );
PluginDescriptor result = pluginCollector.getPluginDescriptor( plugin );
project.addPlugin( plugin );
return result;
}
catch ( ArtifactResolutionException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
String groupId = plugin.getGroupId();
String artifactId = plugin.getArtifactId();
String version = plugin.getVersion();
if ( ( groupId == null ) || ( artifactId == null ) || ( version == null ) )
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginVersionResolutionException e )
{
throw new PluginNotFoundException( plugin, e );
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
else if ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() ) && version.equals( e.getVersion() ) && "maven-plugin".equals( e.getType() ) )
catch ( InvalidPluginException e )
{
throw new PluginNotFoundException( plugin, e );
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
else
catch ( PluginManagerException e )
{
throw e;
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginVersionNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( plugin );
return pluginDescriptor;
}
// We need to load different
@ -296,6 +294,8 @@ public class DefaultPluginManager
}
}
pluginRealm.display();
try
{
logger.debug( "Discovering components in realm: " + pluginRealm );
@ -490,10 +490,8 @@ public class DefaultPluginManager
try
{
for ( Iterator i = projects.iterator(); i.hasNext(); )
for ( MavenProject p : projects )
{
MavenProject p = (MavenProject) i.next();
resolveTransitiveDependencies( session, repositorySystem, mojoDescriptor.isDependencyResolutionRequired(), p, mojoDescriptor.isAggregator() );
}
@ -697,13 +695,41 @@ public class DefaultPluginManager
reportPlugin.setVersion( version );
}
Plugin forLookup = new Plugin();
Plugin plugin = new Plugin();
forLookup.setGroupId( reportPlugin.getGroupId() );
forLookup.setArtifactId( reportPlugin.getArtifactId() );
forLookup.setVersion( version );
plugin.setGroupId( reportPlugin.getGroupId() );
plugin.setArtifactId( reportPlugin.getArtifactId() );
plugin.setVersion( version );
return verifyVersionedPlugin( forLookup, project, session );
try
{
addPlugin( plugin, project, session );
}
catch ( ArtifactNotFoundException e )
{
String groupId = plugin.getGroupId();
String artifactId = plugin.getArtifactId();
String pluginVersion = plugin.getVersion();
if ( ( groupId == null ) || ( artifactId == null ) || ( pluginVersion == null ) )
{
throw new PluginNotFoundException( plugin, e );
}
else if ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() ) && pluginVersion.equals( e.getVersion() ) && "maven-plugin".equals( e.getType() ) )
{
throw new PluginNotFoundException( plugin, e );
}
else
{
throw e;
}
}
PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( plugin );
return pluginDescriptor;
}
private Mojo getConfiguredMojo( MavenSession session, Xpp3Dom dom, MavenProject project, boolean report, MojoExecution mojoExecution )
@ -755,7 +781,7 @@ public class DefaultPluginManager
if ( mojo instanceof ContextEnabled )
{
Map pluginContext = session.getPluginContext( pluginDescriptor, project );
Map<String,Object> pluginContext = session.getPluginContext( pluginDescriptor, project );
if ( pluginContext != null )
{
@ -1763,60 +1789,6 @@ public class DefaultPluginManager
}
}
// Plugin Loader
/**
* Load the {@link PluginDescriptor} instance for the specified plugin, using the project for
* the {@link ArtifactRepository} and other supplemental plugin information as necessary.
*/
public PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, MavenSession session )
throws PluginLoaderException
{
if ( plugin.getGroupId() == null )
{
plugin.setGroupId( PluginDescriptor.getDefaultPluginGroupId() );
}
try
{
PluginDescriptor result = verifyPlugin( plugin, project, session );
// this has been simplified from the old code that injected the plugin management stuff, since
// pluginManagement injection is now handled by the project method.
project.addPlugin( plugin );
return result;
}
catch ( ArtifactResolutionException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginVersionResolutionException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( InvalidPluginException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginManagerException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginVersionNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
}
/**
* Load the {@link PluginDescriptor} instance for the specified report plugin, using the project for
* the {@link ArtifactRepository} and other supplemental report/plugin information as necessary.