diff --git a/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java index cd2ca0c9f7..650fefaf2f 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java @@ -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 resolve( MavenProject project, String scope, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactResolutionException, ArtifactNotFoundException { - List exclusions = new ArrayList(); - - 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 ) diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 6ec14ad96b..ad38797ae5 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -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(); + 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 exclusions = new ArrayList(); + + 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 ); + } } } } diff --git a/maven-core/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java b/maven-core/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java index 760c086dce..f583dee303 100644 --- a/maven-core/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java @@ -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" )); } /**