You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/04/07 09:21:33 UTC

svn commit: r392205 - /maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java

Author: brett
Date: Fri Apr  7 00:21:29 2006
New Revision: 392205

URL: http://svn.apache.org/viewcvs?rev=392205&view=rev
Log:
[MPIR-29] reduce code duplication, and remove IllegalArgumentException if a project fails to load

Modified:
    maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java

Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java?rev=392205&r1=392204&r2=392205&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java Fri Apr  7 00:21:29 2006
@@ -26,6 +26,8 @@
 import org.apache.maven.artifact.resolver.ResolutionListener;
 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.siterenderer.Renderer;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.DependencyManagement;
 import org.apache.maven.project.MavenProject;
@@ -33,8 +35,6 @@
 import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.reporting.AbstractMavenReport;
 import org.apache.maven.reporting.AbstractMavenReportRenderer;
-import org.apache.maven.doxia.sink.Sink;
-import org.apache.maven.doxia.siterenderer.Renderer;
 import org.codehaus.plexus.i18n.I18N;
 
 import java.util.ArrayList;
@@ -191,7 +191,8 @@
 
             DependenciesRenderer r = new DependenciesRenderer( getSink(), locale, listener.getDirectDependencies(),
                                                                listener.getTransitiveDependencies(),
-                                                               listener.getOmittedArtifacts(), listener.getDepTree(), listener.getDepMap() );
+                                                               listener.getOmittedArtifacts(), listener.getDepTree(),
+                                                               listener.getDepMap() );
 
             r.render();
         }
@@ -339,32 +340,7 @@
             {
                 Artifact artifact = (Artifact) i.next();
 
-                MavenProject artifactProject;
-                if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
-                {
-                    dependenciesByScope.put( artifact.getScope(), new String[]{artifact.getGroupId(),
-                        artifact.getArtifactId(), artifact.getVersion(), null, null,
-                        artifact.isOptional() ? "X" : null} );
-                }
-                else
-                {
-                    try
-                    {
-                        // TODO: can we use @requiresDependencyResolution instead, and capture the depth of artifacts in the artifact itself?
-                        artifactProject = getMavenProjectFromRepository( artifact, localRepository );
-                    }
-                    catch ( ProjectBuildingException e )
-                    {
-                        throw new IllegalArgumentException(
-                            "Can't find a valid Maven project in the repository for the artifact [" +
-                                artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() +
-                                "]." );
-                    }
-                    dependenciesByScope.put( artifact.getScope(), new String[]{artifact.getGroupId(),
-                        artifact.getArtifactId(), artifact.getVersion(), artifactProject.getDescription(),
-                        createLinkPatternedText( artifactProject.getUrl(), artifactProject.getUrl() ),
-                        artifact.isOptional() ? "X" : null} );
-                }
+                dependenciesByScope.put( artifact.getScope(), getArtifactRow( artifact ) );
             }
 
             for ( Iterator iter = dependenciesByScope.keySet().iterator(); iter.hasNext(); )
@@ -424,32 +400,7 @@
                 {
                     Artifact artifact = (Artifact) i.next();
 
-                    MavenProject artifactProject;
-                    if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
-                    {
-                        tableRow( new String[]{artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
-                            null, null, artifact.isOptional() ? "X" : null} );
-                    }
-                    else
-                    {
-                        try
-                        {
-                            // TODO: can we use @requiresDependencyResolution instead, and capture the depth of artifacts in the artifact itself?
-                            artifactProject = getMavenProjectFromRepository( artifact, localRepository );
-                        }
-                        catch ( ProjectBuildingException e )
-                        {
-                            // TODO: better exception handling needed - log PBE
-                            throw new IllegalArgumentException(
-                                "Can't find a valid Maven project in the repository for the artifact [" +
-                                    artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" +
-                                    artifact.getVersion() + "]." );
-                        }
-                        tableRow( new String[]{artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
-                            artifactProject.getDescription(),
-                            createLinkPatternedText( artifactProject.getUrl(), artifactProject.getUrl() ),
-                            artifact.isOptional() ? "X" : null} );
-                    }
+                    tableRow( getArtifactRow( artifact ) );
                 }
 
                 endTable();
@@ -483,6 +434,37 @@
             endSection();
         }
 
+        private String[] getArtifactRow( Artifact artifact )
+        {
+            String[] row;
+            if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
+            {
+                row = new String[]{artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), null, null,
+                    artifact.isOptional() ? "X" : null};
+            }
+            else
+            {
+                String artifactDescription = null;
+                String artifactUrl = null;
+                try
+                {
+                    // TODO: can we use @requiresDependencyResolution instead, and capture the depth of artifacts in the artifact itself?
+                    MavenProject artifactProject = getMavenProjectFromRepository( artifact, localRepository );
+                    artifactDescription = artifactProject.getDescription();
+                    artifactUrl = artifactProject.getUrl();
+                }
+                catch ( ProjectBuildingException e )
+                {
+                    getLog().error( "Can't find a valid Maven project in the repository for the artifact [" +
+                        artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + "]." );
+                }
+                row = new String[]{artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
+                    artifactDescription, createLinkPatternedText( artifactUrl, artifactUrl ),
+                    artifact.isOptional() ? "X" : null};
+            }
+            return row;
+        }
+
         private void printDependencyTable( Artifact artifact )
         {
             String id = artifact.getId();
@@ -515,7 +497,7 @@
                         comment = getReportString( "report.dependencies.graph.tables.attached" );
                     }
 
-                    tableRow( new String[]{dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), comment } );
+                    tableRow( new String[]{dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), comment} );
                 }
 
                 endTable();
@@ -726,11 +708,17 @@
         private Artifact getDependency( String key )
         {
             if ( directDep.containsKey( key ) )
+            {
                 return (Artifact) directDep.get( key );
+            }
             else if ( transitiveDep.containsKey( key ) )
+            {
                 return (Artifact) transitiveDep.get( key );
+            }
             else
+            {
                 return null;
+            }
         }
 
         private void addDependency( Artifact artifact )
@@ -756,7 +744,7 @@
                 {
                     if ( artifact.getScope() == null )
                     {
-                        Artifact parent = (Artifact) parents.get(  parents.size() );
+                        Artifact parent = (Artifact) parents.get( parents.size() );
 
                         artifact.setScope( parent.getScope() );
                     }
@@ -768,14 +756,14 @@
 
         public void updateScope( Artifact artifact, String scope )
         {
-            if (  directDep.containsKey( artifact.getId() ) )
+            if ( directDep.containsKey( artifact.getId() ) )
             {
                 Artifact depArtifact = (Artifact) directDep.get( artifact.getId() );
 
                 depArtifact.setScope( scope );
             }
 
-            if (  transitiveDep.containsKey( artifact.getId() ) )
+            if ( transitiveDep.containsKey( artifact.getId() ) )
             {
                 Artifact depArtifact = (Artifact) transitiveDep.get( artifact.getId() );