mirror of https://github.com/apache/maven.git
add quick support for exclusions
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@188779 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
77caea316a
commit
d6d65fc75a
|
@ -19,6 +19,7 @@ package org.apache.maven.artifact;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
|
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -93,4 +94,8 @@ public interface Artifact
|
||||||
String getDownloadUrl();
|
String getDownloadUrl();
|
||||||
|
|
||||||
void setDownloadUrl( String downloadUrl );
|
void setDownloadUrl( String downloadUrl );
|
||||||
|
|
||||||
|
ArtifactFilter getDependencyFilter();
|
||||||
|
|
||||||
|
void setDependencyFilter( ArtifactFilter artifactFilter );
|
||||||
}
|
}
|
|
@ -20,6 +20,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
|
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
|
||||||
|
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -58,6 +59,8 @@ public class DefaultArtifact
|
||||||
|
|
||||||
private String downloadUrl;
|
private String downloadUrl;
|
||||||
|
|
||||||
|
private ArtifactFilter dependencyFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* !!! WARNING !!! Never put <classifier/> in the POM. It is for mojo use
|
* !!! WARNING !!! Never put <classifier/> in the POM. It is for mojo use
|
||||||
* only. Classifier is for specifying derived artifacts, like ejb-client.
|
* only. Classifier is for specifying derived artifacts, like ejb-client.
|
||||||
|
@ -350,4 +353,14 @@ public class DefaultArtifact
|
||||||
{
|
{
|
||||||
this.downloadUrl = downloadUrl;
|
this.downloadUrl = downloadUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArtifactFilter getDependencyFilter()
|
||||||
|
{
|
||||||
|
return dependencyFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDependencyFilter( ArtifactFilter artifactFilter )
|
||||||
|
{
|
||||||
|
this.dependencyFilter = artifactFilter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
|
|
|
|
||||||
| o use enums where appropriate (eg dependency scope)
|
| 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
|
||||||
|
|
|
||||||
-->
|
-->
|
||||||
<model>
|
<model>
|
||||||
<id>maven</id>
|
<id>maven</id>
|
||||||
|
@ -1210,6 +1213,18 @@
|
||||||
<type>String</type>
|
<type>String</type>
|
||||||
<defaultValue>compile</defaultValue>
|
<defaultValue>compile</defaultValue>
|
||||||
</field>
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>exclusions</name>
|
||||||
|
<version>4.0.0</version>
|
||||||
|
<description>
|
||||||
|
Lists a set of artifacts that should be excluded from this dependency's artifact list when it comes to
|
||||||
|
calculating transitive dependencies.
|
||||||
|
</description>
|
||||||
|
<association>
|
||||||
|
<type>Exclusion</type>
|
||||||
|
<multiplicity>*</multiplicity>
|
||||||
|
</association>
|
||||||
|
</field>
|
||||||
</fields>
|
</fields>
|
||||||
<codeSegments>
|
<codeSegments>
|
||||||
<codeSegment>
|
<codeSegment>
|
||||||
|
@ -1322,6 +1337,24 @@
|
||||||
</field>
|
</field>
|
||||||
</fields>
|
</fields>
|
||||||
</class>
|
</class>
|
||||||
|
<class>
|
||||||
|
<name>Exclusion</name>
|
||||||
|
<version>4.0.0</version>
|
||||||
|
<fields>
|
||||||
|
<field>
|
||||||
|
<name>artifactId</name>
|
||||||
|
<version>4.0.0</version>
|
||||||
|
<description><![CDATA[The artifact id of the project to exclude.]]></description>
|
||||||
|
<type>String</type>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>groupId</name>
|
||||||
|
<version>4.0.0</version>
|
||||||
|
<description><![CDATA[The group id of the project to exclude.]]></description>
|
||||||
|
<type>String</type>
|
||||||
|
</field>
|
||||||
|
</fields>
|
||||||
|
</class>
|
||||||
<class>
|
<class>
|
||||||
<name>IssueManagement</name>
|
<name>IssueManagement</name>
|
||||||
<description>
|
<description>
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.apache.maven.project.interpolation.ModelInterpolator;
|
||||||
import org.apache.maven.project.path.PathTranslator;
|
import org.apache.maven.project.path.PathTranslator;
|
||||||
import org.apache.maven.project.validation.ModelValidationResult;
|
import org.apache.maven.project.validation.ModelValidationResult;
|
||||||
import org.apache.maven.project.validation.ModelValidator;
|
import org.apache.maven.project.validation.ModelValidator;
|
||||||
|
import org.apache.maven.project.artifact.MavenMetadataSource;
|
||||||
import org.codehaus.plexus.PlexusConstants;
|
import org.codehaus.plexus.PlexusConstants;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
|
@ -478,21 +479,8 @@ public class DefaultMavenProjectBuilder
|
||||||
|
|
||||||
protected Set createArtifacts( List dependencies )
|
protected Set createArtifacts( List dependencies )
|
||||||
{
|
{
|
||||||
Set projectArtifacts = new HashSet();
|
// TODO: merge with MavenMetadataSource properly
|
||||||
|
return new MavenMetadataSource( artifactResolver, this ).createArtifacts( dependencies, null, null );
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set createPluginArtifacts( List plugins )
|
protected Set createPluginArtifacts( List plugins )
|
||||||
|
|
|
@ -24,7 +24,11 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
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.ExcludesArtifactFilter;
|
||||||
|
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
|
||||||
import org.apache.maven.model.Dependency;
|
import org.apache.maven.model.Dependency;
|
||||||
|
import org.apache.maven.model.Exclusion;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
@ -37,6 +41,7 @@ import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -78,7 +83,7 @@ public class MavenMetadataSource
|
||||||
{
|
{
|
||||||
// TODO: only metadata is really needed - resolve as metadata
|
// TODO: only metadata is really needed - resolve as metadata
|
||||||
Artifact pomArtifact = artifactFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(),
|
Artifact pomArtifact = artifactFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(),
|
||||||
artifact.getVersion(), artifact.getScope(), "pom" );
|
artifact.getVersion(), artifact.getScope(), "pom" );
|
||||||
|
|
||||||
List dependencies = null;
|
List dependencies = null;
|
||||||
|
|
||||||
|
@ -133,10 +138,10 @@ public class MavenMetadataSource
|
||||||
IOUtil.close( reader );
|
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();
|
Set projectArtifacts = new HashSet();
|
||||||
|
|
||||||
|
@ -146,9 +151,36 @@ public class MavenMetadataSource
|
||||||
|
|
||||||
Artifact artifact = artifactFactory.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(),
|
Artifact artifact = artifactFactory.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(),
|
||||||
d.getScope(), d.getType(), inheritedScope );
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue