mirror of https://github.com/apache/maven.git
[MNG-2228] make sure build extensions are filtered from being loaded in plugins
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@480377 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
53760225f5
commit
6a36ae3b72
|
@ -16,6 +16,7 @@ package org.apache.maven.extension;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.MavenArtifactFilterManager;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.ArtifactUtils;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
|
@ -25,9 +26,10 @@ 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.MavenArtifactFilterManager;
|
||||
import org.codehaus.plexus.PlexusConstants;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.PlexusContainerException;
|
||||
|
@ -37,6 +39,8 @@ 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;
|
||||
|
||||
/**
|
||||
* Used to locate extensions.
|
||||
|
@ -54,6 +58,8 @@ public class DefaultExtensionManager
|
|||
|
||||
private PlexusContainer container;
|
||||
|
||||
private PluginManager pluginManager;
|
||||
|
||||
private ArtifactFilter artifactFilter = MavenArtifactFilterManager.createStandardFilter();
|
||||
|
||||
public void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
|
||||
|
@ -65,22 +71,26 @@ public class DefaultExtensionManager
|
|||
|
||||
if ( artifact != null )
|
||||
{
|
||||
ArtifactFilter filter = new ProjectArtifactExceptionFilter( artifactFilter, project.getArtifact() );
|
||||
|
||||
ArtifactFilter filter = new ProjectArtifactExceptionFilter( artifactFilter, project.getArtifact() );
|
||||
|
||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections.singleton( artifact ),
|
||||
project.getArtifact(),
|
||||
localRepository,
|
||||
project.getRemoteArtifactRepositories(),
|
||||
artifactMetadataSource,
|
||||
filter );
|
||||
artifactMetadataSource, filter );
|
||||
|
||||
List excludedArtifacts = new ArrayList( result.getArtifacts().size() );
|
||||
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() );
|
||||
}
|
||||
pluginManager.addToArtifactFilter( new ExcludesArtifactFilter( excludedArtifacts ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,23 +99,25 @@ public class DefaultExtensionManager
|
|||
{
|
||||
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
|
||||
}
|
||||
|
||||
private static final class ProjectArtifactExceptionFilter implements ArtifactFilter
|
||||
{
|
||||
private ArtifactFilter passThroughFilter;
|
||||
private String projectDependencyConflictId;
|
||||
|
||||
ProjectArtifactExceptionFilter( ArtifactFilter passThroughFilter, Artifact projectArtifact )
|
||||
{
|
||||
this.passThroughFilter = passThroughFilter;
|
||||
this.projectDependencyConflictId = projectArtifact.getDependencyConflictId();
|
||||
}
|
||||
|
||||
public boolean include(Artifact artifact) {
|
||||
String depConflictId = artifact.getDependencyConflictId();
|
||||
|
||||
return projectDependencyConflictId.equals( depConflictId )
|
||||
|| passThroughFilter.include( artifact );
|
||||
}
|
||||
private static final class ProjectArtifactExceptionFilter
|
||||
implements ArtifactFilter
|
||||
{
|
||||
private ArtifactFilter passThroughFilter;
|
||||
|
||||
private String projectDependencyConflictId;
|
||||
|
||||
ProjectArtifactExceptionFilter( ArtifactFilter passThroughFilter, Artifact projectArtifact )
|
||||
{
|
||||
this.passThroughFilter = passThroughFilter;
|
||||
this.projectDependencyConflictId = projectArtifact.getDependencyConflictId();
|
||||
}
|
||||
|
||||
public boolean include( Artifact artifact )
|
||||
{
|
||||
String depConflictId = artifact.getDependencyConflictId();
|
||||
|
||||
return projectDependencyConflictId.equals( depConflictId ) || passThroughFilter.include( artifact );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ 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.ScopeArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.artifact.versioning.VersionRange;
|
||||
|
@ -1190,4 +1191,11 @@ public class DefaultPluginManager
|
|||
return pluginContainer.lookupMap( role );
|
||||
}
|
||||
|
||||
public void addToArtifactFilter( ArtifactFilter filter )
|
||||
{
|
||||
AndArtifactFilter newFilter = new AndArtifactFilter();
|
||||
newFilter.add( filter );
|
||||
newFilter.add( artifactFilter );
|
||||
artifactFilter = newFilter;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ 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;
|
||||
|
@ -70,4 +72,6 @@ public interface PluginManager
|
|||
|
||||
Map getPluginComponents( Plugin plugin, String role )
|
||||
throws ComponentLookupException, PluginManagerException;
|
||||
|
||||
void addToArtifactFilter( ArtifactFilter filter );
|
||||
}
|
|
@ -44,6 +44,9 @@
|
|||
<requirement>
|
||||
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.plugin.PluginManager</role>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
|
|
Loading…
Reference in New Issue