You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/09/12 03:56:08 UTC
svn commit: r442413 - in /maven/plugins/trunk/maven-dependency-plugin/src:
main/java/org/apache/maven/plugin/dependency/
main/java/org/apache/maven/plugin/dependency/utils/filters/
test/java/org/apache/maven/plugin/dependency/utils/filters/
Author: brianf
Date: Mon Sep 11 18:56:06 2006
New Revision: 442413
URL: http://svn.apache.org/viewvc?view=rev&rev=442413
Log:
[MDEP-21] & [MDEP-22] added exclude scope option.
Modified:
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ScopeFilter.java
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestScopeFilter.java
Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java?view=diff&rev=442413&r1=442412&r2=442413
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java Mon Sep 11 18:56:06 2006
@@ -62,10 +62,18 @@
/**
* Scope to include. An Empty string indicates all scopes (default).
- * @parameter expression="${scope}" default-value=""
+ * @parameter expression="${includeScope}" default-value=""
* @required
*/
- protected String scope;
+ protected String includeScope;
+
+ /**
+ * Scope to exclude. An Empty string indicates no scopes (default).
+ * @parameter expression="${excludeScope}" default-value=""
+ * @required
+ */
+ protected String excludeScope;
+
/**
* Specify classifier to look for. Example: sources
@@ -127,7 +135,7 @@
FilterArtifacts filter = new FilterArtifacts();
//TODO: dependencies is empty.
filter.addFilter( new TransitivityFilter( project.getDependencyArtifacts(), this.excludeTransitive ) );
- filter.addFilter( new ScopeFilter( this.scope ) );
+ filter.addFilter( new ScopeFilter( this.includeScope , this.excludeScope) );
filter.addFilter( new TypeFilter( this.includeTypes, this.excludeTypes ) );
//perform filtering
Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ScopeFilter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ScopeFilter.java?view=diff&rev=442413&r1=442412&r2=442413
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ScopeFilter.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/filters/ScopeFilter.java Mon Sep 11 18:56:06 2006
@@ -28,21 +28,31 @@
implements ArtifactsFilter
{
- private String scope;
+ private String includeScope;
- public ScopeFilter( String scope )
+ private String excludeScope;
+
+ public ScopeFilter( String includeScope, String excludeScope )
{
- this.scope = scope;
+ this.includeScope = includeScope;
+ this.excludeScope = excludeScope;
}
+ /**
+ * This function determines if filtering needs to be performed. Excludes are ignored if Includes are used.
+ * @param dependencies
+ * the set of dependencies to filter.
+ *
+ * @return a Set of filtered dependencies.
+ */
public Set filter( Set artifacts, Log log )
{
Set results = artifacts;
- if ( StringUtils.isNotEmpty( scope ) )
+ if ( StringUtils.isNotEmpty( includeScope ) )
{
results = new HashSet();
- ScopeArtifactFilter saf = new ScopeArtifactFilter( scope );
+ ScopeArtifactFilter saf = new ScopeArtifactFilter( includeScope );
Iterator iter = artifacts.iterator();
while ( iter.hasNext() )
@@ -54,23 +64,74 @@
}
}
}
+ else if ( StringUtils.isNotEmpty( excludeScope ) )
+ {
+ results = new HashSet();
+ //plexus ScopeArtifactFilter doesn't handle the provided scope so we
+ //need special handling for it.
+ if ( !Artifact.SCOPE_PROVIDED.equals( excludeScope ) )
+ {
+ ScopeArtifactFilter saf = new ScopeArtifactFilter( excludeScope );
+
+ Iterator iter = artifacts.iterator();
+ while ( iter.hasNext() )
+ {
+ Artifact artifact = (Artifact) iter.next();
+ if ( !saf.include( artifact ) )
+ {
+ System.out.println(artifact.getScope());
+ results.add( artifact );
+ }
+ }
+ }
+ else
+ {
+ Iterator iter = artifacts.iterator();
+ while ( iter.hasNext() )
+ {
+ Artifact artifact = (Artifact) iter.next();
+ if ( !Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) )
+ {
+ results.add( artifact );
+ }
+ }
+ }
+
+ }
+
return results;
}
/**
- * @return Returns the scope.
+ * @return Returns the includeScope.
+ */
+ public String getIncludeScope()
+ {
+ return this.includeScope;
+ }
+
+ /**
+ * @param includeScope The includeScope to set.
+ */
+ public void setIncludeScope( String scope )
+ {
+ this.includeScope = scope;
+ }
+
+ /**
+ * @return Returns the excludeScope.
*/
- public String getScope()
+ public String getExcludeScope()
{
- return this.scope;
+ return this.excludeScope;
}
/**
- * @param scope The scope to set.
+ * @param excludeScope The excludeScope to set.
*/
- public void setScope( String scope )
+ public void setExcludeScope( String excludeScope )
{
- this.scope = scope;
+ this.excludeScope = excludeScope;
}
}
Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestScopeFilter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestScopeFilter.java?view=diff&rev=442413&r1=442412&r2=442413
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestScopeFilter.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestScopeFilter.java Mon Sep 11 18:56:06 2006
@@ -61,28 +61,28 @@
public void testScopeFilter()
{
- ScopeFilter filter = new ScopeFilter( Artifact.SCOPE_COMPILE );
+ ScopeFilter filter = new ScopeFilter( Artifact.SCOPE_COMPILE, null );
Set result = filter.filter( artifacts, log );
assertEquals( 2, result.size() );
}
public void testScopeFilter2()
{
- ScopeFilter filter = new ScopeFilter( Artifact.SCOPE_RUNTIME );
+ ScopeFilter filter = new ScopeFilter( Artifact.SCOPE_RUNTIME, null );
Set result = filter.filter( artifacts, log );
assertEquals( 2, result.size() );
}
public void testScopeFilter3()
{
- ScopeFilter filter = new ScopeFilter( Artifact.SCOPE_TEST );
+ ScopeFilter filter = new ScopeFilter( Artifact.SCOPE_TEST, null );
Set result = filter.filter( artifacts, log );
assertEquals( 4, result.size() );
}
public void testScopeFilterNull()
{
- ScopeFilter filter = new ScopeFilter( null );
+ ScopeFilter filter = new ScopeFilter( null , null);
Set result = filter.filter( artifacts, log );
assertEquals( 4, result.size() );
@@ -90,8 +90,29 @@
public void testScopeFilterEmpty()
{
- ScopeFilter filter = new ScopeFilter( "" );
+ ScopeFilter filter = new ScopeFilter( "", "" );
Set result = filter.filter( artifacts, log );
assertEquals( 4, result.size() );
+ }
+
+ public void testExcludeProvided()
+ {
+ ScopeFilter filter = new ScopeFilter ("", Artifact.SCOPE_PROVIDED);
+ Set result = filter.filter( artifacts, log );
+ assertEquals( 3, result.size() );
+ }
+
+ public void testExcludeCompile()
+ {
+ ScopeFilter filter = new ScopeFilter ("", Artifact.SCOPE_COMPILE);
+ Set result = filter.filter( artifacts, log );
+ assertEquals( 2, result.size() );
+ }
+
+ public void testExcludeTest()
+ {
+ ScopeFilter filter = new ScopeFilter ("", Artifact.SCOPE_TEST);
+ Set result = filter.filter( artifacts, log );
+ assertEquals( 0, result.size() );
}
}