diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java b/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java
index cab4f655d1..d411e24983 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java
@@ -19,6 +19,7 @@ package org.apache.maven.artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import java.io.File;
import java.util.List;
@@ -93,4 +94,8 @@ public interface Artifact
String getDownloadUrl();
void setDownloadUrl( String downloadUrl );
+
+ ArtifactFilter getDependencyFilter();
+
+ void setDependencyFilter( ArtifactFilter artifactFilter );
}
\ No newline at end of file
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
index 23032931d8..e04efc50e2 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
@@ -20,6 +20,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
@@ -58,6 +59,8 @@ public class DefaultArtifact
private String downloadUrl;
+ private ArtifactFilter dependencyFilter;
+
/**
* !!! WARNING !!! Never put in the POM. It is for mojo use
* only. Classifier is for specifying derived artifacts, like ejb-client.
@@ -350,4 +353,14 @@ public class DefaultArtifact
{
this.downloadUrl = downloadUrl;
}
+
+ public ArtifactFilter getDependencyFilter()
+ {
+ return dependencyFilter;
+ }
+
+ public void setDependencyFilter( ArtifactFilter artifactFilter )
+ {
+ this.dependencyFilter = artifactFilter;
+ }
}
diff --git a/maven-model/maven.mdo b/maven-model/maven.mdo
index 931bde85b2..b7e8608cf9 100644
--- a/maven-model/maven.mdo
+++ b/maven-model/maven.mdo
@@ -17,6 +17,9 @@
|
| o use enums where appropriate (eg dependency scope)
|
+ | o a number of elements have a grouId/artifactId and sometimes version. It would be good to have them all extend one
+ | definition of these types
+ |
-->
maven
@@ -1210,6 +1213,18 @@
String
compile
+
+ exclusions
+ 4.0.0
+
+ Lists a set of artifacts that should be excluded from this dependency's artifact list when it comes to
+ calculating transitive dependencies.
+
+
+ Exclusion
+ *
+
+
@@ -1322,6 +1337,24 @@
+
+ Exclusion
+ 4.0.0
+
+
+ artifactId
+ 4.0.0
+
+ String
+
+
+ groupId
+ 4.0.0
+
+ String
+
+
+
IssueManagement
diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
index 10dc52ef76..45a99d0af1 100644
--- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
+++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
@@ -41,6 +41,7 @@ import org.apache.maven.project.interpolation.ModelInterpolator;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
+import org.apache.maven.project.artifact.MavenMetadataSource;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
@@ -478,21 +479,8 @@ public class DefaultMavenProjectBuilder
protected Set createArtifacts( List dependencies )
{
- Set projectArtifacts = new HashSet();
-
- for ( Iterator i = dependencies.iterator(); i.hasNext(); )
- {
- Dependency d = (Dependency) i.next();
-
- Artifact artifact = artifactFactory.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(),
- d.getScope(), d.getType(), null );
- if ( artifact != null )
- {
- projectArtifacts.add( artifact );
- }
- }
-
- return projectArtifacts;
+ // TODO: merge with MavenMetadataSource properly
+ return new MavenMetadataSource( artifactResolver, this ).createArtifacts( dependencies, null, null );
}
protected Set createPluginArtifacts( List plugins )
diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
index 78ff1a9f83..64061c4e4e 100644
--- a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
+++ b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
@@ -24,7 +24,11 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
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.artifact.resolver.filter.AndArtifactFilter;
import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
@@ -37,6 +41,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -78,7 +83,7 @@ public class MavenMetadataSource
{
// TODO: only metadata is really needed - resolve as metadata
Artifact pomArtifact = artifactFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(),
- artifact.getVersion(), artifact.getScope(), "pom" );
+ artifact.getVersion(), artifact.getScope(), "pom" );
List dependencies = null;
@@ -133,10 +138,10 @@ public class MavenMetadataSource
IOUtil.close( reader );
}
}
- return createArtifacts( dependencies, artifact.getScope() );
+ return createArtifacts( dependencies, artifact.getScope(), artifact.getDependencyFilter() );
}
- protected Set createArtifacts( List dependencies, String inheritedScope )
+ public Set createArtifacts( List dependencies, String inheritedScope, ArtifactFilter dependencyFilter )
{
Set projectArtifacts = new HashSet();
@@ -146,9 +151,36 @@ public class MavenMetadataSource
Artifact artifact = artifactFactory.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(),
d.getScope(), d.getType(), inheritedScope );
- if ( artifact != null )
+
+ if ( artifact != null && ( dependencyFilter == null || dependencyFilter.include( artifact ) ) )
{
- projectArtifacts.add( artifact );
+ if ( d.getExclusions() != null && !d.getExclusions().isEmpty() )
+ {
+ List exclusions = new ArrayList();
+ for ( Iterator j = d.getExclusions().iterator(); j.hasNext(); )
+ {
+ Exclusion e = (Exclusion) j.next();
+ exclusions.add( e.getGroupId() + ":" + e.getArtifactId() );
+ }
+
+ ArtifactFilter newFilter = new ExcludesArtifactFilter( exclusions );
+
+ if ( dependencyFilter != null )
+ {
+ AndArtifactFilter filter = new AndArtifactFilter();
+ filter.add( dependencyFilter );
+ filter.add( newFilter );
+ dependencyFilter = filter;
+ }
+ else
+ {
+ dependencyFilter = newFilter;
+ }
+ }
+
+ artifact.setDependencyFilter( dependencyFilter );
+
+ projectArtifacts.add( artifact );
}
}