Skip to content

Commit

Permalink
Amended #258: Adding plugin and plugin management dependency includes…
Browse files Browse the repository at this point in the history
…/excludes
  • Loading branch information
jarmoniuk committed Sep 5, 2022
1 parent 0db6ce4 commit 994f65c
Show file tree
Hide file tree
Showing 11 changed files with 247 additions and 12 deletions.
@@ -0,0 +1,7 @@
invoker.goals.1=${project.groupId}:${project.artifactId}:${project.version}:display-dependency-updates -Dverbose=true -Dversions.outputFile=./output1.txt -DoutputEncoding=UTF-8 -DprocessPluginDependenciesInPluginManagement=false -DpluginDependencyIncludes=localhost:dummy-api

invoker.goals.2=${project.groupId}:${project.artifactId}:${project.version}:display-dependency-updates -Dverbose=true -Dversions.outputFile=./output2.txt -DoutputEncoding=UTF-8 -DprocessPluginDependenciesInPluginManagement=false -DpluginDependencyExcludes=localhost:dummy-api

invoker.goals.3=${project.groupId}:${project.artifactId}:${project.version}:display-dependency-updates -Dverbose=true -Dversions.outputFile=./output3.txt -DoutputEncoding=UTF-8 -DprocessPluginDependencies=false -DpluginManagementDependencyIncludes=localhost:dummy-impl

invoker.goals.4=${project.groupId}:${project.artifactId}:${project.version}:display-dependency-updates -Dverbose=true -Dversions.outputFile=./output4.txt -DoutputEncoding=UTF-8 -DprocessPluginDependencies=false -DpluginManagementDependencyExcludes=localhost:dummy-impl
@@ -0,0 +1,47 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-display-dependency-updates-issue-258-dependencyIncludesAndExcludes</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>localhost</groupId>
<artifactId>dummy-maven-plugin</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>localhost</groupId>
<artifactId>dummy-maven-plugin</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-impl</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-parent2</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
@@ -0,0 +1,15 @@
output = new File(basedir, "output1.txt").text
assert output =~ /localhost:dummy-api/
assert output !=~ /localhost:dummy-impl/

output = new File(basedir, "output2.txt").text
assert output !=~ /localhost:dummy-api/
assert output =~ /localhost:dummy-impl/

output = new File(basedir, "output3.txt").text
assert output =~ /localhost:dummy-impl/
assert output !=~ /localhost:dummy-parent2/

output = new File(basedir, "output4.txt").text
assert output !=~ /localhost:dummy-impl/
assert output =~ /localhost:dummy-parent2/
Expand Up @@ -4,7 +4,6 @@ assert buildLog.text.contains( """
[INFO] The following dependencies in Dependencies have newer versions:
[INFO] localhost:dummy-api ....................................... 1.0 -> 3.0
[INFO]
[INFO] ------------------------------------------------------------------------
""".replaceAll( "\n", System.lineSeparator() ) )

return true
Expand Up @@ -5,7 +5,6 @@ assert buildLog.text.contains("""
[INFO] localhost:dummy-api ....................................... 1.0 -> 3.0
[INFO] localhost:dummy-impl ...................................... 1.0 -> 2.2
[INFO]
[INFO] ------------------------------------------------------------------------
""".replaceAll( "\n", System.lineSeparator() ) )

return true
Expand Up @@ -5,7 +5,6 @@ assert buildLog.text.contains("""
[INFO] localhost:dummy-api ....................................... 1.0 -> 3.0
[INFO] localhost:dummy-impl ...................................... 1.0 -> 2.2
[INFO]
[INFO] ------------------------------------------------------------------------
""".replaceAll( "\n", System.lineSeparator() ) )

return true
Expand Up @@ -4,7 +4,6 @@ assert buildLog.text.contains("""
[INFO] The following dependencies in Dependencies have newer versions:
[INFO] localhost:dummy-api ....................................... 1.0 -> 3.0
[INFO]
[INFO] ------------------------------------------------------------------------
""".replaceAll( "\n", System.lineSeparator() ) )

return true
Expand Up @@ -5,7 +5,6 @@ assert buildLog.text.contains("""
[INFO] localhost:dummy-api ....................................... 1.0 -> 3.0
[INFO] localhost:dummy-impl ...................................... 1.0 -> 2.2
[INFO]
[INFO] ------------------------------------------------------------------------
""".replaceAll( "\n", System.lineSeparator() ) )

return true
Expand Up @@ -5,7 +5,6 @@ assert buildLog.text.contains("""
[INFO] localhost:dummy-api ....................................... 1.0 -> 3.0
[INFO] localhost:dummy-impl ...................................... 1.0 -> 2.2
[INFO]
[INFO] ------------------------------------------------------------------------
""".replaceAll( "\n", System.lineSeparator() ) )

return true
Expand Up @@ -28,6 +28,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
Expand Down Expand Up @@ -257,6 +258,94 @@ public class DisplayDependencyUpdatesMojo
@Parameter( property = "verbose", defaultValue = "false" )
private boolean verbose;

/**
* Only take these artifacts into consideration.
* <p>
* Comma-separated list of extended GAV patterns.
*
* <p>
* Extended GAV: groupId:artifactId:version:type:classifier:scope
* </p>
* <p>
* The wildcard "*" can be used as the only, first, last or both characters in each token.
* The version token does support version ranges.
* </p>
*
* <p>
* Example: "mygroup:artifact:*,*:*:*:*:*:compile"
* </p>
*
* @since 2.12.0
*/
@Parameter( property = "pluginDependencyIncludes", defaultValue = WildcardMatcher.WILDCARD )
private List<String> pluginDependencyIncludes;

/**
* Only take these artifacts into consideration.
* <p>
* Comma-separated list of extended GAV patterns.
*
* <p>
* Extended GAV: groupId:artifactId:version:type:classifier:scope
* </p>
* <p>
* The wildcard "*" can be used as the only, first, last or both characters in each token.
* The version token does support version ranges.
* </p>
*
* <p>
* Example: "mygroup:artifact:*,*:*:*:*:*:compile"
* </p>
*
* @since 2.12.0
*/
@Parameter( property = "pluginDependencyExcludes" )
private List<String> pluginDependencyExcludes;

/**
* Only take these artifacts into consideration.
* <p>
* Comma-separated list of extended GAV patterns.
*
* <p>
* Extended GAV: groupId:artifactId:version:type:classifier:scope
* </p>
* <p>
* The wildcard "*" can be used as the only, first, last or both characters in each token.
* The version token does support version ranges.
* </p>
*
* <p>
* Example: "mygroup:artifact:*,*:*:*:*:*:compile"
* </p>
*
* @since 2.12.0
*/
@Parameter( property = "pluginManagementDependencyIncludes", defaultValue = WildcardMatcher.WILDCARD )
private List<String> pluginManagementDependencyIncludes;

/**
* Only take these artifacts into consideration.
* <p>
* Comma-separated list of extended GAV patterns.
*
* <p>
* Extended GAV: groupId:artifactId:version:type:classifier:scope
* </p>
* <p>
* The wildcard "*" can be used as the only, first, last or both characters in each token.
* The version token does support version ranges.
* </p>
*
* <p>
* Example: "mygroup:artifact:*,*:*:*:*:*:compile"
* </p>
*
* @since 2.12.0
*/
@Parameter( property = "pluginManagementDependencyExcludes" )
private List<String> pluginManagementDependencyExcludes;

// --------------------- GETTER / SETTER METHODS ---------------------

private static Set<Dependency> extractPluginDependenciesFromPluginsInPluginManagement( Build build )
Expand Down Expand Up @@ -480,11 +569,16 @@ public void execute()
}
if ( isProcessPluginDependenciesInDependencyManagement() )
{
pluginDependenciesInPluginManagement =
filterPluginManagementIncludes( pluginDependenciesInPluginManagement );

logUpdates( getHelper().lookupDependenciesUpdates( pluginDependenciesInPluginManagement, false ),
"pluginManagement of plugins" );
}
if ( isProcessingPluginDependencies() )
{
pluginDependencies = filterPluginDependencyIncludes( pluginDependencies );

logUpdates( getHelper().lookupDependenciesUpdates( pluginDependencies, false ), "Plugin Dependencies" );
}
}
Expand All @@ -496,13 +590,26 @@ public void execute()

private Set<Dependency> filterDependencyIncludes( Set<Dependency> dependencies )
{
return filterDependencies( dependencies, dependencyIncludes, dependencyExcludes, "dependencies" );
return filterDependencies( dependencies, dependencyIncludes, dependencyExcludes, "Dependencies" );
}

private Set<Dependency> filterDependencyManagementIncludes( Set<Dependency> dependencyManagement )
{
return filterDependencies( dependencyManagement,
dependencyManagementIncludes, dependencyManagementExcludes, "dependecyManagement" );
dependencyManagementIncludes, dependencyManagementExcludes, "Dependecy Management" );
}

private Set<Dependency> filterPluginDependencyIncludes( Set<Dependency> dependencies )
{
return filterDependencies( dependencies, pluginDependencyIncludes, pluginDependencyExcludes,
"Plugin Dependencies" );
}

private Set<Dependency> filterPluginManagementIncludes( Set<Dependency> dependencyManagement )
{
return filterDependencies( dependencyManagement,
pluginManagementDependencyIncludes, pluginManagementDependencyExcludes,
"Plugin Management Dependencies" );
}

private Set<Dependency> filterDependencies(
Expand All @@ -515,15 +622,26 @@ private Set<Dependency> filterDependencies(
DependencyFilter includeDeps = DependencyFilter.parseFrom( includes );
DependencyFilter excludeDeps = DependencyFilter.parseFrom( excludes );

getLog().debug( String.format( "parsed includes in %s: %s -> %s", section, includes, includeDeps ) );
getLog().debug( String.format( "parsed excludes in %s: %s -> %s", section, excludes, excludeDeps ) );
Set<Dependency> filtered = includeDeps.retainingIn( dependencies );
filtered = excludeDeps.removingFrom( filtered );

Set<Dependency> onlyIncludes = includeDeps.retainingIn( dependencies );
Set<Dependency> filtered = excludeDeps.removingFrom( onlyIncludes );
if ( getLog().isDebugEnabled() )
{
getLog().debug( String.format( "parsed includes in %s: %s -> %s", section, includes, includeDeps ) );
getLog().debug( String.format( "parsed excludes in %s: %s -> %s", section, excludes, excludeDeps ) );
getLog().debug( String.format( "Unfiltered %s: ", section ) + output( dependencies ) );
getLog().debug( String.format( "Filtered %s: ", section ) + output( filtered ) );
}

return filtered;
}

private String output( Set<Dependency> dependencies )
{
return dependencies.stream()
.map( d -> String.format( "%s:%s:%s", d.getGroupId(), d.getArtifactId(), d.getVersion() ) )
.collect( Collectors.joining( ", " ) );
}
private DependencyManagement getProjectDependencyManagement( MavenProject project )
{
if ( processDependencyManagementTransitive )
Expand Down
@@ -0,0 +1,54 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-display-dependency-updates-issue-258-dependencyIncludesAndExcludes</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<artifactId>versions-maven-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<outputEncoding>UTF-8</outputEncoding>
</configuration>
</plugin>
<plugin>
<groupId>localhost</groupId>
<artifactId>dummy-maven-plugin</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>localhost</groupId>
<artifactId>dummy-maven-plugin</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-impl</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-parent2</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

0 comments on commit 994f65c

Please sign in to comment.