Working on: MNG-377

o Normalized all references to plugins to use either o.a.m.model.Plugin or o.a.m.plugin.PluginDescriptor instances

o Changed DefaultLifecycleExecutor, PluginManager, DefaultPluginManager, MavenPluginCollector, and DoxiaMojo to reflect the above

o Added mapped-plugin resolution of goal prefixes to the DefaultLifecycleExecutor

o Added caching of PluginMappingManager instance inside of MavenSession

o Modified SettingsUtils to be more resistant to null String-Lists for pluginGroups and activeProfiles during merge.

o Added checks to MavenProject.addPlugin(..) to only add if the plugin doesn't already exist in the model.

Next step is to modify installation and deployment process for plugins to publish plugins.xml repository metadata.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@209677 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-07-07 23:50:25 +00:00
parent 73184be8e3
commit 91dfd62176
9 changed files with 266 additions and 184 deletions

View File

@ -18,6 +18,7 @@ package org.apache.maven.execution;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.plugin.mapping.PluginMappingManager;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings; import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
@ -43,6 +44,8 @@ public class MavenSession
private EventDispatcher eventDispatcher; private EventDispatcher eventDispatcher;
private PluginMappingManager pluginMappingManager;
// TODO: make this the central one, get rid of build settings... // TODO: make this the central one, get rid of build settings...
private final Settings settings; private final Settings settings;
@ -132,4 +135,14 @@ public class MavenSession
{ {
return settings; return settings;
} }
public void setPluginMappingManager( PluginMappingManager pluginMappingManager )
{
this.pluginMappingManager = pluginMappingManager;
}
public PluginMappingManager getPluginMappingManager()
{
return pluginMappingManager;
}
} }

View File

@ -17,6 +17,7 @@ package org.apache.maven.lifecycle;
*/ */
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManagementException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.execution.MavenExecutionResponse; import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
@ -36,6 +37,8 @@ import org.apache.maven.plugin.lifecycle.Execution;
import org.apache.maven.plugin.lifecycle.Lifecycle; import org.apache.maven.plugin.lifecycle.Lifecycle;
import org.apache.maven.plugin.lifecycle.Phase; import org.apache.maven.plugin.lifecycle.Phase;
import org.apache.maven.plugin.mapping.MavenPluginMappingBuilder; import org.apache.maven.plugin.mapping.MavenPluginMappingBuilder;
import org.apache.maven.plugin.mapping.PluginMappingManagementException;
import org.apache.maven.plugin.mapping.PluginMappingManager;
import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.project.injection.ModelDefaultsInjector; import org.apache.maven.project.injection.ModelDefaultsInjector;
@ -123,7 +126,8 @@ public class DefaultLifecycleExecutor
} }
private void executeGoal( String task, MavenSession session, MavenProject project ) private void executeGoal( String task, MavenSession session, MavenProject project )
throws LifecycleExecutionException, PluginNotFoundException, MojoExecutionException, ArtifactResolutionException throws LifecycleExecutionException, PluginNotFoundException, MojoExecutionException,
ArtifactResolutionException
{ {
if ( phases.contains( task ) ) if ( phases.contains( task ) )
{ {
@ -280,8 +284,8 @@ public class DefaultLifecycleExecutor
String goal = tok.nextToken().trim(); String goal = tok.nextToken().trim();
MojoDescriptor mojoDescriptor = getMojoDescriptor( goal, session, project ); MojoDescriptor mojoDescriptor = getMojoDescriptor( goal, session, project );
addToLifecycleMappings( lifecycleMappings, phase, new MojoExecution( mojoDescriptor ), addToLifecycleMappings( lifecycleMappings, phase, new MojoExecution( mojoDescriptor ), session
session.getSettings() ); .getSettings() );
} }
} }
@ -308,7 +312,8 @@ public class DefaultLifecycleExecutor
if ( plugin.getGoals() != null && !plugin.getGoals().isEmpty() ) if ( plugin.getGoals() != null && !plugin.getGoals().isEmpty() )
{ {
getLogger().warn( getLogger().warn(
"DEPRECATED: goal definitions for plugin '" + plugin.getKey() + "' must be in an executions element" ); "DEPRECATED: goal definitions for plugin '" + plugin.getKey()
+ "' must be in an executions element" );
} }
PluginDescriptor pluginDescriptor; PluginDescriptor pluginDescriptor;
@ -341,18 +346,11 @@ public class DefaultLifecycleExecutor
private PluginDescriptor verifyPlugin( Plugin plugin, MavenSession session, MavenProject project ) private PluginDescriptor verifyPlugin( Plugin plugin, MavenSession session, MavenProject project )
throws ArtifactResolutionException, LifecycleExecutionException throws ArtifactResolutionException, LifecycleExecutionException
{ {
String groupId = plugin.getGroupId();
String artifactId = plugin.getArtifactId();
String version = plugin.getVersion();
PluginDescriptor pluginDescriptor; PluginDescriptor pluginDescriptor;
try try
{ {
ArtifactRepository localRepository = session.getLocalRepository(); ArtifactRepository localRepository = session.getLocalRepository();
pluginDescriptor = pluginManager.verifyPlugin( groupId, artifactId, version, project, session.getSettings(), pluginDescriptor = pluginManager.verifyPlugin( plugin, project, session.getSettings(), localRepository );
localRepository );
} }
catch ( PluginManagerException e ) catch ( PluginManagerException e )
{ {
@ -368,8 +366,7 @@ public class DefaultLifecycleExecutor
/** /**
* @deprecated * @deprecated
*/ */
private void bindGoalMapToLifecycle( PluginDescriptor pluginDescriptor, Map goalMap, Map phaseMap, private void bindGoalMapToLifecycle( PluginDescriptor pluginDescriptor, Map goalMap, Map phaseMap, Settings settings )
Settings settings )
{ {
for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); ) for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); )
{ {
@ -470,10 +467,8 @@ public class DefaultLifecycleExecutor
private MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project ) private MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project )
throws ArtifactResolutionException, LifecycleExecutionException throws ArtifactResolutionException, LifecycleExecutionException
{ {
String groupId = null;
String artifactId = null;
String version = null;
String goal = null; String goal = null;
Plugin plugin = null;
PluginDescriptor pluginDescriptor = null; PluginDescriptor pluginDescriptor = null;
@ -484,43 +479,85 @@ public class DefaultLifecycleExecutor
String prefix = tok.nextToken(); String prefix = tok.nextToken();
goal = tok.nextToken(); goal = tok.nextToken();
String id = pluginManager.getPluginIdFromPrefix( prefix ); // Steps for retrieving the plugin model instance:
// 1. request directly from the plugin collector by prefix
pluginDescriptor = pluginManager.getPluginDescriptorForPrefix( prefix );
if ( id == null ) if ( pluginDescriptor != null )
{ {
groupId = PluginDescriptor.getDefaultPluginGroupId(); plugin = new Plugin();
artifactId = PluginDescriptor.getDefaultPluginArtifactId( prefix );
plugin.setGroupId( pluginDescriptor.getGroupId() );
plugin.setArtifactId( pluginDescriptor.getArtifactId() );
plugin.setVersion( pluginDescriptor.getVersion() );
} }
else
// 2. use the plugin resolver to resolve the prefix in the search groups
if ( plugin == null )
{ {
tok = new StringTokenizer( id, ":" ); PluginMappingManager mappingManager = session.getPluginMappingManager();
groupId = tok.nextToken();
artifactId = tok.nextToken(); // don't reassemble the plugin mappings if the session has already been configured with them.
version = tok.nextToken(); if ( mappingManager == null )
{
try
{
List pluginGroupIds = session.getSettings().getPluginGroups();
List pluginRepositories = project.getPluginArtifactRepositories();
ArtifactRepository localRepository = session.getLocalRepository();
mappingManager = pluginMappingBuilder.loadPluginMappings( pluginGroupIds, pluginRepositories,
localRepository );
// lazily configure this on the session.
session.setPluginMappingManager( mappingManager );
}
catch ( RepositoryMetadataManagementException e )
{
throw new LifecycleExecutionException( "Cannot load plugin mappings.", e );
}
catch ( PluginMappingManagementException e )
{
throw new LifecycleExecutionException( "Cannot load plugin mappings.", e );
}
}
plugin = mappingManager.getByPrefix( prefix );
}
// 3. default to o.a.m.plugins and maven-<prefix>-plugin
if ( plugin == null )
{
plugin = new Plugin();
plugin.setGroupId( PluginDescriptor.getDefaultPluginGroupId() );
plugin.setArtifactId( PluginDescriptor.getDefaultPluginArtifactId( prefix ) );
} }
for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); ) for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
{ {
Plugin plugin = (Plugin) i.next(); Plugin buildPlugin = (Plugin) i.next();
if ( plugin.getGroupId().equals( groupId ) && plugin.getArtifactId().equals( artifactId ) ) if ( buildPlugin.getKey().equals( plugin.getKey() ) )
{ {
version = plugin.getVersion(); plugin = buildPlugin;
break; break;
} }
} }
} }
else if ( numTokens == 4 ) else if ( numTokens == 4 )
{ {
groupId = tok.nextToken(); plugin = new Plugin();
artifactId = tok.nextToken();
version = tok.nextToken(); plugin.setGroupId( tok.nextToken() );
plugin.setArtifactId( tok.nextToken() );
plugin.setVersion( tok.nextToken() );
goal = tok.nextToken(); goal = tok.nextToken();
} }
else else
{ {
String message = "Invalid task '" + task + "': you must specify a valid lifecycle phase, or" + String message = "Invalid task '" + task + "': you must specify a valid lifecycle phase, or"
" a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal"; + " a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal";
throw new LifecycleExecutionException( message ); throw new LifecycleExecutionException( message );
} }
@ -528,8 +565,8 @@ public class DefaultLifecycleExecutor
{ {
try try
{ {
pluginDescriptor = pluginManager.verifyPlugin( groupId, artifactId, version, project, pluginDescriptor = pluginManager.verifyPlugin( plugin, project, session.getSettings(), session
session.getSettings(), session.getLocalRepository() ); .getLocalRepository() );
} }
catch ( PluginManagerException e ) catch ( PluginManagerException e )
{ {
@ -541,8 +578,7 @@ public class DefaultLifecycleExecutor
} }
} }
injectHandlerPluginConfiguration( project, pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId(), injectHandlerPluginConfiguration( project, plugin );
pluginDescriptor.getVersion() );
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal ); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
if ( mojoDescriptor == null ) if ( mojoDescriptor == null )
@ -553,26 +589,22 @@ public class DefaultLifecycleExecutor
return mojoDescriptor; return mojoDescriptor;
} }
private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId, private void injectHandlerPluginConfiguration( MavenProject project, Plugin plugin )
String version )
{ {
String key = Plugin.constructKey( groupId, artifactId ); String key = plugin.getKey();
Plugin plugin = (Plugin) project.getBuild().getPluginsAsMap().get( key );
if ( plugin == null ) Plugin buildPlugin = (Plugin) project.getBuild().getPluginsAsMap().get( key );
if ( buildPlugin == null )
{ {
plugin = new Plugin();
plugin.setGroupId( groupId );
plugin.setArtifactId( artifactId );
plugin.setVersion( version );
PluginManagement pluginManagement = project.getPluginManagement(); PluginManagement pluginManagement = project.getPluginManagement();
if ( pluginManagement != null ) if ( pluginManagement != null )
{ {
Plugin def = (Plugin) pluginManagement.getPluginsAsMap().get( key ); Plugin managedPlugin = (Plugin) pluginManagement.getPluginsAsMap().get( key );
if ( def != null )
if ( managedPlugin != null )
{ {
modelDefaultsInjector.mergePluginWithDefaults( plugin, def ); modelDefaultsInjector.mergePluginWithDefaults( plugin, managedPlugin );
} }
} }

View File

@ -29,6 +29,7 @@ import org.apache.maven.artifact.resolver.filter.InversionArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.ReportSet; import org.apache.maven.model.ReportSet;
import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents; import org.apache.maven.monitor.event.MavenEvents;
@ -109,44 +110,55 @@ public class DefaultPluginManager
// //
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
public String getPluginIdFromPrefix( String prefix ) public PluginDescriptor getPluginDescriptorForPrefix( String prefix )
{ {
return pluginCollector.getPluginIdFromPrefix( prefix ); return pluginCollector.getPluginDescriptorForPrefix( prefix );
} }
public PluginDescriptor verifyPlugin( String groupId, String artifactId, String version, MavenProject project, public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
Settings settings, ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException
{ {
// TODO: this should be possibly outside // TODO: this should be possibly outside
// [HTTP-301] All version-resolution logic has been moved to DefaultPluginVersionManager. :) // [HTTP-301] All version-resolution logic has been moved to DefaultPluginVersionManager. :)
if ( version == null ) if ( plugin.getVersion() == null )
{ {
version = pluginVersionManager.resolvePluginVersion( groupId, artifactId, project, settings, String groupId = plugin.getGroupId();
localRepository ); String artifactId = plugin.getArtifactId();
plugin.setVersion( pluginVersionManager.resolvePluginVersion( groupId, artifactId, project, settings,
localRepository ) );
} }
// TODO: this might result in an artifact "RELEASE" being resolved continuously // TODO: this might result in an artifact "RELEASE" being resolved continuously
if ( !pluginCollector.isPluginInstalled( groupId, artifactId ) ) if ( !pluginCollector.isPluginInstalled( plugin ) )
{ {
try try
{ {
Artifact pluginArtifact = artifactFactory.createArtifact( groupId, artifactId, version, Artifact pluginArtifact = artifactFactory.createArtifact( plugin.getGroupId(),
plugin.getArtifactId(),
plugin.getVersion(),
Artifact.SCOPE_RUNTIME, Artifact.SCOPE_RUNTIME,
MojoDescriptor.MAVEN_PLUGIN ); MojoDescriptor.MAVEN_PLUGIN );
addPlugin( groupId, artifactId, version, pluginArtifact, project, localRepository ); // TODO: [jc; 2005-july-06] what's this for?
//plugin.setVersion( pluginArtifact.getBaseVersion() );
version = pluginArtifact.getBaseVersion(); addPlugin( plugin, pluginArtifact, project, localRepository );
project.addPlugin( plugin );
} }
catch ( PlexusContainerException e ) catch ( PlexusContainerException e )
{ {
throw new PluginManagerException( throw new PluginManagerException(
"Error occurred in the artifact container attempting to download plugin " + groupId + ":" + "Error occurred in the artifact container attempting to download plugin " + plugin.getKey(), e );
artifactId, e );
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )
{ {
String groupId = plugin.getGroupId();
String artifactId = plugin.getArtifactId();
String version = plugin.getVersion();
if ( if (
( groupId == null || artifactId == null || version == null || ( groupId == null || artifactId == null || version == null ||
( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() ) && ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() ) &&
@ -160,23 +172,22 @@ public class DefaultPluginManager
} }
} }
} }
return pluginCollector.getPluginDescriptor( groupId, artifactId, version );
return pluginCollector.getPluginDescriptor( plugin );
} }
protected void addPlugin( String groupId, String artifactId, String version, Artifact pluginArtifact, MavenProject project, protected void addPlugin( Plugin plugin, Artifact pluginArtifact, MavenProject project,
ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws ArtifactResolutionException, PlexusContainerException throws ArtifactResolutionException, PlexusContainerException
{ {
String pluginKey = Plugin.constructKey( groupId, artifactId );
artifactResolver.resolve( pluginArtifact, project.getPluginArtifactRepositories(), localRepository ); artifactResolver.resolve( pluginArtifact, project.getPluginArtifactRepositories(), localRepository );
PlexusContainer child = container.createChildContainer( pluginKey, Collections PlexusContainer child = container.createChildContainer( plugin.getKey(), Collections
.singletonList( pluginArtifact.getFile() ), Collections.EMPTY_MAP, Collections.singletonList( pluginCollector ) ); .singletonList( pluginArtifact.getFile() ), Collections.EMPTY_MAP, Collections.singletonList( pluginCollector ) );
// this plugin's descriptor should have been discovered in the child creation, so we should be able to // this plugin's descriptor should have been discovered in the child creation, so we should be able to
// circle around and set the artifacts and class realm // circle around and set the artifacts and class realm
PluginDescriptor addedPlugin = pluginCollector.getPluginDescriptor( groupId, artifactId, version ); PluginDescriptor addedPlugin = pluginCollector.getPluginDescriptor( plugin );
addedPlugin.setClassRealm( child.getContainerRealm() ); addedPlugin.setClassRealm( child.getContainerRealm() );
@ -186,18 +197,6 @@ public class DefaultPluginManager
addedPlugin.setArtifacts( Collections.singletonList( pluginArtifact ) ); addedPlugin.setArtifacts( Collections.singletonList( pluginArtifact ) );
} }
// private void releaseComponent( Object component )
// {
// try
// {
// container.release( component );
// }
// catch ( ComponentLifecycleException e )
// {
// getLogger().error( "Error releasing component - ignoring", e );
// }
// }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Mojo execution // Mojo execution
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -291,11 +290,17 @@ public class DefaultPluginManager
} }
} }
public List getReports( String groupId, String artifactId, String version, ReportSet reportSet, public List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project,
MavenSession session, MavenProject project ) MavenSession session, ArtifactRepository localRepository )
throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException,
ArtifactResolutionException
{ {
PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( groupId, artifactId, version ); Plugin forLookup = new Plugin();
forLookup.setGroupId( reportPlugin.getGroupId() );
forLookup.setArtifactId( reportPlugin.getArtifactId() );
forLookup.setVersion( reportPlugin.getVersion() );
PluginDescriptor pluginDescriptor = verifyPlugin( forLookup, project, session.getSettings(), localRepository );
List reports = new ArrayList(); List reports = new ArrayList();
for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); ) for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); )
@ -317,7 +322,7 @@ public class DefaultPluginManager
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, id ); MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, id );
String executionId = mojoExecution.getExecutionId(); String executionId = mojoExecution.getExecutionId();
Xpp3Dom dom = project.getReportConfiguration( groupId, artifactId, executionId ); Xpp3Dom dom = project.getReportConfiguration( reportPlugin.getGroupId(), reportPlugin.getArtifactId(), executionId );
reports.add( getConfiguredMojo( mojoDescriptor, session, dom, project ) ); reports.add( getConfiguredMojo( mojoDescriptor, session, dom, project ) );
} }

View File

@ -1,6 +1,7 @@
package org.apache.maven.plugin; package org.apache.maven.plugin;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent; import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent;
import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener; import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
@ -9,6 +10,7 @@ import org.codehaus.plexus.logging.AbstractLogEnabled;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -34,9 +36,8 @@ public class MavenPluginCollector
{ {
PluginDescriptor pluginDescriptor = (PluginDescriptor) componentSetDescriptor; PluginDescriptor pluginDescriptor = (PluginDescriptor) componentSetDescriptor;
// String key = pluginDescriptor.getId();
// TODO: see comment in getPluginDescriptor // TODO: see comment in getPluginDescriptor
String key = pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId(); String key = Plugin.constructKey( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId() );
if ( !pluginsInProcess.contains( key ) ) if ( !pluginsInProcess.contains( key ) )
{ {
@ -48,33 +49,29 @@ public class MavenPluginCollector
// we also need to deal with multiple versions somehow - currently, first wins // we also need to deal with multiple versions somehow - currently, first wins
if ( !pluginIdsByPrefix.containsKey( pluginDescriptor.getGoalPrefix() ) ) if ( !pluginIdsByPrefix.containsKey( pluginDescriptor.getGoalPrefix() ) )
{ {
pluginIdsByPrefix.put( pluginDescriptor.getGoalPrefix(), pluginDescriptor.getId() ); pluginIdsByPrefix.put( pluginDescriptor.getGoalPrefix(), pluginDescriptor );
} }
} }
} }
} }
public PluginDescriptor getPluginDescriptor( String groupId, String artifactId, String version ) public PluginDescriptor getPluginDescriptor( Plugin plugin )
{ {
// TODO: include version, but can't do this in the plugin manager as it is not resolved to the right version // TODO: include version, but can't do this in the plugin manager as it is not resolved to the right version
// at that point. Instead, move the duplication check to the artifact container, or store it locally based on // at that point. Instead, move the duplication check to the artifact container, or store it locally based on
// the unresolved version? // the unresolved version?
return (PluginDescriptor) pluginDescriptors.get( Plugin.constructKey( groupId, artifactId ) ); return (PluginDescriptor) pluginDescriptors.get( plugin.getKey() );
} }
public boolean isPluginInstalled( String groupId, String artifactId ) public boolean isPluginInstalled( Plugin plugin )
{ {
// String key = PluginDescriptor.constructPluginKey( groupId, artifactId, version );
// TODO: see comment in getPluginDescriptor // TODO: see comment in getPluginDescriptor
return pluginDescriptors.containsKey( Plugin.constructKey( groupId, artifactId ) ); return pluginDescriptors.containsKey( plugin.getKey() );
} }
public String getPluginIdFromPrefix( String prefix ) public PluginDescriptor getPluginDescriptorForPrefix( String prefix )
{ {
if ( !pluginIdsByPrefix.containsKey( prefix ) ) return (PluginDescriptor) pluginIdsByPrefix.get( prefix );
{
// TODO: lookup remotely
}
return (String) pluginIdsByPrefix.get( prefix );
} }
} }

View File

@ -23,6 +23,8 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings; import org.apache.maven.settings.Settings;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.ReportSet; import org.apache.maven.model.ReportSet;
import java.util.List; import java.util.List;
@ -38,13 +40,14 @@ public interface PluginManager
void executeMojo( MavenProject project, MojoExecution execution, MavenSession session ) void executeMojo( MavenProject project, MojoExecution execution, MavenSession session )
throws MojoExecutionException, PluginManagerException, ArtifactResolutionException; throws MojoExecutionException, PluginManagerException, ArtifactResolutionException;
String getPluginIdFromPrefix( String prefix ); PluginDescriptor getPluginDescriptorForPrefix( String prefix );
PluginDescriptor verifyPlugin( String groupId, String artifactId, String version, MavenProject project, PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
Settings settings, ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException; throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException;
List getReports( String groupId, String artifactId, String version, ReportSet reportSet, MavenSession session, List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session,
MavenProject project ) ArtifactRepository localRepository )
throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException; throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException,
ArtifactResolutionException;
} }

View File

@ -28,6 +28,8 @@ public class DefaultPluginMappingBuilder
{ {
PluginMappingManager mappingManager = new PluginMappingManager(); PluginMappingManager mappingManager = new PluginMappingManager();
if ( pluginGroupIds != null )
{
for ( Iterator it = pluginGroupIds.iterator(); it.hasNext(); ) for ( Iterator it = pluginGroupIds.iterator(); it.hasNext(); )
{ {
String groupId = (String) it.next(); String groupId = (String) it.next();
@ -36,13 +38,19 @@ public class DefaultPluginMappingBuilder
PluginMap pluginMap = readPluginMap( mappingFile ); PluginMap pluginMap = readPluginMap( mappingFile );
if ( pluginMap != null )
{
mappingManager.addPluginMap( pluginMap ); mappingManager.addPluginMap( pluginMap );
} }
}
}
return mappingManager; return mappingManager;
} }
private PluginMap readPluginMap( File mappingFile ) throws PluginMappingManagementException private PluginMap readPluginMap( File mappingFile ) throws PluginMappingManagementException
{
if( mappingFile.exists() )
{ {
Reader fileReader = null; Reader fileReader = null;
try try
@ -66,6 +74,11 @@ public class DefaultPluginMappingBuilder
IOUtil.close( fileReader ); IOUtil.close( fileReader );
} }
} }
else
{
return null;
}
}
private File resolveMappingMetadata( String groupId, List pluginRepositories, ArtifactRepository localRepository ) private File resolveMappingMetadata( String groupId, List pluginRepositories, ArtifactRepository localRepository )
throws RepositoryMetadataManagementException throws RepositoryMetadataManagementException

View File

@ -744,23 +744,18 @@ public class DoxiaMojo
{ {
org.apache.maven.model.ReportPlugin reportPlugin = (org.apache.maven.model.ReportPlugin) it.next(); org.apache.maven.model.ReportPlugin reportPlugin = (org.apache.maven.model.ReportPlugin) it.next();
try // try
{ // {
pluginManager.verifyPlugin( reportPlugin.getGroupId(), reportPlugin.getArtifactId(), // pluginManager.verifyPlugin( reportPlugin, project, settings, localRepository );
reportPlugin.getVersion(), project, settings, localRepository ); // }
} // catch ( PluginVersionResolutionException e )
catch ( ArtifactResolutionException e ) // {
{ // throw new MojoExecutionException( "Cannot resolve version for report plugin", e );
throw new MojoExecutionException( "Cannot find report plugin", e ); // }
} // catch ( PluginManagerException e )
catch ( PluginVersionResolutionException e ) // {
{ // throw new MojoExecutionException( "Cannot find report plugin", e );
throw new MojoExecutionException( "Cannot resolve version for report plugin", e ); // }
}
catch ( PluginManagerException e )
{
throw new MojoExecutionException( "Cannot find report plugin", e );
}
try try
{ {
@ -770,12 +765,11 @@ public class DoxiaMojo
if ( reportSets == null || reportSets.isEmpty() ) if ( reportSets == null || reportSets.isEmpty() )
{ {
reportsList = pluginManager.getReports( reportPlugin.getGroupId(), reportsList = pluginManager.getReports( reportPlugin,
reportPlugin.getArtifactId(),
reportPlugin.getVersion(),
null, null,
project,
session, session,
project ); localRepository );
} }
else else
@ -784,12 +778,11 @@ public class DoxiaMojo
{ {
ReportSet reportSet = (ReportSet) j.next(); ReportSet reportSet = (ReportSet) j.next();
reportsList = pluginManager.getReports( reportPlugin.getGroupId(), reportsList = pluginManager.getReports( reportPlugin,
reportPlugin.getArtifactId(),
reportPlugin.getVersion(),
reportSet, reportSet,
project,
session, session,
project ); localRepository );
} }
} }
@ -816,6 +809,10 @@ public class DoxiaMojo
{ {
throw new MojoExecutionException( "Error getting reports", e ); throw new MojoExecutionException( "Error getting reports", e );
} }
catch ( ArtifactResolutionException e )
{
throw new MojoExecutionException( "Cannot find report plugin", e );
}
} }
} }
return reports; return reports;

View File

@ -854,8 +854,11 @@ public class MavenProject
model.setBuild( build ); model.setBuild( build );
} }
if ( !build.getPluginsAsMap().containsKey( plugin.getKey() ) )
{
build.addPlugin( plugin ); build.addPlugin( plugin );
} }
}
public List getCollectedProjects() public List getCollectedProjects()
{ {

View File

@ -2,6 +2,7 @@ package org.apache.maven.settings;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -43,6 +44,14 @@ public final class SettingsUtils
List dominantActiveProfiles = dominant.getActiveProfiles(); List dominantActiveProfiles = dominant.getActiveProfiles();
List recessiveActiveProfiles = recessive.getActiveProfiles(); List recessiveActiveProfiles = recessive.getActiveProfiles();
if ( recessiveActiveProfiles != null )
{
if ( dominantActiveProfiles == null )
{
dominantActiveProfiles = new ArrayList();
dominant.setActiveProfiles( dominantActiveProfiles );
}
for ( Iterator it = recessiveActiveProfiles.iterator(); it.hasNext(); ) for ( Iterator it = recessiveActiveProfiles.iterator(); it.hasNext(); )
{ {
String profileId = (String) it.next(); String profileId = (String) it.next();
@ -54,10 +63,19 @@ public final class SettingsUtils
dominant.getRuntimeInfo().setActiveProfileSourceLevel( profileId, recessiveSourceLevel ); dominant.getRuntimeInfo().setActiveProfileSourceLevel( profileId, recessiveSourceLevel );
} }
} }
}
List dominantPluginGroupIds = dominant.getPluginGroups(); List dominantPluginGroupIds = dominant.getPluginGroups();
List recessivePluginGroupIds = recessive.getPluginGroups(); List recessivePluginGroupIds = recessive.getPluginGroups();
if( recessivePluginGroupIds != null )
{
if( dominantPluginGroupIds == null )
{
dominantPluginGroupIds = new ArrayList();
dominant.setPluginGroups( dominantPluginGroupIds );
}
for ( Iterator it = recessivePluginGroupIds.iterator(); it.hasNext(); ) for ( Iterator it = recessivePluginGroupIds.iterator(); it.hasNext(); )
{ {
String pluginGroupId = (String) it.next(); String pluginGroupId = (String) it.next();
@ -69,6 +87,7 @@ public final class SettingsUtils
dominant.getRuntimeInfo().setPluginGroupIdSourceLevel( pluginGroupId, recessiveSourceLevel ); dominant.getRuntimeInfo().setPluginGroupIdSourceLevel( pluginGroupId, recessiveSourceLevel );
} }
} }
}
if ( StringUtils.isEmpty( dominant.getLocalRepository() ) ) if ( StringUtils.isEmpty( dominant.getLocalRepository() ) )
{ {