You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2008/03/28 14:16:53 UTC
svn commit: r642223 - in
/maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven:
MavenArtifactFilterManager.java extension/DefaultExtensionManager.java
Author: brett
Date: Fri Mar 28 06:16:51 2008
New Revision: 642223
URL: http://svn.apache.org/viewvc?rev=642223&view=rev
Log:
[MNG-3485] make sure implementations for wagons found in extensions take precedence over the core.
Note the two caveats:
- the class name must match since the component descriptor often comes from the core
- we always use the bundled wagon API, so it must be forward compatible
Modified:
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/MavenArtifactFilterManager.java
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java
Modified: maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/MavenArtifactFilterManager.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/MavenArtifactFilterManager.java?rev=642223&r1=642222&r2=642223&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/MavenArtifactFilterManager.java (original)
+++ maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/MavenArtifactFilterManager.java Fri Mar 28 06:16:51 2008
@@ -63,11 +63,14 @@
artifacts.add( "maven-toolchain" );
//artifacts.add( "plexus-utils" );
artifacts.add( "wagon-provider-api" );
- artifacts.add( "wagon-file" );
- artifacts.add( "wagon-http-lightweight" );
- artifacts.add( "wagon-webdav" );
- artifacts.add( "wagon-ssh" );
- artifacts.add( "wagon-ssh-external" );
+
+ // It should be safe to include implementations, and since this is used by the extension manager they would
+ // get filtered out otherwise
+ //artifacts.add( "wagon-file" );
+ //artifacts.add( "wagon-http-lightweight" );
+ //artifacts.add( "wagon-webdav" );
+ //artifacts.add( "wagon-ssh" );
+ //artifacts.add( "wagon-ssh-external" );
return new ExclusionSetFilter( artifacts );
}
Modified: maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java?rev=642223&r1=642222&r2=642223&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java (original)
+++ maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java Fri Mar 28 06:16:51 2008
@@ -19,6 +19,16 @@
* under the License.
*/
+import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.JarFile;
+
import org.apache.maven.MavenArtifactFilterManager;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
@@ -37,6 +47,11 @@
import org.apache.maven.plugin.DefaultPluginManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.wagon.Wagon;
+import org.codehaus.classworlds.ClassRealm;
+import org.codehaus.classworlds.ClassWorld;
+import org.codehaus.classworlds.DuplicateRealmException;
+import org.codehaus.classworlds.NoSuchRealmException;
+import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusContainerException;
@@ -48,12 +63,6 @@
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
-import java.io.File;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.*;
-import java.util.jar.JarFile;
-
/**
* Used to locate extensions.
*
@@ -71,13 +80,14 @@
private ArtifactMetadataSource artifactMetadataSource;
-
- private PlexusContainer container;
+ private DefaultPlexusContainer container;
private ArtifactFilter artifactFilter = MavenArtifactFilterManager.createStandardFilter();
private WagonManager wagonManager;
+ private PlexusContainer extensionContainer;
+
private static final String CONTAINER_NAME = "extensions";
public void addExtension( Extension extension,
@@ -124,16 +134,6 @@
localRepository,
project.getRemoteArtifactRepositories(),
artifactMetadataSource, filter );
- // create a child container for the extension
- // TODO: this could surely be simpler/different on trunk with the new classworlds
-
- PlexusContainer extensionContainer = getExtensionContainer();
-
- if ( extensionContainer == null )
- {
- extensionContainer =
- container.createChildContainer( CONTAINER_NAME, Collections.EMPTY_LIST, Collections.EMPTY_MAP );
- }
// gross hack for some backwards compat (MNG-2749)
// if it is a lone artifact, then we assume it to be a resource package, and put it in the main container
@@ -178,6 +178,14 @@
}
else
{
+ // create a child container for the extension
+ // TODO: this could surely be simpler/different on trunk with the new classworlds
+
+ if ( extensionContainer == null )
+ {
+ extensionContainer = createContainer();
+ }
+
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
{
Artifact a = (Artifact) i.next();
@@ -188,18 +196,71 @@
extensionContainer.addJarResource( a.getFile() );
}
+
+ if ( getLogger().isDebugEnabled() )
+ {
+ extensionContainer.getContainerRealm().display();
+ }
}
+ }
+ }
- if ( getLogger().isDebugEnabled() )
+ private PlexusContainer createContainer()
+ throws PlexusContainerException
+ {
+ DefaultPlexusContainer child = new DefaultPlexusContainer();
+
+ ClassWorld classWorld = container.getClassWorld();
+ child.setClassWorld( classWorld );
+
+ ClassRealm childRealm = null;
+
+ // note: ideally extensions would live in their own realm, but this would mean that things like wagon-scm would
+ // have no way to obtain SCM extensions
+ String childRealmId = "plexus.core.child-container[" + CONTAINER_NAME + "]";
+ try
+ {
+ childRealm = classWorld.getRealm( childRealmId );
+ }
+ catch ( NoSuchRealmException e )
+ {
+ try
+ {
+ childRealm = classWorld.newRealm( childRealmId );
+ }
+ catch ( DuplicateRealmException impossibleError )
{
- extensionContainer.getContainerRealm().display();
+ getLogger().error( "An impossible error has occurred. After getRealm() failed, newRealm() " +
+ "produced duplication error on same id!", impossibleError );
}
}
+
+ childRealm.setParent( container.getContainerRealm() );
+
+ child.setCoreRealm( childRealm );
+
+ child.setName( CONTAINER_NAME );
+
+ // This is what we are skipping - we use the parent realm, but not the parent container since otherwise
+ // we won't reload component descriptors that already exist in there
+// child.setParentPlexusContainer( this );
+
+ // ----------------------------------------------------------------------
+ // Set all the child elements from the parent that were set
+ // programmatically.
+ // ----------------------------------------------------------------------
+
+ child.setLoggerManager( container.getLoggerManager() );
+
+ child.initialize();
+
+ child.start();
+
+ return child;
}
public void registerWagons()
{
- PlexusContainer extensionContainer = getExtensionContainer();
if ( extensionContainer != null )
{
try
@@ -214,17 +275,10 @@
}
}
- private PlexusContainer getExtensionContainer()
- {
- // note: ideally extensions would live in their own realm, but this would mean that things like wagon-scm would
- // have no way to obtain SCM extensions
- return container.getChildContainer( CONTAINER_NAME );
- }
-
public void contextualize( Context context )
throws ContextException
{
- this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+ this.container = (DefaultPlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
private static final class ProjectArtifactExceptionFilter