Skip to content

Commit

Permalink
Add support for include and exclude patterns for project dependencies
Browse files Browse the repository at this point in the history
Add support for include and exclude patterns for project dependencies nicoulaj#36
nicoulaj#36
  • Loading branch information
tombueng committed May 12, 2021
1 parent 607c016 commit 5968947
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter;
import org.apache.maven.shared.artifact.filter.collection.ClassifierFilter;
import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter;

import java.util.HashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -145,6 +147,42 @@ public class ArtifactsMojo
@Parameter
protected String excludeClassifiers;

/**
* Comma-separated list of includes. For all secondary project artifacts matching any of the given includes checksums are generated.
* If not set all secondary project artifacts are considered.
*
* @since 1.11
*/
@Parameter
protected String groupdIDincludes;

/**
* Comma-separated list of excludes. For all secondary project artifacts matching any of the given excludes checksums are not generated.
* Takes precedence over {@link #groupdIDincludes}.
*
* @since 1.11
*/
@Parameter
protected String groupdIDexcludes;

/**
* Comma-separated list of includes. For all secondary project artifacts matching any of the given includes checksums are generated.
* If not set all secondary project artifacts are considered.
*
* @since 1.11
*/
@Parameter
protected String artifactIDincludes;

/**
* Comma-separated list of excludes. For all secondary project artifacts matching any of the given excludes checksums are not generated.
* Takes precedence over {@link #artifactIDincludes}.
*
* @since 1.11
*/
@Parameter
protected String artifactIDexcludes;

/**
* Constructor.
*/
Expand Down Expand Up @@ -177,6 +215,10 @@ protected List<ChecksumFile> getFilesToProcess()
Set<Artifact> filteredArtifacts = new HashSet<>(project.getAttachedArtifacts());
ClassifierFilter classifierFilter = new ClassifierFilter( includeClassifiers, excludeClassifiers );
filteredArtifacts = classifierFilter.filter( filteredArtifacts );
ArtifactIdFilter artifactIDFilter = new ArtifactIdFilter( artifactIDincludes, artifactIDexcludes );
filteredArtifacts = artifactIDFilter.filter( filteredArtifacts );
GroupIdFilter groupIdFilter = new GroupIdFilter( groupdIDincludes, groupdIDexcludes );
filteredArtifacts = groupIdFilter.filter( filteredArtifacts );
for ( Artifact artifact : filteredArtifacts )
{
if ( hasValidFile( artifact ) )
Expand Down Expand Up @@ -289,4 +331,6 @@ protected String getShasumSummaryFile()
{
return shasumSummaryFile;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter;
import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter;

import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -154,6 +156,43 @@ public class DependenciesMojo
@Parameter( defaultValue = "false" )
protected boolean transitive;

/**
* Comma-separated list of includes. For all secondary project artifacts matching any of the given includes checksums are generated.
* If not set all secondary project artifacts are considered.
*
* @since 1.11
*/
@Parameter
protected String groupdIDincludes;

/**
* Comma-separated list of excludes. For all secondary project artifacts matching any of the given excludes checksums are not generated.
* Takes precedence over {@link #groupdIDincludes}.
*
* @since 1.11
*/
@Parameter
protected String groupdIDexcludes;

/**
* Comma-separated list of includes. For all secondary project artifacts matching any of the given includes checksums are generated.
* If not set all secondary project artifacts are considered.
*
* @since 1.11
*/
@Parameter
protected String artifactIDincludes;

/**
* Comma-separated list of excludes. For all secondary project artifacts matching any of the given excludes checksums are not generated.
* Takes precedence over {@link #artifactIDincludes}.
*
* @since 1.11
*/
@Parameter
protected String artifactIDexcludes;


/**
* Constructor.
*/
Expand All @@ -174,6 +213,10 @@ protected List<ChecksumFile> getFilesToProcess()
List<ChecksumFile> files = new LinkedList<>();

Set<Artifact> artifacts = transitive ? project.getArtifacts() : project.getDependencyArtifacts();
ArtifactIdFilter artifactIDFilter = new ArtifactIdFilter( artifactIDincludes, artifactIDexcludes );
Set<Artifact> filteredArtifacts = artifactIDFilter.filter(artifacts);
GroupIdFilter groupIdFilter = new GroupIdFilter( groupdIDincludes, groupdIDexcludes );
filteredArtifacts = groupIdFilter.filter( filteredArtifacts );
for ( Artifact artifact : artifacts )
{
if ( ( scopes == null || scopes.contains( artifact.getScope() ) ) && ( types == null || types.contains(
Expand Down Expand Up @@ -257,4 +300,6 @@ protected String getShasumSummaryFile()
{
return shasumSummaryFile;
}


}

0 comments on commit 5968947

Please sign in to comment.