diff options
author | Emmanuel Venisse <evenisse@apache.org> | 2006-10-05 20:19:57 +0000 |
---|---|---|
committer | Emmanuel Venisse <evenisse@apache.org> | 2006-10-05 20:19:57 +0000 |
commit | d6da7571400f2da6bef30397d81bdf58d13fa32f (patch) | |
tree | 805ee560f9cec1bc0effdb77cb5b9399512d4815 | |
parent | fd29c31a300948181e25750d298edb2f4a122d45 (diff) | |
download | archiva-d6da7571400f2da6bef30397d81bdf58d13fa32f.tar.gz archiva-d6da7571400f2da6bef30397d81bdf58d13fa32f.zip |
[MRM-130][MRM-201]Improve the search results page to look like and share code with the dependency pages
Submitted by: Henry Yandell
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@453356 13f79535-47bb-0310-9956-ffa450edef68
6 files changed, 284 insertions, 80 deletions
diff --git a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java index 4f1f581d5..9b573b652 100644 --- a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java +++ b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java @@ -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; } diff --git a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java index c89c29383..7ca7cb817 100644 --- a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java +++ b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java @@ -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 index 000000000..d74799f70 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/VersionMerger.java @@ -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; + } + } +} diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/artifactDependencies.jspf b/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/artifactDependencies.jspf index 3f15e6bed..3d77e35d8 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/artifactDependencies.jspf +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/artifactDependencies.jspf @@ -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> diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp index 9ef4f69e3..65be89b1d 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp @@ -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> 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 index 000000000..0dc437515 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/tags/showArtifactTitle.tag @@ -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>
|