]> source.dussan.org Git - archiva.git/commitdiff
[MRM-130][MRM-201]Improve the search results page to look like and share code with...
authorEmmanuel Venisse <evenisse@apache.org>
Thu, 5 Oct 2006 20:19:57 +0000 (20:19 +0000)
committerEmmanuel Venisse <evenisse@apache.org>
Thu, 5 Oct 2006 20:19:57 +0000 (20:19 +0000)
Submitted by: Henry Yandell

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

archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java
archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/VersionMerger.java [new file with mode: 0644]
archiva-webapp/src/main/webapp/WEB-INF/jsp/include/artifactDependencies.jspf
archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp
archiva-webapp/src/main/webapp/WEB-INF/tags/showArtifactTitle.tag [new file with mode: 0644]

index 4f1f581d5bf06e39ed1db9627c60796871b4bb4e..9b573b652f54cc996ade949ae4518723443de55d 100644 (file)
@@ -32,10 +32,11 @@ import org.apache.maven.archiva.indexer.lucene.LuceneQuery;
 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 @@ public class SearchAction
     /**
      * Search results.
      */
-    private List searchResults;
+    private Collection searchResults;
 
     /**
      * @plexus.requirement
@@ -108,6 +109,8 @@ public class SearchAction
             return INPUT;
         }
 
+        searchResults = VersionMerger.merge(searchResults);
+
         return SUCCESS;
     }
 
@@ -178,7 +181,7 @@ public class SearchAction
         this.md5 = md5;
     }
 
-    public List getSearchResults()
+    public Collection getSearchResults()
     {
         return searchResults;
     }
index c89c2938325546b76e926d599319a210215f4471..7ca7cb81768f5691fbf5e80443c2e262a3c96664 100644 (file)
@@ -46,6 +46,7 @@ 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;
+import org.apache.maven.archiva.web.util.VersionMerger;
 
 import java.io.File;
 import java.io.IOException;
@@ -143,17 +144,7 @@ public class ShowArtifactAction
         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 @@ public class ShowArtifactAction
         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;
     }
diff --git a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/VersionMerger.java b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/VersionMerger.java
new file mode 100644 (file)
index 0000000..d74799f
--- /dev/null
@@ -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;
+        }
+    }
+}
index 3f15e6bed5166f796db4914c94e8223f258657af..3d77e35d8095cc5c192a1fce31b9d3112808a303 100644 (file)
@@ -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>
index 9ef4f69e3fbc16f86b280e9a6ac6328b56e166ec..65be89b1deaf8d4be4ce5568856c5296493d9217 100644 (file)
@@ -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>
 
 <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>
                 <a href="artifact.html">Details</a>
               </td>
               --%>
-          </tr>
+          </p>
         </c:forEach>
-      </table>
     </div>
-  </div>
 </div>
 </body>
 </html>
diff --git a/archiva-webapp/src/main/webapp/WEB-INF/tags/showArtifactTitle.tag b/archiva-webapp/src/main/webapp/WEB-INF/tags/showArtifactTitle.tag
new file mode 100644 (file)
index 0000000..0dc4375
--- /dev/null
@@ -0,0 +1,43 @@
+<%--\r
+  ~ Copyright 2005-2006 The Apache Software Foundation.\r
+  ~\r
+  ~ Licensed under the Apache License, Version 2.0 (the "License");\r
+  ~ you may not use this file except in compliance with the License.\r
+  ~ You may obtain a copy of the License at\r
+  ~\r
+  ~      http://www.apache.org/licenses/LICENSE-2.0\r
+  ~\r
+  ~ Unless required by applicable law or agreed to in writing, software\r
+  ~ distributed under the License is distributed on an "AS IS" BASIS,\r
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  ~ See the License for the specific language governing permissions and\r
+  ~ limitations under the License.\r
+  --%>\r
+\r
+<%@ taglib prefix="ww" uri="/webwork" %>\r
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>\r
+<%@ attribute name="groupId" required="true" %>\r
+<%@ attribute name="artifactId" %>\r
+<%@ attribute name="version" %>\r
+\r
+  <span class="artifact-title">\r
+    <c:set var="url">\r
+      <c:choose>\r
+        <c:when test="${!empty(version)}">\r
+          <ww:url action="showArtifact" namespace="/">\r
+            <ww:param name="groupId" value="%{'${groupId}'}"/>\r
+            <ww:param name="artifactId" value="%{'${artifactId}'}"/>\r
+            <ww:param name="version" value="%{'${version}'}"/>\r
+          </ww:url>\r
+        </c:when>\r
+        <c:otherwise>\r
+          <ww:url action="browseArtifact" namespace="/">\r
+            <ww:param name="groupId" value="%{'${groupId}'}"/>\r
+            <ww:param name="artifactId" value="%{'${artifactId}'}"/>\r
+          </ww:url>\r
+        </c:otherwise>\r
+      </c:choose>\r
+    </c:set>\r
+      <%-- TODO: showing the name and description would be nice, but that would require loading the POMs --%>\r
+    <a href="${url}">${artifactId}</a>\r
+  </span>\r