]> source.dussan.org Git - archiva.git/commitdiff
Add a tab for dependency tree
authorBrett Porter <brett@apache.org>
Mon, 18 Sep 2006 01:40:26 +0000 (01:40 +0000)
committerBrett Porter <brett@apache.org>
Mon, 18 Sep 2006 01:40:26 +0000 (01:40 +0000)
Submitted by: Pete Marvin King (with modifications)

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@447183 13f79535-47bb-0310-9956-ffa450edef68

archiva-webapp/pom.xml
archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
archiva-webapp/src/main/java/org/apache/maven/archiva/web/mapper/RepositoryActionMapper.java
archiva-webapp/src/main/resources/xwork.xml
archiva-webapp/src/main/webapp/WEB-INF/jsp/include/dependencyTree.jspf [new file with mode: 0644]
archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp

index a36ff7e67c1150283ca697503d6b6ddebe8710b3..91753eb4ca7d870fdbd502ce977cb4127ae86d95 100644 (file)
       <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>
       <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>
       <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>
index eb9ea5dab3101cee9272330dd57dd819f8adcd47..c89c2938325546b76e926d599319a210215f4471 100644 (file)
@@ -30,13 +30,19 @@ import org.apache.maven.archiva.indexer.lucene.LuceneQuery;
 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.Collections;
 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 @@ public class ShowArtifactAction
      */
     private RepositoryArtifactIndexFactory factory;
 
+    /**
+     * @plexus.requirement
+     */
+    private ArtifactMetadataSource artifactMetadataSource;
+
+    /**
+     * @plexus.requirement
+     */
+    private ArtifactCollector collector;
+
     private String groupId;
 
     private String artifactId;
@@ -96,6 +113,8 @@ public class ShowArtifactAction
 
     private Collection dependencies;
 
+    private List dependencyTree;
+
     public String artifact()
         throws ConfigurationStoreException, IOException, XmlPullParserException, ProjectBuildingException
     {
@@ -182,6 +201,65 @@ public class ShowArtifactAction
         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 @@ public class ShowArtifactAction
         return dependencies;
     }
 
+    public List getDependencyTree()
+    {
+        return dependencyTree;
+    }
+
     public String getGroupId()
     {
         return groupId;
@@ -324,21 +407,6 @@ public class ShowArtifactAction
             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 )
         {
             // We use DefaultArtifactVersion to get the correct sorting order later, however it does not have
index 73f3fd3dc1129f814b12688ea6f69894ebdd4875..60aa8ada93f9d1900b420e07ee47f3b1710915c6 100644 (file)
@@ -61,6 +61,11 @@ public class RepositoryActionMapper
             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" );
@@ -118,6 +123,10 @@ public class RepositoryActionMapper
                     {
                         return new ActionMapping( "showArtifactDependees", "/", "", params );
                     }
+                    else if ( "dependencyTree".equals( parts[3] ) )
+                    {
+                        return new ActionMapping( "showArtifactDependencyTree", "/", "", params );
+                    }
                 }
             }
         }
index 4b5cda060a1404dd45fc2f7f5045aa462da0ff92..c2bb8b42135117c9ec4bc21365d4877272d75b0c 100644 (file)
     <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">
diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/dependencyTree.jspf b/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/dependencyTree.jspf
new file mode 100644 (file)
index 0000000..a86b779
--- /dev/null
@@ -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
index d05ce8586b93c62129f842aaba43d648f36524e6..2747ab0b7b8a12e5aed04cb8fa9049140dbb50f8 100644 (file)
         </ww:url>
       </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}"/>
       <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" %>
       </c:otherwise>