Skip to content

Commit

Permalink
Fixed #34
Browse files Browse the repository at this point in the history
 o First implementation to report the plugin dependencies as well.
  • Loading branch information
khmarbaise committed Jun 7, 2017
1 parent 55f519e commit 62bc814
Showing 1 changed file with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,15 +35,15 @@
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;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import javax.xml.stream.XMLStreamException;

/**
* Displays all dependencies that have newer versions available.
*
Expand Down Expand Up @@ -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.
*
Expand All @@ -89,6 +98,22 @@ public class DisplayDependencyUpdatesMojo

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

private static Set<Dependency> extractDependenciesFromPlugins( List<Plugin> plugins )
{
Set<Dependency> 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.
Expand Down Expand Up @@ -139,6 +164,11 @@ public boolean isProcessingDependencies()
return processDependencies;
}

public boolean isProcessingPluginDependencies()
{
return processPluginDependencies;
}

public boolean isVerbose()
{
return verbose;
Expand Down Expand Up @@ -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() )
Expand All @@ -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 )
{
Expand Down

0 comments on commit 62bc814

Please sign in to comment.