You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ev...@apache.org on 2006/10/05 22:19:58 UTC

svn commit: r453356 - in /maven/archiva/trunk/archiva-webapp/src/main: java/org/apache/maven/archiva/web/action/ java/org/apache/maven/archiva/web/util/ webapp/WEB-INF/jsp/ webapp/WEB-INF/jsp/include/ webapp/WEB-INF/tags/

Author: evenisse
Date: Thu Oct  5 13:19:57 2006
New Revision: 453356

URL: http://svn.apache.org/viewvc?view=rev&rev=453356
Log:
[MRM-130][MRM-201]Improve the search results page to look like and share code with the dependency pages
Submitted by: Henry Yandell

Added:
    maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/VersionMerger.java   (with props)
    maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/tags/showArtifactTitle.tag
Modified:
    maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java
    maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
    maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/artifactDependencies.jspf
    maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp

Modified: maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java?view=diff&rev=453356&r1=453355&r2=453356
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java (original)
+++ maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java Thu Oct  5 13:19:57 2006
@@ -32,10 +32,11 @@
 import org.apache.maven.archiva.indexer.lucene.LuceneRepositoryArtifactIndex;
 import org.apache.maven.archiva.indexer.record.StandardIndexRecordFields;
 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
+import org.apache.maven.archiva.web.util.VersionMerger;
 
 import java.io.File;
 import java.net.MalformedURLException;
-import java.util.List;
+import java.util.Collection;
 
 /**
  * Search all indexed fields by the given criteria.
@@ -58,7 +59,7 @@
     /**
      * Search results.
      */
-    private List searchResults;
+    private Collection searchResults;
 
     /**
      * @plexus.requirement
@@ -108,6 +109,8 @@
             return INPUT;
         }
 
+        searchResults = VersionMerger.merge(searchResults);
+
         return SUCCESS;
     }
 
@@ -178,7 +181,7 @@
         this.md5 = md5;
     }
 
-    public List getSearchResults()
+    public Collection getSearchResults()
     {
         return searchResults;
     }

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=453356&r1=453355&r2=453356
==============================================================================
--- 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 Thu Oct  5 13:19:57 2006
@@ -46,6 +46,7 @@
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
+import org.apache.maven.archiva.web.util.VersionMerger;
 
 import java.io.File;
 import java.io.IOException;
@@ -143,17 +144,7 @@
         model = project.getModel();
 
         // TODO: should this be the whole set of artifacts, and be more like the maven dependencies report?
-
-        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;
+        this.dependencies = VersionMerger.wrap(project.getModel().getDependencies());
 
         return SUCCESS;
     }
@@ -176,27 +167,7 @@
         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();
+        dependencies = VersionMerger.merge(records);
 
         return SUCCESS;
     }

Added: maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/VersionMerger.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/VersionMerger.java?view=auto&rev=453356
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/VersionMerger.java (added)
+++ maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/VersionMerger.java Thu Oct  5 13:19:57 2006
@@ -0,0 +1,212 @@
+package org.apache.maven.archiva.web.util;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.model.Dependency;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.apache.maven.archiva.indexer.record.StandardArtifactIndexRecord;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+public class VersionMerger {
+
+    public static List /*<DependencyWrapper>*/ wrap(List /*<StandardArtifactIndexRecord>*/ artifacts) 
+    {
+        List dependencies = new ArrayList();
+
+        for ( Iterator i = artifacts.iterator(); i.hasNext(); )
+        {
+            Dependency dependency = (Dependency) i.next();
+
+            dependencies.add( new DependencyWrapper( dependency ) );
+        }
+
+        return dependencies;
+    }
+
+    public static Collection /*<DependencyWrapper*/ merge(Collection /*<StandardArtifactIndexRecord>*/ artifacts) 
+    {
+        Map dependees = new LinkedHashMap();
+
+        for ( Iterator i = artifacts.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 );
+            }
+        }
+
+        return dependees.values();
+    }
+
+    public static class DependencyWrapper
+    {
+        private final String groupId;
+
+        private final String artifactId;
+
+        /**
+         * Versions added. We ignore duplicates since you might add those with varying classifiers.
+         */
+        private Set versions = new HashSet();
+
+        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 )
+        {
+            // We use DefaultArtifactVersion to get the correct sorting order later, however it does not have
+            // hashCode properly implemented, so we add it here.
+            // TODO: add these methods to the actual DefaultArtifactVersion and use that.
+            versions.add( new DefaultArtifactVersion( version )
+            {
+                public int hashCode()
+                {
+                    int result;
+                    result = getBuildNumber();
+                    result = 31 * result + getMajorVersion();
+                    result = 31 * result + getMinorVersion();
+                    result = 31 * result + getIncrementalVersion();
+                    result = 31 * result + ( getQualifier() != null ? getQualifier().hashCode() : 0 );
+                    return result;
+                }
+
+                public boolean equals( Object o )
+                {
+                    if ( this == o )
+                    {
+                        return true;
+                    }
+                    if ( o == null || getClass() != o.getClass() )
+                    {
+                        return false;
+                    }
+
+                    DefaultArtifactVersion that = (DefaultArtifactVersion) o;
+
+                    if ( getBuildNumber() != that.getBuildNumber() )
+                    {
+                        return false;
+                    }
+                    if ( getIncrementalVersion() != that.getIncrementalVersion() )
+                    {
+                        return false;
+                    }
+                    if ( getMajorVersion() != that.getMajorVersion() )
+                    {
+                        return false;
+                    }
+                    if ( getMinorVersion() != that.getMinorVersion() )
+                    {
+                        return false;
+                    }
+                    if ( getQualifier() != null ? !getQualifier().equals( that.getQualifier() )
+                        : that.getQualifier() != null )
+                    {
+                        return false;
+                    }
+
+                    return true;
+                }
+            } );
+
+            if ( versions.size() == 1 )
+            {
+                this.version = version;
+            }
+            else
+            {
+                this.version = null;
+            }
+        }
+
+        public String getGroupId()
+        {
+            return groupId;
+        }
+
+        public String getArtifactId()
+        {
+            return artifactId;
+        }
+
+        public List getVersions()
+        {
+            List versions = new ArrayList( this.versions );
+            Collections.sort( versions );
+            return versions;
+        }
+
+        public String getVersion()
+        {
+            return version;
+        }
+    }
+}

Propchange: maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/VersionMerger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/VersionMerger.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/artifactDependencies.jspf
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/artifactDependencies.jspf?view=diff&rev=453356&r1=453355&r2=453356
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/artifactDependencies.jspf (original)
+++ maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/artifactDependencies.jspf Thu Oct  5 13:19:57 2006
@@ -5,25 +5,9 @@
 <%-- TODO: paginate! --%>
 <c:forEach items="${dependencies}" var="dependency">
   <h3>
-    <c:set var="url">
-      <c:choose>
-        <c:when test="${!empty(dependency.version)}">
-          <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}'}"/>
-          </ww:url>
-        </c:when>
-        <c:otherwise>
-          <ww:url action="browseArtifact" namespace="/">
-            <ww:param name="groupId" value="%{'${dependency.groupId}'}"/>
-            <ww:param name="artifactId" value="%{'${dependency.artifactId}'}"/>
-          </ww:url>
-        </c:otherwise>
-      </c:choose>
-    </c:set>
-      <%-- TODO: showing the name and description would be nice, but that would require loading the POMs --%>
-    <a href="${url}">${dependency.artifactId}</a>
+    <my:showArtifactTitle groupId="${dependency.groupId}" artifactId="${dependency.artifactId}"
+                          version="${dependency.version}"/>
+                         
   </h3>
 
   <p>
@@ -34,4 +18,4 @@
 </c:forEach>
 <c:if test="${empty(dependencies)}">
   <strong>No results</strong>
-</c:if>
\ No newline at end of file
+</c:if>

Modified: maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp?view=diff&rev=453356&r1=453355&r2=453356
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp (original)
+++ maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp Thu Oct  5 13:19:57 2006
@@ -16,6 +16,7 @@
 
 <%@ taglib uri="/webwork" prefix="ww" %>
 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
 
 <html>
 <head>
@@ -25,37 +26,29 @@
 
 <body>
 
-<h1>Search Results</h1>
+<h1>Search</h1>
 
 <div id="contentArea">
   <div id="searchBox">
     <%@ include file="/WEB-INF/jsp/include/quickSearchForm.jspf" %>
+  </div>
 
+    <h1>Results</h1>
     <div id="resultsBox">
-      <table class="bodyTable">
-        <tr class="a">
-          <th>Group</th>
-          <th>Artifact</th>
-          <th>Version</th>
-          <%-- TODO
-                    <th>Hits</th>
-                    <th></th>
-          --%>
-        </tr>
         <ww:set name="searchResults" value="searchResults" />
         <c:forEach items="${searchResults}" var="record" varStatus="i">
-          <tr class="${i.index % 2 == 0 ? "b" : "a"}">
-            <td>
-              <c:out value="${record.groupId}" />
-            </td>
-            <td>
-              <c:out value="${record.artifactId}" />
-            </td>
-            <td>
-              <c:out value="${record.version}" />
-            </td>
+
+
+          <h3 class="artifact-title">
+            <my:showArtifactTitle groupId="${record.groupId}" artifactId="${record.artifactId}"
+                                  version="${record.version}"/>
+          </h3>
+
+          <p>
+          <my:showArtifactLink groupId="${record.groupId}" artifactId="${record.artifactId}" 
+                               version="${record.version}" versions="${record.versions}"/>
+
               <%-- TODO: hits
-            <td>
               <table border="1px" width="100%" cellspacing="0">
                 <c:forEach items="${result.fieldMatchesEntrySet}" var="entry">
                   <tr>
@@ -82,11 +75,9 @@
                 <a href="artifact.html">Details</a>
               </td>
               --%>
-          </tr>
+          </p>
         </c:forEach>
-      </table>
     </div>
-  </div>
 </div>
 </body>
 </html>

Added: maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/tags/showArtifactTitle.tag
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/tags/showArtifactTitle.tag?view=auto&rev=453356
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/tags/showArtifactTitle.tag (added)
+++ maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/tags/showArtifactTitle.tag Thu Oct  5 13:19:57 2006
@@ -0,0 +1,43 @@
+<%--
+  ~ 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 uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ attribute name="groupId" required="true" %>
+<%@ attribute name="artifactId" %>
+<%@ attribute name="version" %>
+
+  <span class="artifact-title">
+    <c:set var="url">
+      <c:choose>
+        <c:when test="${!empty(version)}">
+          <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:when>
+        <c:otherwise>
+          <ww:url action="browseArtifact" namespace="/">
+            <ww:param name="groupId" value="%{'${groupId}'}"/>
+            <ww:param name="artifactId" value="%{'${artifactId}'}"/>
+          </ww:url>
+        </c:otherwise>
+      </c:choose>
+    </c:set>
+      <%-- TODO: showing the name and description would be nice, but that would require loading the POMs --%>
+    <a href="${url}">${artifactId}</a>
+  </span>