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 7292610a63..6c383a8951 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 @@ -284,7 +284,10 @@ public class DefaultPluginManager { try { - pluginRealm = realmManager.createPluginRealm( projectPlugin, pluginArtifact, artifacts ); + pluginRealm = realmManager.createPluginRealm( projectPlugin, + pluginArtifact, + artifacts, + coreArtifactFilterManager.getArtifactFilter() ); getLogger().debug( "Created realm: " + pluginRealm + " for plugin: " + projectPlugin.getKey() ); } @@ -425,6 +428,8 @@ public class DefaultPluginManager repositories.addAll( project.getRemoteArtifactRepositories() ); + ArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME ); + ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencies, pluginArtifact, @@ -435,7 +440,7 @@ public class DefaultPluginManager : new ArrayList( repositories ), artifactMetadataSource, - coreArtifactFilterManager.getArtifactFilter() ); + filter ); Set resolved = new HashSet( result.getArtifacts() ); diff --git a/maven-project/src/main/java/org/apache/maven/realm/DefaultMavenRealmManager.java b/maven-project/src/main/java/org/apache/maven/realm/DefaultMavenRealmManager.java index a0310cb658..ef93bf08bd 100644 --- a/maven-project/src/main/java/org/apache/maven/realm/DefaultMavenRealmManager.java +++ b/maven-project/src/main/java/org/apache/maven/realm/DefaultMavenRealmManager.java @@ -20,6 +20,7 @@ package org.apache.maven.realm; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.model.Plugin; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainerException; @@ -130,7 +131,7 @@ public class DefaultMavenRealmManager e ); } - populateRealm( id, realm, extensionArtifact, artifacts ); + populateRealm( id, realm, extensionArtifact, artifacts, null ); return realm; } @@ -267,7 +268,8 @@ public class DefaultMavenRealmManager public ClassRealm createPluginRealm( Plugin plugin, Artifact pluginArtifact, - Collection artifacts ) + Collection artifacts, + ArtifactFilter coreArtifactFilter ) throws RealmManagementException { String id = RealmUtils.createPluginRealmId( plugin ); @@ -286,7 +288,7 @@ public class DefaultMavenRealmManager e ); } - populateRealm( id, realm, pluginArtifact, artifacts ); + populateRealm( id, realm, pluginArtifact, artifacts, coreArtifactFilter ); logger.debug( "Saving artifacts:\n\n" + artifacts + "\n\nfor plugin: " + id ); pluginArtifacts.put( id, artifacts ); @@ -297,7 +299,8 @@ public class DefaultMavenRealmManager private void populateRealm( String id, ClassRealm realm, Artifact mainArtifact, - Collection artifacts ) + Collection artifacts, + ArtifactFilter coreArtifactFilter ) throws RealmManagementException { if ( !artifacts.contains( mainArtifact ) ) @@ -318,16 +321,24 @@ public class DefaultMavenRealmManager for ( Iterator it = artifacts.iterator(); it.hasNext(); ) { Artifact artifact = (Artifact) it.next(); - try + + if ( ( coreArtifactFilter == null ) || coreArtifactFilter.include( artifact ) ) { - realm.addURL( artifact.getFile().toURI().toURL() ); + try + { + realm.addURL( artifact.getFile().toURI().toURL() ); + } + catch ( MalformedURLException e ) + { + throw new RealmManagementException( id, artifact, "Invalid URL for artifact file: " + + artifact.getFile() + + " to be used in realm: " + id + + ".", e ); + } } - catch ( MalformedURLException e ) + else { - throw new RealmManagementException( id, artifact, "Invalid URL for artifact file: " - + artifact.getFile() - + " to be used in realm: " + id - + ".", e ); + logger.debug( "Excluding artifact: " + artifact.getArtifactId() + " from plugin realm; it's already included in Maven's core." ); } } } diff --git a/maven-project/src/main/java/org/apache/maven/realm/MavenRealmManager.java b/maven-project/src/main/java/org/apache/maven/realm/MavenRealmManager.java index 994c8ce4f8..911039d85f 100644 --- a/maven-project/src/main/java/org/apache/maven/realm/MavenRealmManager.java +++ b/maven-project/src/main/java/org/apache/maven/realm/MavenRealmManager.java @@ -1,6 +1,7 @@ package org.apache.maven.realm; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.model.Plugin; import org.codehaus.plexus.classworlds.realm.ClassRealm; @@ -34,7 +35,8 @@ public interface MavenRealmManager ClassRealm createPluginRealm( Plugin plugin, Artifact pluginArtifact, - Collection artifacts ) + Collection artifacts, + ArtifactFilter coreArtifactFilter ) throws RealmManagementException; void disposePluginRealm( Plugin plugin );