Index: maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java =================================================================== --- maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java (wersja 572447) +++ maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java (kopia robocza) @@ -26,23 +26,28 @@ import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.logging.AbstractLogEnabled; +import com.sun.jmx.remote.util.OrderClassLoaders; + import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; public class MavenPluginCollector extends AbstractLogEnabled implements ComponentDiscoveryListener { + /** + * Map from pluginDescriptor.getKey (groupId:artifactId) into (ordered) map from version into pluginDescriptor + * Internal map is ordered to make sure that builds are determinic (used pluginVersion is determined) + */ + private Map/* > */pluginDescriptors = new HashMap(); - private Set pluginsInProcess = new HashSet(); + private Map/* > */pluginIdsByPrefix = new HashMap(); - private Map pluginDescriptors = new HashMap(); - - private Map pluginIdsByPrefix = new HashMap(); - // ---------------------------------------------------------------------- // Mojo discovery // ---------------------------------------------------------------------- @@ -53,59 +58,125 @@ if ( componentSetDescriptor instanceof PluginDescriptor ) { PluginDescriptor pluginDescriptor = (PluginDescriptor) componentSetDescriptor; - - // TODO: see comment in getPluginDescriptor - String key = Plugin.constructKey( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId() ); - - if ( !pluginsInProcess.contains( key ) ) - { - pluginsInProcess.add( key ); - pluginDescriptors.put( key, pluginDescriptor ); + putIntoPluginDescriptors( pluginDescriptor ); + putIntoPluginIdsByPrefix( pluginDescriptor ); + } + } - // TODO: throw an (not runtime) exception if there is a prefix overlap - means doing so elsewhere - // we also need to deal with multiple versions somehow - currently, first wins - if ( !pluginIdsByPrefix.containsKey( pluginDescriptor.getGoalPrefix() ) ) - { - pluginIdsByPrefix.put( pluginDescriptor.getGoalPrefix(), pluginDescriptor ); - } + public PluginDescriptor getPluginDescriptor( Plugin plugin ) + { + SortedMap/* */pluginVersions = (SortedMap) pluginDescriptors.get( plugin.getKey() ); + if ( pluginVersions != null ) + { + PluginDescriptor res; + if ( plugin.getVersion() != null ) + { + res = (PluginDescriptor) pluginVersions.get( plugin.getVersion() ); } + else + { + res = getDefaultPluginDescriptorVersion( pluginVersions ); + } + return res; } + else + { + return null; + } } - public PluginDescriptor getPluginDescriptor( Plugin plugin ) + private PluginDescriptor getDefaultPluginDescriptorVersion( SortedMap pluginVersions ) { - // 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.getKey() ); + if ( pluginVersions.size() > 0 ) + { + return (PluginDescriptor) pluginVersions.get( pluginVersions.lastKey() ); + } + else + { + return null; + } } public boolean isPluginInstalled( Plugin plugin ) { // TODO: see comment in getPluginDescriptor - return pluginDescriptors.containsKey( plugin.getKey() ); + return getPluginDescriptor( plugin ) != null; } public PluginDescriptor getPluginDescriptorForPrefix( String prefix ) { - return (PluginDescriptor) pluginIdsByPrefix.get( prefix ); + return getPluginDescriptorForPrefix( prefix, null ); } - public void flushPluginDescriptor( Plugin plugin ) + public PluginDescriptor getPluginDescriptorForPrefix( String prefix, String version ) { - pluginsInProcess.remove( plugin.getKey() ); - pluginDescriptors.remove( plugin.getKey() ); - - for ( Iterator it = pluginIdsByPrefix.entrySet().iterator(); it.hasNext(); ) + SortedMap/* */pluginVersions = (SortedMap) pluginIdsByPrefix.get( prefix ); + if ( pluginVersions != null ) { - Map.Entry entry = (Map.Entry) it.next(); - - if ( plugin.getKey().equals( entry.getValue() ) ) + PluginDescriptor res; + if ( version != null ) { - it.remove(); + res = (PluginDescriptor) pluginVersions.get( version ); } + else + { + res = getDefaultPluginDescriptorVersion( pluginVersions ); + } + return res; } + else + { + return null; + } } + public void flushPluginDescriptor( Plugin plugin ) + { + getPluginDescriptor( plugin ).cleanPluginDescriptor(); + } + + /** + * Puts given pluginDescriptor into pluginDescriptors map (if the map does not contains plugin for specified maven + * version) + * + * @param pluginDescriptor + */ + protected void putIntoPluginDescriptors( PluginDescriptor pluginDescriptor ) + { + String key = Plugin.constructKey( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId() ); + + SortedMap/* */descriptorsVersions = (SortedMap) pluginDescriptors.get( key ); + if ( descriptorsVersions == null ) + { + descriptorsVersions = new TreeMap(); + pluginDescriptors.put( key, descriptorsVersions ); + } + + putIntoVersionsMap( descriptorsVersions, pluginDescriptor ); + } + + protected void putIntoVersionsMap( SortedMap/* */pluginVersions, + PluginDescriptor pluginDescriptor ) + { + if ( !pluginVersions.containsKey( pluginDescriptor.getVersion() ) ) + { + pluginVersions.put( pluginDescriptor.getVersion(), pluginDescriptor ); + } + } + + protected void putIntoPluginIdsByPrefix( PluginDescriptor pluginDescriptor ) + { + String goalPrefix = pluginDescriptor.getGoalPrefix(); + + SortedMap/* */descriptorsVersions = (SortedMap) pluginIdsByPrefix.get( goalPrefix ); + if ( descriptorsVersions == null ) + { + descriptorsVersions = new TreeMap(); + pluginIdsByPrefix.put( goalPrefix, descriptorsVersions ); + } + + putIntoVersionsMap( descriptorsVersions, pluginDescriptor ); + } + } Index: maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java =================================================================== --- maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java (wersja 572447) +++ maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java (kopia robocza) @@ -140,44 +140,42 @@ return pluginCollector.getPluginDescriptorForPrefix( prefix ); } - public Plugin getPluginDefinitionForPrefix( String prefix, - MavenSession session, - MavenProject project ) + public Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project ) { - // TODO: since this is only used in the lifecycle executor, maybe it should be moved there? There is no other + // TODO: since this is only used in the lifecycle executor, maybe it + // should be moved there? There is no other // use for the mapping manager in here return pluginMappingManager.getByPrefix( prefix, session.getSettings().getPluginGroups(), - project.getPluginArtifactRepositories(), - session.getLocalRepository() ); + project.getPluginArtifactRepositories(), session.getLocalRepository() ); } - public PluginDescriptor verifyPlugin( Plugin plugin, - MavenProject project, - Settings settings, + public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings, ArtifactRepository localRepository ) throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException, InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException { // 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 ) { - String version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(), - project, settings, localRepository ); + String version = + pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(), project, + settings, localRepository ); plugin.setVersion( version ); } return verifyVersionedPlugin( plugin, project, localRepository ); } - private PluginDescriptor verifyVersionedPlugin( Plugin plugin, - MavenProject project, + private PluginDescriptor verifyVersionedPlugin( Plugin plugin, MavenProject project, ArtifactRepository localRepository ) throws PluginVersionResolutionException, ArtifactNotFoundException, ArtifactResolutionException, InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException { - // TODO: this might result in an artifact "RELEASE" being resolved continuously + // 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. @@ -198,7 +196,7 @@ artifactResolver.resolve( pluginArtifact, project.getPluginArtifactRepositories(), localRepository ); - PlexusContainer pluginContainer = container.getChildContainer( plugin.getKey() ); + PlexusContainer pluginContainer = container.getChildContainer( generateChildContainerName( plugin ) ); File pluginFile = pluginArtifact.getFile(); @@ -206,10 +204,22 @@ { addPlugin( plugin, pluginArtifact, project, localRepository ); } + else if ( !doesPluginDescriptorMatchPlugin( pluginCollector.getPluginDescriptor( plugin ), plugin, project ) ) + { + if ( getLogger() != null ) + getLogger().info( + "Reloading plugin container for: " + plugin != null ? plugin.getKey() : "null" + + ". The plugin does not match" ); + pluginContainer.dispose(); + + pluginCollector.flushPluginDescriptor( plugin ); + addPlugin( plugin, pluginArtifact, project, localRepository ); + } else if ( pluginFile.lastModified() > pluginContainer.getCreationDate().getTime() ) { getLogger().info( - "Reloading plugin container for: " + plugin.getKey() + ". The plugin artifact has changed." ); + "Reloading plugin container for: " + plugin.getKey() + + ". The plugin artifact has changed." ); pluginContainer.dispose(); @@ -244,22 +254,44 @@ return pluginCollector.getPluginDescriptor( plugin ); } + private boolean doesPluginDescriptorMatchPlugin( PluginDescriptor pluginDescriptor, Plugin plugin, + MavenProject project ) throws InvalidPluginException + { + Set dependenciesFromPlugin=getIntroducedDependenciesForPlugin( project, plugin ); + return areArtifactSetsEqual(dependenciesFromPlugin, pluginDescriptor.getIntroducedDependencyArtifacts()); + } + + private static boolean areArtifactSetsEqual( Set dependenciesFromPlugin, Set introducedDependencyArtifacts ) + { + return computativeHashCode(dependenciesFromPlugin)==computativeHashCode(introducedDependencyArtifacts); + } + + private static long computativeHashCode( Set dependenciesFromPlugin ) + { + long hashCode=1; + Iterator/**/ iter=dependenciesFromPlugin.iterator(); + while(iter.hasNext()) + { + hashCode=(hashCode*iter.next().hashCode())%2096543357; + } + return hashCode; + } + /** * @todo would be better to store this in the plugin descriptor, but then it won't be available to the version - * manager which executes before the plugin is instantiated + * manager which executes before the plugin is instantiated */ - private void checkRequiredMavenVersion( Plugin plugin, - ArtifactRepository localRepository, - List remoteRepositories ) + private void checkRequiredMavenVersion( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories ) throws PluginVersionResolutionException, InvalidPluginException { try { - Artifact artifact = artifactFactory.createProjectArtifact( plugin.getGroupId(), plugin.getArtifactId(), - plugin.getVersion() ); + Artifact artifact = + artifactFactory.createProjectArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ); MavenProject project = mavenProjectBuilder.buildFromRepository( artifact, 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 ) { DefaultArtifactVersion requiredVersion = @@ -273,14 +305,12 @@ } catch ( ProjectBuildingException e ) { - throw new InvalidPluginException( - "Unable to build project for plugin '" + plugin.getKey() + "': " + e.getMessage(), e ); + throw new InvalidPluginException( "Unable to build project for plugin '" + plugin.getKey() + "': " + + e.getMessage(), e ); } } - protected void addPlugin( Plugin plugin, - Artifact pluginArtifact, - MavenProject project, + protected void addPlugin( Plugin plugin, Artifact pluginArtifact, MavenProject project, ArtifactRepository localRepository ) throws PluginManagerException, InvalidPluginException { @@ -288,12 +318,38 @@ try { - child = container.createChildContainer( plugin.getKey(), - Collections.singletonList( pluginArtifact.getFile() ), - Collections.EMPTY_MAP, - Collections.singletonList( pluginCollector ) ); + child = + container.createChildContainer( generateChildContainerName( plugin ), + Collections.singletonList( pluginArtifact.getFile() ), + Collections.EMPTY_MAP, Collections.singletonList( pluginCollector ) ); + + /* This code is connected to bug in plexus (1.0-alpha-9) that + * created new DiscoveryListener instead of using's parent's. + * + * The code removes the listener ASAP. + * */ try { + MavenPluginCollector childMavenPluginCollector = + (MavenPluginCollector) child.lookup( MavenPluginCollector.class.getName() ); + if ( childMavenPluginCollector != pluginCollector ) + { + child.removeComponentDiscoveryListener( childMavenPluginCollector ); + child.release( childMavenPluginCollector ); + if ( getLogger() != null ) + getLogger().debug( "Removed unnecessary resolutin listener (bug in Plexus 1.0-alpha-9" ); + } + }catch(ComponentLookupException e) + { + //Do nothing + }catch(ComponentLifecycleException e) + { + if(getLogger()!=null) + getLogger().warn(e.getMessage(),e); + } + + try + { child.getContainerRealm().importFrom( "plexus.core", "org.codehaus.plexus.util.xml.Xpp3Dom" ); child.getContainerRealm().importFrom( "plexus.core", "org.codehaus.plexus.util.xml.pull" ); } @@ -304,11 +360,12 @@ } catch ( PlexusContainerException e ) { - throw new PluginManagerException( - "Failed to create plugin container for plugin '" + plugin + "': " + e.getMessage(), e ); + throw new PluginManagerException( "Failed to create plugin container for plugin '" + plugin + "': " + + e.getMessage(), e ); } - // 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 PluginDescriptor addedPlugin = pluginCollector.getPluginDescriptor( plugin ); @@ -319,15 +376,29 @@ addedPlugin.setClassRealm( child.getContainerRealm() ); - // we're only setting the plugin's artifact itself as the artifact list, to allow it to be retrieved - // later when the plugin is first invoked. Retrieving this artifact will in turn allow us to - // transitively resolve its dependencies, and add them to the plugin container... + // we're only setting the plugin's artifact itself as the artifact list, + // to allow it to be retrieved + // later when the plugin is first invoked. Retrieving this artifact will + // in turn allow us to + // transitively resolve its dependencies, and add them to the plugin + // container... addedPlugin.setArtifacts( Collections.singletonList( pluginArtifact ) ); + addedPlugin.setIntroducedDependencyArtifacts( getIntroducedDependenciesForPlugin( project, plugin ) ); + } + // ---------------------------------------------------------------------- + // Mojo execution + // ---------------------------------------------------------------------- + + private Set getIntroducedDependenciesForPlugin( MavenProject project, Plugin plugin ) + throws InvalidPluginException + { try { - // the only Plugin instance which will have dependencies is the one specified in the project. - // We need to look for a Plugin instance there, in case the instance we're using didn't come from + // the only Plugin instance which will have dependencies is the one + // specified in the project. + // We need to look for a Plugin instance there, in case the instance + // we're using didn't come from // the project. Plugin projectPlugin = (Plugin) project.getBuild().getPluginsAsMap().get( plugin.getKey() ); @@ -336,33 +407,31 @@ projectPlugin = plugin; } - Set artifacts = MavenMetadataSource.createArtifacts( artifactFactory, projectPlugin.getDependencies(), null, - null, project ); + Set artifacts = + MavenMetadataSource.createArtifacts( artifactFactory, projectPlugin.getDependencies(), null, null, + project ); -// Set artifacts = -// MavenMetadataSource.createArtifacts( artifactFactory, plugin.getDependencies(), null, null, project ); + // Set artifacts = + // MavenMetadataSource.createArtifacts( artifactFactory, + // plugin.getDependencies(), null, null, project ); - addedPlugin.setIntroducedDependencyArtifacts( artifacts ); + return artifacts; } catch ( InvalidDependencyVersionException e ) { throw new InvalidPluginException( "Plugin '" + plugin + "' is invalid: " + e.getMessage(), e ); } + } - // ---------------------------------------------------------------------- - // Mojo execution - // ---------------------------------------------------------------------- - - public void executeMojo( MavenProject project, - MojoExecution mojoExecution, - MavenSession session ) + public void executeMojo( MavenProject project, MojoExecution mojoExecution, MavenSession session ) throws ArtifactResolutionException, MojoExecutionException, MojoFailureException, ArtifactNotFoundException, InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); - // NOTE: I'm putting these checks in here, since this is the central point of access for + // NOTE: I'm putting these checks in here, since this is the central + // point of access for // anything that wants to execute a mojo. if ( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem() ) { @@ -438,7 +507,7 @@ try { Thread.currentThread().setContextClassLoader( - mojoDescriptor.getPluginDescriptor().getClassRealm().getClassLoader() ); + mojoDescriptor.getPluginDescriptor().getClassRealm().getClassLoader() ); plugin.execute(); @@ -477,16 +546,15 @@ } } - public MavenReport getReport( MavenProject project, - MojoExecution mojoExecution, - MavenSession session ) + public MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session ) throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException, ArtifactResolutionException { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); PluginDescriptor descriptor = mojoDescriptor.getPluginDescriptor(); - Xpp3Dom dom = project.getReportConfiguration( descriptor.getGroupId(), descriptor.getArtifactId(), - mojoExecution.getExecutionId() ); + Xpp3Dom dom = + project.getReportConfiguration( descriptor.getGroupId(), descriptor.getArtifactId(), + mojoExecution.getExecutionId() ); if ( mojoExecution.getConfiguration() != null ) { dom = Xpp3Dom.mergeXpp3Dom( dom, mojoExecution.getConfiguration() ); @@ -495,9 +563,7 @@ return (MavenReport) getConfiguredMojo( session, dom, project, true, mojoExecution ); } - public PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, - MavenProject project, - MavenSession session ) + public PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session ) throws PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException, InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException @@ -506,10 +572,10 @@ if ( version == null ) { - version = pluginVersionManager.resolveReportPluginVersion( reportPlugin.getGroupId(), - reportPlugin.getArtifactId(), project, - session.getSettings(), - session.getLocalRepository() ); + version = + pluginVersionManager.resolveReportPluginVersion( reportPlugin.getGroupId(), + reportPlugin.getArtifactId(), project, + session.getSettings(), session.getLocalRepository() ); reportPlugin.setVersion( version ); } @@ -525,7 +591,7 @@ private PlexusContainer getPluginContainer( PluginDescriptor pluginDescriptor ) throws PluginManagerException { - String pluginKey = pluginDescriptor.getPluginLookupKey(); + String pluginKey = generateChildContainerName( pluginDescriptor ); PlexusContainer pluginContainer = container.getChildContainer( pluginKey ); @@ -537,10 +603,17 @@ return pluginContainer; } - private Mojo getConfiguredMojo( MavenSession session, - Xpp3Dom dom, - MavenProject project, - boolean report, + private String generateChildContainerName( Plugin plugin ) + { + return plugin.getKey() + ":" + plugin.getVersion(); + } + + private String generateChildContainerName( PluginDescriptor pluginDescriptor ) + { + return pluginDescriptor.getPluginLookupKey() + ":" + pluginDescriptor.getVersion(); + } + + private Mojo getConfiguredMojo( MavenSession session, Xpp3Dom dom, MavenProject project, boolean report, MojoExecution mojoExecution ) throws PluginConfigurationException, ArtifactNotFoundException, PluginManagerException, ArtifactResolutionException @@ -551,8 +624,10 @@ PlexusContainer pluginContainer = getPluginContainer( pluginDescriptor ); - // if this is the first time this plugin has been used, the plugin's container will only - // contain the plugin's artifact in isolation; we need to finish resolving the plugin's + // if this is the first time this plugin has been used, the plugin's + // container will only + // contain the plugin's artifact in isolation; we need to finish + // resolving the plugin's // dependencies, and add them to the container. ensurePluginContainerIsComplete( pluginDescriptor, pluginContainer, project, session ); @@ -562,7 +637,8 @@ plugin = (Mojo) pluginContainer.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() ); if ( report && !( plugin instanceof MavenReport ) ) { - // TODO: the mojoDescriptor should actually capture this information so we don't get this far + // TODO: the mojoDescriptor should actually capture this + // information so we don't get this far return null; } } @@ -591,40 +667,42 @@ pomConfiguration = new XmlPlexusConfiguration( dom ); } - // Validate against non-editable (@readonly) parameters, to make sure users aren't trying to + // Validate against non-editable (@readonly) parameters, to make sure + // users aren't trying to // override in the POM. validatePomConfiguration( mojoDescriptor, pomConfiguration ); PlexusConfiguration mergedConfiguration = mergeMojoConfiguration( pomConfiguration, mojoDescriptor ); - // TODO: plexus changes to make this more like the component descriptor so this can be used instead - // PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration, - // mojoDescriptor.getConfiguration() ); + // TODO: plexus changes to make this more like the component descriptor + // so this can be used instead + // PlexusConfiguration mergedConfiguration = mergeConfiguration( + // pomConfiguration, + // mojoDescriptor.getConfiguration() ); - ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, mojoExecution, - pathTranslator, getLogger(), - project, - session.getExecutionProperties() ); + ExpressionEvaluator expressionEvaluator = + new PluginParameterExpressionEvaluator( session, mojoExecution, pathTranslator, getLogger(), project, + session.getExecutionProperties() ); - PlexusConfiguration extractedMojoConfiguration = - extractMojoConfiguration( mergedConfiguration, mojoDescriptor ); + PlexusConfiguration extractedMojoConfiguration = extractMojoConfiguration( mergedConfiguration, mojoDescriptor ); checkRequiredParameters( mojoDescriptor, extractedMojoConfiguration, expressionEvaluator ); - populatePluginFields( plugin, mojoDescriptor, extractedMojoConfiguration, pluginContainer, - expressionEvaluator ); + populatePluginFields( plugin, mojoDescriptor, extractedMojoConfiguration, pluginContainer, expressionEvaluator ); return plugin; } - private void ensurePluginContainerIsComplete( PluginDescriptor pluginDescriptor, - PlexusContainer pluginContainer, - MavenProject project, - MavenSession session ) + private void ensurePluginContainerIsComplete( PluginDescriptor pluginDescriptor, PlexusContainer pluginContainer, + MavenProject project, MavenSession session ) throws ArtifactNotFoundException, PluginManagerException, ArtifactResolutionException { // if the plugin's already been used once, don't re-do this step... - // otherwise, we have to finish resolving the plugin's classpath and start the container. - if ( pluginDescriptor.getArtifacts() != null && pluginDescriptor.getArtifacts().size() == 1 ) + // otherwise, we have to finish resolving the plugin's classpath and + // start the container. + // if (pluginDescriptor.getArtifacts() != null + // && pluginDescriptor.getArtifacts().size() == 1) { + + if ( pluginDescriptor.getNeedToBeComplited() ) { Artifact pluginArtifact = (Artifact) pluginDescriptor.getArtifacts().get( 0 ); @@ -633,8 +711,9 @@ ResolutionGroup resolutionGroup; try { - resolutionGroup = artifactMetadataSource.retrieve( pluginArtifact, localRepository, - project.getPluginArtifactRepositories() ); + resolutionGroup = + artifactMetadataSource.retrieve( pluginArtifact, localRepository, + project.getPluginArtifactRepositories() ); } catch ( ArtifactMetadataRetrievalException e ) { @@ -651,11 +730,10 @@ repositories.addAll( resolutionGroup.getResolutionRepositories() ); repositories.addAll( project.getRemoteArtifactRepositories() ); - ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencies, pluginArtifact, - Collections.EMPTY_MAP, - localRepository, repositories, - artifactMetadataSource, - artifactFilter ); + ArtifactResolutionResult result = + artifactResolver.resolveTransitively( dependencies, pluginArtifact, Collections.EMPTY_MAP, + localRepository, repositories, artifactMetadataSource, + artifactFilter ); Set resolved = result.getArtifacts(); @@ -669,7 +747,7 @@ try { - pluginContainer.addJarResource( artifact.getFile() ); + pluginContainer.addJarResource( artifact.getFile() ); } catch ( PlexusContainerException e ) { @@ -692,17 +770,26 @@ allResolved.addAll( resolved ); allResolved.addAll( unresolved ); + // We want the source artifact to be first + allResolved.remove( pluginArtifact ); + allResolved.add( 0, pluginArtifact ); + pluginDescriptor.setArtifacts( allResolved ); + pluginDescriptor.setNeedToBeComplited( false ); } } public static void checkPlexusUtils( ResolutionGroup resolutionGroup, ArtifactFactory artifactFactory ) { // ---------------------------------------------------------------------------- - // If the plugin already declares a dependency on plexus-utils then we're all - // set as the plugin author is aware of its use. If we don't have a dependency - // on plexus-utils then we must protect users from stupid plugin authors who - // did not declare a direct dependency on plexus-utils because the version + // If the plugin already declares a dependency on plexus-utils then + // we're all + // set as the plugin author is aware of its use. If we don't have a + // dependency + // on plexus-utils then we must protect users from stupid plugin authors + // who + // did not declare a direct dependency on plexus-utils because the + // version // Maven uses is hidden from downstream use. We will also bump up any // anything below 1.1 to 1.1 as this mimics the behaviour in 2.0.5 where // plexus-utils 1.1 was being forced into use. @@ -736,19 +823,19 @@ if ( !plexusUtilsPresent ) { - // We will add plexus-utils as every plugin was getting this anyway from Maven itself. We will set the - // version to the latest version we know that works as of the 2.0.6 release. We set the scope to runtime + // We will add plexus-utils as every plugin was getting this anyway + // from Maven itself. We will set the + // 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. - resolutionGroup.getArtifacts().add( artifactFactory.createArtifact( "org.codehaus.plexus", - "plexus-utils", "1.1", - Artifact.SCOPE_RUNTIME, "jar" ) ); + resolutionGroup.getArtifacts().add( + artifactFactory.createArtifact( "org.codehaus.plexus", "plexus-utils", + "1.1", Artifact.SCOPE_RUNTIME, "jar" ) ); } } - private void resolveCoreArtifacts( List unresolved, - ArtifactRepository localRepository, - List resolutionRepositories ) + private void resolveCoreArtifacts( List unresolved, ArtifactRepository localRepository, List resolutionRepositories ) throws ArtifactResolutionException, ArtifactNotFoundException { for ( Iterator it = unresolved.iterator(); it.hasNext(); ) @@ -820,24 +907,29 @@ } else { - // TODO: I defy anyone to find these messages in the '-X' output! Do we need a new log 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 - // removed - shouldn't need DEBUG to diagnose a problem most of the time. - getLogger().debug( "*** WARNING: Configuration \'" + child.getName() + "\' is not used in goal \'" + - mojoDescriptor.getFullGoalName() + "; this may indicate a typo... ***" ); + // TODO: I defy anyone to find these messages in the '-X' + // output! Do we need a new log 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 + // removed - shouldn't need DEBUG to diagnose a problem most of + // the time. + getLogger().debug( + "*** WARNING: Configuration \'" + child.getName() + "\' is not used in goal \'" + + mojoDescriptor.getFullGoalName() + "; this may indicate a typo... ***" ); } } return extractedConfiguration; } - private void checkRequiredParameters( MojoDescriptor goal, - PlexusConfiguration configuration, + private void checkRequiredParameters( MojoDescriptor goal, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator ) throws PluginConfigurationException { - // TODO: this should be built in to the configurator, as we presently double process the expressions + // TODO: this should be built in to the configurator, as we presently + // double process the expressions List parameters = goal.getParameters(); @@ -908,8 +1000,7 @@ } } - private void validatePomConfiguration( MojoDescriptor goal, - PlexusConfiguration pomConfiguration ) + private void validatePomConfiguration( MojoDescriptor goal, PlexusConfiguration pomConfiguration ) throws PluginConfigurationException { List parameters = goal.getParameters(); @@ -936,11 +1027,12 @@ if ( value != null ) { - // 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() ) { - StringBuffer errorMessage = new StringBuffer() - .append( "ERROR: Cannot override read-only parameter: " ); + StringBuffer errorMessage = + new StringBuffer().append( "ERROR: Cannot override read-only parameter: " ); errorMessage.append( key ); errorMessage.append( " in goal: " ).append( goal.getFullGoalName() ); @@ -956,8 +1048,7 @@ } } - private PlexusConfiguration mergeMojoConfiguration( XmlPlexusConfiguration fromPom, - MojoDescriptor mojoDescriptor ) + private PlexusConfiguration mergeMojoConfiguration( XmlPlexusConfiguration fromPom, MojoDescriptor mojoDescriptor ) { XmlPlexusConfiguration result = new XmlPlexusConfiguration( fromPom.getName() ); result.setValue( fromPom.getValue( null ) ); @@ -984,7 +1075,8 @@ PlexusConfiguration mojoConfig = fromMojo.getChild( paramName, false ); - // first we'll merge configurations from the aliased and real params. + // first we'll merge configurations from the aliased and real + // params. // TODO: Is this the right thing to do? if ( aliased != null ) { @@ -1082,7 +1174,7 @@ result.addChild( buildTopDownMergedConfiguration( childDom, childRec ) ); } else - { // FIXME: copy, or use reference? + { // FIXME: copy, or use reference? result.addChild( copyConfiguration( childDom ) ); } } @@ -1116,11 +1208,8 @@ // Mojo Parameter Handling // ---------------------------------------------------------------------- - private void populatePluginFields( Mojo plugin, - MojoDescriptor mojoDescriptor, - PlexusConfiguration configuration, - PlexusContainer pluginContainer, - ExpressionEvaluator expressionEvaluator ) + private void populatePluginFields( Mojo plugin, MojoDescriptor mojoDescriptor, PlexusConfiguration configuration, + PlexusContainer pluginContainer, ExpressionEvaluator expressionEvaluator ) throws PluginConfigurationException { ComponentConfigurator configurator = null; @@ -1129,8 +1218,10 @@ { String configuratorId = mojoDescriptor.getComponentConfigurator(); - // TODO: could the configuration be passed to lookup and the configurator known to plexus via the descriptor - // so that this meethod could entirely be handled by a plexus lookup? + // TODO: could the configuration be passed to lookup and the + // configurator known to plexus via the descriptor + // so that this meethod could entirely be handled by a plexus + // lookup? if ( StringUtils.isNotEmpty( configuratorId ) ) { configurator = @@ -1155,7 +1246,8 @@ } catch ( ComponentLookupException e ) { - throw new PluginConfigurationException( mojoDescriptor.getPluginDescriptor(), + throw new PluginConfigurationException( + mojoDescriptor.getPluginDescriptor(), "Unable to retrieve component configurator for plugin configuration", e ); } @@ -1175,8 +1267,7 @@ } } - public static String createPluginParameterRequiredMessage( MojoDescriptor mojo, - Parameter parameter, + public static String createPluginParameterRequiredMessage( MojoDescriptor mojo, Parameter parameter, String expression ) { StringBuffer message = new StringBuffer(); @@ -1215,32 +1306,32 @@ // Artifact resolution // ---------------------------------------------------------------------- - private void resolveTransitiveDependencies( MavenSession context, - ArtifactResolver artifactResolver, - String scope, - ArtifactFactory artifactFactory, - MavenProject project ) + private void resolveTransitiveDependencies( MavenSession context, ArtifactResolver artifactResolver, String scope, + ArtifactFactory artifactFactory, MavenProject project ) throws ArtifactResolutionException, ArtifactNotFoundException, InvalidDependencyVersionException { ArtifactFilter filter = new ScopeArtifactFilter( scope ); - // TODO: such a call in MavenMetadataSource too - packaging not really the intention of type - Artifact artifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(), - project.getVersion(), project.getPackaging() ); + // TODO: such a call in MavenMetadataSource too - packaging not really + // the intention of type + Artifact artifact = + artifactFactory.createBuildArtifact( project.getGroupId(), 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. - // Don't recreate if already created - for effeciency, and because clover plugin adds to it + // Don't recreate if already created - for effeciency, and because + // clover plugin adds to it if ( project.getDependencyArtifacts() == null ) { project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) ); } - ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(), - artifact, - project.getManagedVersionMap(), - context.getLocalRepository(), - project.getRemoteArtifactRepositories(), - artifactMetadataSource, filter ); + ArtifactResolutionResult result = + artifactResolver.resolveTransitively( project.getDependencyArtifacts(), artifact, + project.getManagedVersionMap(), context.getLocalRepository(), + project.getRemoteArtifactRepositories(), artifactMetadataSource, + filter ); project.setArtifacts( result.getArtifacts() ); } @@ -1249,9 +1340,7 @@ // Artifact downloading // ---------------------------------------------------------------------- - private void downloadDependencies( MavenProject project, - MavenSession context, - ArtifactResolver artifactResolver ) + private void downloadDependencies( MavenProject project, MavenSession context, ArtifactResolver artifactResolver ) throws ArtifactResolutionException, ArtifactNotFoundException { ArtifactRepository localRepository = context.getLocalRepository(); @@ -1265,9 +1354,7 @@ } } - public Object getPluginComponent( Plugin plugin, - String role, - String roleHint ) + public Object getPluginComponent( Plugin plugin, String role, String roleHint ) throws PluginManagerException, ComponentLookupException { PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( plugin ); @@ -1277,8 +1364,7 @@ return pluginContainer.lookup( role, roleHint ); } - public Map getPluginComponents( Plugin plugin, - String role ) + public Map getPluginComponents( Plugin plugin, String role ) throws ComponentLookupException, PluginManagerException { PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( plugin ); Index: maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java =================================================================== --- maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java (wersja 572447) +++ maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java (kopia robocza) @@ -59,7 +59,7 @@ private boolean inheritedByDefault = true; private List artifacts; - + private Map lifecycleMappings; private ClassRealm classRealm; @@ -73,6 +73,12 @@ private String description; + /** + * This fields is flag that marks situation that introducedDependencyArtifacts has changed (or another change was + * made that require new resolving of dependencies + */ + private boolean needToBeComplited = true; + // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @@ -86,8 +92,10 @@ throws DuplicateMojoDescriptorException { MojoDescriptor existing = null; - // this relies heavily on the equals() and hashCode() for ComponentDescriptor, - // which uses role:roleHint for identity...and roleHint == goalPrefix:goal. + // this relies heavily on the equals() and hashCode() for + // ComponentDescriptor, + // which uses role:roleHint for identity...and roleHint == + // goalPrefix:goal. // role does not vary for Mojos. List mojos = getComponents(); @@ -100,8 +108,9 @@ if ( existing != null ) { - throw new DuplicateMojoDescriptorException( getGoalPrefix(), mojoDescriptor.getGoal(), existing - .getImplementation(), mojoDescriptor.getImplementation() ); + throw new DuplicateMojoDescriptorException( getGoalPrefix(), mojoDescriptor.getGoal(), + existing.getImplementation(), + mojoDescriptor.getImplementation() ); } else { @@ -160,7 +169,7 @@ /** * Parse maven-...-plugin. - * + * * @todo move to plugin-tools-api as a default only */ public static String getGoalPrefixFromArtifactId( String artifactId ) @@ -248,14 +257,15 @@ return getId().equals( ( (PluginDescriptor) object ).getId() ); } - public int hashCode() - { - return 10 + getId().hashCode(); - } + // public int hashCode() + // { + // return 10 + getId().hashCode(); + // } public MojoDescriptor getMojo( String goal ) { - // TODO: could we use a map? Maybe if the parent did that for components too, as this is too vulnerable to + // TODO: could we use a map? Maybe if the parent did that for components + // too, as this is too vulnerable to // changes above not being propogated to the map MojoDescriptor mojoDescriptor = null; @@ -307,6 +317,34 @@ return (Lifecycle) lifecycleMappings.get( lifecycle ); } + public void setName( String name ) + { + this.name = name; + } + + public String getName() + { + return name; + } + + public void setDescription( String description ) + { + this.description = description; + } + + public String getDescription() + { + return description; + } + + /*----------------------------------------------------------------------- + * Additional logic that does not belongs (unfortunately) to + * PluginDescriptor logic + * + * In fact the setIntroducedDependencyArtifacts code should be moved away + * the class because it is not logical part of PluginDescriptor + */ + public void setClassRealm( ClassRealm classRealm ) { this.classRealm = classRealm; @@ -326,24 +364,28 @@ { return introducedDependencyArtifacts != null ? introducedDependencyArtifacts : Collections.EMPTY_SET; } - - public void setName( String name ) + + public boolean getNeedToBeComplited() { - this.name = name; + return needToBeComplited; } - - public String getName() + + public void setNeedToBeComplited( boolean a_needToBeComplited ) { - return name; + needToBeComplited = a_needToBeComplited; } - - public void setDescription( String description ) + + /** + * Removes all changes made by MavenPluginManager.ensurePluginContainerIsComplete method. Should move the + * PlexusDescriptor to state the same after it was created by plexus during the PluginDiscovery process. + */ + public void cleanPluginDescriptor() { - this.description = description; + + if ( artifacts != null && artifacts.size() > 1 ) + setArtifacts( Collections.singletonList( artifacts.get( 0 ) ) ); + introducedDependencyArtifacts = null; + setClassRealm( null ); + needToBeComplited = true; } - - public String getDescription() - { - return description; - } -} +}; \ brakuje znaku końca linii na końcu pliku