diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java index 1d6c28dfad..e6ff906dea 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java @@ -18,6 +18,7 @@ package org.apache.maven.execution; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.monitor.event.EventDispatcher; +import org.apache.maven.plugin.mapping.PluginMappingManager; import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Settings; import org.codehaus.plexus.PlexusContainer; @@ -42,6 +43,8 @@ public class MavenSession private List goals; private EventDispatcher eventDispatcher; + + private PluginMappingManager pluginMappingManager; // TODO: make this the central one, get rid of build settings... private final Settings settings; @@ -132,4 +135,14 @@ public class MavenSession { return settings; } + + public void setPluginMappingManager( PluginMappingManager pluginMappingManager ) + { + this.pluginMappingManager = pluginMappingManager; + } + + public PluginMappingManager getPluginMappingManager() + { + return pluginMappingManager; + } } \ No newline at end of file diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index 401d38dcaa..505ed9934b 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -17,6 +17,7 @@ package org.apache.maven.lifecycle; */ 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.execution.MavenExecutionResponse; 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.Phase; 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.project.MavenProject; import org.apache.maven.project.injection.ModelDefaultsInjector; @@ -70,7 +73,7 @@ public class DefaultLifecycleExecutor // ---------------------------------------------------------------------- private ModelDefaultsInjector modelDefaultsInjector; - + private MavenPluginMappingBuilder pluginMappingBuilder; private PluginManager pluginManager; @@ -123,7 +126,8 @@ public class DefaultLifecycleExecutor } private void executeGoal( String task, MavenSession session, MavenProject project ) - throws LifecycleExecutionException, PluginNotFoundException, MojoExecutionException, ArtifactResolutionException + throws LifecycleExecutionException, PluginNotFoundException, MojoExecutionException, + ArtifactResolutionException { if ( phases.contains( task ) ) { @@ -138,7 +142,7 @@ public class DefaultLifecycleExecutor } private void executeGoalWithLifecycle( String task, MavenSession session, Map lifecycleMappings, - MavenProject project ) + MavenProject project ) throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException { List goals = processGoalChain( task, lifecycleMappings ); @@ -280,8 +284,8 @@ public class DefaultLifecycleExecutor String goal = tok.nextToken().trim(); MojoDescriptor mojoDescriptor = getMojoDescriptor( goal, session, project ); - addToLifecycleMappings( lifecycleMappings, phase, new MojoExecution( mojoDescriptor ), - session.getSettings() ); + addToLifecycleMappings( lifecycleMappings, phase, new MojoExecution( mojoDescriptor ), session + .getSettings() ); } } @@ -308,7 +312,8 @@ public class DefaultLifecycleExecutor if ( plugin.getGoals() != null && !plugin.getGoals().isEmpty() ) { 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; @@ -341,18 +346,11 @@ public class DefaultLifecycleExecutor private PluginDescriptor verifyPlugin( Plugin plugin, MavenSession session, MavenProject project ) throws ArtifactResolutionException, LifecycleExecutionException { - String groupId = plugin.getGroupId(); - - String artifactId = plugin.getArtifactId(); - - String version = plugin.getVersion(); - PluginDescriptor pluginDescriptor; try { ArtifactRepository localRepository = session.getLocalRepository(); - pluginDescriptor = pluginManager.verifyPlugin( groupId, artifactId, version, project, session.getSettings(), - localRepository ); + pluginDescriptor = pluginManager.verifyPlugin( plugin, project, session.getSettings(), localRepository ); } catch ( PluginManagerException e ) { @@ -368,8 +366,7 @@ public class DefaultLifecycleExecutor /** * @deprecated */ - private void bindGoalMapToLifecycle( PluginDescriptor pluginDescriptor, Map goalMap, Map phaseMap, - Settings settings ) + private void bindGoalMapToLifecycle( PluginDescriptor pluginDescriptor, Map goalMap, Map phaseMap, Settings settings ) { for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); ) { @@ -393,7 +390,7 @@ public class DefaultLifecycleExecutor } private void bindExecutionToLifecycle( PluginDescriptor pluginDescriptor, Map phaseMap, PluginExecution execution, - Settings settings ) + Settings settings ) throws LifecycleExecutionException { for ( Iterator i = execution.getGoals().iterator(); i.hasNext(); ) @@ -424,7 +421,7 @@ public class DefaultLifecycleExecutor } private void addToLifecycleMappings( Map lifecycleMappings, String phase, MojoExecution mojoExecution, - Settings settings ) + Settings settings ) { List goals = (List) lifecycleMappings.get( phase ); @@ -470,10 +467,8 @@ public class DefaultLifecycleExecutor private MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project ) throws ArtifactResolutionException, LifecycleExecutionException { - String groupId = null; - String artifactId = null; - String version = null; String goal = null; + Plugin plugin = null; PluginDescriptor pluginDescriptor = null; @@ -484,43 +479,85 @@ public class DefaultLifecycleExecutor String prefix = tok.nextToken(); goal = tok.nextToken(); - String id = pluginManager.getPluginIdFromPrefix( prefix ); - - if ( id == null ) + // Steps for retrieving the plugin model instance: + // 1. request directly from the plugin collector by prefix + pluginDescriptor = pluginManager.getPluginDescriptorForPrefix( prefix ); + + if ( pluginDescriptor != null ) { - groupId = PluginDescriptor.getDefaultPluginGroupId(); - artifactId = PluginDescriptor.getDefaultPluginArtifactId( prefix ); + plugin = new Plugin(); + + 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, ":" ); - groupId = tok.nextToken(); - artifactId = tok.nextToken(); - version = tok.nextToken(); + PluginMappingManager mappingManager = session.getPluginMappingManager(); + + // don't reassemble the plugin mappings if the session has already been configured with them. + 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--plugin + if ( plugin == null ) + { + plugin = new Plugin(); + plugin.setGroupId( PluginDescriptor.getDefaultPluginGroupId() ); + plugin.setArtifactId( PluginDescriptor.getDefaultPluginArtifactId( prefix ) ); } 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; } } } else if ( numTokens == 4 ) { - groupId = tok.nextToken(); - artifactId = tok.nextToken(); - version = tok.nextToken(); + plugin = new Plugin(); + + plugin.setGroupId( tok.nextToken() ); + plugin.setArtifactId( tok.nextToken() ); + plugin.setVersion( tok.nextToken() ); + goal = tok.nextToken(); } else { - 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"; + 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"; throw new LifecycleExecutionException( message ); } @@ -528,8 +565,8 @@ public class DefaultLifecycleExecutor { try { - pluginDescriptor = pluginManager.verifyPlugin( groupId, artifactId, version, project, - session.getSettings(), session.getLocalRepository() ); + pluginDescriptor = pluginManager.verifyPlugin( plugin, project, session.getSettings(), session + .getLocalRepository() ); } catch ( PluginManagerException e ) { @@ -541,8 +578,7 @@ public class DefaultLifecycleExecutor } } - injectHandlerPluginConfiguration( project, pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId(), - pluginDescriptor.getVersion() ); + injectHandlerPluginConfiguration( project, plugin ); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal ); if ( mojoDescriptor == null ) @@ -553,26 +589,22 @@ public class DefaultLifecycleExecutor return mojoDescriptor; } - private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId, - String version ) + private void injectHandlerPluginConfiguration( MavenProject project, Plugin plugin ) { - String key = Plugin.constructKey( groupId, artifactId ); - Plugin plugin = (Plugin) project.getBuild().getPluginsAsMap().get( key ); + String key = plugin.getKey(); + + Plugin buildPlugin = (Plugin) project.getBuild().getPluginsAsMap().get( key ); - if ( plugin == null ) + if ( buildPlugin == null ) { - plugin = new Plugin(); - plugin.setGroupId( groupId ); - plugin.setArtifactId( artifactId ); - plugin.setVersion( version ); - PluginManagement pluginManagement = project.getPluginManagement(); if ( pluginManagement != null ) { - Plugin def = (Plugin) pluginManagement.getPluginsAsMap().get( key ); - if ( def != null ) + Plugin managedPlugin = (Plugin) pluginManagement.getPluginsAsMap().get( key ); + + if ( managedPlugin != null ) { - modelDefaultsInjector.mergePluginWithDefaults( plugin, def ); + modelDefaultsInjector.mergePluginWithDefaults( plugin, managedPlugin ); } } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index b8033beb00..4a500ee729 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -29,6 +29,7 @@ import org.apache.maven.artifact.resolver.filter.InversionArtifactFilter; import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; +import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.ReportSet; import org.apache.maven.monitor.event.EventDispatcher; 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, - Settings settings, ArtifactRepository localRepository ) + + public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings, + ArtifactRepository localRepository ) throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException { // TODO: this should be possibly outside // [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, - localRepository ); + String groupId = plugin.getGroupId(); + String artifactId = plugin.getArtifactId(); + + plugin.setVersion( pluginVersionManager.resolvePluginVersion( groupId, artifactId, project, settings, + localRepository ) ); } // TODO: this might result in an artifact "RELEASE" being resolved continuously - if ( !pluginCollector.isPluginInstalled( groupId, artifactId ) ) + if ( !pluginCollector.isPluginInstalled( plugin ) ) { try { - Artifact pluginArtifact = artifactFactory.createArtifact( groupId, artifactId, version, + Artifact pluginArtifact = artifactFactory.createArtifact( plugin.getGroupId(), + plugin.getArtifactId(), + plugin.getVersion(), Artifact.SCOPE_RUNTIME, MojoDescriptor.MAVEN_PLUGIN ); - addPlugin( groupId, artifactId, version, pluginArtifact, project, localRepository ); - - version = pluginArtifact.getBaseVersion(); + // TODO: [jc; 2005-july-06] what's this for? + //plugin.setVersion( pluginArtifact.getBaseVersion() ); + + addPlugin( plugin, pluginArtifact, project, localRepository ); + + project.addPlugin( plugin ); } catch ( PlexusContainerException e ) { throw new PluginManagerException( - "Error occurred in the artifact container attempting to download plugin " + groupId + ":" + - artifactId, e ); + "Error occurred in the artifact container attempting to download plugin " + plugin.getKey(), e ); } catch ( ArtifactResolutionException e ) { + String groupId = plugin.getGroupId(); + String artifactId = plugin.getArtifactId(); + String version = plugin.getVersion(); + if ( ( groupId == null || artifactId == null || version == null || ( 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 ) throws ArtifactResolutionException, PlexusContainerException { - String pluginKey = Plugin.constructKey( groupId, artifactId ); - 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 ) ); // 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 - PluginDescriptor addedPlugin = pluginCollector.getPluginDescriptor( groupId, artifactId, version ); + PluginDescriptor addedPlugin = pluginCollector.getPluginDescriptor( plugin ); addedPlugin.setClassRealm( child.getContainerRealm() ); @@ -186,18 +197,6 @@ public class DefaultPluginManager 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 // ---------------------------------------------------------------------- @@ -291,12 +290,18 @@ public class DefaultPluginManager } } - public List getReports( String groupId, String artifactId, String version, ReportSet reportSet, - MavenSession session, MavenProject project ) - throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException + public List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, + MavenSession session, ArtifactRepository localRepository ) + 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(); for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); ) { @@ -317,7 +322,7 @@ public class DefaultPluginManager MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, id ); 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 ) ); } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java b/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java index 6b56653e27..8424a2f8e8 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java @@ -1,6 +1,7 @@ package org.apache.maven.plugin; import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent; import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener; @@ -9,6 +10,7 @@ import org.codehaus.plexus.logging.AbstractLogEnabled; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -16,11 +18,11 @@ public class MavenPluginCollector extends AbstractLogEnabled implements ComponentDiscoveryListener { - + private Set pluginsInProcess = new HashSet(); - + private Map pluginDescriptors = new HashMap(); - + private Map pluginIdsByPrefix = new HashMap(); // ---------------------------------------------------------------------- @@ -33,10 +35,9 @@ public class MavenPluginCollector if ( componentSetDescriptor instanceof PluginDescriptor ) { PluginDescriptor pluginDescriptor = (PluginDescriptor) componentSetDescriptor; - - // String key = pluginDescriptor.getId(); + // TODO: see comment in getPluginDescriptor - String key = pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId(); + String key = Plugin.constructKey( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId() ); if ( !pluginsInProcess.contains( key ) ) { @@ -48,33 +49,29 @@ public class MavenPluginCollector // we also need to deal with multiple versions somehow - currently, first wins 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 // at that point. Instead, move the duplication check to the artifact container, or store it locally based on // the unresolved version? - return (PluginDescriptor) pluginDescriptors.get( Plugin.constructKey( groupId, artifactId ) ); - } - - public boolean isPluginInstalled( String groupId, String artifactId ) - { - // String key = PluginDescriptor.constructPluginKey( groupId, artifactId, version ); - // TODO: see comment in getPluginDescriptor - return pluginDescriptors.containsKey( Plugin.constructKey( groupId, artifactId ) ); + return (PluginDescriptor) pluginDescriptors.get( plugin.getKey() ); } - public String getPluginIdFromPrefix( String prefix ) + public boolean isPluginInstalled( Plugin plugin ) { - if ( !pluginIdsByPrefix.containsKey( prefix ) ) - { - // TODO: lookup remotely - } - return (String) pluginIdsByPrefix.get( prefix ); + // TODO: see comment in getPluginDescriptor + return pluginDescriptors.containsKey( plugin.getKey() ); } + + public PluginDescriptor getPluginDescriptorForPrefix( String prefix ) + { + return (PluginDescriptor) pluginIdsByPrefix.get( prefix ); + } + } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java index 29bc05c555..5d5da99129 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java @@ -23,6 +23,8 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.project.MavenProject; 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 java.util.List; @@ -38,13 +40,14 @@ public interface PluginManager void executeMojo( MavenProject project, MojoExecution execution, MavenSession session ) throws MojoExecutionException, PluginManagerException, ArtifactResolutionException; - String getPluginIdFromPrefix( String prefix ); + PluginDescriptor getPluginDescriptorForPrefix( String prefix ); - PluginDescriptor verifyPlugin( String groupId, String artifactId, String version, MavenProject project, - Settings settings, ArtifactRepository localRepository ) + PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings, + ArtifactRepository localRepository ) throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException; - List getReports( String groupId, String artifactId, String version, ReportSet reportSet, MavenSession session, - MavenProject project ) - throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException; + List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session, + ArtifactRepository localRepository ) + throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException, + ArtifactResolutionException; } \ No newline at end of file diff --git a/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/DefaultPluginMappingBuilder.java b/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/DefaultPluginMappingBuilder.java index 1cde60f5b5..27b94a70dd 100644 --- a/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/DefaultPluginMappingBuilder.java +++ b/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/DefaultPluginMappingBuilder.java @@ -28,15 +28,21 @@ public class DefaultPluginMappingBuilder { PluginMappingManager mappingManager = new PluginMappingManager(); - for ( Iterator it = pluginGroupIds.iterator(); it.hasNext(); ) + if ( pluginGroupIds != null ) { - String groupId = (String) it.next(); + for ( Iterator it = pluginGroupIds.iterator(); it.hasNext(); ) + { + String groupId = (String) it.next(); - File mappingFile = resolveMappingMetadata( groupId, pluginRepositories, localRepository ); + File mappingFile = resolveMappingMetadata( groupId, pluginRepositories, localRepository ); - PluginMap pluginMap = readPluginMap( mappingFile ); - - mappingManager.addPluginMap( pluginMap ); + PluginMap pluginMap = readPluginMap( mappingFile ); + + if ( pluginMap != null ) + { + mappingManager.addPluginMap( pluginMap ); + } + } } return mappingManager; @@ -44,26 +50,33 @@ public class DefaultPluginMappingBuilder private PluginMap readPluginMap( File mappingFile ) throws PluginMappingManagementException { - Reader fileReader = null; - try + if( mappingFile.exists() ) { - fileReader = new FileReader( mappingFile ); + Reader fileReader = null; + try + { + fileReader = new FileReader( mappingFile ); - PluginMappingXpp3Reader mappingReader = new PluginMappingXpp3Reader(); - - return mappingReader.read(fileReader); + PluginMappingXpp3Reader mappingReader = new PluginMappingXpp3Reader(); + + return mappingReader.read(fileReader); + } + catch ( IOException e ) + { + throw new PluginMappingManagementException( "Cannot read plugin mappings from: " + mappingFile, e ); + } + catch ( XmlPullParserException e ) + { + throw new PluginMappingManagementException( "Cannot parse plugin mappings from: " + mappingFile, e ); + } + finally + { + IOUtil.close( fileReader ); + } } - catch ( IOException e ) + else { - throw new PluginMappingManagementException( "Cannot read plugin mappings from: " + mappingFile, e ); - } - catch ( XmlPullParserException e ) - { - throw new PluginMappingManagementException( "Cannot parse plugin mappings from: " + mappingFile, e ); - } - finally - { - IOUtil.close( fileReader ); + return null; } } diff --git a/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java index afdc76bca7..6eb35cd1b1 100644 --- a/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java +++ b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java @@ -744,23 +744,18 @@ public class DoxiaMojo { org.apache.maven.model.ReportPlugin reportPlugin = (org.apache.maven.model.ReportPlugin) it.next(); - try - { - pluginManager.verifyPlugin( reportPlugin.getGroupId(), reportPlugin.getArtifactId(), - reportPlugin.getVersion(), project, settings, localRepository ); - } - catch ( ArtifactResolutionException e ) - { - throw new MojoExecutionException( "Cannot find report plugin", e ); - } - catch ( PluginVersionResolutionException e ) - { - throw new MojoExecutionException( "Cannot resolve version for report plugin", e ); - } - catch ( PluginManagerException e ) - { - throw new MojoExecutionException( "Cannot find report plugin", e ); - } +// try +// { +// pluginManager.verifyPlugin( reportPlugin, project, settings, localRepository ); +// } +// catch ( PluginVersionResolutionException e ) +// { +// throw new MojoExecutionException( "Cannot resolve version for report plugin", e ); +// } +// catch ( PluginManagerException e ) +// { +// throw new MojoExecutionException( "Cannot find report plugin", e ); +// } try { @@ -770,12 +765,11 @@ public class DoxiaMojo if ( reportSets == null || reportSets.isEmpty() ) { - reportsList = pluginManager.getReports( reportPlugin.getGroupId(), - reportPlugin.getArtifactId(), - reportPlugin.getVersion(), + reportsList = pluginManager.getReports( reportPlugin, null, + project, session, - project ); + localRepository ); } else @@ -784,12 +778,11 @@ public class DoxiaMojo { ReportSet reportSet = (ReportSet) j.next(); - reportsList = pluginManager.getReports( reportPlugin.getGroupId(), - reportPlugin.getArtifactId(), - reportPlugin.getVersion(), + reportsList = pluginManager.getReports( reportPlugin, reportSet, + project, session, - project ); + localRepository ); } } @@ -816,6 +809,10 @@ public class DoxiaMojo { throw new MojoExecutionException( "Error getting reports", e ); } + catch ( ArtifactResolutionException e ) + { + throw new MojoExecutionException( "Cannot find report plugin", e ); + } } } return reports; diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java index 1198fa7c86..e36aa36838 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java @@ -854,7 +854,10 @@ public class MavenProject model.setBuild( build ); } - build.addPlugin( plugin ); + if ( !build.getPluginsAsMap().containsKey( plugin.getKey() ) ) + { + build.addPlugin( plugin ); + } } public List getCollectedProjects() diff --git a/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java b/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java index d1b96c182a..f0ef7d2455 100644 --- a/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java +++ b/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java @@ -2,6 +2,7 @@ package org.apache.maven.settings; import org.codehaus.plexus.util.StringUtils; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -43,30 +44,48 @@ public final class SettingsUtils List dominantActiveProfiles = dominant.getActiveProfiles(); List recessiveActiveProfiles = recessive.getActiveProfiles(); - for ( Iterator it = recessiveActiveProfiles.iterator(); it.hasNext(); ) + if ( recessiveActiveProfiles != null ) { - String profileId = (String) it.next(); - - if ( !dominantActiveProfiles.contains( profileId ) ) + if ( dominantActiveProfiles == null ) { - dominantActiveProfiles.add( profileId ); + dominantActiveProfiles = new ArrayList(); + dominant.setActiveProfiles( dominantActiveProfiles ); + } + + for ( Iterator it = recessiveActiveProfiles.iterator(); it.hasNext(); ) + { + String profileId = (String) it.next(); - dominant.getRuntimeInfo().setActiveProfileSourceLevel( profileId, recessiveSourceLevel ); + if ( !dominantActiveProfiles.contains( profileId ) ) + { + dominantActiveProfiles.add( profileId ); + + dominant.getRuntimeInfo().setActiveProfileSourceLevel( profileId, recessiveSourceLevel ); + } } } List dominantPluginGroupIds = dominant.getPluginGroups(); List recessivePluginGroupIds = recessive.getPluginGroups(); - for ( Iterator it = recessivePluginGroupIds.iterator(); it.hasNext(); ) + if( recessivePluginGroupIds != null ) { - String pluginGroupId = (String) it.next(); - - if ( !dominantPluginGroupIds.contains( pluginGroupId ) ) + if( dominantPluginGroupIds == null ) { - dominantPluginGroupIds.add( pluginGroupId ); + dominantPluginGroupIds = new ArrayList(); + dominant.setPluginGroups( dominantPluginGroupIds ); + } + + for ( Iterator it = recessivePluginGroupIds.iterator(); it.hasNext(); ) + { + String pluginGroupId = (String) it.next(); - dominant.getRuntimeInfo().setPluginGroupIdSourceLevel( pluginGroupId, recessiveSourceLevel ); + if ( !dominantPluginGroupIds.contains( pluginGroupId ) ) + { + dominantPluginGroupIds.add( pluginGroupId ); + + dominant.getRuntimeInfo().setPluginGroupIdSourceLevel( pluginGroupId, recessiveSourceLevel ); + } } }