Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#123 filter artifacts per scope #334

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:compare-dependencies
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:compare-dependencies -Dscope=compile
invoker.systemPropertiesFile = test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
<artifactId>it-compare-dependencies-001</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>compare dependency versions</name>

<name>#123 add scope filter property</name>
<description>
the scope filter property to allow excluding artifacts based on scope:
junit is set to test scope and we ask a comparison in scope compile
</description>
<dependencyManagement>

<dependencies>
Expand All @@ -20,7 +23,8 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.1</version>
<version>4.0</version>
<scope>test</scope>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ try

if ( buf.indexOf( "2.0.10 -> 2.0.9" ) < 0 )
{
System.err.println( "Version diff in maven artifact not found" );
System.err.println( "Version diff in maven artifact not found. it should be processed because its scope is compile" );
return false;
}
if ( buf.indexOf( "4.0 -> 4.1" ) > 0 )
{
System.err.println( "Version diff in junit artifact found. it should be excluded because its scope is test" );
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Parent;
Expand Down Expand Up @@ -92,6 +93,15 @@ public abstract class AbstractVersionsDependencyUpdaterMojo
@Parameter
private String[] excludes = null;


/**
* a scope to use to filter the artifacts matching the asked scope or better
*
* @since 2.8
*/
@Parameter(property = "scope")
private String scope = null;

/**
* Whether to process the dependencies section of the project.
*
Expand Down Expand Up @@ -381,6 +391,12 @@ protected boolean isIncluded( Artifact artifact )
result = result && excludesFilter.include( artifact );
}

ArtifactFilter scopeFilter = this.getScopeArtifactFilter();

if (scopeFilter != null) {
result = result && scopeFilter.include(artifact);
}

return result;
}

Expand Down Expand Up @@ -430,6 +446,14 @@ else if ( excludes != null )
return excludesFilter;
}

private ArtifactFilter getScopeArtifactFilter() {
if (scope == null) {
return null;
}
return new ScopeArtifactFilter(scope);
}


/**
* To handle multiple includes with version range like "group:artifact:jar:[1.0.0,2.2)", we have to use a parsing a
* little bit more complex than split().
Expand Down