*/
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;
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.
*/
private ConfigurationStore configurationStore;
+ /**
+ * @plexus.requirement
+ */
+ private RepositoryArtifactIndexFactory factory;
+
private String groupId;
private String artifactId;
private Model model;
- private List dependencies;
+ private Collection dependencies;
public String artifact()
throws ConfigurationStoreException, IOException, XmlPullParserException, ProjectBuildingException
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
{
return model;
}
- public List getDependencies()
+ public Collection getDependencies()
{
return dependencies;
}
{
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;
+ }
+ }
}
+<%@ 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>
</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