]> source.dussan.org Git - archiva.git/commitdiff
[MRM-131] add depended on by page
authorBrett Porter <brett@apache.org>
Sat, 26 Aug 2006 18:07:54 +0000 (18:07 +0000)
committerBrett Porter <brett@apache.org>
Sat, 26 Aug 2006 18:07:54 +0000 (18:07 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@437197 13f79535-47bb-0310-9956-ffa450edef68

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/browseArtifact.jsp
archiva-webapp/src/main/webapp/WEB-INF/jsp/include/artifactDependencies.jspf
archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp
archiva-webapp/src/main/webapp/WEB-INF/tags/currentWWUrl.tag

index 438934f6c3ca5e31e3b4c921c2404c4bea173f4a..2b80de6d877163195abba33e3814d25e80a3bccf 100644 (file)
@@ -17,13 +17,22 @@ package org.apache.maven.archiva.web.action;
  */
 
 import com.opensymphony.xwork.ActionSupport;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.TermQuery;
 import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.ConfigurationStore;
 import org.apache.maven.archiva.configuration.ConfigurationStoreException;
 import org.apache.maven.archiva.configuration.ConfiguredRepositoryFactory;
+import org.apache.maven.archiva.indexer.RepositoryArtifactIndex;
+import org.apache.maven.archiva.indexer.RepositoryArtifactIndexFactory;
+import org.apache.maven.archiva.indexer.RepositoryIndexException;
+import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
+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.repository.ArtifactRepository;
+import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Model;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectBuilder;
@@ -31,8 +40,15 @@ import org.apache.maven.project.ProjectBuildingException;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
+import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Browse the repository.
@@ -62,6 +78,11 @@ public class ShowArtifactAction
      */
     private ConfigurationStore configurationStore;
 
+    /**
+     * @plexus.requirement
+     */
+    private RepositoryArtifactIndexFactory factory;
+
     private String groupId;
 
     private String artifactId;
@@ -70,7 +91,7 @@ public class ShowArtifactAction
 
     private Model model;
 
-    private List dependencies;
+    private Collection dependencies;
 
     public String artifact()
         throws ConfigurationStoreException, IOException, XmlPullParserException, ProjectBuildingException
@@ -100,11 +121,78 @@ public class ShowArtifactAction
         model = project.getModel();
 
         // TODO: should this be the whole set of artifacts, and be more like the maven dependencies report?
-        dependencies = project.getModel().getDependencies();
+
+        List dependencies = new ArrayList();
+
+        for ( Iterator i = project.getModel().getDependencies().iterator(); i.hasNext(); )
+        {
+            Dependency dependency = (Dependency) i.next();
+
+            dependencies.add( new DependencyWrapper( dependency ) );
+        }
+
+        this.dependencies = dependencies;
+
+        return SUCCESS;
+    }
+
+    public String dependees()
+        throws ConfigurationStoreException, IOException, XmlPullParserException, ProjectBuildingException,
+        RepositoryIndexException, RepositoryIndexSearchException
+    {
+        if ( !checkParameters() )
+        {
+            return ERROR;
+        }
+
+        MavenProject project = readProject();
+
+        model = project.getModel();
+
+        RepositoryArtifactIndex index = getIndex();
+
+        String id = createId( groupId, artifactId, version );
+        List records = index.search( new LuceneQuery( new TermQuery( new Term( "dependencies", id ) ) ) );
+
+        Map dependees = new LinkedHashMap();
+
+        for ( Iterator i = records.iterator(); i.hasNext(); )
+        {
+            StandardArtifactIndexRecord record = (StandardArtifactIndexRecord) i.next();
+
+            String key = record.getGroupId() + ":" + record.getArtifactId();
+            if ( dependees.containsKey( key ) )
+            {
+                DependencyWrapper wrapper = (DependencyWrapper) dependees.get( key );
+                wrapper.addVersion( record.getVersion() );
+            }
+            else
+            {
+                DependencyWrapper wrapper = new DependencyWrapper( record );
+
+                dependees.put( key, wrapper );
+            }
+        }
+
+        dependencies = dependees.values();
 
         return SUCCESS;
     }
 
+    private static String createId( String groupId, String artifactId, String version )
+    {
+        return groupId + ":" + artifactId + ":" + version;
+    }
+
+    private RepositoryArtifactIndex getIndex()
+        throws ConfigurationStoreException, RepositoryIndexException
+    {
+        Configuration configuration = configurationStore.getConfigurationFromStore();
+        File indexPath = new File( configuration.getIndexPath() );
+
+        return factory.createStandardIndex( indexPath );
+    }
+
     private MavenProject readProject()
         throws ConfigurationStoreException, ProjectBuildingException
     {
@@ -149,7 +237,7 @@ public class ShowArtifactAction
         return model;
     }
 
-    public List getDependencies()
+    public Collection getDependencies()
     {
         return dependencies;
     }
@@ -183,4 +271,87 @@ public class ShowArtifactAction
     {
         this.version = version;
     }
+
+    public static class DependencyWrapper
+    {
+        private final String groupId;
+
+        private final String artifactId;
+
+        private List versions = new ArrayList();
+
+        private String version;
+
+        private String scope;
+
+        private String classifier;
+
+        public DependencyWrapper( StandardArtifactIndexRecord record )
+        {
+            this.groupId = record.getGroupId();
+
+            this.artifactId = record.getArtifactId();
+
+            addVersion( record.getVersion() );
+        }
+
+        public DependencyWrapper( Dependency dependency )
+        {
+            this.groupId = dependency.getGroupId();
+
+            this.artifactId = dependency.getArtifactId();
+
+            this.scope = dependency.getScope();
+
+            this.classifier = dependency.getClassifier();
+
+            addVersion( dependency.getVersion() );
+        }
+
+        public String getScope()
+        {
+            return scope;
+        }
+
+        public String getClassifier()
+        {
+            return classifier;
+        }
+
+        public void addVersion( String version )
+        {
+            versions.add( version );
+
+            if ( versions.size() == 1 )
+            {
+                this.version = version;
+            }
+            else
+            {
+                this.version = null;
+                // TODO: use version comparator!
+                Collections.sort( versions );
+            }
+        }
+
+        public String getGroupId()
+        {
+            return groupId;
+        }
+
+        public String getArtifactId()
+        {
+            return artifactId;
+        }
+
+        public List getVersions()
+        {
+            return versions;
+        }
+
+        public String getVersion()
+        {
+            return version;
+        }
+    }
 }
index 9ebb1471903e24bdbe523d24df85160f9c2cd7ed..73f3fd3dc1129f814b12688ea6f69894ebdd4875 100644 (file)
@@ -56,6 +56,11 @@ public class RepositoryActionMapper
             return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" +
                 params.remove( "version" ) + "/dependencies";
         }
+        else if ( "showArtifactDependees".equals( actionMapping.getName() ) )
+        {
+            return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" +
+                params.remove( "version" ) + "/dependedonby";
+        }
         else if ( "proxy".equals( actionMapping.getName() ) )
         {
             return PROXY_PREFIX + params.remove( "path" );
@@ -109,6 +114,10 @@ public class RepositoryActionMapper
                     {
                         return new ActionMapping( "showArtifactDependencies", "/", "", params );
                     }
+                    else if ( "dependedonby".equals( parts[3] ) )
+                    {
+                        return new ActionMapping( "showArtifactDependees", "/", "", params );
+                    }
                 }
             }
         }
index 6075bf321339b7d3a2591df29210fe8fc2c554d5..87f83ee666da80902dcefb7a9a98b780a82f58bd 100644 (file)
       <result>/WEB-INF/jsp/showArtifact.jsp</result>
     </action>
 
+    <action name="showArtifactDependees" class="showArtifactAction" method="dependees">
+      <result>/WEB-INF/jsp/showArtifact.jsp</result>
+    </action>
+
     <action name="proxy" class="proxyAction">
       <result type="stream">
         <param name="contentType">${contentType}</param>
index 95ee19f6710c9febd9d8c187862e374b877d1c10..5270423f5a574901afdedc5aa2d865b38ee26842 100644 (file)
     <ul>
       <ww:set name="versions" value="versions"/>
       <c:forEach items="${versions}" var="version">
-        <ww:url id="url" action="showArtifact" namespace="/">
-          <ww:param name="groupId" value="%{'${groupId}'}"/>
-          <ww:param name="artifactId" value="%{'${artifactId}'}"/>
-          <ww:param name="version" value="%{'${version}'}"/>
-        </ww:url>
+        <c:set var="url">
+          <ww:url action="showArtifact" namespace="/">
+            <ww:param name="groupId" value="%{'${groupId}'}"/>
+            <ww:param name="artifactId" value="%{'${artifactId}'}"/>
+            <ww:param name="version" value="%{'${version}'}"/>
+          </ww:url>
+        </c:set>
         <li><a href="${url}">${version}/</a></li>
       </c:forEach>
     </ul>
index 984425ccf1095459e763d0172902ef9a23dabe4b..140933ae568cd3481e67b44fcd3bede71354446d 100644 (file)
@@ -1,13 +1,19 @@
+<%@ taglib prefix="ww" uri="/webwork" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+<%-- TODO: paginate --%>
 <c:forEach items="${dependencies}" var="dependency">
   <h3>
     <c:set var="url">
       <ww:url action="showArtifact" namespace="/">
         <ww:param name="groupId" value="%{'${dependency.groupId}'}"/>
         <ww:param name="artifactId" value="%{'${dependency.artifactId}'}"/>
-        <ww:param name="version" value="%{'${dependency.version}'}"/>
+        <c:if test="${!empty(dependency.version)}">
+          <ww:param name="version" value="%{'${dependency.version}'}"/>
+        </c:if>
       </ww:url>
     </c:set>
-    <%-- TODO: showing the name and description would be nice, but that would require loading the POMs --%>
+      <%-- TODO: showing the name and description would be nice, but that would require loading the POMs --%>
     <a href="${url}">${dependency.artifactId}</a>
   </h3>
 
                 <a href="${url}">${part}</a> /
               </c:forTokens>
               <strong>${dependency.artifactId}</strong>
-              | <strong>Version(s):</strong> ${dependency.version}
+              | <strong>Version(s):</strong>
+              <c:choose>
+                <c:when test="${!empty(dependency.version)}">
+                  <c:set var="url">
+                    <ww:url action="showArtifact" namespace="/">
+                      <ww:param name="groupId" value="%{'${dependency.groupId}'}"/>
+                      <ww:param name="artifactId" value="%{'${dependency.artifactId}'}"/>
+                      <c:if test="${!empty(dependency.version)}">
+                        <ww:param name="version" value="%{'${dependency.version}'}"/>
+                      </c:if>
+                    </ww:url>
+                  </c:set>
+                  <a href="${url}">${dependency.version}</a>
+                </c:when>
+                <c:otherwise>
+                  <c:forEach items="${dependency.versions}" var="version" varStatus="i">
+                    <c:set var="url">
+                      <ww:url action="showArtifact" namespace="/">
+                        <ww:param name="groupId" value="%{'${dependency.groupId}'}"/>
+                        <ww:param name="artifactId" value="%{'${dependency.artifactId}'}"/>
+                        <ww:param name="version" value="%{'${version}'}"/>
+                      </ww:url>
+                    </c:set>
+                    <a href="${url}">${version}</a>
+                    <c:if test="${!i.last}">,</c:if>
+                  </c:forEach>
+                </c:otherwise>
+              </c:choose>
               <c:if test="${!empty(dependency.scope)}">
                 | <strong>Scope:</strong> ${dependency.scope}
               </c:if>
@@ -41,4 +74,7 @@
               </c:if>
             </span>
   </p>
-</c:forEach>
\ No newline at end of file
+</c:forEach>
+<c:if test="${empty(dependencies)}">
+  <strong>No results</strong>
+</c:if>
\ No newline at end of file
index 62630465a5d143b86f880ad25cf306f9ea22bdac..556c9142475012b1ceb8e57df069086e547aa026 100644 (file)
         </ww:url>
       </c:set>
       <my:currentWWUrl url="${url}">Dependencies</my:currentWWUrl>
+      <c:set var="url">
+        <ww:url action="showArtifactDependees">
+          <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}">Depended On By</my:currentWWUrl>
       <%-- TODO:
-          <a href="TODO">Depended On</a>
           <a href="TODO">Mailing Lists</a>
       --%>
     </p>
index fcc5cecb0a276b9732acb9297f3c6be541f2effd..98b5303f7c097aa3303cc2fb770fd8b520a66e65 100644 (file)
 <%@ attribute name="action" %>\r
 <%@ attribute name="namespace" %>\r
 <%@ attribute name="url" %>\r
+\r
 <c:set var="currentUrl">\r
   <ww:url/>\r
 </c:set>\r
-<c:if test="${empty(url)}">\r
+<c:if test="${!empty(action) && !empty(namespace)}">\r
   <c:set var="url">\r
     <ww:url action="${action}" namespace="${namespace}"/>\r
   </c:set>\r