From 6dc709e9b98963760f513b8be7b2767addc54354 Mon Sep 17 00:00:00 2001
From: Brett Porter
Date: Sat, 26 Aug 2006 18:07:54 +0000
Subject: [PATCH] [MRM-131] add depended on by page
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@437197 13f79535-47bb-0310-9956-ffa450edef68
---
.../web/action/ShowArtifactAction.java | 177 +++++++++++++++++-
.../web/mapper/RepositoryActionMapper.java | 9 +
archiva-webapp/src/main/resources/xwork.xml | 4 +
.../webapp/WEB-INF/jsp/browseArtifact.jsp | 12 +-
.../jsp/include/artifactDependencies.jspf | 44 ++++-
.../main/webapp/WEB-INF/jsp/showArtifact.jsp | 9 +-
.../main/webapp/WEB-INF/tags/currentWWUrl.tag | 3 +-
7 files changed, 244 insertions(+), 14 deletions(-)
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 438934f6c..2b80de6d8 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
@@ -17,13 +17,22 @@ package org.apache.maven.archiva.web.action;
*/
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;
@@ -31,8 +40,15 @@ import org.apache.maven.project.ProjectBuildingException;
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.
@@ -62,6 +78,11 @@ public class ShowArtifactAction
*/
private ConfigurationStore configurationStore;
+ /**
+ * @plexus.requirement
+ */
+ private RepositoryArtifactIndexFactory factory;
+
private String groupId;
private String artifactId;
@@ -70,7 +91,7 @@ public class ShowArtifactAction
private Model model;
- private List dependencies;
+ private Collection dependencies;
public String artifact()
throws ConfigurationStoreException, IOException, XmlPullParserException, ProjectBuildingException
@@ -100,11 +121,78 @@ public class ShowArtifactAction
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
{
@@ -149,7 +237,7 @@ public class ShowArtifactAction
return model;
}
- public List getDependencies()
+ public Collection getDependencies()
{
return dependencies;
}
@@ -183,4 +271,87 @@ public class ShowArtifactAction
{
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;
+ }
+ }
}
diff --git a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/mapper/RepositoryActionMapper.java b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/mapper/RepositoryActionMapper.java
index 9ebb14719..73f3fd3dc 100644
--- a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/mapper/RepositoryActionMapper.java
+++ b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/mapper/RepositoryActionMapper.java
@@ -56,6 +56,11 @@ public class RepositoryActionMapper
return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" +
params.remove( "version" ) + "/dependencies";
}
+ else if ( "showArtifactDependees".equals( actionMapping.getName() ) )
+ {
+ return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" +
+ params.remove( "version" ) + "/dependedonby";
+ }
else if ( "proxy".equals( actionMapping.getName() ) )
{
return PROXY_PREFIX + params.remove( "path" );
@@ -109,6 +114,10 @@ public class RepositoryActionMapper
{
return new ActionMapping( "showArtifactDependencies", "/", "", params );
}
+ else if ( "dependedonby".equals( parts[3] ) )
+ {
+ return new ActionMapping( "showArtifactDependees", "/", "", params );
+ }
}
}
}
diff --git a/archiva-webapp/src/main/resources/xwork.xml b/archiva-webapp/src/main/resources/xwork.xml
index 6075bf321..87f83ee66 100644
--- a/archiva-webapp/src/main/resources/xwork.xml
+++ b/archiva-webapp/src/main/resources/xwork.xml
@@ -115,6 +115,10 @@
/WEB-INF/jsp/showArtifact.jsp
+
+ /WEB-INF/jsp/showArtifact.jsp
+
+
${contentType}
diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/browseArtifact.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/browseArtifact.jsp
index 95ee19f67..5270423f5 100644
--- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/browseArtifact.jsp
+++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/browseArtifact.jsp
@@ -53,11 +53,13 @@
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 984425ccf..140933ae5 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
@@ -1,13 +1,19 @@
+<%@ taglib prefix="ww" uri="/webwork" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+<%-- TODO: paginate --%>
-
+
+
+
- <%-- 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 --%>
${dependency.artifactId}
@@ -32,7 +38,34 @@
${part} /
${dependency.artifactId}
- | Version(s): ${dependency.version}
+ | Version(s):
+
+
+
+
+
+
+
+
+
+
+
+ ${dependency.version}
+
+
+
+
+
+
+
+
+
+
+ ${version}
+ ,
+
+
+
| Scope: ${dependency.scope}
@@ -41,4 +74,7 @@
-
\ No newline at end of file
+
+
+ No results
+
\ No newline at end of file
diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp
index 62630465a..556c91424 100644
--- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp
+++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp
@@ -67,8 +67,15 @@
Dependencies
+
+
+
+
+
+
+
+ Depended On By
<%-- TODO:
- Depended On
Mailing Lists
--%>
diff --git a/archiva-webapp/src/main/webapp/WEB-INF/tags/currentWWUrl.tag b/archiva-webapp/src/main/webapp/WEB-INF/tags/currentWWUrl.tag
index fcc5cecb0..98b5303f7 100644
--- a/archiva-webapp/src/main/webapp/WEB-INF/tags/currentWWUrl.tag
+++ b/archiva-webapp/src/main/webapp/WEB-INF/tags/currentWWUrl.tag
@@ -19,10 +19,11 @@
<%@ attribute name="action" %>
<%@ attribute name="namespace" %>
<%@ attribute name="url" %>
+
-
+
--
2.39.5