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.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.apache.maven.MavenArtifactFilterManager;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.ArtifactUtils;
|
import org.apache.maven.artifact.ArtifactUtils;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
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.ArtifactResolutionResult;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
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.model.Extension;
|
||||||
|
import org.apache.maven.plugin.PluginManager;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.MavenArtifactFilterManager;
|
|
||||||
import org.codehaus.plexus.PlexusConstants;
|
import org.codehaus.plexus.PlexusConstants;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.PlexusContainerException;
|
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.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to locate extensions.
|
* Used to locate extensions.
|
||||||
|
@ -54,6 +58,8 @@ public class DefaultExtensionManager
|
||||||
|
|
||||||
private PlexusContainer container;
|
private PlexusContainer container;
|
||||||
|
|
||||||
|
private PluginManager pluginManager;
|
||||||
|
|
||||||
private ArtifactFilter artifactFilter = MavenArtifactFilterManager.createStandardFilter();
|
private ArtifactFilter artifactFilter = MavenArtifactFilterManager.createStandardFilter();
|
||||||
|
|
||||||
public void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
|
public void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
|
||||||
|
@ -65,22 +71,26 @@ public class DefaultExtensionManager
|
||||||
|
|
||||||
if ( artifact != null )
|
if ( artifact != null )
|
||||||
{
|
{
|
||||||
ArtifactFilter filter = new ProjectArtifactExceptionFilter( artifactFilter, project.getArtifact() );
|
ArtifactFilter filter = new ProjectArtifactExceptionFilter( artifactFilter, project.getArtifact() );
|
||||||
|
|
||||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections.singleton( artifact ),
|
ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections.singleton( artifact ),
|
||||||
project.getArtifact(),
|
project.getArtifact(),
|
||||||
localRepository,
|
localRepository,
|
||||||
project.getRemoteArtifactRepositories(),
|
project.getRemoteArtifactRepositories(),
|
||||||
artifactMetadataSource,
|
artifactMetadataSource, filter );
|
||||||
filter );
|
|
||||||
|
List excludedArtifacts = new ArrayList( result.getArtifacts().size() );
|
||||||
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
|
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
|
||||||
{
|
{
|
||||||
Artifact a = (Artifact) i.next();
|
Artifact a = (Artifact) i.next();
|
||||||
|
|
||||||
|
excludedArtifacts.add( ArtifactUtils.versionlessKey( a ) );
|
||||||
|
|
||||||
a = project.replaceWithActiveArtifact( a );
|
a = project.replaceWithActiveArtifact( a );
|
||||||
|
|
||||||
container.addJarResource( a.getFile() );
|
container.addJarResource( a.getFile() );
|
||||||
}
|
}
|
||||||
|
pluginManager.addToArtifactFilter( new ExcludesArtifactFilter( excludedArtifacts ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,22 +100,24 @@ public class DefaultExtensionManager
|
||||||
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
|
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class ProjectArtifactExceptionFilter implements ArtifactFilter
|
private static final class ProjectArtifactExceptionFilter
|
||||||
|
implements ArtifactFilter
|
||||||
{
|
{
|
||||||
private ArtifactFilter passThroughFilter;
|
private ArtifactFilter passThroughFilter;
|
||||||
private String projectDependencyConflictId;
|
|
||||||
|
|
||||||
ProjectArtifactExceptionFilter( ArtifactFilter passThroughFilter, Artifact projectArtifact )
|
private String projectDependencyConflictId;
|
||||||
{
|
|
||||||
this.passThroughFilter = passThroughFilter;
|
|
||||||
this.projectDependencyConflictId = projectArtifact.getDependencyConflictId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean include(Artifact artifact) {
|
ProjectArtifactExceptionFilter( ArtifactFilter passThroughFilter, Artifact projectArtifact )
|
||||||
String depConflictId = artifact.getDependencyConflictId();
|
{
|
||||||
|
this.passThroughFilter = passThroughFilter;
|
||||||
|
this.projectDependencyConflictId = projectArtifact.getDependencyConflictId();
|
||||||
|
}
|
||||||
|
|
||||||
return projectDependencyConflictId.equals( depConflictId )
|
public boolean include( Artifact artifact )
|
||||||
|| passThroughFilter.include( 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.ArtifactResolver;
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
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.artifact.resolver.filter.AndArtifactFilter;
|
||||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
import org.apache.maven.artifact.versioning.VersionRange;
|
import org.apache.maven.artifact.versioning.VersionRange;
|
||||||
|
@ -1190,4 +1191,11 @@ public class DefaultPluginManager
|
||||||
return pluginContainer.lookupMap( role );
|
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.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
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.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
|
@ -70,4 +72,6 @@ public interface PluginManager
|
||||||
|
|
||||||
Map getPluginComponents( Plugin plugin, String role )
|
Map getPluginComponents( Plugin plugin, String role )
|
||||||
throws ComponentLookupException, PluginManagerException;
|
throws ComponentLookupException, PluginManagerException;
|
||||||
|
|
||||||
|
void addToArtifactFilter( ArtifactFilter filter );
|
||||||
}
|
}
|
|
@ -44,6 +44,9 @@
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
|
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.plugin.PluginManager</role>
|
||||||
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue