diff --git a/src/it/it-display-dependency-updates-007-issue-34/invoker.properties b/src/it/it-display-dependency-updates-007-issue-34/invoker.properties
new file mode 100644
index 0000000000..d065873965
--- /dev/null
+++ b/src/it/it-display-dependency-updates-007-issue-34/invoker.properties
@@ -0,0 +1 @@
+invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:display-dependency-updates
diff --git a/src/it/it-display-dependency-updates-007-issue-34/pom.xml b/src/it/it-display-dependency-updates-007-issue-34/pom.xml
new file mode 100644
index 0000000000..223372df2b
--- /dev/null
+++ b/src/it/it-display-dependency-updates-007-issue-34/pom.xml
@@ -0,0 +1,69 @@
+
+ 4.0.0
+ localhost
+ it-display-dependency-updates-004
+ 1.0
+ pom
+ display-dependency-updates-004
+ http://localhost/
+
+
+
+ localhost
+ dummy-api
+ 1.0
+
+
+
+
+
+ localhost
+ dummy-api
+ 2.0
+
+
+
+
+
+
+ localhost
+ dummy-maven-plugin
+ 1.0
+
+
+ localhost
+ dummy-api
+ 1.0
+
+
+
+
+
+ maven-clean-plugin
+ 2.2
+
+
+ maven-deploy-plugin
+ 2.3
+
+
+ maven-install-plugin
+ 2.2
+
+
+ maven-site-plugin
+ 2.0
+
+
+ maven-project-info-reports-plugin
+ 2.1
+
+
+
+
+
+
+ false
+
+
diff --git a/src/it/it-display-dependency-updates-007-issue-34/verify.bsh b/src/it/it-display-dependency-updates-007-issue-34/verify.bsh
new file mode 100644
index 0000000000..a8505ddc73
--- /dev/null
+++ b/src/it/it-display-dependency-updates-007-issue-34/verify.bsh
@@ -0,0 +1,32 @@
+import java.io.*;
+import org.codehaus.plexus.util.FileUtils;
+import java.util.regex.*;
+
+try
+{
+ System.out.println("Running verification...");
+ File file = new File( basedir, "build.log" );
+ String buf = FileUtils.fileRead( file );
+
+[INFO] The following dependencies in Dependencies have newer versions:
+[INFO] localhost:dummy-api ....................................... 2.0 -> 3.0
+[INFO]
+
+[INFO] The following dependencies in pluginManagement of plugins have newer versions:
+[INFO] localhost:dummy-api ....................................... 1.0 -> 3.0
+
+ Pattern p = Pattern.compile( "localhost:dummy-api .* 1.1" );
+ Matcher m = p.matcher( buf.toString() );
+ if ( m.find() )
+ {
+ System.out.println( "localhost:dummy-api 1.1 was processed (but should not have been)" );
+ return false;
+ }
+}
+catch( Throwable t )
+{
+ t.printStackTrace();
+ return false;
+}
+
+return true;
diff --git a/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java b/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java
index c8ab8f016e..71295ac68c 100644
--- a/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java
+++ b/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java
@@ -23,7 +23,9 @@
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.model.Build;
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 +36,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 +43,8 @@
import java.util.Set;
import java.util.TreeSet;
+import javax.xml.stream.XMLStreamException;
+
/**
* Displays all dependencies that have newer versions available.
*
@@ -79,6 +81,22 @@ public class DisplayDependencyUpdatesMojo
@Parameter( property = "processDependencies", defaultValue = "true" )
protected boolean processDependencies;
+ /**
+ * Whether to process the dependencies sections of plugins.
+ *
+ * @since 2.5
+ */
+ @Parameter( property = "processPluginDependencies", defaultValue = "true" )
+ protected boolean processPluginDependencies;
+
+ /**
+ * Whether to process the dependencies sections of plugins which are defined in pluginManagement.
+ *
+ * @since 2.5
+ */
+ @Parameter( property = "processPluginDependenciesInPluginManagement", defaultValue = "true" )
+ protected boolean processPluginDependenciesInPluginManagement;
+
/**
* Whether to show additional information such as dependencies that do not need updating.
*
@@ -89,6 +107,41 @@ public class DisplayDependencyUpdatesMojo
// --------------------- GETTER / SETTER METHODS ---------------------
+ private static Set extractPluginDependenciesFromPluginsInPluginManagement( Build build )
+ {
+ Set result = new TreeSet( new DependencyComparator() );
+ if ( build.getPluginManagement() != null )
+ {
+ for ( Plugin plugin : build.getPluginManagement().getPlugins() )
+ {
+ if ( plugin.getDependencies() != null && !plugin.getDependencies().isEmpty() )
+ {
+ for ( Dependency pluginDependency : plugin.getDependencies() )
+ {
+ result.add( pluginDependency );
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ 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.
@@ -99,9 +152,9 @@ public class DisplayDependencyUpdatesMojo
* management dependencies.
* @since 1.0-beta-1
*/
- private static Set removeDependencyManagment( Set dependencies, Set dependencyManagement )
+ private static Set removeDependencyManagment( Set dependencies, Set dependencyManagement )
{
- Set result = new TreeSet( new DependencyComparator() );
+ Set result = new TreeSet( new DependencyComparator() );
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
{
Dependency c = (Dependency) i.next();
@@ -139,6 +192,16 @@ public boolean isProcessingDependencies()
return processDependencies;
}
+ public boolean isProcessingPluginDependencies()
+ {
+ return processPluginDependencies;
+ }
+
+ public boolean isProcessPluginDependenciesInDependencyManagement()
+ {
+ return processPluginDependenciesInPluginManagement;
+ }
+
public boolean isVerbose()
{
return verbose;
@@ -159,7 +222,7 @@ public void execute()
{
logInit();
- Set dependencyManagement = new TreeSet( new DependencyComparator() );
+ Set dependencyManagement = new TreeSet( new DependencyComparator() );
if ( getProject().getDependencyManagement() != null )
{
@@ -206,7 +269,7 @@ public void execute()
}
}
- Set dependencies = new TreeSet( new DependencyComparator() );
+ Set dependencies = new TreeSet( new DependencyComparator() );
dependencies.addAll( getProject().getDependencies() );
if ( isProcessingDependencyManagement() )
@@ -214,6 +277,20 @@ public void execute()
dependencies = removeDependencyManagment( dependencies, dependencyManagement );
}
+ Set pluginDependencies = new TreeSet( new DependencyComparator() );
+
+ if ( isProcessingPluginDependencies() )
+ {
+ pluginDependencies = extractDependenciesFromPlugins( getProject().getBuildPlugins() );
+ }
+
+ Set pluginDependenciesInPluginManagement = new TreeSet( new DependencyComparator() );
+ if ( isProcessPluginDependenciesInDependencyManagement() )
+ {
+ pluginDependenciesInPluginManagement =
+ extractPluginDependenciesFromPluginsInPluginManagement( getProject().getBuild() );
+ }
+
try
{
if ( isProcessingDependencyManagement() )
@@ -225,6 +302,15 @@ public void execute()
{
logUpdates( getHelper().lookupDependenciesUpdates( dependencies, false ), "Dependencies" );
}
+ if ( isProcessPluginDependenciesInDependencyManagement() )
+ {
+ logUpdates( getHelper().lookupDependenciesUpdates( pluginDependenciesInPluginManagement, false ),
+ "pluginManagement of plugins" );
+ }
+ if ( isProcessingPluginDependencies() )
+ {
+ logUpdates( getHelper().lookupDependenciesUpdates( pluginDependencies, false ), "Plugin Dependencies" );
+ }
}
catch ( InvalidVersionSpecificationException e )
{
@@ -236,7 +322,7 @@ public void execute()
}
}
- private void logUpdates( Map updates, String section )
+ private void logUpdates( Map updates, String section )
{
List withUpdates = new ArrayList();
List usingCurrent = new ArrayList();
@@ -266,7 +352,7 @@ private void logUpdates( Map updates, String section )
}
}
String right = " " + ( latest == null ? current : current + " -> " + latest.toString() );
- List t = latest == null ? usingCurrent : withUpdates;
+ List t = latest == null ? usingCurrent : withUpdates;
if ( right.length() + left.length() + 3 > INFO_PAD_SIZE )
{
t.add( left + "..." );
@@ -278,27 +364,39 @@ private void logUpdates( Map updates, String section )
t.add( StringUtils.rightPad( left, INFO_PAD_SIZE - right.length(), "." ) + right );
}
}
- if ( isVerbose() && usingCurrent.isEmpty() && !withUpdates.isEmpty() )
- {
- logLine( false, "No dependencies in " + section + " are using the newest version." );
- logLine( false, "" );
- }
- else if ( isVerbose() && !usingCurrent.isEmpty() )
+
+ if ( isVerbose() )
{
- logLine( false, "The following dependencies in " + section + " are using the newest version:" );
- i = usingCurrent.iterator();
- while ( i.hasNext() )
+ if ( usingCurrent.isEmpty() )
{
- logLine( false, (String) i.next() );
+ if ( !withUpdates.isEmpty() )
+ {
+ logLine( false, "No dependencies in " + section + " are using the newest version." );
+ logLine( false, "" );
+ }
}
- logLine( false, "" );
- }
- if ( withUpdates.isEmpty() && !usingCurrent.isEmpty() )
+ else
+ {
+ logLine( false, "The following dependencies in " + section + " are using the newest version:" );
+ i = usingCurrent.iterator();
+ while ( i.hasNext() )
+ {
+ logLine( false, (String) i.next() );
+ }
+ logLine( false, "" );
+ }
+ }
+
+
+ if ( withUpdates.isEmpty() )
{
- logLine( false, "No dependencies in " + section + " have newer versions." );
- logLine( false, "" );
+ if ( !usingCurrent.isEmpty() )
+ {
+ logLine( false, "No dependencies in " + section + " have newer versions." );
+ logLine( false, "" );
+ }
}
- else if ( !withUpdates.isEmpty() )
+ else
{
logLine( false, "The following dependencies in " + section + " have newer versions:" );
i = withUpdates.iterator();