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.
/**
* Search results.
*/
- private List searchResults;
+ private Collection searchResults;
/**
* @plexus.requirement
return INPUT;
}
+ searchResults = VersionMerger.merge(searchResults);
+
return SUCCESS;
}
this.md5 = md5;
}
- public List getSearchResults()
+ public Collection getSearchResults()
{
return searchResults;
}
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;
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;
}
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;
}
--- /dev/null
+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;
+ }
+ }
+}
<%-- 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>
</c:forEach>
<c:if test="${empty(dependencies)}">
<strong>No results</strong>
-</c:if>
\ No newline at end of file
+</c:if>
<%@ 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>
--- /dev/null
+<%--\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