[MNG-4274] Plugins with an undeclared but transitive dependency on plexus-utils via a core artifact get wrong version of p-u

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@800087 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-02 14:42:41 +00:00
parent bc744b544b
commit 67a2275ac9
3 changed files with 74 additions and 23 deletions

View File

@ -39,7 +39,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ResolutionErrorHandler; import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.classrealm.ClassRealmManager; import org.apache.maven.classrealm.ClassRealmManager;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
@ -237,12 +237,15 @@ public class DefaultPluginManager
// TODO: Turn this into a component so it can be tested. // TODO: Turn this into a component so it can be tested.
// //
/**
* Gets all artifacts required for the class realm of the specified plugin. An artifact in the result list that has
* no file set is meant to be excluded from the plugin realm in favor of the equivalent library from the current
* core distro.
*/
List<Artifact> getPluginArtifacts( Artifact pluginArtifact, Plugin pluginAsSpecifiedInPom, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories ) List<Artifact> getPluginArtifacts( Artifact pluginArtifact, Plugin pluginAsSpecifiedInPom, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws ArtifactNotFoundException, ArtifactResolutionException throws ArtifactNotFoundException, ArtifactResolutionException
{ {
AndArtifactFilter filter = new AndArtifactFilter(); ArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM );
filter.add( coreArtifactFilterManager.getCoreArtifactFilter() );
filter.add( new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM ) );
Set<Artifact> dependenciesToResolveForPlugin = new LinkedHashSet<Artifact>(); Set<Artifact> dependenciesToResolveForPlugin = new LinkedHashSet<Artifact>();
@ -273,16 +276,33 @@ public class DefaultPluginManager
.setLocalRepository( localRepository ) .setLocalRepository( localRepository )
.setRemoteRepostories( remoteRepositories ) .setRemoteRepostories( remoteRepositories )
.setFilter( filter ) .setFilter( filter )
.setResolveRoot( true )
.setResolveTransitively( true ); .setResolveTransitively( true );
//.setResolveRoot( false );
// FIXME setTransferListener // FIXME setTransferListener
ArtifactResolutionResult result = repositorySystem.resolve( request ); ArtifactResolutionResult result = repositorySystem.collect( request );
resolutionErrorHandler.throwErrors( request, result ); resolutionErrorHandler.throwErrors( request, result );
logger.debug( "Using the following artifacts for classpath of: " + pluginArtifact.getId() + ":\n\n" + result.getArtifacts().toString().replace( ',', '\n' ) ); List<Artifact> pluginArtifacts = new ArrayList<Artifact>( result.getArtifacts() );
return new ArrayList<Artifact>( result.getArtifacts() ); request.setResolveRoot( true ).setResolveTransitively( false ).setArtifactDependencies( null );
filter = coreArtifactFilterManager.getCoreArtifactFilter();
for ( Artifact artifact : pluginArtifacts )
{
if ( filter.include( artifact ) )
{
result = repositorySystem.resolve( request.setArtifact( artifact ) );
resolutionErrorHandler.throwErrors( request, result );
}
else
{
artifact.setFile( null );
}
}
return pluginArtifacts;
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -407,8 +427,20 @@ public class DefaultPluginManager
throw new IllegalStateException( e ); // XXX throw new IllegalStateException( e ); // XXX
} }
if ( logger.isDebugEnabled() )
{
logger.debug( "Populating plugin realm for " + constructPluginKey( plugin ) );
}
for ( Artifact a : pluginArtifacts ) for ( Artifact a : pluginArtifacts )
{ {
if ( a.getFile() != null )
{
if ( logger.isDebugEnabled() )
{
logger.debug( " Included: " + a.getId() );
}
try try
{ {
pluginRealm.addURL( a.getFile().toURI().toURL() ); pluginRealm.addURL( a.getFile().toURI().toURL() );
@ -418,6 +450,14 @@ public class DefaultPluginManager
// Not going to happen // Not going to happen
} }
} }
else
{
if ( logger.isDebugEnabled() )
{
logger.debug( " Excluded: " + a.getId() );
}
}
}
pluginDescriptor.setClassRealm( pluginRealm ); pluginDescriptor.setClassRealm( pluginRealm );
pluginDescriptor.setArtifacts( pluginArtifacts ); pluginDescriptor.setArtifacts( pluginArtifacts );

View File

@ -33,6 +33,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ResolutionErrorHandler; import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.classrealm.ClassRealmManager; import org.apache.maven.classrealm.ClassRealmManager;
import org.apache.maven.model.Build; import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
@ -173,7 +174,6 @@ public class DefaultProjectBuildingHelper
request.setArtifact( artifact ); request.setArtifact( artifact );
request.setArtifactDependencies( dependencies ); request.setArtifactDependencies( dependencies );
request.setResolveTransitively( true ); request.setResolveTransitively( true );
request.setFilter( artifactFilterManager.getCoreArtifactFilter() );
request.setLocalRepository( localRepository ); request.setLocalRepository( localRepository );
request.setRemoteRepostories( remoteRepositories ); request.setRemoteRepostories( remoteRepositories );
// FIXME setTransferListener // FIXME setTransferListener
@ -182,11 +182,15 @@ public class DefaultProjectBuildingHelper
resolutionErrorHandler.throwErrors( request, result ); resolutionErrorHandler.throwErrors( request, result );
ArtifactFilter filter = artifactFilterManager.getCoreArtifactFilter();
for ( Artifact resultArtifact : result.getArtifacts() ) for ( Artifact resultArtifact : result.getArtifacts() )
{
if ( filter.include( resultArtifact ) )
{ {
if ( logger.isDebugEnabled() ) if ( logger.isDebugEnabled() )
{ {
logger.debug( " " + resultArtifact.getFile() ); logger.debug( " Included: " + resultArtifact.getId() );
} }
try try
@ -199,6 +203,14 @@ public class DefaultProjectBuildingHelper
+ artifact.getFile(), e ); + artifact.getFile(), e );
} }
} }
else
{
if ( logger.isDebugEnabled() )
{
logger.debug( " Excluded: " + resultArtifact.getId() );
}
}
}
} }
} }

View File

@ -226,7 +226,6 @@ public class PluginManagerTest
*/ */
List<Artifact> artifacts = pluginManager.getPluginArtifacts( pluginArtifact, plugin, getLocalRepository(), getPluginArtifactRepositories() ); List<Artifact> artifacts = pluginManager.getPluginArtifacts( pluginArtifact, plugin, getLocalRepository(), getPluginArtifactRepositories() );
assertEquals( 4, artifacts.size() );
for ( Artifact a : artifacts ) for ( Artifact a : artifacts )
{ {