From a96a03d0a0c5e023c0935bcb92977454bd45fadd Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Tue, 7 Jun 2005 00:37:01 +0000 Subject: [PATCH] o Removed dependency on plexus-container-artifact, using nested DefaultPlexusContainer instances instead for plugin isolation. o Moved marmalade support dependencies out of maven-core, since they can be supported on demand now o changed the ordering of the ant and assembly plugins, to show that the classloader (plugin param) bug is fixed. o added a method in PluginDescriptor which is similar to o.a.m.model.Plugin.getId() (I think that's the method; it's the one that results in a key of 'g:a') o moved wagon-ssh dependency into maven-core, since there is a new issue related to nested containers and wagons which are introduced as plugin dependencies. This should be solved using a mechanism similar to plugin-manager for wagon-manager impl in future anyway git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@187639 13f79535-47bb-0310-9956-ffa450edef68 --- maven-core/pom.xml | 17 ++-- .../java/org/apache/maven/cli/MavenCli.java | 10 +- .../maven/plugin/DefaultPluginManager.java | 94 +++++++++++++------ .../java/org/apache/maven/MavenTestUtils.java | 4 +- .../plugin/descriptor/PluginDescriptor.java | 7 +- maven-plugins/maven-deploy-plugin/pom.xml | 12 --- maven-plugins/pom.xml | 3 +- 7 files changed, 83 insertions(+), 64 deletions(-) diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 2ad4a97eaf..2e445ef49e 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -14,11 +14,6 @@ wagon-provider-api 1.0-alpha-3 - - plexus - plexus-container-artifact - 1.0-alpha-4-SNAPSHOT - org.apache.maven maven-monitor @@ -76,12 +71,6 @@ 2.0-SNAPSHOT runtime - - org.apache.maven - maven-script-marmalade - 2.0-SNAPSHOT - runtime - plexus plexus-container-default @@ -98,6 +87,12 @@ 1.0-alpha-3 runtime + + org.apache.maven.wagon + wagon-ssh + 1.0-alpha-3 + runtime + diff --git a/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java index 4f89bd432a..07afb41486 100644 --- a/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java @@ -44,7 +44,7 @@ import org.codehaus.classworlds.ClassWorld; import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.embed.ArtifactEnabledEmbedder; +import org.codehaus.plexus.embed.Embedder; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.LoggerManager; import org.codehaus.plexus.util.FileUtils; @@ -148,7 +148,7 @@ public class MavenCli // bring the maven component to life for use. // ---------------------------------------------------------------------- - ArtifactEnabledEmbedder embedder = new ArtifactEnabledEmbedder(); + Embedder embedder = new Embedder(); try { @@ -276,7 +276,7 @@ public class MavenCli } } - private static MavenExecutionRequest createRequest( List files, ArtifactEnabledEmbedder embedder, + private static MavenExecutionRequest createRequest( List files, Embedder embedder, CommandLine commandLine, Settings settings, EventDispatcher eventDispatcher, LoggerManager manager ) throws ComponentLookupException @@ -330,7 +330,7 @@ public class MavenCli return files; } - private static Maven createMavenInstance( ArtifactEnabledEmbedder embedder ) + private static Maven createMavenInstance( Embedder embedder ) throws ComponentLookupException { // TODO [BP]: doing this here as it is CLI specific, though it doesn't feel like the right place (likewise logger). @@ -340,7 +340,7 @@ public class MavenCli return (Maven) embedder.lookup( Maven.ROLE ); } - private static ArtifactRepository createLocalRepository( ArtifactEnabledEmbedder embedder, Settings settings, + private static ArtifactRepository createLocalRepository( Embedder embedder, Settings settings, CommandLine commandLine ) throws ComponentLookupException { 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 39f5d16864..4e3e2ce245 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 @@ -38,10 +38,9 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.artifact.MavenMetadataSource; import org.apache.maven.project.path.PathTranslator; -import org.codehaus.plexus.ArtifactEnabledContainer; -import org.codehaus.plexus.ArtifactEnabledContainerException; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.component.configurator.ComponentConfigurationException; import org.codehaus.plexus.component.configurator.ComponentConfigurator; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; @@ -62,8 +61,10 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; +import java.io.File; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -159,22 +160,21 @@ public class DefaultPluginManager return (PluginDescriptor) pluginDescriptorsByPrefix.get( prefix ); } - private boolean isPluginInstalled( String groupId, String artifactId, String version ) + private boolean isPluginInstalled( String pluginKey ) { // String key = PluginDescriptor.constructPluginKey( groupId, artifactId, version ); // TODO: see comment in getPluginDescriptor - String key = groupId + ":" + artifactId; - return pluginDescriptors.containsKey( key ); + return pluginDescriptors.containsKey( pluginKey ); } - private boolean isPluginInstalled( String prefix ) + private boolean isPluginInstalledForPrefix( String prefix ) { return pluginDescriptorsByPrefix.containsKey( prefix ); } public PluginDescriptor verifyPlugin( String prefix ) { - if ( !isPluginInstalled( prefix ) ) + if ( !isPluginInstalledForPrefix( prefix ) ) { // TODO: lookup remotely } @@ -184,6 +184,9 @@ public class DefaultPluginManager public PluginDescriptor verifyPlugin( String groupId, String artifactId, String version, MavenSession session ) throws ArtifactResolutionException, PluginManagerException { + + String pluginKey = groupId + ":" + artifactId; + // TODO: this should be possibly outside if ( version == null ) { @@ -232,17 +235,18 @@ public class DefaultPluginManager } // TODO: this might result in an artifact "RELEASE" being resolved continuously - if ( !isPluginInstalled( groupId, artifactId, version ) ) + if ( !isPluginInstalled( pluginKey ) ) { try { - Artifact pluginArtifact = artifactFactory.createArtifact( groupId, artifactId, version, null, + Artifact pluginArtifact = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, MojoDescriptor.MAVEN_PLUGIN, null ); - addPlugin( pluginArtifact, session ); + + addPlugin( pluginKey, pluginArtifact, session ); version = pluginArtifact.getBaseVersion(); } - catch ( ArtifactEnabledContainerException e ) + catch ( PlexusContainerException e ) { throw new PluginManagerException( "Error occurred in the artifact container attempting to download plugin " + groupId + ":" + artifactId, e ); @@ -268,8 +272,8 @@ public class DefaultPluginManager return getPluginDescriptor( groupId, artifactId, version ); } - protected void addPlugin( Artifact pluginArtifact, MavenSession session ) - throws ArtifactEnabledContainerException, ArtifactResolutionException, ComponentLookupException + protected void addPlugin( String pluginKey, Artifact pluginArtifact, MavenSession session ) + throws ArtifactResolutionException, ComponentLookupException, PlexusContainerException { ArtifactResolver artifactResolver = null; MavenProjectBuilder mavenProjectBuilder = null; @@ -282,10 +286,21 @@ public class DefaultPluginManager MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, mavenProjectBuilder ); - ( (ArtifactEnabledContainer) container ).addComponent( pluginArtifact, artifactResolver, - session.getPluginRepositories(), - session.getLocalRepository(), metadataSource, - artifactFilter ); + ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections.singleton( pluginArtifact ), session.getRemoteRepositories(), session.getLocalRepository(), metadataSource, artifactFilter ); + + Map resolved = result.getArtifacts(); + + List files = new ArrayList(); + + for ( Iterator it = resolved.values().iterator(); it.hasNext(); ) + { + Artifact artifact = (Artifact) it.next(); + File artifactFile = artifact.getFile(); + + files.add( artifact.getFile() ); + } + + container.createChildContainer( pluginKey, files, Collections.EMPTY_MAP, Collections.singletonList( this ) ); } finally { @@ -319,6 +334,8 @@ public class DefaultPluginManager public void executeMojo( MavenSession session, MojoDescriptor mojoDescriptor ) throws ArtifactResolutionException, PluginManagerException, MojoExecutionException { + PlexusContainer pluginContainer = null; + if ( mojoDescriptor.isDependencyResolutionRequired() != null ) { @@ -357,7 +374,16 @@ public class DefaultPluginManager try { - plugin = (Mojo) container.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() ); + String pluginKey = mojoDescriptor.getPluginDescriptor().getPluginLookupKey(); + + pluginContainer = container.getChildContainer( pluginKey ); + + if( pluginContainer == null ) + { + throw new PluginConfigurationException( "Cannot find PlexusContainer for plugin: " + pluginKey ); + } + + plugin = (Mojo) pluginContainer.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() ); plugin.setLog( mojoLogger ); String goalId = mojoDescriptor.getGoal(); @@ -395,9 +421,9 @@ public class DefaultPluginManager try { getPluginConfigurationFromExpressions( plugin, mojoDescriptor, mergedConfiguration, - expressionEvaluator ); + pluginContainer, expressionEvaluator ); - populatePluginFields( plugin, mojoDescriptor, mergedConfiguration, expressionEvaluator ); + populatePluginFields( plugin, mojoDescriptor, mergedConfiguration, pluginContainer, expressionEvaluator ); } catch ( ExpressionEvaluationException e ) { @@ -435,7 +461,17 @@ public class DefaultPluginManager } finally { - releaseComponent( plugin ); + try + { + pluginContainer.release( plugin ); + } + catch ( ComponentLifecycleException e ) + { + if( getLogger().isErrorEnabled() ) + { + getLogger().error( "Error releasing plugin - ignoring.", e ); + } + } } } @@ -527,7 +563,7 @@ public class DefaultPluginManager // ---------------------------------------------------------------------- private void populatePluginFields( Mojo plugin, MojoDescriptor mojoDescriptor, PlexusConfiguration configuration, - ExpressionEvaluator expressionEvaluator ) + PlexusContainer pluginContainer, ExpressionEvaluator expressionEvaluator ) throws PluginConfigurationException { ComponentConfigurator configurator = null; @@ -539,14 +575,14 @@ public class DefaultPluginManager // TODO: should this be known to the component factory instead? And if so, should configuration be part of lookup? if ( StringUtils.isNotEmpty( configuratorId ) ) { - configurator = (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE, configuratorId ); + configurator = (ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE, configuratorId ); } else { - configurator = (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE ); + configurator = (ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE ); } - configurator.configureComponent( plugin, configuration, expressionEvaluator ); + configurator.configureComponent( plugin, configuration, expressionEvaluator, pluginContainer.getContainerRealm() ); } catch ( ComponentConfigurationException e ) @@ -564,7 +600,7 @@ public class DefaultPluginManager { try { - container.release( configurator ); + pluginContainer.release( configurator ); } catch ( ComponentLifecycleException e ) { @@ -599,7 +635,7 @@ public class DefaultPluginManager */ private void getPluginConfigurationFromExpressions( Mojo plugin, MojoDescriptor goal, PlexusConfiguration mergedConfiguration, - ExpressionEvaluator expressionEvaluator ) + PlexusContainer pluginContainer, ExpressionEvaluator expressionEvaluator ) throws ExpressionEvaluationException, PluginConfigurationException { List parameters = goal.getParameters(); @@ -795,7 +831,6 @@ public class DefaultPluginManager "bsh", "classworlds", "doxia-core", - "marmalade-core", "maven-artifact", "maven-core", "maven-model", @@ -806,12 +841,9 @@ public class DefaultPluginManager "maven-project", "maven-reporting-api", "maven-script-beanshell", - "maven-script-marmalade", "maven-settings", "plexus-bsh-factory", - "plexus-container-artifact", "plexus-container-default", - "plexus-marmalade-factory", "plexus-utils", "wagon-provider-api" } ); diff --git a/maven-core/src/test/java/org/apache/maven/MavenTestUtils.java b/maven-core/src/test/java/org/apache/maven/MavenTestUtils.java index e9ef7b5369..159a9c9b97 100644 --- a/maven-core/src/test/java/org/apache/maven/MavenTestUtils.java +++ b/maven-core/src/test/java/org/apache/maven/MavenTestUtils.java @@ -18,7 +18,7 @@ package org.apache.maven; import org.codehaus.classworlds.ClassRealm; import org.codehaus.classworlds.ClassWorld; -import org.codehaus.plexus.DefaultArtifactEnabledContainer; +import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusContainer; import java.io.File; @@ -37,7 +37,7 @@ public class MavenTestUtils public static PlexusContainer getContainerInstance() { - return new DefaultArtifactEnabledContainer(); + return new DefaultPlexusContainer(); } public static void customizeContext( PlexusContainer container, File basedir, File mavenHome, File mavenHomeLocal ) diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java index bbc992c956..aa06b5d6fa 100644 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java @@ -100,7 +100,12 @@ public class PluginDescriptor { return groupId + ":" + artifactId + ":" + version; } - + + public String getPluginLookupKey() + { + return groupId + ":" + artifactId; + } + public String getId() { String id = constructPluginKey( groupId, artifactId, version ); diff --git a/maven-plugins/maven-deploy-plugin/pom.xml b/maven-plugins/maven-deploy-plugin/pom.xml index 5ca1b7d2be..7e394c9a78 100644 --- a/maven-plugins/maven-deploy-plugin/pom.xml +++ b/maven-plugins/maven-deploy-plugin/pom.xml @@ -21,17 +21,5 @@ maven-artifact 2.0-alpha-2 - - org.apache.maven.wagon - wagon-file - 1.0-alpha-3 - runtime - - - org.apache.maven.wagon - wagon-ssh - 1.0-alpha-3 - runtime - diff --git a/maven-plugins/pom.xml b/maven-plugins/pom.xml index 55eeffd7ce..9b1f954c63 100644 --- a/maven-plugins/pom.xml +++ b/maven-plugins/pom.xml @@ -76,9 +76,8 @@ - - maven-assembly-plugin maven-ant-plugin + maven-assembly-plugin maven-clean-plugin maven-compiler-plugin maven-deploy-plugin