From c6ad9aa729f9fe128869eb84dd7bb9310954685e Mon Sep 17 00:00:00 2001 From: Vincent Siveton Date: Fri, 15 Jul 2005 23:31:53 +0000 Subject: [PATCH] MNG-411: all transitive dependencies report git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@219261 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven-project-info-reports-plugin/pom.xml | 36 +++++- .../projectinfo/DependenciesReport.java | 111 ++++++++++++++++-- .../project-info-report_en.properties | 22 ++++ .../project-info-report_fr.properties | 24 +++- .../project-info-reports-plugin-test1/pom.xml | 64 ++++++++++ .../maven/report/projectinfo/test1/App.java | 13 ++ .../report/projectinfo/test1/AppTest.java | 38 ++++++ 7 files changed, 291 insertions(+), 17 deletions(-) create mode 100644 maven-reports/maven-project-info-reports-plugin/src/test/projects/project-info-reports-plugin-test1/pom.xml create mode 100644 maven-reports/maven-project-info-reports-plugin/src/test/projects/project-info-reports-plugin-test1/src/main/java/org/apache/maven/report/projectinfo/test1/App.java create mode 100644 maven-reports/maven-project-info-reports-plugin/src/test/projects/project-info-reports-plugin-test1/src/test/java/org/apache/maven/report/projectinfo/test1/AppTest.java diff --git a/maven-reports/maven-project-info-reports-plugin/pom.xml b/maven-reports/maven-project-info-reports-plugin/pom.xml index 78323df6c3..fc6ad195e6 100644 --- a/maven-reports/maven-project-info-reports-plugin/pom.xml +++ b/maven-reports/maven-project-info-reports-plugin/pom.xml @@ -1,3 +1,23 @@ + + + + 4.0.0 @@ -10,10 +30,16 @@ maven-plugin Maven Project Info Reports Plugin 2005 - - + + + vsiveton Vincent Siveton - vincent.siveton@gmail.com - - + vsiveton@apache.org + Apache Software Foundation + + Java Developer + + -5 + + diff --git a/maven-reports/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java b/maven-reports/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java index 0c007f9d49..39c81ac457 100644 --- a/maven-reports/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java +++ b/maven-reports/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java @@ -16,8 +16,8 @@ package org.apache.maven.report.projectinfo; * limitations under the License. */ +import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Dependency; -import org.apache.maven.model.Model; import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.AbstractMavenReportRenderer; import org.apache.maven.reporting.AbstractMavenReport; @@ -26,14 +26,20 @@ import org.codehaus.doxia.sink.Sink; import org.codehaus.doxia.site.renderer.SiteRenderer; import java.io.IOException; +import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Locale; import java.util.ResourceBundle; +import java.util.Set; /** + * Generates the dependencies report. + * * @goal dependencies * * @author Jason van Zyl + * @author Vincent Siveton * @version $Id$ * @plexus.component */ @@ -116,7 +122,7 @@ public class DependenciesReport { try { - DependenciesRenderer r = new DependenciesRenderer( getSink(), getProject().getModel(), locale ); + DependenciesRenderer r = new DependenciesRenderer( getSink(), getProject(), locale ); r.render(); } @@ -137,20 +143,19 @@ public class DependenciesReport static class DependenciesRenderer extends AbstractMavenReportRenderer { - private Model model; + private MavenProject project; private Locale locale; - public DependenciesRenderer( Sink sink, Model model, Locale locale ) + public DependenciesRenderer( Sink sink, MavenProject project, Locale locale ) { super( sink ); - this.model = model; + this.project = project; this.locale = locale; } - // How to i18n these ... public String getTitle() { return getBundle( locale ).getString( "report.dependencies.title" ); @@ -160,7 +165,10 @@ public class DependenciesReport { startSection( getTitle() ); - if ( model.getDependencies().isEmpty() ) + // Dependencies report + List dependencies = project.getDependencies(); + + if ( dependencies.isEmpty() ) { // TODO: should the report just be excluded? paragraph( getBundle( locale ).getString( "report.dependencies.nolist" ) ); @@ -172,14 +180,12 @@ public class DependenciesReport tableCaption( getBundle( locale ).getString( "report.dependencies.intro" ) ); String groupId = getBundle( locale ).getString( "report.dependencies.column.groupId" ); - String artifactId = getBundle( locale ).getString( "report.dependencies.column.artifactId" ); - String version = getBundle( locale ).getString( "report.dependencies.column.version" ); tableHeader( new String[]{groupId, artifactId, version} ); - for ( Iterator i = model.getDependencies().iterator(); i.hasNext(); ) + for ( Iterator i = dependencies.iterator(); i.hasNext(); ) { Dependency d = (Dependency) i.next(); @@ -188,8 +194,91 @@ public class DependenciesReport endTable(); } - + endSection(); + + // Transitive dependencies + if ( !dependencies.isEmpty() ) + { + Set artifacts = getTransitiveDependencies( project ); + + startSection( getBundle( locale ).getString( "report.transitivedependencies.title" ) ); + + if ( artifacts.isEmpty() ) + { + // TODO: should the report just be excluded? + paragraph( getBundle( locale ).getString( "report.transitivedependencies.nolist" ) ); + } + else + { + startTable(); + + tableCaption( getBundle( locale ).getString( "report.transitivedependencies.intro" ) ); + + String groupId = getBundle( locale ).getString( "report.transitivedependencies.column.groupId" ); + String artifactId = getBundle( locale ).getString( "report.transitivedependencies.column.artifactId" ); + String version = getBundle( locale ).getString( "report.transitivedependencies.column.version" ); + + tableHeader( new String[]{groupId, artifactId, version} ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + + tableRow( new String[]{artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()} ); + } + + endTable(); + } + + endSection(); + } + + } + + /** + * Return a set of artifact which are not already present in the dependencies list. + * + * @param project a Maven project + * @return a set of transitive dependencies + */ + private Set getTransitiveDependencies( MavenProject project ) + { + Set result = new HashSet(); + + if ( ( project.getDependencies() == null ) || + ( project.getArtifacts() == null ) ) + { + return result; + } + + List dependencies = project.getDependencies(); + Set artifacts = project.getArtifacts(); + + for ( Iterator j = artifacts.iterator(); j.hasNext(); ) + { + Artifact artifact = (Artifact)j.next(); + + boolean toadd = true; + for ( Iterator i = dependencies.iterator(); i.hasNext(); ) + { + Dependency dependency = (Dependency) i.next(); + if ( ( artifact.getArtifactId().equals( dependency.getArtifactId() ) ) && + ( artifact.getGroupId().equals( dependency.getGroupId() ) ) && + ( artifact.getVersion().equals( dependency.getVersion() ) ) ) + { + toadd = false; + break; + } + } + + if ( toadd ) + { + result.add( artifact ); + } + } + + return result; } } diff --git a/maven-reports/maven-project-info-reports-plugin/src/main/resources/project-info-report_en.properties b/maven-reports/maven-project-info-reports-plugin/src/main/resources/project-info-report_en.properties index fee10a8e95..7bd7fc261d 100644 --- a/maven-reports/maven-project-info-reports-plugin/src/main/resources/project-info-report_en.properties +++ b/maven-reports/maven-project-info-reports-plugin/src/main/resources/project-info-report_en.properties @@ -1,3 +1,19 @@ +# ------------------------------------------------------------------- +# Copyright 2001-2005 The Apache Software Foundation. +# +# Licensed 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. +# ------------------------------------------------------------------- + report.dependencies.name=Dependencies report.dependencies.nolist=There are no dependencies for this project. It is a standalone application that does not depend on any other project. report.dependencies.title=Project Dependencies @@ -6,6 +22,12 @@ report.dependencies.intro=The following is a list of dependencies for this proje report.dependencies.column.groupId=GroupId report.dependencies.column.artifactId=ArtifactId report.dependencies.column.version=Version +report.transitivedependencies.title=Project Transitive Dependencies +report.transitivedependencies.nolist=There are no transitive dependencies for this project. +report.transitivedependencies.intro=The following is a list of transitive dependencies for this project. Transitive dependencies are the dependencies of the project dependencies : +report.transitivedependencies.column.groupId=GroupId +report.transitivedependencies.column.artifactId=ArtifactId +report.transitivedependencies.column.version=Version report.mailing-lists.name=Mailing Lists report.mailing-lists.nolist=There are no mailing lists currently associated with this project. report.mailing-lists.title=Project Mailing Lists diff --git a/maven-reports/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties b/maven-reports/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties index 667a23fec7..51e427af03 100644 --- a/maven-reports/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties +++ b/maven-reports/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties @@ -1,11 +1,33 @@ +# ------------------------------------------------------------------- +# Copyright 2001-2005 The Apache Software Foundation. +# +# Licensed 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. +# ------------------------------------------------------------------- + report.dependencies.name=Dépendances report.dependencies.nolist=Il n'y a aucune dépendance pour ce projet. C'est une application autonome qui ne dépend d'aucun autre projet. report.dependencies.title=Dépendances du projet report.dependencies.description=Ce document liste les dépendances du projet et fournit les informations sur chaque dépendance. -report.dependencies.intro= Ce qui suit est la liste de dépendances pour ce projet. Ces dépendances sont requises pour compiler et exécuter l'application : +report.dependencies.intro=Ce qui suit est la liste de dépendances pour ce projet. Ces dépendances sont requises pour compiler et exécuter l'application : report.dependencies.column.groupId=GroupId report.dependencies.column.artifactId=ArtifactId report.dependencies.column.version=Version +report.transitivedependencies.title=Dépendances transitives du projet +report.transitivedependencies.nolist=Il n'y a aucune dépendance transitive pour ce projet. +report.transitivedependencies.intro=Ce qui suit est la liste de dépendances transitives pour ce projet. Les dépendances transitives sont les dépendances des dépendances du projet : +report.transitivedependencies.column.groupId=GroupId +report.transitivedependencies.column.artifactId=ArtifactId +report.transitivedependencies.column.version=Version report.mailing-lists.name=Listes de diffusion report.mailing-lists.nolist= Il n'y a aucune liste de diffusion actuellement liée à ce projet. report.mailing-lists.title=Listes de diffusion du projet diff --git a/maven-reports/maven-project-info-reports-plugin/src/test/projects/project-info-reports-plugin-test1/pom.xml b/maven-reports/maven-project-info-reports-plugin/src/test/projects/project-info-reports-plugin-test1/pom.xml new file mode 100644 index 0000000000..d36caabcfb --- /dev/null +++ b/maven-reports/maven-project-info-reports-plugin/src/test/projects/project-info-reports-plugin-test1/pom.xml @@ -0,0 +1,64 @@ + + + + + + 4.0.0 + org.apache.maven.report.projectinfo.test1 + project-info-reports-plugin-test1 + jar + 1.0-SNAPSHOT + 2005 + Maven ProjectInfo Report Test1 + Test the transitive dependencies of this project + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + commons-cli + commons-cli + 1.0 + + + + + vsiveton + Vincent Siveton + vsiveton@apache.org + Apache Software Foundation + + Java Developer + + -5 + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + + + + diff --git a/maven-reports/maven-project-info-reports-plugin/src/test/projects/project-info-reports-plugin-test1/src/main/java/org/apache/maven/report/projectinfo/test1/App.java b/maven-reports/maven-project-info-reports-plugin/src/test/projects/project-info-reports-plugin-test1/src/main/java/org/apache/maven/report/projectinfo/test1/App.java new file mode 100644 index 0000000000..0bb109841d --- /dev/null +++ b/maven-reports/maven-project-info-reports-plugin/src/test/projects/project-info-reports-plugin-test1/src/main/java/org/apache/maven/report/projectinfo/test1/App.java @@ -0,0 +1,13 @@ +package org.apache.maven.report.projectinfo.test1; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/maven-reports/maven-project-info-reports-plugin/src/test/projects/project-info-reports-plugin-test1/src/test/java/org/apache/maven/report/projectinfo/test1/AppTest.java b/maven-reports/maven-project-info-reports-plugin/src/test/projects/project-info-reports-plugin-test1/src/test/java/org/apache/maven/report/projectinfo/test1/AppTest.java new file mode 100644 index 0000000000..7782ff70b5 --- /dev/null +++ b/maven-reports/maven-project-info-reports-plugin/src/test/projects/project-info-reports-plugin-test1/src/test/java/org/apache/maven/report/projectinfo/test1/AppTest.java @@ -0,0 +1,38 @@ +org.apache.maven.report.projectinfo.test1; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +}