diff --git a/src/it/it-display-dependency-updates-issue-258-dependencyIncludesAndExcludes/invoker.properties b/src/it/it-display-dependency-updates-issue-258-dependencyIncludesAndExcludes/invoker.properties
new file mode 100644
index 0000000000..43a2441cb8
--- /dev/null
+++ b/src/it/it-display-dependency-updates-issue-258-dependencyIncludesAndExcludes/invoker.properties
@@ -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
\ No newline at end of file
diff --git a/src/it/it-display-dependency-updates-issue-258-dependencyIncludesAndExcludes/pom.xml b/src/it/it-display-dependency-updates-issue-258-dependencyIncludesAndExcludes/pom.xml
new file mode 100644
index 0000000000..aebe5f65d1
--- /dev/null
+++ b/src/it/it-display-dependency-updates-issue-258-dependencyIncludesAndExcludes/pom.xml
@@ -0,0 +1,47 @@
+
+ 4.0.0
+ localhost
+ it-display-dependency-updates-issue-258-dependencyIncludesAndExcludes
+ 1.0
+ pom
+
+
+
+
+ localhost
+ dummy-maven-plugin
+ 1.0
+
+
+ localhost
+ dummy-api
+ 1.0
+
+
+
+
+
+
+
+ localhost
+ dummy-maven-plugin
+ 1.0
+
+
+ localhost
+ dummy-impl
+ 1.0
+
+
+ localhost
+ dummy-parent2
+ 1.0
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/it/it-display-dependency-updates-issue-258-dependencyIncludesAndExcludes/verify.groovy b/src/it/it-display-dependency-updates-issue-258-dependencyIncludesAndExcludes/verify.groovy
new file mode 100644
index 0000000000..db50bf4bfb
--- /dev/null
+++ b/src/it/it-display-dependency-updates-issue-258-dependencyIncludesAndExcludes/verify.groovy
@@ -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/
diff --git a/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java b/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java
index dd10d1a82c..f8100f911f 100644
--- a/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java
+++ b/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java
@@ -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;
@@ -257,6 +258,94 @@ public class DisplayDependencyUpdatesMojo
@Parameter( property = "verbose", defaultValue = "false" )
private boolean verbose;
+ /**
+ * Only take these artifacts into consideration.
+ *
+ * Comma-separated list of extended GAV patterns.
+ *
+ *
+ * Extended GAV: groupId:artifactId:version:type:classifier:scope
+ *
+ *
+ * The wildcard "*" can be used as the only, first, last or both characters in each token.
+ * The version token does support version ranges.
+ *
+ *
+ *
+ * Example: "mygroup:artifact:*,*:*:*:*:*:compile"
+ *
+ *
+ * @since 2.12.0
+ */
+ @Parameter( property = "pluginDependencyIncludes", defaultValue = WildcardMatcher.WILDCARD )
+ private List pluginDependencyIncludes;
+
+ /**
+ * Only take these artifacts into consideration.
+ *
+ * Comma-separated list of extended GAV patterns.
+ *
+ *
+ * Extended GAV: groupId:artifactId:version:type:classifier:scope
+ *
+ *
+ * The wildcard "*" can be used as the only, first, last or both characters in each token.
+ * The version token does support version ranges.
+ *
+ *
+ *
+ * Example: "mygroup:artifact:*,*:*:*:*:*:compile"
+ *
+ *
+ * @since 2.12.0
+ */
+ @Parameter( property = "pluginDependencyExcludes" )
+ private List pluginDependencyExcludes;
+
+ /**
+ * Only take these artifacts into consideration.
+ *
+ * Comma-separated list of extended GAV patterns.
+ *
+ *
+ * Extended GAV: groupId:artifactId:version:type:classifier:scope
+ *
+ *
+ * The wildcard "*" can be used as the only, first, last or both characters in each token.
+ * The version token does support version ranges.
+ *
+ *
+ *
+ * Example: "mygroup:artifact:*,*:*:*:*:*:compile"
+ *
+ *
+ * @since 2.12.0
+ */
+ @Parameter( property = "pluginManagementDependencyIncludes", defaultValue = WildcardMatcher.WILDCARD )
+ private List pluginManagementDependencyIncludes;
+
+ /**
+ * Only take these artifacts into consideration.
+ *
+ * Comma-separated list of extended GAV patterns.
+ *
+ *
+ * Extended GAV: groupId:artifactId:version:type:classifier:scope
+ *
+ *
+ * The wildcard "*" can be used as the only, first, last or both characters in each token.
+ * The version token does support version ranges.
+ *
+ *
+ *
+ * Example: "mygroup:artifact:*,*:*:*:*:*:compile"
+ *
+ *
+ * @since 2.12.0
+ */
+ @Parameter( property = "pluginManagementDependencyExcludes" )
+ private List pluginManagementDependencyExcludes;
+
// --------------------- GETTER / SETTER METHODS ---------------------
private static Set extractPluginDependenciesFromPluginsInPluginManagement( Build build )
@@ -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" );
}
}
@@ -496,13 +590,26 @@ public void execute()
private Set filterDependencyIncludes( Set dependencies )
{
- return filterDependencies( dependencies, dependencyIncludes, dependencyExcludes, "dependencies" );
+ return filterDependencies( dependencies, dependencyIncludes, dependencyExcludes, "Dependencies" );
}
private Set filterDependencyManagementIncludes( Set dependencyManagement )
{
return filterDependencies( dependencyManagement,
- dependencyManagementIncludes, dependencyManagementExcludes, "dependecyManagement" );
+ dependencyManagementIncludes, dependencyManagementExcludes, "Dependecy Management" );
+ }
+
+ private Set filterPluginDependencyIncludes( Set dependencies )
+ {
+ return filterDependencies( dependencies, pluginDependencyIncludes, pluginDependencyExcludes,
+ "Plugin Dependencies" );
+ }
+
+ private Set filterPluginManagementIncludes( Set dependencyManagement )
+ {
+ return filterDependencies( dependencyManagement,
+ pluginManagementDependencyIncludes, pluginManagementDependencyExcludes,
+ "Plugin Management Dependencies" );
}
private Set filterDependencies(
@@ -515,15 +622,26 @@ private Set 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 filtered = includeDeps.retainingIn( dependencies );
+ filtered = excludeDeps.removingFrom( filtered );
- Set onlyIncludes = includeDeps.retainingIn( dependencies );
- Set 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 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 )
@@ -563,7 +681,7 @@ private UpdateScope calculateUpdateScope()
return result;
}
- protected void logUpdates( Map updates, String section )
+ private void logUpdates( Map updates, String section )
{
List withUpdates = new ArrayList<>();
List usingCurrent = new ArrayList<>();
@@ -594,15 +712,15 @@ protected void logUpdates( Map updates, String sec
}
String right = " " + ( latest == null ? current : current + " -> " + latest );
List 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 );
}
}
diff --git a/src/test/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojoTest.java b/src/test/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojoTest.java
deleted file mode 100644
index 38c5a0ab69..0000000000
--- a/src/test/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojoTest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package org.codehaus.mojo.versions;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.util.Collections;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Stream;
-
-import org.apache.maven.artifact.DefaultArtifact;
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
-import org.apache.maven.model.Dependency;
-import org.codehaus.mojo.versions.api.ArtifactVersions;
-import org.codehaus.mojo.versions.ordering.MavenVersionComparator;
-import org.junit.Test;
-
-import static org.apache.maven.artifact.Artifact.SCOPE_COMPILE;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.matchesPattern;
-import static org.hamcrest.core.Is.is;
-
-/**
- * Unit tests for {@linkplain DisplayDependencyUpdatesMojo}.
- *
- * @author Andrzej Jarmoniuk
- */
-public class DisplayDependencyUpdatesMojoTest
-{
- @Test
- public void testOutputLineLength() throws IOException
- {
- Map updates = Collections.singletonMap(
- DependencyBuilder.dependencyWith( "default-group", "default-artifact", "1.0.0" ), new ArtifactVersions(
- new DefaultArtifact( "default-group", "default-artifact", "1.0.0", SCOPE_COMPILE, "pom",
- "default", null ), Collections.singletonList( new DefaultArtifactVersion( "1.0.1" ) ),
- new MavenVersionComparator() ) );
- Stream.of( 60, 80, 120, 150 ).forEach( lineLength -> {
- DisplayDependencyUpdatesMojo mojo = new DisplayDependencyUpdatesMojo();
- mojo.outputLineWidth = lineLength;
- mojo.outputEncoding = "UTF-8";
- try
- {
- mojo.outputFile = File.createTempFile( "displayDependencyUpdates", "txt" );
- }
- catch ( IOException e )
- {
- throw new RuntimeException( e );
- }
- try
- {
- mojo.logUpdates( updates, "DEFAULT-SECTION" );
- String output = String.join( "\n", Files.readAllLines( mojo.outputFile.toPath() ) );
- Pattern pattern =
- Pattern.compile( ".*\n(\\s*default-group:default-artifact\\s.*\\s1.0.0 -> 1.0.1\\s*)\n.*" );
- Matcher matcher = pattern.matcher( output );
- assertThat( "Pattern should match with line length " + lineLength, output, matchesPattern( pattern ) );
- assertThat( matcher.matches(), is( true ) );
- String dependencyUpdateLine = matcher.toMatchResult().group( 1 );
- assertThat( "Line length of the dependency update line should match " + lineLength,
- dependencyUpdateLine.length(), is( lineLength ) );
- }
- catch ( IOException e )
- {
- throw new RuntimeException( e );
- }
- finally
- {
- assertThat( mojo.outputFile.delete(), is( true ) );
- }
-
- } );
- }
-}
diff --git a/src/test/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojoTest.java b/src/test/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojoTest.java
deleted file mode 100644
index 723501dde8..0000000000
--- a/src/test/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojoTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package org.codehaus.mojo.versions;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.util.Collections;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Stream;
-
-import org.apache.maven.artifact.DefaultArtifact;
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.codehaus.mojo.versions.api.ArtifactVersions;
-import org.codehaus.mojo.versions.ordering.MavenVersionComparator;
-import org.junit.Test;
-
-import static org.apache.maven.artifact.Artifact.SCOPE_COMPILE;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.matchesPattern;
-import static org.hamcrest.core.Is.is;
-
-/**
- * Unit tests for {@linkplain DisplayPluginUpdatesMojo}.
- *
- * @author Andrzej Jarmoniuk
- */
-public class DisplayPluginUpdatesMojoTest
-{
- @Test
- public void testOutputLineLength() throws IOException
- {
- Map updates = Collections.singletonMap(
- DependencyBuilder.dependencyWith( "default-group", "default-artifact", "1.0.0" ), new ArtifactVersions(
- new DefaultArtifact( "default-group", "default-artifact", "1.0.0", SCOPE_COMPILE, "pom",
- "default", null ), Collections.singletonList( new DefaultArtifactVersion( "1.0.1" ) ),
- new MavenVersionComparator() ) );
- Stream.of( 60, 80, 120, 150 ).forEach( lineLength -> {
- DisplayPluginUpdatesMojo mojo = new DisplayPluginUpdatesMojo();
- mojo.outputLineWidth = lineLength;
- mojo.outputEncoding = "UTF-8";
- try
- {
- mojo.outputFile = File.createTempFile( "displayDependencyUpdates", "txt" );
- }
- catch ( IOException e )
- {
- throw new RuntimeException( e );
- }
- try
- {
- mojo.execute();
- String output = String.join( "\n", Files.readAllLines( mojo.outputFile.toPath() ) );
- Pattern pattern =
- Pattern.compile( ".*\n(\\s*default-group:default-artifact\\s.*\\s1.0.0 -> 1.0.1\\s*)\n.*" );
- Matcher matcher = pattern.matcher( output );
- assertThat( "Pattern should match with line length " + lineLength, output, matchesPattern( pattern ) );
- assertThat( matcher.matches(), is( true ) );
- String dependencyUpdateLine = matcher.toMatchResult().group( 1 );
- assertThat( "Line length of the dependency update line should match " + lineLength,
- dependencyUpdateLine.length(), is( lineLength ) );
- }
- catch ( IOException e )
- {
- throw new RuntimeException( e );
- }
- catch ( MojoExecutionException e )
- {
- throw new RuntimeException( e );
- }
- catch ( MojoFailureException e )
- {
- throw new RuntimeException( e );
- }
- finally
- {
- assertThat( mojo.outputFile.delete(), is( true ) );
- }
-
- } );
- }
-}
diff --git a/src/test/resources/org/codehaus/mojo/display-dependency-updates/issue-258-pom.xml b/src/test/resources/org/codehaus/mojo/display-dependency-updates/issue-258-pom.xml
new file mode 100644
index 0000000000..890f68ffc1
--- /dev/null
+++ b/src/test/resources/org/codehaus/mojo/display-dependency-updates/issue-258-pom.xml
@@ -0,0 +1,54 @@
+
+ 4.0.0
+ localhost
+ it-display-dependency-updates-issue-258-dependencyIncludesAndExcludes
+ 1.0
+ pom
+
+
+
+
+ versions-maven-plugin
+
+ true
+ UTF-8
+
+
+
+ localhost
+ dummy-maven-plugin
+ 1.0
+
+
+ localhost
+ dummy-api
+ 1.0
+
+
+
+
+
+
+
+ localhost
+ dummy-maven-plugin
+ 1.0
+
+
+ localhost
+ dummy-impl
+ 1.0
+
+
+ localhost
+ dummy-parent2
+ 1.0
+
+
+
+
+
+
+
\ No newline at end of file