maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joak...@apache.org
Subject svn commit: r477353 - in /maven/plugins/trunk/maven-project-info-reports-plugin: ./ src/main/java/org/apache/maven/report/projectinfo/ src/main/java/org/apache/maven/report/projectinfo/dependencies/ src/main/java/org/apache/maven/report/projectinfo/dep...
Date Mon, 20 Nov 2006 21:36:06 GMT
Author: joakime
Date: Mon Nov 20 13:36:05 2006
New Revision: 477353

URL: http://svn.apache.org/viewvc?view=rev&rev=477353
Log:
* refactored out Dependency Tree components in favor of MNG-2654 maven-dependency-tree component.
* break archiva <-> mpir dependency.
* updated to use new JarAnalyzerFactory mechanism present in maven-shared-jar.


Removed:
    maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/ReportResolutionListener.java
    maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/dependencies/
Modified:
    maven/plugins/trunk/maven-project-info-reports-plugin/pom.xml
    maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java
    maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/Dependencies.java
    maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java

Modified: maven/plugins/trunk/maven-project-info-reports-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/pom.xml?view=diff&rev=477353&r1=477352&r2=477353
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/pom.xml Mon Nov 20 13:36:05 2006
@@ -122,6 +122,11 @@
       <version>1.0-SNAPSHOT</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-dependency-tree</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
       <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-provider-api</artifactId>
       <version>1.0-beta-2-SNAPSHOT</version>

Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java?view=diff&rev=477353&r1=477352&r2=477353
==============================================================================
--- 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
Mon Nov 20 13:36:05 2006
@@ -19,25 +19,18 @@
 import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
 import org.apache.maven.artifact.resolver.ArtifactCollector;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.project.MavenProjectBuilder;
-import org.apache.maven.project.ProjectBuildingException;
-import org.apache.maven.project.artifact.InvalidDependencyVersionException;
 import org.apache.maven.report.projectinfo.dependencies.Dependencies;
 import org.apache.maven.report.projectinfo.dependencies.DependenciesReportConfiguration;
-import org.apache.maven.report.projectinfo.dependencies.ReportResolutionListener;
 import org.apache.maven.report.projectinfo.dependencies.RepositoryUtils;
 import org.apache.maven.report.projectinfo.dependencies.renderer.DependenciesRenderer;
 import org.apache.maven.settings.Settings;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.context.Context;
-import org.codehaus.plexus.context.ContextException;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+import org.apache.maven.shared.dependency.tree.DependencyTree;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
+import org.apache.maven.shared.jar.JarAnalyzerFactory;
 
-import java.util.Collections;
 import java.util.Locale;
-import java.util.Map;
 
 /**
  * Generates the Project Dependencies report.
@@ -50,7 +43,6 @@
  */
 public class DependenciesReport
     extends AbstractProjectInfoReport
-    implements Contextualizable
 {
     /**
      * Maven Project Builder.
@@ -73,8 +65,18 @@
      * @component
      */
     private WagonManager wagonManager;
+    
+    /**
+     * @component
+     */
+    private DependencyTreeBuilder dependencyTreeBuilder;
 
     /**
+     * @component
+     */
+    private JarAnalyzerFactory jarAnalyzerFactory;
+    
+    /**
      * The current user system settings for use in Maven.
      *
      * @parameter expression="${settings}"
@@ -94,8 +96,6 @@
      */
     private boolean dependencyLocationsEnabled;
 
-    private PlexusContainer container;
-
     /**
      * @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
      */
@@ -121,56 +121,33 @@
                                                          project.getRemoteArtifactRepositories(),
                                                          project.getPluginArtifactRepositories(),
localRepository );
 
-        ReportResolutionListener listener = resolveProject();
+        DependencyTree dependencyTree = resolveProject();
 
-        Dependencies dependencies = new Dependencies( project, listener, container );
+        Dependencies dependencies = new Dependencies( project, dependencyTree, jarAnalyzerFactory
);
 
         DependenciesReportConfiguration config =
             new DependenciesReportConfiguration( dependencyDetailsEnabled, dependencyLocationsEnabled
);
 
         DependenciesRenderer r =
-            new DependenciesRenderer( getSink(), locale, i18n, dependencies, listener, config,
repoUtils );
+            new DependenciesRenderer( getSink(), locale, i18n, dependencies, dependencyTree,
config, repoUtils );
 
         repoUtils.setLog( getLog() );
         r.setLog( getLog() );
         r.render();
     }
 
-    private ReportResolutionListener resolveProject()
+    private DependencyTree resolveProject()
     {
-        Map managedVersions = null;
         try
         {
-            managedVersions = Dependencies.getManagedVersionMap( project, factory );
+            return dependencyTreeBuilder.buildDependencyTree( project, localRepository, factory,
+                                                              artifactMetadataSource, collector
);
         }
-        catch ( ProjectBuildingException e )
+        catch ( DependencyTreeBuilderException e )
         {
-            getLog().error( "An error occurred while resolving project dependencies.", e
);
-        }
-
-        ReportResolutionListener listener = new ReportResolutionListener();
-
-        try
-        {
-            // TODO site:run Why do we need to resolve this...
-            if ( project.getDependencyArtifacts() == null )
-            {
-                project.setDependencyArtifacts( project.createArtifacts( factory, null, null
) );
-            }
-            collector.collect( project.getDependencyArtifacts(), project.getArtifact(), managedVersions,
-                               localRepository, project.getRemoteArtifactRepositories(),
artifactMetadataSource, null,
-                               Collections.singletonList( listener ) );
-        }
-        catch ( ArtifactResolutionException e )
-        {
-            getLog().error( "An error occurred while resolving project dependencies.", e
);
-        }
-        catch ( InvalidDependencyVersionException e )
-        {
-            getLog().error( "An error occurred while resolving project dependencies.", e
);
-        }
-
-        return listener;
+            getLog().error( "Unable to build dependency tree.", e );
+            return null;
+        } 
     }
 
     /**
@@ -179,11 +156,5 @@
     public String getOutputName()
     {
         return "dependencies";
-    }
-
-    public void contextualize( Context context )
-        throws ContextException
-    {
-        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
     }
 }

Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/Dependencies.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/Dependencies.java?view=diff&rev=477353&r1=477352&r2=477353
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/Dependencies.java
(original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/Dependencies.java
Mon Nov 20 13:36:05 2006
@@ -18,23 +18,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.versioning.InvalidVersionSpecificationException;
-import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.model.DependencyManagement;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuildingException;
-import org.apache.maven.report.projectinfo.dependencies.ReportResolutionListener.Node;
-import org.apache.maven.shared.jar.Jar;
-import org.apache.maven.shared.jar.JarException;
+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.JarAnalyzerException;
+import org.apache.maven.shared.jar.JarAnalyzerFactory;
 import org.apache.maven.shared.jar.classes.JarClasses;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 
 import java.io.File;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -43,19 +36,18 @@
 public class Dependencies
 {
     private List projectDependencies;
+    private DependencyTree dependencyTree;
+    private JarAnalyzerFactory jarAnalyzerFactory;
 
-    private ReportResolutionListener resolvedDependencies;
-
-    private Jar jar;
-
-    public Dependencies( MavenProject project, ReportResolutionListener listener, PlexusContainer
container )
+    public Dependencies( MavenProject project, DependencyTree dependencyTree, JarAnalyzerFactory
jarAnalyzerFactory )
     {
-        this.projectDependencies = listener.getRootNode().getChildren();
-        this.resolvedDependencies = listener;
+        this.dependencyTree = dependencyTree;
+        this.projectDependencies = dependencyTree.getRootNode().getChildren();
+        this.jarAnalyzerFactory = jarAnalyzerFactory;
 
         /*
-        * Workaround to ensure proper File objects in the Artifacts from the ReportResolutionListener
-        */
+         * Workaround to ensure proper File objects in the Artifacts from the ReportResolutionListener
+         */
         Map projectMap = new HashMap();
         Iterator it = project.getArtifacts().iterator();
         while ( it.hasNext() )
@@ -64,60 +56,10 @@
             projectMap.put( ArtifactUtils.versionlessKey( artifact ), artifact );
         }
 
-        mapArtifactFiles( listener.getRootNode(), projectMap );
-
-        // quick fix
-        try
-        { 
-            if ( container != null )
-            {    
-                this.jar = (Jar) container.lookup( Jar.ROLE );
-            }    
-        }
-        catch ( ComponentLookupException ex )
-        {
-            //TODO: handle exception
-        }
+        mapArtifactFiles( dependencyTree.getRootNode(), projectMap );
     } 
     
-    public static Map getManagedVersionMap( MavenProject project, ArtifactFactory factory
)
-        throws ProjectBuildingException
-    {
-        DependencyManagement dependencyManagement = project.getDependencyManagement();
-        Map managedVersionMap;
-
-        if ( dependencyManagement != null && dependencyManagement.getDependencies()
!= null )
-        {
-            managedVersionMap = new HashMap();
-            for ( Iterator i = dependencyManagement.getDependencies().iterator(); i.hasNext();
)
-            {
-                Dependency d = (Dependency) i.next();
-
-                try
-                {
-                    VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion()
);
-                    Artifact artifact = factory.createDependencyArtifact( d.getGroupId(),
d.getArtifactId(),
-                                                                          versionRange, d.getType(),
d.getClassifier(),
-                                                                          d.getScope() );
-                    managedVersionMap.put( d.getManagementKey(), artifact );
-                }
-                catch ( InvalidVersionSpecificationException e )
-                {
-                    throw new ProjectBuildingException( project.getId(), "Unable to parse
version '" + d.getVersion() +
-                        "' for dependency '" + d.getManagementKey() + "': " + e.getMessage(),
e );
-                }
-            }
-        }
-        else
-        {
-            managedVersionMap = Collections.EMPTY_MAP;
-        }
-
-        return managedVersionMap;
-    }
-
-
-    private void mapArtifactFiles( Node node, Map projectMap )
+    private void mapArtifactFiles( DependencyNode node, Map projectMap )
     {
         List childs = node.getChildren();
         if ( ( childs == null ) || childs.isEmpty() )
@@ -128,7 +70,7 @@
         Iterator it = childs.iterator();
         while ( it.hasNext() )
         {
-            Node anode = (ReportResolutionListener.Node) it.next();
+            DependencyNode anode = (DependencyNode) it.next();
             String key = ArtifactUtils.versionlessKey( anode.getArtifact() );
             Artifact projartifact = (Artifact) projectMap.get( key );
             if ( projartifact != null )
@@ -152,22 +94,14 @@
 
     public List getTransitiveDependencies()
     {
-        List deps = new ArrayList( resolvedDependencies.getArtifacts() );
+        List deps = new ArrayList( dependencyTree.getArtifacts() );
         deps.removeAll( projectDependencies );
         return deps;
     }
 
     public List getAllDependencies()
     {
-        List deps = new ArrayList();
-
-        for ( Iterator it = resolvedDependencies.getArtifacts().iterator(); it.hasNext();
)
-        {
-            ReportResolutionListener.Node node = (ReportResolutionListener.Node) it.next();
-            Artifact artifact = node.getArtifact();
-            deps.add( artifact );
-        }
-        return deps;
+        return dependencyTree.getArtifacts();
     }
 
     public Map getDependenciesByScope()
@@ -189,19 +123,14 @@
     }
 
     public JarDependencyDetails getJarDependencyDetails( Artifact artifact )
-        throws JarException
+        throws JarAnalyzerException
     {
         File artifactFile = artifact.getFile();
-        JarClasses jarClasses;
-
-        jar.setFile( artifactFile );
-        jarClasses = jar.getClasses();
+        
+        JarAnalyzer jar = jarAnalyzerFactory.getJarAnalyzer( artifactFile ); 
+        
+        JarClasses jarClasses = jar.getClasses();
 
         return new JarDependencyDetails( jarClasses, jar.isSealed(), jar.getEntries() );
-    }
-    
-    public ReportResolutionListener.Node getResolvedRoot()
-    {
-        return resolvedDependencies.getRootNode();
     }
 }

Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java?view=diff&rev=477353&r1=477352&r2=477353
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java
(original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java
Mon Nov 20 13:36:05 2006
@@ -13,10 +13,11 @@
 import org.apache.maven.report.projectinfo.dependencies.Dependencies;
 import org.apache.maven.report.projectinfo.dependencies.DependenciesReportConfiguration;
 import org.apache.maven.report.projectinfo.dependencies.JarDependencyDetails;
-import org.apache.maven.report.projectinfo.dependencies.ReportResolutionListener;
 import org.apache.maven.report.projectinfo.dependencies.RepositoryUtils;
 import org.apache.maven.reporting.AbstractMavenReportRenderer;
-import org.apache.maven.shared.jar.JarException;
+import org.apache.maven.shared.dependency.tree.DependencyNode;
+import org.apache.maven.shared.dependency.tree.DependencyTree;
+import org.apache.maven.shared.jar.JarAnalyzerException;
 import org.codehaus.plexus.i18n.I18N;
 import org.codehaus.plexus.util.StringUtils;
 
@@ -50,7 +51,7 @@
         JAR_SUBTYPE.add( "ejb" );
     }
 
-    private final ReportResolutionListener listener;
+    private final DependencyTree dependencyTree;
 
     private Dependencies dependencies;
 
@@ -80,15 +81,15 @@
         }
     };
 
-    public DependenciesRenderer( Sink sink, Locale locale, I18N _i18n, Dependencies _dependencies,
-                                 ReportResolutionListener listener, DependenciesReportConfiguration
config,
+    public DependenciesRenderer( Sink sink, Locale _locale, I18N _i18n, Dependencies _dependencies,
+                                 DependencyTree _depTree, DependenciesReportConfiguration
_config,
                                  RepositoryUtils _repoUtils )
     {
         super( sink );
 
-        this.locale = locale;
+        this.locale = _locale;
 
-        this.listener = listener;
+        this.dependencyTree = _depTree;
 
         this.repoUtils = _repoUtils;
 
@@ -96,7 +97,7 @@
 
         this.i18n = _i18n;
 
-        this.configuration = config;
+        this.configuration = _config;
     }
 
     public void setLog( Log _log )
@@ -231,7 +232,7 @@
         startSection( getReportString( "report.dependencies.graph.tree.title" ) );
         sink.paragraph();
         sink.list();
-        printDependencyListing( listener.getRootNode() );
+        printDependencyListing( dependencyTree.getRootNode() );
         sink.list_();
         sink.paragraph_();
         endSection();
@@ -342,7 +343,7 @@
                             decFormat.format( jarDetails.getPackageSize() ), jarDetails.getJdkRevision(),
debugstr,
                             sealedstr} );
                     }
-                    catch ( JarException e )
+                    catch ( JarAnalyzerException e )
                     {
                         createExceptionInfoTableRow( artifact, artifactFile, e );
                     }
@@ -532,7 +533,7 @@
     private void renderSectionDependencyListing()
     {
         startSection( getReportString( "report.dependencies.graph.tables.title" ) );
-        printDescriptionsAndURLs( listener.getRootNode() );
+        printDescriptionsAndURLs( dependencyTree.getRootNode() );
         endSection();
     }
 
@@ -599,7 +600,7 @@
             artifact.getClassifier(), artifact.getType(), artifact.isOptional() ? "(optional)"
: " "};
     }
 
-    private void printDependencyListing( ReportResolutionListener.Node node )
+    private void printDependencyListing( DependencyNode node )
     {
         Artifact artifact = node.getArtifact();
         String id = artifact.getDependencyConflictId();
@@ -616,7 +617,7 @@
             sink.list();
             for ( Iterator deps = node.getChildren().iterator(); deps.hasNext(); )
             {
-                ReportResolutionListener.Node dep = (ReportResolutionListener.Node) deps.next();
+                DependencyNode dep = (DependencyNode) deps.next();
                 printDependencyListing( dep );
             }
             sink.list_();
@@ -626,7 +627,7 @@
         sink.listItem_();
     }
 
-    private void printDescriptionsAndURLs( ReportResolutionListener.Node node )
+    private void printDescriptionsAndURLs( DependencyNode node )
     {
         Artifact artifact = node.getArtifact();
         String id = artifact.getDependencyConflictId();
@@ -713,7 +714,7 @@
 
             for ( Iterator deps = node.getChildren().iterator(); deps.hasNext(); )
             {
-                ReportResolutionListener.Node dep = (ReportResolutionListener.Node) deps.next();
+                DependencyNode dep = (DependencyNode) deps.next();
                 printDescriptionsAndURLs( dep );
             }
         }



Mime
View raw message