Skip to content

Commit

Permalink
Fixed #46
Browse files Browse the repository at this point in the history
 o Added processDependencyManagement option to control the reporting
   of dependencyManagement.
   Thanks to Bruce Brouwer.
  • Loading branch information
khmarbaise committed Jun 15, 2017
1 parent 9b42718 commit 8391dbd
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/it/it-dependency-updates-report-003/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=site
93 changes: 93 additions & 0 deletions src/it/it-dependency-updates-report-003/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<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-dependency-updates-report-003</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>dependency-updates-report</name>
<url>http://localhost/</url>

<properties>
<processDependencyManagement>false</processDependencyManagement>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<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.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>@sitePluginVersion@</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>

<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.1</version>
<reportSets>
<reportSet/>
</reportSets>
</plugin>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<reportSets>
<reportSet>
<reports>
<report>dependency-updates-report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>
7 changes: 7 additions & 0 deletions src/it/it-dependency-updates-report-003/src/site/site.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<project>
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-default-skin</artifactId>
<version>1.0</version>
</skin>
</project>
33 changes: 33 additions & 0 deletions src/it/it-dependency-updates-report-003/verify.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.io.*;
import org.codehaus.plexus.util.FileUtils;

try
{
File file = new File( basedir, "target/site/dependency-updates-report.html" );
String buf = FileUtils.fileRead( file, "UTF-8" );

String result = buf.toString()
.replaceAll( "<[^>]+>", " " )
.replaceAll( "&[^;]+;", " " )
.replaceAll( "\\s+", " " );

if ( result.indexOf( "localhost dummy-api 1.1 compile jar 1.1.0-2 1.1.1 1.2 2.0" ) < 0 )
{
System.out.println( "Did not pick up updated in dependencies section" );
System.out.println( "Result = \"" + result +"\"" );
return false;
}
if ( !result.contains("This project does not declare any dependencies in a dependencyManagement section."))
{
System.out.println( "Did not ignore dependencyManagement" );
System.out.println( "Result = \"" + result +"\"" );
return false;
}
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

return true;
1 change: 1 addition & 0 deletions src/it/it-dependency-updates-report-004/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=site
96 changes: 96 additions & 0 deletions src/it/it-dependency-updates-report-004/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<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-dependency-updates-report-004</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>dependency-updates-report</name>
<url>http://localhost/</url>

<description>
using the default for processDependencyManagement.
</description>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-impl</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
<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.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>@sitePluginVersion@</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>

<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.1</version>
<reportSets>
<reportSet/>
</reportSets>
</plugin>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<reportSets>
<reportSet>
<reports>
<report>dependency-updates-report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>
7 changes: 7 additions & 0 deletions src/it/it-dependency-updates-report-004/src/site/site.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<project>
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-default-skin</artifactId>
<version>1.0</version>
</skin>
</project>
39 changes: 39 additions & 0 deletions src/it/it-dependency-updates-report-004/verify.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.io.*;
import org.codehaus.plexus.util.FileUtils;

try
{
File file = new File( basedir, "target/site/dependency-updates-report.html" );
String buf = FileUtils.fileRead( file, "UTF-8" );

String result = buf.toString()
.replaceAll( "<[^>]+>", " " )
.replaceAll( "&[^;]+;", " " )
.replaceAll( "\\s+", " " );

if ( !result.contains( "localhost dummy-api 1.1 jar 1.1.0-2 1.1.1 1.2 2.0" ) )
{
System.out.println( "Did not pick up updated in Dependency Management section" );
System.out.println( "Result = \"" + result +"\"" );
return false;
}
if ( !result.contains( "localhost dummy-impl 1.1 jar 1.2 2.0" ) )
{
System.out.println( "Did not pick up updated in Dependency Management section" );
System.out.println( "Result = \"" + result +"\"" );
return false;
}
if ( !result.contains( "This project does not declare any dependencies." ) )
{
System.out.println( "Dependency Management should have processed" );
System.out.println( "Result = \"" + result +"\"" );
return false;
}
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.mojo.versions.api.ArtifactVersions;
Expand All @@ -49,6 +50,14 @@ public class DependencyUpdatesReport
extends AbstractVersionsReport
{

/**
* Whether to process the <code>dependencyManagement</code> in pom or not.
*
* @since 2.5
*/
@Parameter( property = "processDependencyManagement", defaultValue = "true" )
private boolean processDependencyManagement;

/**
* Report formats (html and/or xml). HTML by default.
*
Expand Down Expand Up @@ -81,20 +90,28 @@ public boolean canGenerateReport()
protected void doGenerateReport( Locale locale, Sink sink )
throws MavenReportException
{
Set dependencies = new TreeSet( new DependencyComparator() );
dependencies.addAll( getProject().getDependencies() );

Set dependencyManagement = new TreeSet( new DependencyComparator() );
dependencyManagement.addAll( getProject().getDependencyManagement() == null ? Collections.EMPTY_LIST
dependencyManagement.addAll( getProject().getDependencyManagement() == null ? Collections.emptySet()
: getProject().getDependencyManagement().getDependencies() );

Set dependencies = new TreeSet( new DependencyComparator() );
dependencies.addAll( getProject().getDependencies() );
dependencies = removeDependencyManagment( dependencies, dependencyManagement );
if ( processDependencyManagement )
{
dependencies = removeDependencyManagment( dependencies, dependencyManagement );
}

try
{
Map<Dependency, ArtifactVersions> dependencyUpdates =
getHelper().lookupDependenciesUpdates( dependencies, false );
Map<Dependency, ArtifactVersions> dependencyManagementUpdates =
getHelper().lookupDependenciesUpdates( dependencyManagement, false );

Map<Dependency, ArtifactVersions> dependencyManagementUpdates = Collections.emptyMap();
if ( processDependencyManagement )
{
dependencyManagementUpdates = getHelper().lookupDependenciesUpdates( dependencyManagement, false );
}
for ( String format : formats )
{
if ( "html".equals( format ) )
Expand Down

0 comments on commit 8391dbd

Please sign in to comment.