mirror of https://github.com/apache/maven.git
[MNG-4180] [regression] Dependency exclusions are applied globally
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@784296 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d5eae80ab1
commit
3eb4ffb445
|
@ -1,7 +1,5 @@
|
|||
package org.apache.maven;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -12,12 +10,8 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
|||
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
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.ExcludesArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Exclusion;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.artifact.ProjectArtifact;
|
||||
import org.apache.maven.repository.RepositorySystem;
|
||||
|
@ -37,32 +31,10 @@ public class DefaultProjectDependenciesResolver
|
|||
public Set<Artifact> resolve( MavenProject project, String scope, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||
{
|
||||
List<String> exclusions = new ArrayList<String>();
|
||||
|
||||
for ( Dependency d : project.getDependencies() )
|
||||
{
|
||||
if ( d.getExclusions() != null )
|
||||
{
|
||||
for ( Exclusion e : d.getExclusions() )
|
||||
{
|
||||
exclusions.add( e.getGroupId() + ":" + e.getArtifactId() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ArtifactFilter scopeFilter = new ScopeArtifactFilter( scope );
|
||||
|
||||
ArtifactFilter filter;
|
||||
|
||||
if ( ! exclusions.isEmpty() )
|
||||
{
|
||||
filter = new AndArtifactFilter( Arrays.asList( new ArtifactFilter[]{ new ExcludesArtifactFilter( exclusions ), scopeFilter } ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
filter = scopeFilter;
|
||||
}
|
||||
|
||||
ArtifactFilter filter = scopeFilter;
|
||||
|
||||
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
|
||||
.setArtifact( new ProjectArtifact( project ) )
|
||||
.setResolveRoot( false )
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.maven.project.artifact;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
@ -33,10 +34,13 @@ import org.apache.maven.artifact.repository.metadata.Metadata;
|
|||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
|
||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
|
||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
|
||||
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
|
||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Exclusion;
|
||||
import org.apache.maven.project.DefaultProjectBuildingRequest;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectBuilder;
|
||||
|
@ -135,6 +139,8 @@ public class MavenMetadataSource
|
|||
{
|
||||
artifacts = new LinkedHashSet<Artifact>();
|
||||
|
||||
ArtifactFilter dependencyFilter = artifact.getDependencyFilter();
|
||||
|
||||
for ( Dependency d : dependencies )
|
||||
{
|
||||
String effectiveScope = getEffectiveScope( d.getScope(), artifact.getScope() );
|
||||
|
@ -153,14 +159,34 @@ public class MavenMetadataSource
|
|||
dependencyArtifact = repositorySystem.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(), effectiveScope, d.getType() );
|
||||
}
|
||||
|
||||
dependencyArtifact.setOptional( d.isOptional() );
|
||||
|
||||
if ( Artifact.SCOPE_SYSTEM.equals( effectiveScope ) )
|
||||
if ( dependencyFilter == null || dependencyFilter.include( dependencyArtifact ) )
|
||||
{
|
||||
dependencyArtifact.setFile( new File( d.getSystemPath() ) );
|
||||
}
|
||||
|
||||
artifacts.add( dependencyArtifact );
|
||||
dependencyArtifact.setOptional( d.isOptional() );
|
||||
|
||||
if ( Artifact.SCOPE_SYSTEM.equals( effectiveScope ) )
|
||||
{
|
||||
dependencyArtifact.setFile( new File( d.getSystemPath() ) );
|
||||
}
|
||||
|
||||
if ( !d.getExclusions().isEmpty() )
|
||||
{
|
||||
List<String> exclusions = new ArrayList<String>();
|
||||
|
||||
for ( Exclusion e : d.getExclusions() )
|
||||
{
|
||||
exclusions.add( e.getGroupId() + ":" + e.getArtifactId() );
|
||||
}
|
||||
|
||||
ArtifactFilter newFilter = new ExcludesArtifactFilter( exclusions );
|
||||
if ( dependencyFilter != null )
|
||||
{
|
||||
newFilter = new AndArtifactFilter( Arrays.asList( dependencyFilter, newFilter ) );
|
||||
}
|
||||
dependencyArtifact.setDependencyFilter( newFilter );
|
||||
}
|
||||
|
||||
artifacts.add( dependencyArtifact );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,11 +76,11 @@ public class ProjectInheritanceTest
|
|||
|
||||
assertNotNull("No artifacts", map);
|
||||
assertTrue("No Artifacts", map.size() > 0);
|
||||
assertTrue("Set size should be 3, is " + map.size(), map.size() == 3);
|
||||
assertTrue("Set size should be 2, is " + map.size(), map.size() == 2);
|
||||
|
||||
assertTrue("maven-test:t09-a is not in the project", map.containsKey( "maven-test:t09-a" ));
|
||||
assertTrue("maven-test:t09-b is not in the project", map.containsKey( "maven-test:t09-b" ));
|
||||
|
||||
assertFalse("maven-test:t09-c is in the project", map.containsKey( "maven-test:t09-c" ));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue