maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ltheu...@apache.org
Subject svn commit: r682163 [2/8] - in /maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1: ./ src/main/java/org/apache/maven/report/projectinfo/ src/main/java/org/apache/maven/report/projectinfo/dependencies/ src/main/java/org/apache/maven/...
Date Sun, 03 Aug 2008 13:18:17 GMT
Modified: maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/ScmReport.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/ScmReport.java?rev=682163&r1=682162&r2=682163&view=diff
==============================================================================
--- maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/ScmReport.java (original)
+++ maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/ScmReport.java Sun Aug  3 06:18:15 2008
@@ -22,6 +22,7 @@
 import org.apache.maven.doxia.sink.Sink;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Scm;
+import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.reporting.AbstractMavenReportRenderer;
 import org.apache.maven.scm.manager.NoSuchScmProviderException;
 import org.apache.maven.scm.manager.ScmManager;
@@ -34,10 +35,13 @@
 import org.codehaus.plexus.i18n.I18N;
 import org.codehaus.plexus.util.StringUtils;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Locale;
 
 /**
- * Generates the Project Source Code Management report.
+ * Generates the Project Source Code Management (SCM) report.
  *
  * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
  * @version $Id$
@@ -47,6 +51,10 @@
 public class ScmReport
     extends AbstractProjectInfoReport
 {
+    // ----------------------------------------------------------------------
+    // Mojo parameters
+    // ----------------------------------------------------------------------
+
     /**
      * Maven SCM Manager.
      *
@@ -57,7 +65,7 @@
     protected ScmManager scmManager;
 
     /**
-     * The directory name to checkout right after the scm url
+     * The directory name to checkout right after the SCM url.
      *
      * @parameter expression="${project.artifactId}"
      * @required
@@ -65,23 +73,25 @@
     private String checkoutDirectoryName;
 
     /**
-     * The scm anonymous connection url.
+     * The SCM anonymous connection url respecting the SCM URL Format.
      *
      * @parameter default-value="${project.scm.connection}"
      * @since 2.1
+     * @see <a href="http://maven.apache.org/scm/scm-url-format.html">SCM URL Format< /a>
      */
     private String anonymousConnection;
 
     /**
-     * The scm developer connection url.
+     * The SCM developer connection url respecting the SCM URL Format.
      *
      * @parameter default-value="${project.scm.developerConnection}"
      * @since 2.1
+     * @see <a href="http://maven.apache.org/scm/scm-url-format.html">SCM URL Format< /a>
      */
     private String developerConnection;
 
     /**
-     * The scm web access url.
+     * The SCM web access url.
      *
      * @parameter default-value="${project.scm.url}"
      * @since 2.1
@@ -107,9 +117,9 @@
     /** {@inheritDoc} */
     public void executeReport( Locale locale )
     {
-        ScmRenderer r =
-            new ScmRenderer( scmManager, getSink(), getProject().getModel(), i18n, locale, checkoutDirectoryName,
-                    webAccessUrl, anonymousConnection, developerConnection );
+        ScmRenderer r = new ScmRenderer( getLog(), scmManager, getSink(), getProject().getModel(), i18n, locale,
+                                         checkoutDirectoryName, webAccessUrl, anonymousConnection,
+                                         developerConnection );
 
         r.render();
     }
@@ -124,9 +134,14 @@
     // Private
     // ----------------------------------------------------------------------
 
+    /**
+     * Internal renderer class
+     */
     private static class ScmRenderer
         extends AbstractMavenReportRenderer
     {
+        private Log log;
+
         private Model model;
 
         private I18N i18n;
@@ -146,11 +161,13 @@
 
         private String webAccessUrl;
 
-        ScmRenderer( ScmManager scmManager, Sink sink, Model model, I18N i18n, Locale locale, String checkoutDirName,
-                     String webAccessUrl, String anonymousConnection, String devConnection )
+        ScmRenderer( Log log, ScmManager scmManager, Sink sink, Model model, I18N i18n, Locale locale,
+                     String checkoutDirName, String webAccessUrl, String anonymousConnection, String devConnection )
         {
             super( sink );
 
+            this.log = log;
+
             this.scmManager = scmManager;
 
             this.model = model;
@@ -286,7 +303,7 @@
 
         /**
          * Render the anonymous access section depending the repository.
-         * <p>Note: ClearCase, Starteam et Perforce seems to have no anonymous access.</>
+         * <p>Note: ClearCase, Starteam et Perforce seems to have no anonymous access.</p>
          *
          * @param anonymousRepository the anonymous repository
          */
@@ -302,27 +319,22 @@
 
             if ( anonymousRepository != null && isScmSystem( anonymousRepository, "cvs" ) )
             {
-                CvsScmProviderRepository cvsRepo =
-                    (CvsScmProviderRepository) anonymousRepository.getProviderRepository();
+                CvsScmProviderRepository cvsRepo = (CvsScmProviderRepository) anonymousRepository
+                    .getProviderRepository();
 
                 anonymousAccessCVS( cvsRepo );
             }
             else if ( anonymousRepository != null && isScmSystem( anonymousRepository, "svn" ) )
             {
-                SvnScmProviderRepository svnRepo =
-                    (SvnScmProviderRepository) anonymousRepository.getProviderRepository();
+                SvnScmProviderRepository svnRepo = (SvnScmProviderRepository) anonymousRepository
+                    .getProviderRepository();
 
                 anonymousAccessSVN( svnRepo );
             }
             else
             {
-                paragraph(
-                    i18n.getString( "project-info-report", locale, "report.scm.anonymousaccess.general.intro" ) );
-
-                if ( anonymousConnection.length() < 4 )
-                {
-                    throw new IllegalArgumentException( "The source repository connection is too short." );
-                }
+                paragraph( i18n.getString( "project-info-report", locale,
+                                           "report.scm.anonymousaccess.general.intro" ) );
 
                 verbatimText( anonymousConnection.substring( 4 ) );
             }
@@ -356,15 +368,15 @@
             }
             else if ( devRepository != null && isScmSystem( devRepository, "perforce" ) )
             {
-                PerforceScmProviderRepository perforceRepo =
-                    (PerforceScmProviderRepository) devRepository.getProviderRepository();
+                PerforceScmProviderRepository perforceRepo = (PerforceScmProviderRepository) devRepository
+                    .getProviderRepository();
 
                 developerAccessPerforce( perforceRepo );
             }
             else if ( devRepository != null && isScmSystem( devRepository, "starteam" ) )
             {
-                StarteamScmProviderRepository starteamRepo =
-                    (StarteamScmProviderRepository) devRepository.getProviderRepository();
+                StarteamScmProviderRepository starteamRepo = (StarteamScmProviderRepository) devRepository
+                    .getProviderRepository();
 
                 developerAccessStarteam( starteamRepo );
             }
@@ -378,11 +390,6 @@
             {
                 paragraph( i18n.getString( "project-info-report", locale, "report.scm.devaccess.general.intro" ) );
 
-                if ( devConnection.length() < 4 )
-                {
-                    throw new IllegalArgumentException( "The source repository connection is too short." );
-                }
-
                 verbatimText( devConnection.substring( 4 ) );
             }
 
@@ -402,22 +409,23 @@
             {
                 SvnScmProviderRepository svnRepo = (SvnScmProviderRepository) devRepository.getProviderRepository();
 
-                paragraph(
-                    i18n.getString( "project-info-report", locale, "report.scm.accessbehindfirewall.svn.intro" ) );
+                paragraph( i18n.getString( "project-info-report", locale,
+                                           "report.scm.accessbehindfirewall.svn.intro" ) );
 
                 StringBuffer sb = new StringBuffer();
-                sb.append( "$ svn checkout " ).append( svnRepo.getUrl() ).append( " " ).append( checkoutDirectoryName );
+                sb.append( "$ svn checkout " ).append( svnRepo.getUrl() );
+                sb.append( " " ).append( checkoutDirectoryName );
                 verbatimText( sb.toString() );
             }
             else if ( devRepository != null && isScmSystem( devRepository, "cvs" ) )
             {
-                linkPatternedText(
-                    i18n.getString( "project-info-report", locale, "report.scm.accessbehindfirewall.cvs.intro" ) );
+                linkPatternedText( i18n.getString( "project-info-report", locale,
+                                                   "report.scm.accessbehindfirewall.cvs.intro" ) );
             }
             else
             {
-                paragraph(
-                    i18n.getString( "project-info-report", locale, "report.scm.accessbehindfirewall.general.intro" ) );
+                paragraph( i18n.getString( "project-info-report", locale,
+                                           "report.scm.accessbehindfirewall.general.intro" ) );
             }
 
             endSection();
@@ -427,20 +435,21 @@
          * Render the access from behind a firewall section
          *
          * @param anonymousRepository the anonymous repository
-         * @param devRepository       the dev repository
+         * @param devRepository the dev repository
          */
         private void renderAccessThroughProxySection( ScmRepository anonymousRepository, ScmRepository devRepository )
         {
             if ( isScmSystem( anonymousRepository, "svn" ) || isScmSystem( devRepository, "svn" ) )
             {
-                startSection( i18n.getString( "project-info-report", locale, "report.scm.accessthroughtproxy.title" ) );
+                startSection( i18n.getString( "project-info-report", locale,
+                                              "report.scm.accessthroughtproxy.title" ) );
 
-                paragraph(
-                    i18n.getString( "project-info-report", locale, "report.scm.accessthroughtproxy.svn.intro1" ) );
-                paragraph(
-                    i18n.getString( "project-info-report", locale, "report.scm.accessthroughtproxy.svn.intro2" ) );
-                paragraph(
-                    i18n.getString( "project-info-report", locale, "report.scm.accessthroughtproxy.svn.intro3" ) );
+                paragraph( i18n.getString( "project-info-report", locale,
+                                           "report.scm.accessthroughtproxy.svn.intro1" ) );
+                paragraph( i18n.getString( "project-info-report", locale,
+                                           "report.scm.accessthroughtproxy.svn.intro2" ) );
+                paragraph( i18n.getString( "project-info-report", locale,
+                                           "report.scm.accessthroughtproxy.svn.intro3" ) );
 
                 StringBuffer sb = new StringBuffer();
                 sb.append( "[global]" );
@@ -624,7 +633,8 @@
                 }
                 else if ( svnRepo.getUrl().startsWith( "svn://" ) )
                 {
-                    paragraph( i18n.getString( "project-info-report", locale, "report.scm.devaccess.svn.intro1.svn" ) );
+                    paragraph( i18n.getString( "project-info-report", locale,
+                                               "report.scm.devaccess.svn.intro1.svn" ) );
                 }
                 else if ( svnRepo.getUrl().startsWith( "svn+ssh://" ) )
                 {
@@ -660,22 +670,84 @@
          */
         public ScmRepository getScmRepository( String scmUrl )
         {
+            if ( StringUtils.isEmpty( scmUrl ) )
+            {
+                return null;
+            }
+
             ScmRepository repo = null;
-            if ( !StringUtils.isEmpty( scmUrl ) )
+            List messages = new ArrayList();
+            try
+            {
+                messages.addAll( scmManager.validateScmRepository( scmUrl ) );
+            }
+            catch ( Exception e )
             {
-                try
+                messages.add( e.getMessage() );
+            }
+
+            if ( messages.size() > 0 )
+            {
+                StringBuffer sb = new StringBuffer();
+                boolean isIntroAdded = false;
+                for ( Iterator it = messages.iterator(); it.hasNext(); )
                 {
-                    repo = scmManager.makeScmRepository( scmUrl );
+                    String msg = it.next().toString();
+
+                    // Ignore NoSuchScmProviderException msg
+                    // See impl of AbstractScmManager#validateScmRepository()
+                    if ( msg.startsWith( "No such provider" ) )
+                    {
+                        continue;
+                    }
+
+                    if ( !isIntroAdded )
+                    {
+                        sb.append( "This SCM url '" + scmUrl + "' is invalid due to the following errors:" );
+                        sb.append( "\n" );
+                        isIntroAdded = true;
+                    }
+                    sb.append( " * " );
+                    sb.append( msg );
+                    sb.append( "\n" );
                 }
-                catch ( NoSuchScmProviderException e )
+
+                if ( StringUtils.isNotEmpty( sb.toString() ) )
                 {
-                    // ignore
+                    sb.append( "For more information about SCM URL Format, please refer to: "
+                        + "http://maven.apache.org/scm/scm-url-format.html" );
+
+                    throw new IllegalArgumentException( sb.toString() );
                 }
-                catch ( ScmRepositoryException e )
+            }
+
+            try
+            {
+                repo = scmManager.makeScmRepository( scmUrl );
+            }
+            catch ( NoSuchScmProviderException e )
+            {
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( e.getMessage(), e );
+                }
+            }
+            catch ( ScmRepositoryException e )
+            {
+                if ( log.isDebugEnabled() )
                 {
-                    // ignore
+                    log.debug( e.getMessage(), e );
                 }
             }
+            catch ( Exception e )
+            {
+                // Should be already catched
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( e.getMessage(), e );
+                }
+            }
+
             return repo;
         }
 
@@ -686,7 +758,7 @@
          * </p>
          *
          * @param scmRepository a SCM repository
-         * @param scmProvider   a SCM provider name
+         * @param scmProvider a SCM provider name
          * @return true if the provider of the given SCM repository is equal to the given scm provider.
          * @see <a href="http://svn.apache.org/repos/asf/maven/scm/trunk/maven-scm-providers/">maven-scm-providers</a>
          */

Modified: maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/TeamListReport.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/TeamListReport.java?rev=682163&r1=682162&r2=682163&view=diff
==============================================================================
--- maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/TeamListReport.java (original)
+++ maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/TeamListReport.java Sun Aug  3 06:18:15 2008
@@ -80,6 +80,9 @@
     // Private
     // ----------------------------------------------------------------------
 
+    /**
+     * Internal renderer class
+     */
     private static class TeamListRenderer
         extends AbstractMavenReportRenderer
     {

Modified: maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/Dependencies.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/Dependencies.java?rev=682163&r1=682162&r2=682163&view=diff
==============================================================================
--- maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/Dependencies.java (original)
+++ maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/Dependencies.java Sun Aug  3 06:18:15 2008
@@ -23,7 +23,6 @@
 import org.apache.maven.artifact.ArtifactUtils;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.shared.dependency.tree.DependencyNode;
-import org.apache.maven.shared.dependency.tree.DependencyTree;
 import org.apache.maven.shared.jar.JarAnalyzer;
 import org.apache.maven.shared.jar.JarData;
 import org.apache.maven.shared.jar.classes.JarClassesAnalysis;
@@ -43,17 +42,51 @@
 {
     private final MavenProject project;
 
-    private final List projectDependencies;
-
-    private final DependencyTree dependencyTree;
+    private final DependencyNode dependencyTreeNode;
 
     private final JarClassesAnalysis classesAnalyzer;
 
-    public Dependencies( MavenProject project, DependencyTree dependencyTree, JarClassesAnalysis classesAnalyzer )
+    /**
+     * @since 2.1
+     */
+    private List projectDependencies;
+
+    /**
+     * @since 2.1
+     */
+    private List projectTransitiveDependencies;
+
+    /**
+     * @since 2.1
+     */
+    private List allDependencies;
+
+    /**
+     * @since 2.1
+     */
+    private Map dependenciesByScope;
+
+    /**
+     * @since 2.1
+     */
+    private Map transitiveDependenciesByScope;
+
+    /**
+     * @since 2.1
+     */
+    private Map dependencyDetails;
+
+    /**
+     * Default constructor
+     *
+     * @param project
+     * @param dependencyTreeNode
+     * @param classesAnalyzer
+     */
+    public Dependencies( MavenProject project, DependencyNode dependencyTreeNode, JarClassesAnalysis classesAnalyzer )
     {
         this.project = project;
-        this.dependencyTree = dependencyTree;
-        this.projectDependencies = dependencyTree.getRootNode().getChildren();
+        this.dependencyTreeNode = dependencyTreeNode;
         this.classesAnalyzer = classesAnalyzer;
 
         /*
@@ -67,7 +100,7 @@
             projectMap.put( ArtifactUtils.versionlessKey( artifact ), artifact );
         }
 
-        mapArtifactFiles( dependencyTree.getRootNode(), projectMap );
+        mapArtifactFiles( dependencyTreeNode, projectMap );
     }
 
     /**
@@ -80,32 +113,134 @@
         return project;
     }
 
+    /**
+     * @return <code>true</code> if getProjectDependencies() is not empty, <code>false</code> otherwise.
+     */
     public boolean hasDependencies()
     {
-        return ( projectDependencies != null ) && ( !this.projectDependencies.isEmpty() );
+        return ( getProjectDependencies() != null ) && ( !getProjectDependencies().isEmpty() );
     }
 
+    /**
+     * @return a list of <code>Artifact</code> from the project.
+     */
     public List getProjectDependencies()
     {
-        return new ArrayList( projectDependencies );
+        if ( projectDependencies != null )
+        {
+            return projectDependencies;
+        }
+
+        projectDependencies = new ArrayList();
+        for ( Iterator i = dependencyTreeNode.getChildren().iterator(); i.hasNext(); )
+        {
+            DependencyNode dependencyNode = (DependencyNode) i.next();
+
+            projectDependencies.add( dependencyNode.getArtifact() );
+        }
+
+        return projectDependencies;
     }
 
+    /**
+     * @return a list of transitive <code>Artifact</code> from the project.
+     */
     public List getTransitiveDependencies()
     {
-        List deps = new ArrayList( dependencyTree.getArtifacts() );
-        deps.removeAll( projectDependencies );
-        return deps;
+        if ( projectTransitiveDependencies != null )
+        {
+            return projectTransitiveDependencies;
+        }
+
+        projectTransitiveDependencies = new ArrayList( getAllDependencies() );
+        projectTransitiveDependencies.removeAll( getProjectDependencies() );
+
+        return projectTransitiveDependencies;
     }
 
+    /**
+     * @return a list of included <code>Artifact</code> returned by the dependency tree.
+     */
     public List getAllDependencies()
     {
-        return dependencyTree.getArtifacts();
+        if ( allDependencies != null )
+        {
+            return allDependencies;
+        }
+
+        allDependencies = new ArrayList();
+        for ( Iterator i = dependencyTreeNode.getChildren().iterator(); i.hasNext(); )
+        {
+            DependencyNode dependencyNode = (DependencyNode) i.next();
+
+            if ( dependencyNode.getState() != DependencyNode.INCLUDED )
+            {
+                continue;
+            }
+
+            if ( dependencyNode.getArtifact().getGroupId().equals( project.getGroupId() )
+                && dependencyNode.getArtifact().getArtifactId().equals( project.getArtifactId() )
+                && dependencyNode.getArtifact().getVersion().equals( project.getVersion() ) )
+            {
+                continue;
+            }
+
+            if ( !allDependencies.contains( dependencyNode.getArtifact() ) )
+            {
+                allDependencies.add( dependencyNode.getArtifact() );
+            }
+            getAllDependencies( dependencyNode );
+        }
+
+        return allDependencies;
     }
 
-    public Map getDependenciesByScope()
+    /**
+     * @param isTransitively <code>true</code> to return transitive dependencies, <code>false</code> otherwise.
+     * @return a map with supported scopes as key and a list of <code>Artifact</code> as values.
+     * @see Artifact#SCOPE_COMPILE
+     * @see Artifact#SCOPE_PROVIDED
+     * @see Artifact#SCOPE_RUNTIME
+     * @see Artifact#SCOPE_SYSTEM
+     * @see Artifact#SCOPE_TEST
+     */
+    public Map getDependenciesByScope( boolean isTransitively )
     {
-        Map dependenciesByScope = new HashMap();
-        for ( Iterator i = getAllDependencies().iterator(); i.hasNext(); )
+        if ( isTransitively )
+        {
+            if ( transitiveDependenciesByScope != null )
+            {
+                return transitiveDependenciesByScope;
+            }
+
+            transitiveDependenciesByScope = new HashMap();
+            for ( Iterator i = getTransitiveDependencies().iterator(); i.hasNext(); )
+            {
+                Artifact artifact = (Artifact) i.next();
+
+                List multiValue = (List) transitiveDependenciesByScope.get( artifact.getScope() );
+                if ( multiValue == null )
+                {
+                    multiValue = new ArrayList();
+                }
+
+                if ( !multiValue.contains( artifact ) )
+                {
+                    multiValue.add( artifact );
+                }
+                transitiveDependenciesByScope.put( artifact.getScope(), multiValue );
+            }
+
+            return transitiveDependenciesByScope;
+        }
+
+        if ( dependenciesByScope != null )
+        {
+            return dependenciesByScope;
+        }
+
+        dependenciesByScope = new HashMap();
+        for ( Iterator i = getProjectDependencies().iterator(); i.hasNext(); )
         {
             Artifact artifact = (Artifact) i.next();
 
@@ -114,17 +249,37 @@
             {
                 multiValue = new ArrayList();
             }
-            multiValue.add( artifact );
+
+            if ( !multiValue.contains( artifact ) )
+            {
+                multiValue.add( artifact );
+            }
             dependenciesByScope.put( artifact.getScope(), multiValue );
         }
+
         return dependenciesByScope;
     }
 
+    /**
+     * @param artifact
+     * @return the jardata object from the artifact
+     * @throws IOException if any
+     */
     public JarData getJarDependencyDetails( Artifact artifact )
         throws IOException
     {
-        JarAnalyzer jarAnalyzer = new JarAnalyzer( artifact.getFile() );
+        if ( dependencyDetails == null )
+        {
+            dependencyDetails = new HashMap();
+        }
+
+        JarData old = (JarData) dependencyDetails.get( artifact.getId() );
+        if ( dependencyDetails.get( artifact.getId() ) != null )
+        {
+            return old;
+        }
 
+        JarAnalyzer jarAnalyzer = new JarAnalyzer( artifact.getFile() );
         try
         {
             classesAnalyzer.analyze( jarAnalyzer );
@@ -134,6 +289,8 @@
             jarAnalyzer.closeQuietly();
         }
 
+        dependencyDetails.put( artifact.getId(), jarAnalyzer.getJarData() );
+
         return jarAnalyzer.getJarData();
     }
 
@@ -163,4 +320,44 @@
             mapArtifactFiles( anode, projectMap );
         }
     }
+
+    /**
+     * Recursive method to get all dependencies from a given <code>dependencyNode</code>
+     *
+     * @param dependencyNode not null
+     */
+    private void getAllDependencies( DependencyNode dependencyNode )
+    {
+        if ( dependencyNode == null || dependencyNode.getChildren() == null )
+        {
+            if ( !allDependencies.contains( dependencyNode.getArtifact() ) )
+            {
+                allDependencies.add( dependencyNode.getArtifact() );
+            }
+            return;
+        }
+
+        for ( Iterator i = dependencyNode.getChildren().iterator(); i.hasNext(); )
+        {
+            DependencyNode subdependencyNode = (DependencyNode) i.next();
+
+            if ( subdependencyNode.getState() != DependencyNode.INCLUDED )
+            {
+                continue;
+            }
+
+            if ( subdependencyNode.getArtifact().getGroupId().equals( project.getGroupId() )
+                && subdependencyNode.getArtifact().getArtifactId().equals( project.getArtifactId() )
+                && subdependencyNode.getArtifact().getVersion().equals( project.getVersion() ) )
+            {
+                continue;
+            }
+
+            if ( !allDependencies.contains( subdependencyNode.getArtifact() ) )
+            {
+                allDependencies.add( subdependencyNode.getArtifact() );
+            }
+            getAllDependencies( subdependencyNode );
+        }
+    }
 }

Modified: maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/DependenciesReportConfiguration.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/DependenciesReportConfiguration.java?rev=682163&r1=682162&r2=682163&view=diff
==============================================================================
--- maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/DependenciesReportConfiguration.java (original)
+++ maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/DependenciesReportConfiguration.java Sun Aug  3 06:18:15 2008
@@ -20,6 +20,8 @@
  */
 
 /**
+ * Wrap DependenciesReport Mojo parameters.
+ *
  * @version $Id$
  * @since 2.1
  */
@@ -29,21 +31,29 @@
 
     private boolean dependencyLocationsEnabled;
 
+    /**
+     * @param detailsEnabled
+     * @param locationEnabled
+     */
     public DependenciesReportConfiguration( boolean detailsEnabled, boolean locationEnabled )
     {
         this.dependencyDetailsEnabled = detailsEnabled;
         this.dependencyLocationsEnabled = locationEnabled;
     }
 
+    /**
+     * @return value of Mojo dependencyDetailsEnabled parameter.
+     */
     public boolean getDependencyDetailsEnabled()
     {
         return dependencyDetailsEnabled;
     }
 
+    /**
+     * @return value of Mojo dependencyLocationsEnabled parameter.
+     */
     public boolean getDependencyLocationsEnabled()
     {
-        //TODO:
-        //   ( !settings.isOffline() && dependencyLocationsEnabled )
         return dependencyLocationsEnabled;
     }
 }

Modified: maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/ManagementDependencies.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/ManagementDependencies.java?rev=682163&r1=682162&r2=682163&view=diff
==============================================================================
--- maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/ManagementDependencies.java (original)
+++ maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/ManagementDependencies.java Sun Aug  3 06:18:15 2008
@@ -30,32 +30,49 @@
 
 /**
  * @author Nick Stolwijk
- * @version $Id:$
+ * @version $Id$
  * @since 2.1
  */
 public class ManagementDependencies
 {
-    private final List projectDependencies;
+    private final List managementDependencies;
 
+    /**
+     * @param projectDependencies
+     */
     public ManagementDependencies( List projectDependencies )
     {
-        this.projectDependencies = projectDependencies;
+        this.managementDependencies = projectDependencies;
     }
 
+    /**
+     * @return <code>true</code> if managementDependencies is not null and not empty.
+     */
     public boolean hasDependencies()
     {
-        return ( projectDependencies != null ) && ( !this.projectDependencies.isEmpty() );
+        return ( managementDependencies != null ) && ( !this.managementDependencies.isEmpty() );
     }
 
-    public List getProjectDependencies()
+    /**
+     * @return managementDependencies
+     */
+    public List getManagementDependencies()
     {
-        return new ArrayList( projectDependencies );
+        return new ArrayList( managementDependencies );
     }
 
-    public Map getDependenciesByScope()
+    /**
+     * @return the managementDependencies by scope
+     * @see Artifact#SCOPE_COMPILE
+     * @see Artifact#SCOPE_PROVIDED
+     * @see Artifact#SCOPE_RUNTIME
+     * @see Artifact#SCOPE_SYSTEM
+     * @see Artifact#SCOPE_TEST
+     */
+    public Map getManagementDependenciesByScope()
     {
         Map dependenciesByScope = new HashMap();
-        for ( Iterator i = getProjectDependencies().iterator(); i.hasNext(); )
+        for ( Iterator i = getManagementDependencies().iterator(); i.hasNext(); )
         {
             Dependency dependency = (Dependency) i.next();
             String scope = dependency.getScope() != null ? dependency.getScope() : Artifact.SCOPE_COMPILE;

Modified: maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/RepositoryUtils.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/RepositoryUtils.java?rev=682163&r1=682162&r2=682163&view=diff
==============================================================================
--- maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/RepositoryUtils.java (original)
+++ maven/plugins/branches/maven-project-info-reports-plugin-doxia-beta-1/src/main/java/org/apache/maven/report/projectinfo/dependencies/RepositoryUtils.java Sun Aug  3 06:18:15 2008
@@ -20,9 +20,16 @@
  */
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactUtils;
 import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.manager.WagonConfigurationException;
 import org.apache.maven.artifact.manager.WagonManager;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
 import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.metadata.Metadata;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
+import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
@@ -42,38 +49,64 @@
 import org.apache.maven.wagon.observers.Debug;
 import org.apache.maven.wagon.proxy.ProxyInfo;
 import org.apache.maven.wagon.repository.Repository;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.logging.LoggerManager;
+import org.codehaus.plexus.util.StringUtils;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 /**
+ * Utilities methods to play with repository
+ *
  * @version $Id$
  * @since 2.1
  */
 public class RepositoryUtils
 {
-    private Log log;
+    private final Log log;
 
-    private WagonManager wagonManager;
+    private final LoggerManager loggerManager;
 
-    private Settings settings;
+    private final WagonManager wagonManager;
 
-    private MavenProjectBuilder mavenProjectBuilder;
+    private final Settings settings;
 
-    private ArtifactFactory factory;
+    private final MavenProjectBuilder mavenProjectBuilder;
 
-    private List remoteRepositories;
+    private final ArtifactFactory factory;
 
-    private List pluginRepositories;
+    private final List remoteRepositories;
 
-    private ArtifactResolver resolver;
+    private final List pluginRepositories;
 
-    private ArtifactRepository localRepository;
+    private final ArtifactResolver resolver;
 
-    public RepositoryUtils( WagonManager wagonManager, Settings settings, MavenProjectBuilder mavenProjectBuilder,
-                            ArtifactFactory factory, ArtifactResolver resolver, List remoteRepositories,
-                            List pluginRepositories, ArtifactRepository localRepository )
+    private final ArtifactRepository localRepository;
+
+    private final RepositoryMetadataManager repositoryMetadataManager;
+
+    /**
+     * @param log
+     * @param loggerManager
+     * @param wagonManager
+     * @param settings
+     * @param mavenProjectBuilder
+     * @param factory
+     * @param resolver
+     * @param remoteRepositories
+     * @param pluginRepositories
+     * @param localRepository
+     * @param repositoryMetadataManager
+     */
+    public RepositoryUtils( Log log, LoggerManager loggerManager, WagonManager wagonManager, Settings settings,
+                            MavenProjectBuilder mavenProjectBuilder, ArtifactFactory factory,
+                            ArtifactResolver resolver, List remoteRepositories, List pluginRepositories,
+                            ArtifactRepository localRepository, RepositoryMetadataManager repositoryMetadataManager )
     {
+        this.log = log;
+        this.loggerManager = loggerManager;
         this.wagonManager = wagonManager;
         this.settings = settings;
         this.mavenProjectBuilder = mavenProjectBuilder;
@@ -82,64 +115,98 @@
         this.remoteRepositories = remoteRepositories;
         this.pluginRepositories = pluginRepositories;
         this.localRepository = localRepository;
+        this.repositoryMetadataManager = repositoryMetadataManager;
     }
 
-    public void setLog( Log log )
-    {
-        this.log = log;
-    }
-
+    /**
+     * @return localrepo
+     */
     public ArtifactRepository getLocalRepository()
     {
         return localRepository;
     }
 
+    /**
+     * @return remote artifact repo
+     */
     public List getRemoteArtifactRepositories()
     {
         return remoteRepositories;
     }
 
+    /**
+     * @return plugin artifact repo
+     */
     public List getPluginArtifactRepositories()
     {
         return pluginRepositories;
     }
 
+    /**
+     * @param artifact not null
+     * @throws ArtifactResolutionException if any
+     * @throws ArtifactNotFoundException if any
+     * @see ArtifactResolver#resolve(Artifact, List, ArtifactRepository)
+     */
     public void resolve( Artifact artifact )
         throws ArtifactResolutionException, ArtifactNotFoundException
     {
-        List remoteRepositories = new ArrayList();
-        remoteRepositories.addAll( pluginRepositories );
-        remoteRepositories.addAll( remoteRepositories );
+        List repos = new ArrayList();
+        repos.addAll( pluginRepositories );
+        repos.addAll( remoteRepositories );
 
-        resolver.resolve( artifact, remoteRepositories, localRepository );
+        resolver.resolveAlways( artifact, repos, localRepository );
     }
 
+    /**
+     * @param repo not null
+     * @param artifact not null
+     * @return <code>true</code> if the artifact exists in the given repo, <code>false</code> otherwise or if
+     * the repo is blacklisted.
+     */
     public boolean dependencyExistsInRepo( ArtifactRepository repo, Artifact artifact )
     {
-        Wagon wagon;
+        if ( repo.isBlacklisted() )
+        {
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "The repo '" + repo.getId() + "' is black listed - Ignored it" );
+            }
+            return false;
+        }
+
+        String id = repo.getId();
+        Repository repository = new Repository( id, repo.getUrl() );
 
+        Wagon wagon;
         try
         {
-            wagon = wagonManager.getWagon( repo.getProtocol() );
+            wagon = wagonManager.getWagon( repository );
         }
         catch ( UnsupportedProtocolException e )
         {
             log.error( "Unsupported protocol: '" + repo.getProtocol() + "'", e );
             return false;
         }
+        catch ( WagonConfigurationException e )
+        {
+            log.error( "Unsupported protocol: '" + repo.getProtocol() + "'", e );
+            return false;
+        }
 
-        try
+        if ( log.isDebugEnabled() )
         {
             Debug debug = new Debug();
 
             wagon.addSessionListener( debug );
             wagon.addTransferListener( debug );
+        }
 
-            String id = repo.getId();
-            Repository repository = new Repository( id, repo.getUrl() );
+        try
+        {
             AuthenticationInfo auth = wagonManager.getAuthenticationInfo( repo.getId() );
 
-            ProxyInfo proxyInfo = getProxyInfo( settings );
+            ProxyInfo proxyInfo = getProxyInfo();
             if ( proxyInfo != null )
             {
                 wagon.connect( repository, auth, proxyInfo );
@@ -148,26 +215,56 @@
             {
                 wagon.connect( repository, auth );
             }
-            return ( wagon.resourceExists( repo.pathOf( artifact ) ) );
+
+            return wagon.resourceExists( StringUtils.replace( getDependencyUrlFromRepository( artifact, repo ),
+                                                              repo.getUrl(), "" ) );
         }
         catch ( ConnectionException e )
         {
-            log.error( "Unable to connect to: " + repo.getUrl(), e );
+            if ( log.isDebugEnabled() )
+            {
+                log.error( "Unable to connect to: " + repo.getUrl(), e );
+            }
+            else
+            {
+                log.error( "Unable to connect to: " + repo.getUrl() );
+            }
             return false;
         }
         catch ( AuthenticationException e )
         {
-            log.error( "Unable to connect to: " + repo.getUrl(), e );
+            if ( log.isDebugEnabled() )
+            {
+                log.error( "Unable to connect to: " + repo.getUrl(), e );
+            }
+            else
+            {
+                log.error( "Unable to connect to: " + repo.getUrl() );
+            }
             return false;
         }
         catch ( TransferFailedException e )
         {
-            log.error( "Unable to determine if resource " + artifact + " exists in " + repo.getUrl(), e );
+            if ( log.isDebugEnabled() )
+            {
+                log.error( "Unable to determine if resource " + artifact + " exists in " + repo.getUrl(), e );
+            }
+            else
+            {
+                log.error( "Unable to determine if resource " + artifact + " exists in " + repo.getUrl() );
+            }
             return false;
         }
         catch ( AuthorizationException e )
         {
-            log.error( "Unable to connect to: " + repo.getUrl(), e );
+            if ( log.isDebugEnabled() )
+            {
+                log.error( "Unable to connect to: " + repo.getUrl(), e );
+            }
+            else
+            {
+                log.error( "Unable to connect to: " + repo.getUrl() );
+            }
             return false;
         }
         catch ( AbstractMethodError e )
@@ -183,19 +280,145 @@
             }
             catch ( ConnectionException e )
             {
-                log.error( "Error disconnecting wagon - ignored", e );
+                if ( log.isDebugEnabled() )
+                {
+                    log.error( "Error disconnecting wagon - ignored", e );
+                }
+                else
+                {
+                    log.error( "Error disconnecting wagon - ignored" );
+                }
+            }
+        }
+    }
+
+    /**
+     * Get the <code>Maven project</code> from the repository depending the <code>Artifact</code> given.
+     *
+     * @param artifact an artifact
+     * @return the Maven project for the given artifact
+     * @throws ProjectBuildingException if any
+     */
+    public MavenProject getMavenProjectFromRepository( Artifact artifact )
+        throws ProjectBuildingException
+    {
+        Artifact projectArtifact = artifact;
+
+        boolean allowStubModel = false;
+        if ( !"pom".equals( artifact.getType() ) )
+        {
+            projectArtifact = factory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
+                                                             artifact.getVersion(), artifact.getScope() );
+            allowStubModel = true;
+        }
+
+        // TODO: we should use the MavenMetadataSource instead
+        return mavenProjectBuilder.buildFromRepository( projectArtifact, remoteRepositories, localRepository,
+                                                        allowStubModel );
+    }
+
+    /**
+     * @param artifact not null
+     * @param repo not null
+     * @return the artifact url in the given repo for the given artifact. If it is a snapshot artifact, the version
+     * will be the timestamp and the build number from the metadata. Could return null if the repo is blacklisted.
+     */
+    public String getDependencyUrlFromRepository( Artifact artifact, ArtifactRepository repo )
+    {
+        if ( repo.isBlacklisted() )
+        {
+            return null;
+        }
+
+        Artifact copyArtifact = ArtifactUtils.copyArtifact( artifact );
+        // Try to get the last artifact repo name depending the snapshot version
+        if ( ( artifact.isSnapshot() && repo.getSnapshots().isEnabled() ) )
+        {
+            if ( artifact.getBaseVersion().equals( artifact.getVersion() ))
+            {
+                // Try to resolve it if not already done
+                if ( artifact.getMetadataList() == null || artifact.getMetadataList().isEmpty() )
+                {
+                    try
+                    {
+                        resolve( artifact );
+                    }
+                    catch ( ArtifactResolutionException e )
+                    {
+                        log.error( "Artifact: " + artifact.getId() + " could not be resolved." );
+                    }
+                    catch ( ArtifactNotFoundException e )
+                    {
+                        log.error( "Artifact: " + artifact.getId() + " was not found." );
+                    }
+                }
+
+                for ( Iterator it = artifact.getMetadataList().iterator(); it.hasNext(); )
+                {
+                    ArtifactMetadata m = (ArtifactMetadata) it.next();
+
+                    if ( m instanceof SnapshotArtifactRepositoryMetadata )
+                    {
+                        SnapshotArtifactRepositoryMetadata snapshotMetadata = (SnapshotArtifactRepositoryMetadata) m;
+
+                        // Removed not found log
+                        int oldThreshold = loggerManager.getThreshold();
+                        loggerManager.setThreshold( RepositoryMetadataManager.class.getName(), Logger.LEVEL_DISABLED );
+                        try
+                        {
+                            repositoryMetadataManager.resolveAlways( snapshotMetadata, localRepository, repo );
+                        }
+                        catch ( RepositoryMetadataResolutionException e )
+                        {
+                            loggerManager.setThreshold( RepositoryMetadataManager.class.getName(), oldThreshold );
+                            if ( log.isDebugEnabled() )
+                            {
+                                log.error( "Unable to connect to: " + repo.getUrl(), e );
+                            }
+                            else
+                            {
+                                log.error( "Unable to connect to: " + repo.getUrl() );
+                            }
+                            return repo.getUrl() + "/" + repo.pathOf( copyArtifact );
+                        }
+                        finally
+                        {
+                            loggerManager.setThreshold( RepositoryMetadataManager.class.getName(), oldThreshold );
+                        }
+
+                        Metadata metadata = snapshotMetadata.getMetadata();
+                        if ( metadata.getVersioning() == null || metadata.getVersioning().getSnapshot() == null
+                            || metadata.getVersioning().getSnapshot().isLocalCopy()
+                            || metadata.getVersioning().getSnapshot().getTimestamp() == null )
+                        {
+                            continue;
+                        }
+
+                        // create the version according SnapshotTransformation
+                        String version =
+                            StringUtils.replace( copyArtifact.getVersion(), Artifact.SNAPSHOT_VERSION,
+                                                 metadata.getVersioning().getSnapshot().getTimestamp() )
+                                + "-" + metadata.getVersioning().getSnapshot().getBuildNumber();
+                        copyArtifact.setVersion( version );
+                    }
+                }
             }
         }
+
+        return repo.getUrl() + "/" + repo.pathOf( copyArtifact );
     }
 
+    // ----------------------------------------------------------------------
+    // Private methods
+    // ----------------------------------------------------------------------
+
     /**
      * Convenience method to map a <code>Proxy</code> object from the user system settings to a <code>ProxyInfo</code>
      * object.
      *
-     * @param settings the system settings
-     * @return a proxyInfo object instancied or null if no active proxy is define in the settings.xml
+     * @return a proxyInfo object instanced or null if no active proxy is define in the settings.xml
      */
-    public ProxyInfo getProxyInfo( Settings settings )
+    private ProxyInfo getProxyInfo()
     {
         ProxyInfo proxyInfo = null;
         if ( settings != null && settings.getActiveProxy() != null )
@@ -213,31 +436,4 @@
 
         return proxyInfo;
     }
-
-    /**
-     * Get the <code>Maven project</code> from the repository depending the <code>Artifact</code> given.
-     *
-     * @param artifact        an artifact
-     * @param localRepository the local repository
-     * @return the Maven project for the given artifact
-     * @throws org.apache.maven.project.ProjectBuildingException
-     *          if any
-     */
-    public MavenProject getMavenProjectFromRepository( Artifact artifact, ArtifactRepository localRepository )
-        throws ProjectBuildingException
-    {
-        Artifact projectArtifact = artifact;
-
-        boolean allowStubModel = false;
-        if ( !"pom".equals( artifact.getType() ) )
-        {
-            projectArtifact = factory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
-                                                             artifact.getVersion(), artifact.getScope() );
-            allowStubModel = true;
-        }
-
-        // TODO: we should use the MavenMetadataSource instead
-        return mavenProjectBuilder.buildFromRepository( projectArtifact, remoteRepositories, localRepository,
-                                                        allowStubModel );
-    }
 }



Mime
View raw message