From 62bc8146ba1c2fa34afc2e3ec0b30121ac5d8e53 Mon Sep 17 00:00:00 2001 From: Karl Heinz Marbaise Date: Wed, 7 Jun 2017 23:28:13 +0200 Subject: [PATCH] Fixed #34 o First implementation to report the plugin dependencies as well. --- .../DisplayDependencyUpdatesMojo.java | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java b/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java index c8ab8f016e..0e732c233b 100644 --- a/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java @@ -24,6 +24,7 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.model.Dependency; +import org.apache.maven.model.Plugin; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -34,8 +35,6 @@ import org.codehaus.mojo.versions.utils.DependencyComparator; import org.codehaus.plexus.util.StringUtils; -import javax.xml.stream.XMLStreamException; - import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -43,6 +42,8 @@ import java.util.Set; import java.util.TreeSet; +import javax.xml.stream.XMLStreamException; + /** * Displays all dependencies that have newer versions available. * @@ -79,6 +80,14 @@ public class DisplayDependencyUpdatesMojo @Parameter( property = "processDependencies", defaultValue = "true" ) protected boolean processDependencies; + /** + * Whether to process the dependencies sections of plugins. + * + * @since 2.5 + */ + @Parameter( property = "processDependencies", defaultValue = "true" ) + protected boolean processPluginDependencies; + /** * Whether to show additional information such as dependencies that do not need updating. * @@ -89,6 +98,22 @@ public class DisplayDependencyUpdatesMojo // --------------------- GETTER / SETTER METHODS --------------------- + private static Set extractDependenciesFromPlugins( List plugins ) + { + Set result = new TreeSet( new DependencyComparator() ); + for ( Plugin plugin : plugins ) + { + if ( plugin.getDependencies() != null && !plugin.getDependencies().isEmpty() ) + { + for ( Dependency pluginDependency : plugin.getDependencies() ) + { + result.add( pluginDependency ); + } + } + } + return result; + } + /** * Returns a set of dependencies where the dependencies which are defined in the dependency management section have * been filtered out. @@ -139,6 +164,11 @@ public boolean isProcessingDependencies() return processDependencies; } + public boolean isProcessingPluginDependencies() + { + return processPluginDependencies; + } + public boolean isVerbose() { return verbose; @@ -214,6 +244,13 @@ public void execute() dependencies = removeDependencyManagment( dependencies, dependencyManagement ); } + Set pluginDependencies = new TreeSet( new DependencyComparator() ); + + if ( isProcessingPluginDependencies() ) + { + pluginDependencies = extractDependenciesFromPlugins( getProject().getBuildPlugins() ); + } + try { if ( isProcessingDependencyManagement() ) @@ -225,6 +262,10 @@ public void execute() { logUpdates( getHelper().lookupDependenciesUpdates( dependencies, false ), "Dependencies" ); } + if ( isProcessingPluginDependencies() ) + { + logUpdates( getHelper().lookupDependenciesUpdates( pluginDependencies, false ), "Plugin Dependencies" ); + } } catch ( InvalidVersionSpecificationException e ) {