You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by br...@apache.org on 2006/09/18 03:40:27 UTC

svn commit: r447183 - in /maven/archiva/trunk/archiva-webapp: ./ src/main/java/org/apache/maven/archiva/web/action/ src/main/java/org/apache/maven/archiva/web/mapper/ src/main/resources/ src/main/webapp/WEB-INF/jsp/ src/main/webapp/WEB-INF/jsp/include/

Author: brett
Date: Sun Sep 17 18:40:26 2006
New Revision: 447183

URL: http://svn.apache.org/viewvc?view=rev&rev=447183
Log:
Add a tab for dependency tree
Submitted by: Pete Marvin King (with modifications)

Added:
    maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/dependencyTree.jspf
Modified:
    maven/archiva/trunk/archiva-webapp/pom.xml
    maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
    maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/mapper/RepositoryActionMapper.java
    maven/archiva/trunk/archiva-webapp/src/main/resources/xwork.xml
    maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp

Modified: maven/archiva/trunk/archiva-webapp/pom.xml
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/pom.xml?view=diff&rev=447183&r1=447182&r2=447183
==============================================================================
--- maven/archiva/trunk/archiva-webapp/pom.xml (original)
+++ maven/archiva/trunk/archiva-webapp/pom.xml Sun Sep 17 18:40:26 2006
@@ -111,6 +111,17 @@
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-project</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-project-info-reports-plugin</artifactId>
+      <version>2.1-SNAPSHOT</version>
+      <exclusions>
+        <exclusion>
+            <groupId>plexus</groupId>
+            <artifactId>plexus-utils</artifactId>
+        </exclusion>
+      </exclusions>      
+    </dependency>    
     <!-- Plexus Security Dependencies -->
     <dependency>
       <groupId>org.codehaus.plexus.security</groupId>
@@ -157,7 +168,7 @@
       <artifactId>plexus-security-authorization-rbac-authorizer</artifactId>
       <version>1.0-SNAPSHOT</version>
     </dependency>
-        <dependency>
+    <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-jdo2</artifactId>
       <version>1.0-alpha-7-SNAPSHOT</version>
@@ -176,8 +187,8 @@
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
       <version>1.2</version>
-    </dependency>
-     <dependency>
+    </dependency>    
+    <dependency>
       <groupId>org.apache.derby</groupId>
       <artifactId>derby</artifactId>
        <version>10.1.2.1</version>

Modified: maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java?view=diff&rev=447183&r1=447182&r2=447183
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java (original)
+++ maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java Sun Sep 17 18:40:26 2006
@@ -30,13 +30,19 @@
 import org.apache.maven.archiva.indexer.record.StandardArtifactIndexRecord;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
 import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Model;
 import org.apache.maven.project.MavenProject;
 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.ReportResolutionListener;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
@@ -49,6 +55,7 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -86,6 +93,16 @@
      */
     private RepositoryArtifactIndexFactory factory;
 
+    /**
+     * @plexus.requirement
+     */
+    private ArtifactMetadataSource artifactMetadataSource;
+
+    /**
+     * @plexus.requirement
+     */
+    private ArtifactCollector collector;
+
     private String groupId;
 
     private String artifactId;
@@ -96,6 +113,8 @@
 
     private Collection dependencies;
 
+    private List dependencyTree;
+
     public String artifact()
         throws ConfigurationStoreException, IOException, XmlPullParserException, ProjectBuildingException
     {
@@ -182,6 +201,65 @@
         return SUCCESS;
     }
 
+    public String dependencyTree()
+        throws ConfigurationStoreException, ProjectBuildingException, InvalidDependencyVersionException,
+        ArtifactResolutionException
+    {
+        if ( !checkParameters() )
+        {
+            return ERROR;
+        }
+
+        Configuration configuration = configurationStore.getConfigurationFromStore();
+        List repositories = repositoryFactory.createRepositories( configuration );
+
+        Artifact artifact = artifactFactory.createProjectArtifact( groupId, artifactId, version );
+        // TODO: maybe we can decouple the assembly parts of the project builder from the repository handling to get rid of the temp repo
+        ArtifactRepository localRepository = repositoryFactory.createLocalRepository( configuration );
+        MavenProject project = projectBuilder.buildFromRepository( artifact, repositories, localRepository );
+
+        model = project.getModel();
+
+        getLogger().debug( " processing : " + groupId + ":" + artifactId + ":" + version );
+
+        Dependencies dependencies =
+            collectDependencies( project, artifact, localRepository, repositories );
+
+        dependencyTree = new LinkedList();
+        populateFlatTreeList( dependencies.getResolvedRoot(), dependencyTree );
+
+        return SUCCESS;
+    }
+
+    private void populateFlatTreeList( ReportResolutionListener.Node currentNode, List dependencyList )
+    {
+        ReportResolutionListener.Node childNode;
+
+        for ( Iterator iterator = currentNode.getChildren().iterator(); iterator.hasNext(); )
+        {
+            childNode = (ReportResolutionListener.Node) iterator.next();
+            dependencyList.add( childNode );
+            populateFlatTreeList( childNode, dependencyList );
+        }
+    }
+
+    private Dependencies collectDependencies( MavenProject project, Artifact artifact,
+                                              ArtifactRepository localRepository, List repositories )
+        throws ArtifactResolutionException, ProjectBuildingException, InvalidDependencyVersionException,
+        ConfigurationStoreException
+    {
+        Map managedDependencyMap = Dependencies.getManagedVersionMap( project, artifactFactory );
+
+        ReportResolutionListener listener = new ReportResolutionListener();
+
+        project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
+
+        collector.collect( project.getDependencyArtifacts(), artifact, managedDependencyMap, localRepository,
+                           repositories, artifactMetadataSource, null, Collections.singletonList( listener ) );
+
+        return new Dependencies( project, listener, null );
+    }
+
     private static String createId( String groupId, String artifactId, String version )
     {
         return groupId + ":" + artifactId + ":" + version;
@@ -245,6 +323,11 @@
         return dependencies;
     }
 
+    public List getDependencyTree()
+    {
+        return dependencyTree;
+    }
+
     public String getGroupId()
     {
         return groupId;
@@ -322,21 +405,6 @@
         public String getClassifier()
         {
             return classifier;
-        }
-
-        private static class Ver
-        {
-            private int buildNumber;
-
-            private int major;
-
-            private int minor;
-
-            private int incremental;
-
-            private String qualifier;
-
-
         }
 
         public void addVersion( String version )

Modified: maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/mapper/RepositoryActionMapper.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/mapper/RepositoryActionMapper.java?view=diff&rev=447183&r1=447182&r2=447183
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/mapper/RepositoryActionMapper.java (original)
+++ maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/mapper/RepositoryActionMapper.java Sun Sep 17 18:40:26 2006
@@ -61,6 +61,11 @@
             return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" +
                 params.remove( "version" ) + "/dependedonby";
         }
+        else if ( "showArtifactDependencyTree".equals( actionMapping.getName() ) )
+        {
+            return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" +
+                params.remove( "version" ) + "/dependencyTree";
+        }
         else if ( "proxy".equals( actionMapping.getName() ) )
         {
             return PROXY_PREFIX + params.remove( "path" );
@@ -117,6 +122,10 @@
                     else if ( "dependedonby".equals( parts[3] ) )
                     {
                         return new ActionMapping( "showArtifactDependees", "/", "", params );
+                    }
+                    else if ( "dependencyTree".equals( parts[3] ) )
+                    {
+                        return new ActionMapping( "showArtifactDependencyTree", "/", "", params );
                     }
                 }
             }

Modified: maven/archiva/trunk/archiva-webapp/src/main/resources/xwork.xml
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/resources/xwork.xml?view=diff&rev=447183&r1=447182&r2=447183
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/resources/xwork.xml (original)
+++ maven/archiva/trunk/archiva-webapp/src/main/resources/xwork.xml Sun Sep 17 18:40:26 2006
@@ -133,6 +133,10 @@
     <action name="showArtifactDependees" class="showArtifactAction" method="dependees">
       <result>/WEB-INF/jsp/showArtifact.jsp</result>
     </action>
+    
+    <action name="showArtifactDependencyTree" class="showArtifactAction" method="dependencyTree">
+      <result>/WEB-INF/jsp/showArtifact.jsp</result>
+    </action>
 
     <action name="proxy" class="proxyAction">
       <result type="stream">

Added: maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/dependencyTree.jspf
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/dependencyTree.jspf?view=auto&rev=447183
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/dependencyTree.jspf (added)
+++ maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/dependencyTree.jspf Sun Sep 17 18:40:26 2006
@@ -0,0 +1,54 @@
+<%--
+  ~ Copyright 2005-2006 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.
+  --%>
+
+<%@ taglib prefix="ww" uri="/webwork" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
+
+
+<ul>
+  <c:set var="prevDepth" value="1"/>
+  <ww:set name="dependencyTree" value="dependencyTree"/>
+  <c:forEach items="${dependencyTree}" var="node">
+    <c:choose>
+      <c:when test="${node.depth < prevDepth}">
+        </ul>
+        <li>
+      </c:when>
+      <c:when test="${node.depth > prevDepth}">
+        <ul>
+        <li>
+      </c:when>
+      <c:otherwise>
+        <li>
+      </c:otherwise>
+    </c:choose>
+    <c:set var="url">
+      <ww:url action="showArtifact" namespace="/">
+        <ww:param name="groupId" value="%{'${node.artifact.groupId}'}"/>
+        <ww:param name="artifactId" value="%{'${node.artifact.artifactId}'}"/>
+        <ww:param name="version" value="%{'${node.artifact.version}'}"/>
+      </ww:url>
+    </c:set>
+    <a href="${url}">
+      <%-- TODO! show this like the other dependencies: g / g1 / g2 / artifactId / version --%>
+      <c:out value="${node.artifact.dependencyConflictId}"/>
+    </a>
+    </li>
+    <c:set var="prevDepth" value="${node.depth}" />
+  </c:forEach>
+</ul>
+  
\ No newline at end of file

Modified: maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp?view=diff&rev=447183&r1=447182&r2=447183
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp (original)
+++ maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp Sun Sep 17 18:40:26 2006
@@ -103,6 +103,14 @@
       </c:set>
       <my:currentWWUrl url="${url}">Dependencies</my:currentWWUrl>
       <c:set var="url">
+        <ww:url action="showArtifactDependencyTree">
+          <ww:param name="groupId" value="%{groupId}"/>
+          <ww:param name="artifactId" value="%{artifactId}"/>
+          <ww:param name="version" value="%{version}"/>
+        </ww:url>
+      </c:set>
+      <my:currentWWUrl url="${url}">Dependency Tree</my:currentWWUrl>
+      <c:set var="url">
         <ww:url action="showArtifactDependees">
           <ww:param name="groupId" value="%{groupId}"/>
           <ww:param name="artifactId" value="%{artifactId}"/>
@@ -122,6 +130,9 @@
     <c:choose>
       <c:when test="${dependencies != null}">
         <%@ include file="/WEB-INF/jsp/include/artifactDependencies.jspf" %>
+      </c:when>
+      <c:when test="${dependencyTree != null}">
+        <%@ include file="/WEB-INF/jsp/include/dependencyTree.jspf" %>
       </c:when>
       <c:otherwise>
         <%@ include file="/WEB-INF/jsp/include/artifactInfo.jspf" %>