diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java index 12ed85a2c2..bee4ab958b 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java @@ -127,10 +127,6 @@ public class ArtifactResolutionRequest return this; } - // ------------------------------------------------------------------------ - // - // ------------------------------------------------------------------------ - public ArtifactMetadataSource getMetadataSource() { return metadataSource; 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 3363ec2990..0685d56df1 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 @@ -41,6 +41,7 @@ import org.apache.maven.lifecycle.mapping.LifecycleMapping; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.PluginExecutionException; import org.apache.maven.plugin.PluginLoaderException; import org.apache.maven.plugin.PluginManager; import org.apache.maven.plugin.PluginParameterExpressionEvaluator; @@ -64,6 +65,12 @@ import org.codehaus.plexus.util.xml.Xpp3Dom; //TODO: Inside an IDE we are replacing the notion of our reactor with a workspace. In both of these cases // we need to layer these as local repositories. //TODO: Cache the lookups of the PluginDescriptors +//TODO: check for online status in the build plan and die if necessary +//TODO if ( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem() ) +//{ +// throw new PluginExecutionException( mojoExecution, project, "Cannot execute mojo: " + mojoDescriptor.getGoal() +// + ". It requires a project with an existing pom.xml, but the build is not using one." ); +//} /** * @author Jason van Zyl diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginClassLoaderCache.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginClassLoaderCache.java index 518714abba..71412d1610 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginClassLoaderCache.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginClassLoaderCache.java @@ -22,4 +22,8 @@ public class DefaultPluginClassLoaderCache return pluginClassLoaders.get( key ); } + public int size() + { + return pluginClassLoaders.size(); + } } 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 e8ad5bde98..bf0caa3e6d 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 @@ -148,10 +148,6 @@ public class DefaultPluginManager { throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e ); } - catch ( PluginVersionResolutionException e ) - { - throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e ); - } catch ( PluginContainerException e ) { throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e ); @@ -168,7 +164,7 @@ public class DefaultPluginManager } protected PluginDescriptor addPlugin( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories ) - throws ArtifactNotFoundException, ArtifactResolutionException, PluginVersionResolutionException, PluginContainerException, PluginVersionNotFoundException + throws ArtifactNotFoundException, ArtifactResolutionException, PluginContainerException, PluginVersionNotFoundException { Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin ); @@ -181,7 +177,14 @@ public class DefaultPluginManager resolutionErrorHandler.throwErrors( request, result ); - ClassRealm pluginRealm = container.createChildRealm( pluginKey( plugin ) ); + ClassRealm pluginRealm = pluginClassLoaderCache.get( constructPluginKey( plugin ) ); + + if ( pluginRealm != null ) + { + return getPluginDescriptor( plugin ); + } + + pluginRealm = container.createChildRealm( pluginKey( plugin ) ); Set pluginArtifacts = getPluginArtifacts( pluginArtifact, plugin, localRepository, remoteRepositories ); @@ -196,13 +199,9 @@ public class DefaultPluginManager // Not going to happen } } - - //pluginRealm.display(); - + try { - logger.debug( "Discovering components in realm: " + pluginRealm ); - container.discoverComponents( pluginRealm ); } catch ( PlexusConfigurationException e ) @@ -215,21 +214,10 @@ public class DefaultPluginManager } pluginClassLoaderCache.put( constructPluginKey( plugin ), pluginRealm ); - - PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin ); - - // We just need to keep track of the realm, if we need to augment we will wrap the realm - pluginDescriptor.setPluginArtifact( pluginArtifact ); - pluginDescriptor.setArtifacts( new ArrayList( pluginArtifacts ) ); - pluginDescriptor.setClassRealm( pluginRealm ); - - return pluginDescriptor; + + return getPluginDescriptor( plugin ); } - // plugin artifact - // its dependencies while filtering out what's in the core - // layering on the project level plugin dependencies - private Set getPluginArtifacts( Artifact pluginArtifact, Plugin pluginAsSpecifiedinPom, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactNotFoundException, ArtifactResolutionException { @@ -283,23 +271,6 @@ public class DefaultPluginManager MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); - if ( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem() ) - { - throw new PluginExecutionException( mojoExecution, project, "Cannot execute mojo: " + mojoDescriptor.getGoal() - + ". It requires a project with an existing pom.xml, but the build is not using one." ); - } - - if ( mojoDescriptor.isOnlineRequired() && session.isOffline() ) - { - // TODO: Should we error out, or simply warn and skip?? - throw new PluginExecutionException( mojoExecution, project, "Mojo: " + mojoDescriptor.getGoal() + " requires online mode for execution. Maven is currently offline." ); - } - - if ( mojoDescriptor.getDeprecated() != null ) - { - logger.warn( "Mojo: " + mojoDescriptor.getGoal() + " is deprecated.\n" + mojoDescriptor.getDeprecated() ); - } - String goalName = mojoDescriptor.getFullGoalName(); Mojo mojo = null; @@ -311,15 +282,13 @@ public class DefaultPluginManager } // by this time, the pluginDescriptor has had the correct realm setup from getConfiguredMojo(..) - ClassRealm pluginRealm; + ClassRealm pluginRealm = pluginClassLoaderCache.get( constructPluginKey( mojoDescriptor.getPluginDescriptor() ) ); ClassRealm oldLookupRealm = container.getLookupRealm(); ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try - { - mojo = getConfiguredMojo( session, mojoExecution, project, false, mojoExecution ); - - pluginRealm = pluginClassLoaderCache.get( constructPluginKey( mojoDescriptor.getPluginDescriptor() ) ); + { + mojo = getConfiguredMojo( session, project, mojoExecution, pluginRealm ); Thread.currentThread().setContextClassLoader( pluginRealm ); @@ -371,15 +340,13 @@ public class DefaultPluginManager } } - private Mojo getConfiguredMojo( MavenSession session, MojoExecution MojoExecution, MavenProject project, boolean report, MojoExecution mojoExecution ) + private Mojo getConfiguredMojo( MavenSession session, MavenProject project, MojoExecution mojoExecution, ClassRealm pluginRealm ) throws PluginConfigurationException, PluginManagerException { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); - ClassRealm pluginRealm = pluginDescriptor.getClassRealm(); - // We are forcing the use of the plugin realm for all lookups that might occur during // the lifecycle that is part of the lookup. Here we are specifically trying to keep // lookups that occur in contextualize calls in line with the right realm. @@ -388,8 +355,6 @@ public class DefaultPluginManager ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader( pluginRealm ); - logger.debug( "Looking up mojo " + mojoDescriptor.getRoleHint() + " in realm " + pluginRealm.getId() + " - descRealmId=" + mojoDescriptor.getRealm() ); - Mojo mojo; try @@ -434,7 +399,7 @@ public class DefaultPluginManager ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, mojoExecution ); - populatePluginFields( mojo, mojoDescriptor, pomConfiguration, expressionEvaluator ); + populatePluginFields( mojo, mojoDescriptor, pluginRealm, pomConfiguration, expressionEvaluator ); Thread.currentThread().setContextClassLoader( oldClassLoader ); @@ -445,14 +410,11 @@ public class DefaultPluginManager // Mojo Parameter Handling // ---------------------------------------------------------------------- - private void populatePluginFields( Mojo plugin, MojoDescriptor mojoDescriptor, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator ) + private void populatePluginFields( Mojo mojo, MojoDescriptor mojoDescriptor, ClassRealm realm, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator ) throws PluginConfigurationException { ComponentConfigurator configurator = null; - // TODO: What is the point in using the plugin realm here instead of the core realm? - ClassRealm realm = mojoDescriptor.getPluginDescriptor().getClassRealm(); - try { String configuratorId = mojoDescriptor.getComponentConfigurator(); @@ -473,7 +435,7 @@ public class DefaultPluginManager logger.debug( "Configuring mojo '" + mojoDescriptor.getId() + "' with " + ( configuratorId == null ? "basic" : configuratorId ) + " configurator -->" ); // This needs to be able to use methods - configurator.configureComponent( plugin, configuration, expressionEvaluator, realm, listener ); + configurator.configureComponent( mojo, configuration, expressionEvaluator, realm, listener ); logger.debug( "-- end configuration --" ); } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginClassLoaderCache.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginClassLoaderCache.java index 0f8e9a09c0..b30abf9147 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginClassLoaderCache.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginClassLoaderCache.java @@ -16,4 +16,6 @@ public interface PluginClassLoaderCache void put( String key, ClassRealm pluginClassLoader ); ClassRealm get( String key ); + + int size(); } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index ec207a0215..c4aef0f418 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -106,7 +106,7 @@ public class DefaultMavenProjectBuilder public MavenProject build( File pomFile, ProjectBuilderConfiguration configuration ) throws ProjectBuildingException - { + { MavenProject project = projectCache.get( pomFile.getAbsolutePath() ); if ( project != null ) diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectCache.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectCache.java index bab61d2bb3..f83ba36ddf 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectCache.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectCache.java @@ -20,4 +20,9 @@ public class DefaultMavenProjectCache { projectCache.put( key, project ); } + + public int size() + { + return projectCache.size(); + } } diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProjectCache.java b/maven-core/src/main/java/org/apache/maven/project/MavenProjectCache.java index a981b435f4..26634f5034 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProjectCache.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProjectCache.java @@ -5,4 +5,6 @@ public interface MavenProjectCache MavenProject get( String absolutePath ); void put( String absolutePath, MavenProject project ); + + int size(); } diff --git a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java index e909eb54fb..539fcfcb0c 100644 --- a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java @@ -112,10 +112,17 @@ public class DefaultMavenProjectBuilderTest throws Exception { ArtifactRepositoryLayout repoLayout = lookup( ArtifactRepositoryLayout.class, "legacy" ); - - ArtifactRepository r = new DefaultArtifactRepository( "local", "file://" + localRepoDir.getAbsolutePath(), - repoLayout ); - + ArtifactRepository r = new DefaultArtifactRepository( "local", "file://" + localRepoDir.getAbsolutePath(), repoLayout ); return r; } + + public void xtestLoop() throws Exception + { + while( true ) + { + File f1 = getTestFile( "src/test/resources/projects/duplicate-plugins-merged-pom.xml" ); + getProject( f1 ); + } + } + }