Skip to content

Commit

Permalink
Fixed mojohaus#258: Adding plugin and plugin management dependency in…
Browse files Browse the repository at this point in the history
…cludes/excludes
  • Loading branch information
jarmoniuk committed Sep 5, 2022
1 parent b5ff527 commit fc8a10a
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 208 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 @@ -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 Expand Up @@ -563,7 +681,7 @@ private UpdateScope calculateUpdateScope()
return result;
}

protected void logUpdates( Map<Dependency, ArtifactVersions> updates, String section )
private void logUpdates( Map<Dependency, ArtifactVersions> updates, String section )
{
List<String> withUpdates = new ArrayList<>();
List<String> usingCurrent = new ArrayList<>();
Expand Down Expand Up @@ -594,15 +712,15 @@ protected void logUpdates( Map<Dependency, ArtifactVersions> updates, String sec
}
String right = " " + ( latest == null ? current : current + " -> " + latest );
List<String> t = latest == null ? usingCurrent : withUpdates;
if ( right.length() + left.length() + 3 > outputLineWidth )
if ( right.length() + left.length() + 3 > INFO_PAD_SIZE + getOutputLineWidthOffset() )
{
t.add( left + "..." );
t.add( StringUtils.leftPad( right, outputLineWidth ) );
t.add( StringUtils.leftPad( right, INFO_PAD_SIZE + getOutputLineWidthOffset() ) );

}
else
{
t.add( StringUtils.rightPad( left, outputLineWidth - right.length(), "." )
t.add( StringUtils.rightPad( left, INFO_PAD_SIZE + getOutputLineWidthOffset() - right.length(), "." )
+ right );
}
}
Expand Down

This file was deleted.

0 comments on commit fc8a10a

Please sign in to comment.