From 9f50eabea54343fca522f42a2a41ffdb086e3240 Mon Sep 17 00:00:00 2001 From: Igor Fedorenko Date: Wed, 25 Mar 2015 15:39:27 -0400 Subject: [PATCH] MNG-5793 do not register same realm both with plugin and extensions realm caches Signed-off-by: Igor Fedorenko --- .../internal/DefaultMavenPluginManager.java | 115 +++++++++--------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java index d300c45f5d..d32e04c162 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java @@ -333,35 +333,63 @@ public class DefaultMavenPluginManager throws PluginResolutionException, PluginContainerException { Plugin plugin = pluginDescriptor.getPlugin(); - MavenProject project = session.getCurrentProject(); - Map foreignImports = calcImports( project, parent, imports ); - - PluginRealmCache.Key cacheKey = - pluginRealmCache.createKey( plugin, parent, foreignImports, filter, project.getRemotePluginRepositories(), - session.getRepositorySession() ); - - PluginRealmCache.CacheRecord cacheRecord = pluginRealmCache.get( cacheKey ); - - if ( cacheRecord != null ) + if ( plugin.isExtensions() ) { - pluginDescriptor.setClassRealm( cacheRecord.realm ); - pluginDescriptor.setArtifacts( new ArrayList( cacheRecord.artifacts ) ); + ExtensionRealmCache.CacheRecord extensionRecord; + try + { + RepositorySystemSession repositorySession = session.getRepositorySession(); + extensionRecord = setupExtensionsRealm( project, plugin, repositorySession ); + } + catch ( PluginManagerException e ) + { + // extensions realm is expected to be fully setup at this point + // any exception means a problem in maven code, not a user error + throw new IllegalStateException( e ); + } + + ClassRealm pluginRealm = extensionRecord.realm; + List pluginArtifacts = extensionRecord.artifacts; + for ( ComponentDescriptor componentDescriptor : pluginDescriptor.getComponents() ) { - componentDescriptor.setRealm( cacheRecord.realm ); + componentDescriptor.setRealm( pluginRealm ); } + + pluginDescriptor.setClassRealm( pluginRealm ); + pluginDescriptor.setArtifacts( pluginArtifacts ); } else { - createPluginRealm( pluginDescriptor, session, parent, foreignImports, filter ); + Map foreignImports = calcImports( project, parent, imports ); - cacheRecord = - pluginRealmCache.put( cacheKey, pluginDescriptor.getClassRealm(), pluginDescriptor.getArtifacts() ); + PluginRealmCache.Key cacheKey = + pluginRealmCache.createKey( plugin, parent, foreignImports, filter, + project.getRemotePluginRepositories(), session.getRepositorySession() ); + + PluginRealmCache.CacheRecord cacheRecord = pluginRealmCache.get( cacheKey ); + + if ( cacheRecord != null ) + { + pluginDescriptor.setClassRealm( cacheRecord.realm ); + pluginDescriptor.setArtifacts( new ArrayList( cacheRecord.artifacts ) ); + for ( ComponentDescriptor componentDescriptor : pluginDescriptor.getComponents() ) + { + componentDescriptor.setRealm( cacheRecord.realm ); + } + } + else + { + createPluginRealm( pluginDescriptor, session, parent, foreignImports, filter ); + + cacheRecord = + pluginRealmCache.put( cacheKey, pluginDescriptor.getClassRealm(), pluginDescriptor.getArtifacts() ); + } + + pluginRealmCache.register( project, cacheKey, cacheRecord ); } - - pluginRealmCache.register( project, cacheKey, cacheRecord ); } private void createPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent, @@ -388,49 +416,24 @@ public class DefaultMavenPluginManager final List pluginArtifacts; RepositorySystemSession repositorySession = session.getRepositorySession(); - if ( plugin.isExtensions() ) - { - ExtensionRealmCache.CacheRecord extensionRecord; - try - { - extensionRecord = setupExtensionsRealm( project, plugin, repositorySession ); - } - catch ( PluginManagerException e ) - { - // extensions realm is expected to be fully setup at this point - // any exception means a problem in maven code, not a user error - throw new IllegalStateException( e ); - } + DependencyFilter dependencyFilter = project.getExtensionDependencyFilter(); + dependencyFilter = AndDependencyFilter.newInstance( dependencyFilter, filter ); - pluginRealm = extensionRecord.realm; - pluginArtifacts = extensionRecord.artifacts; + DependencyNode root = + pluginDependenciesResolver.resolve( plugin, RepositoryUtils.toArtifact( pluginArtifact ), + dependencyFilter, project.getRemotePluginRepositories(), + repositorySession ); - for ( ComponentDescriptor componentDescriptor : pluginDescriptor.getComponents() ) - { - componentDescriptor.setRealm( pluginRealm ); - } - } - else - { - DependencyFilter dependencyFilter = project.getExtensionDependencyFilter(); - dependencyFilter = AndDependencyFilter.newInstance( dependencyFilter, filter ); + PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); + root.accept( nlg ); - DependencyNode root = - pluginDependenciesResolver.resolve( plugin, RepositoryUtils.toArtifact( pluginArtifact ), - dependencyFilter, project.getRemotePluginRepositories(), - repositorySession ); + pluginArtifacts = toMavenArtifacts( root, nlg ); - PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); - root.accept( nlg ); + pluginRealm = + classRealmManager.createPluginRealm( plugin, parent, null, foreignImports, + toAetherArtifacts( pluginArtifacts ) ); - pluginArtifacts = toMavenArtifacts( root, nlg ); - - pluginRealm = - classRealmManager.createPluginRealm( plugin, parent, null, foreignImports, - toAetherArtifacts( pluginArtifacts ) ); - - discoverPluginComponents( pluginRealm, plugin, pluginDescriptor ); - } + discoverPluginComponents( pluginRealm, plugin, pluginDescriptor ); pluginDescriptor.setClassRealm( pluginRealm ); pluginDescriptor.setArtifacts( pluginArtifacts );