mirror of https://github.com/apache/maven.git
[MNG-2228] put extensions in a child container. This guarantees separation avoiding root classloader pollution that was causing plugins such as the release plugin to fail when using wagon-webdav.
Merged from: r492068, maven-2.0.x branch git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@492071 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
51c6fefb31
commit
3d073bd7d3
|
@ -53,6 +53,7 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -89,6 +90,9 @@ public class DefaultWagonManager
|
|||
|
||||
private boolean interactive = true;
|
||||
|
||||
private Map availableWagons = new HashMap();
|
||||
|
||||
// TODO: this leaks the component in the public api - it is never released back to the container
|
||||
public Wagon getWagon( Repository repository )
|
||||
throws UnsupportedProtocolException, WagonConfigurationException
|
||||
{
|
||||
|
@ -109,26 +113,39 @@ public class DefaultWagonManager
|
|||
public Wagon getWagon( String protocol )
|
||||
throws UnsupportedProtocolException
|
||||
{
|
||||
Wagon wagon;
|
||||
PlexusContainer container = getWagonContainer( protocol );
|
||||
|
||||
Wagon wagon;
|
||||
try
|
||||
{
|
||||
wagon = (Wagon) container.lookup( Wagon.ROLE, protocol );
|
||||
wagon.setInteractive( interactive );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
catch ( ComponentLookupException e1 )
|
||||
{
|
||||
throw new UnsupportedProtocolException(
|
||||
"Cannot find wagon which supports the requested protocol: " + protocol, e );
|
||||
"Cannot find wagon which supports the requested protocol: " + protocol, e1 );
|
||||
}
|
||||
|
||||
wagon.setInteractive( interactive );
|
||||
|
||||
return wagon;
|
||||
}
|
||||
|
||||
public void putArtifact( File source, Artifact artifact, ArtifactRepository repository )
|
||||
private PlexusContainer getWagonContainer( String protocol )
|
||||
{
|
||||
PlexusContainer container = this.container;
|
||||
|
||||
if ( availableWagons.containsKey( protocol ) )
|
||||
{
|
||||
container = (PlexusContainer) availableWagons.get( protocol );
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
public void putArtifact( File source, Artifact artifact, ArtifactRepository deploymentRepository )
|
||||
throws TransferFailedException
|
||||
{
|
||||
putRemoteFile( repository, source, repository.pathOf( artifact ), downloadMonitor );
|
||||
putRemoteFile( deploymentRepository, source, deploymentRepository.pathOf( artifact ), downloadMonitor );
|
||||
}
|
||||
|
||||
public void putArtifactMetadata( File source, ArtifactMetadata artifactMetadata, ArtifactRepository repository )
|
||||
|
@ -248,7 +265,7 @@ public class DefaultWagonManager
|
|||
{
|
||||
disconnectWagon( wagon );
|
||||
|
||||
releaseWagon( wagon );
|
||||
releaseWagon( protocol, wagon );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -331,8 +348,6 @@ public class DefaultWagonManager
|
|||
|
||||
failIfNotOnline();
|
||||
|
||||
Wagon wagon;
|
||||
|
||||
ArtifactRepository mirror = getMirror( repository.getId() );
|
||||
if ( mirror != null )
|
||||
{
|
||||
|
@ -342,6 +357,7 @@ public class DefaultWagonManager
|
|||
}
|
||||
|
||||
String protocol = repository.getProtocol();
|
||||
Wagon wagon;
|
||||
try
|
||||
{
|
||||
wagon = getWagon( protocol );
|
||||
|
@ -507,7 +523,7 @@ public class DefaultWagonManager
|
|||
{
|
||||
disconnectWagon( wagon );
|
||||
|
||||
releaseWagon( wagon );
|
||||
releaseWagon( protocol, wagon );
|
||||
}
|
||||
|
||||
if ( downloaded )
|
||||
|
@ -631,8 +647,9 @@ public class DefaultWagonManager
|
|||
}
|
||||
}
|
||||
|
||||
private void releaseWagon( Wagon wagon )
|
||||
private void releaseWagon( String protocol, Wagon wagon )
|
||||
{
|
||||
PlexusContainer container = getWagonContainer( protocol );
|
||||
try
|
||||
{
|
||||
container.release( wagon );
|
||||
|
@ -765,6 +782,13 @@ public class DefaultWagonManager
|
|||
this.interactive = interactive;
|
||||
}
|
||||
|
||||
public void registerWagons( Collection wagons, PlexusContainer extensionContainer )
|
||||
{
|
||||
for ( Iterator i = wagons.iterator(); i.hasNext(); )
|
||||
{
|
||||
availableWagons.put( i.next(), extensionContainer );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the server configuration to the wagon
|
||||
|
|
|
@ -27,9 +27,11 @@ import org.apache.maven.wagon.authentication.AuthenticationInfo;
|
|||
import org.apache.maven.wagon.events.TransferListener;
|
||||
import org.apache.maven.wagon.proxy.ProxyInfo;
|
||||
import org.apache.maven.wagon.repository.Repository;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -46,11 +48,10 @@ public interface WagonManager
|
|||
* Get a Wagon provider that understands the protocol passed as argument.
|
||||
* It doesn't configure the Wagon.
|
||||
*
|
||||
* @deprecated prone to errors. use {@link #getWagon(Repository)} instead.
|
||||
*
|
||||
* @param protocol the protocol the {@link Wagon} will handle
|
||||
* @return the {@link Wagon} instance able to handle the protocol provided
|
||||
* @throws UnsupportedProtocolException if there is no provider able to handle the protocol
|
||||
* @deprecated prone to errors. use {@link #getWagon(Repository)} instead.
|
||||
*/
|
||||
Wagon getWagon( String protocol )
|
||||
throws UnsupportedProtocolException;
|
||||
|
@ -111,4 +112,6 @@ public interface WagonManager
|
|||
void addConfiguration( String repositoryId, Xpp3Dom configuration );
|
||||
|
||||
void setInteractive( boolean interactive );
|
||||
|
||||
void registerWagons( Collection wagons, PlexusContainer extensionContainer );
|
||||
}
|
|
@ -19,6 +19,7 @@ package org.apache.maven.extension;
|
|||
import org.apache.maven.MavenArtifactFilterManager;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.ArtifactUtils;
|
||||
import org.apache.maven.artifact.manager.WagonManager;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
|
@ -26,21 +27,21 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
|||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
|
||||
import org.apache.maven.model.Extension;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.wagon.Wagon;
|
||||
import org.codehaus.plexus.PlexusConstants;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.PlexusContainerException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.context.Context;
|
||||
import org.codehaus.plexus.context.ContextException;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Used to locate extensions.
|
||||
|
@ -50,6 +51,7 @@ import java.util.ArrayList;
|
|||
* @version $Id$
|
||||
*/
|
||||
public class DefaultExtensionManager
|
||||
extends AbstractLogEnabled
|
||||
implements ExtensionManager, Contextualizable
|
||||
{
|
||||
private ArtifactResolver artifactResolver;
|
||||
|
@ -58,15 +60,19 @@ public class DefaultExtensionManager
|
|||
|
||||
private PlexusContainer container;
|
||||
|
||||
private PluginManager pluginManager;
|
||||
|
||||
private ArtifactFilter artifactFilter = MavenArtifactFilterManager.createStandardFilter();
|
||||
|
||||
private WagonManager wagonManager;
|
||||
|
||||
private static final String CONTAINER_NAME = "extensions";
|
||||
|
||||
public void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, PlexusContainerException, ArtifactNotFoundException
|
||||
{
|
||||
String extensionId = ArtifactUtils.versionlessKey( extension.getGroupId(), extension.getArtifactId() );
|
||||
|
||||
getLogger().debug( "Initialising extension: " + extensionId );
|
||||
|
||||
Artifact artifact = (Artifact) project.getExtensionArtifactMap().get( extensionId );
|
||||
|
||||
if ( artifact != null )
|
||||
|
@ -79,21 +85,53 @@ public class DefaultExtensionManager
|
|||
project.getRemoteArtifactRepositories(),
|
||||
artifactMetadataSource, filter );
|
||||
|
||||
List excludedArtifacts = new ArrayList( result.getArtifacts().size() );
|
||||
// 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.singletonList( artifact.getFile() ),
|
||||
Collections.EMPTY_MAP );
|
||||
}
|
||||
|
||||
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
|
||||
{
|
||||
Artifact a = (Artifact) i.next();
|
||||
|
||||
excludedArtifacts.add( ArtifactUtils.versionlessKey( a ) );
|
||||
|
||||
a = project.replaceWithActiveArtifact( a );
|
||||
|
||||
container.addJarResource( a.getFile() );
|
||||
getLogger().debug( "Adding to extension classpath: " + a.getFile() );
|
||||
|
||||
extensionContainer.addJarResource( a.getFile() );
|
||||
}
|
||||
pluginManager.addToArtifactFilter( new ExcludesArtifactFilter( excludedArtifacts ) );
|
||||
}
|
||||
}
|
||||
|
||||
public void registerWagons()
|
||||
{
|
||||
PlexusContainer extensionContainer = getExtensionContainer();
|
||||
if ( extensionContainer != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
Map wagons = extensionContainer.lookupMap( Wagon.ROLE );
|
||||
wagonManager.registerWagons( wagons.keySet(), extensionContainer );
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
// now wagons found in the extension
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
|
|
|
@ -33,4 +33,6 @@ public interface ExtensionManager
|
|||
{
|
||||
void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException, PlexusContainerException, ArtifactNotFoundException;
|
||||
|
||||
void registerWagons();
|
||||
}
|
||||
|
|
|
@ -168,6 +168,8 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
}
|
||||
|
||||
extensionManager.registerWagons();
|
||||
|
||||
try
|
||||
{
|
||||
Map handlers = findArtifactTypeHandlers( project, session.getSettings(), session.getLocalRepository() );
|
||||
|
|
|
@ -1198,12 +1198,4 @@ public class DefaultPluginManager
|
|||
{
|
||||
return container.lookupMap( role );
|
||||
}
|
||||
|
||||
public void addToArtifactFilter( ArtifactFilter filter )
|
||||
{
|
||||
AndArtifactFilter newFilter = new AndArtifactFilter();
|
||||
newFilter.add( filter );
|
||||
newFilter.add( artifactFilter );
|
||||
artifactFilter = newFilter;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@ package org.apache.maven.plugin;
|
|||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.Plugin;
|
||||
|
@ -73,5 +71,4 @@ public interface PluginManager
|
|||
Map getPluginComponents( Plugin plugin, String role )
|
||||
throws ComponentLookupException, PluginManagerException;
|
||||
|
||||
void addToArtifactFilter( ArtifactFilter filter );
|
||||
}
|
|
@ -45,7 +45,7 @@
|
|||
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.plugin.PluginManager</role>
|
||||
<role>org.apache.maven.artifact.manager.WagonManager</role>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
@ -328,7 +328,8 @@
|
|||
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
|
||||
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
|
||||
<process-test-resources>
|
||||
org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
|
||||
org.apache.maven.plugins:maven-resources-plugin:testResources
|
||||
</process-test-resources>
|
||||
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
|
||||
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
|
||||
<package>
|
||||
|
@ -357,7 +358,8 @@
|
|||
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
|
||||
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
|
||||
<process-test-resources>
|
||||
org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
|
||||
org.apache.maven.plugins:maven-resources-plugin:testResources
|
||||
</process-test-resources>
|
||||
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
|
||||
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
|
||||
<package>
|
||||
|
@ -391,7 +393,8 @@
|
|||
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
|
||||
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
|
||||
<process-test-resources>
|
||||
org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
|
||||
org.apache.maven.plugins:maven-resources-plugin:testResources
|
||||
</process-test-resources>
|
||||
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
|
||||
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
|
||||
<package>
|
||||
|
@ -419,7 +422,8 @@
|
|||
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
|
||||
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
|
||||
<process-test-resources>
|
||||
org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
|
||||
org.apache.maven.plugins:maven-resources-plugin:testResources
|
||||
</process-test-resources>
|
||||
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
|
||||
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
|
||||
<package>org.apache.maven.plugins:maven-war-plugin:war</package>
|
||||
|
@ -443,7 +447,8 @@
|
|||
<!-- START SNIPPET: ear-lifecycle -->
|
||||
<phases>
|
||||
<generate-resources>
|
||||
org.apache.maven.plugins:maven-ear-plugin:generate-application-xml</generate-resources>
|
||||
org.apache.maven.plugins:maven-ear-plugin:generate-application-xml
|
||||
</generate-resources>
|
||||
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
|
||||
<package>org.apache.maven.plugins:maven-ear-plugin:ear</package>
|
||||
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
|
||||
|
@ -468,7 +473,8 @@
|
|||
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
|
||||
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
|
||||
<process-test-resources>
|
||||
org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
|
||||
org.apache.maven.plugins:maven-resources-plugin:testResources
|
||||
</process-test-resources>
|
||||
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
|
||||
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
|
||||
<package>org.apache.maven.plugins:maven-rar-plugin:rar</package>
|
||||
|
|
Loading…
Reference in New Issue