diff options
author | Brett Porter <brett@apache.org> | 2006-09-18 01:40:26 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2006-09-18 01:40:26 +0000 |
commit | d9d167c5c35b9c71f911f763bd043f67246d6859 (patch) | |
tree | 3f671f5beb5a10f73184a8aea2837182d9ce9dc1 /archiva-webapp | |
parent | 18c7e96632543d5005dc7805b5d229fde5c38e1e (diff) | |
download | archiva-d9d167c5c35b9c71f911f763bd043f67246d6859.tar.gz archiva-d9d167c5c35b9c71f911f763bd043f67246d6859.zip |
Add a tab for dependency tree
Submitted by: Pete Marvin King (with modifications)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@447183 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-webapp')
6 files changed, 175 insertions, 18 deletions
diff --git a/archiva-webapp/pom.xml b/archiva-webapp/pom.xml index a36ff7e67..91753eb4c 100644 --- a/archiva-webapp/pom.xml +++ b/archiva-webapp/pom.xml @@ -111,6 +111,17 @@ <groupId>org.apache.maven</groupId> <artifactId>maven-project</artifactId> </dependency> + <dependency> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-project-info-reports-plugin</artifactId> + <version>2.1-SNAPSHOT</version> + <exclusions> + <exclusion> + <groupId>plexus</groupId> + <artifactId>plexus-utils</artifactId> + </exclusion> + </exclusions> + </dependency> <!-- Plexus Security Dependencies --> <dependency> <groupId>org.codehaus.plexus.security</groupId> @@ -157,7 +168,7 @@ <artifactId>plexus-security-authorization-rbac-authorizer</artifactId> <version>1.0-SNAPSHOT</version> </dependency> - <dependency> + <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-jdo2</artifactId> <version>1.0-alpha-7-SNAPSHOT</version> @@ -176,8 +187,8 @@ <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-utils</artifactId> <version>1.2</version> - </dependency> - <dependency> + </dependency> + <dependency> <groupId>org.apache.derby</groupId> <artifactId>derby</artifactId> <version>10.1.2.1</version> 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 eb9ea5dab..c89c29383 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 @@ -30,13 +30,19 @@ 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.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactCollector; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; 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.apache.maven.project.ProjectBuildingException; +import org.apache.maven.project.artifact.InvalidDependencyVersionException; +import org.apache.maven.report.projectinfo.dependencies.Dependencies; +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; @@ -49,6 +55,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -86,6 +93,16 @@ public class ShowArtifactAction */ private RepositoryArtifactIndexFactory factory; + /** + * @plexus.requirement + */ + private ArtifactMetadataSource artifactMetadataSource; + + /** + * @plexus.requirement + */ + private ArtifactCollector collector; + private String groupId; private String artifactId; @@ -96,6 +113,8 @@ public class ShowArtifactAction private Collection dependencies; + private List dependencyTree; + public String artifact() throws ConfigurationStoreException, IOException, XmlPullParserException, ProjectBuildingException { @@ -182,6 +201,65 @@ public class ShowArtifactAction return SUCCESS; } + public String dependencyTree() + throws ConfigurationStoreException, ProjectBuildingException, InvalidDependencyVersionException, + ArtifactResolutionException + { + if ( !checkParameters() ) + { + return ERROR; + } + + Configuration configuration = configurationStore.getConfigurationFromStore(); + List repositories = repositoryFactory.createRepositories( configuration ); + + Artifact artifact = artifactFactory.createProjectArtifact( groupId, artifactId, version ); + // TODO: maybe we can decouple the assembly parts of the project builder from the repository handling to get rid of the temp repo + ArtifactRepository localRepository = repositoryFactory.createLocalRepository( configuration ); + MavenProject project = projectBuilder.buildFromRepository( artifact, repositories, localRepository ); + + model = project.getModel(); + + getLogger().debug( " processing : " + groupId + ":" + artifactId + ":" + version ); + + Dependencies dependencies = + collectDependencies( project, artifact, localRepository, repositories ); + + dependencyTree = new LinkedList(); + populateFlatTreeList( dependencies.getResolvedRoot(), dependencyTree ); + + return SUCCESS; + } + + private void populateFlatTreeList( ReportResolutionListener.Node currentNode, List dependencyList ) + { + ReportResolutionListener.Node childNode; + + for ( Iterator iterator = currentNode.getChildren().iterator(); iterator.hasNext(); ) + { + childNode = (ReportResolutionListener.Node) iterator.next(); + dependencyList.add( childNode ); + populateFlatTreeList( childNode, dependencyList ); + } + } + + private Dependencies collectDependencies( MavenProject project, Artifact artifact, + ArtifactRepository localRepository, List repositories ) + throws ArtifactResolutionException, ProjectBuildingException, InvalidDependencyVersionException, + ConfigurationStoreException + { + Map managedDependencyMap = Dependencies.getManagedVersionMap( project, artifactFactory ); + + ReportResolutionListener listener = new ReportResolutionListener(); + + project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) ); + + collector.collect( project.getDependencyArtifacts(), artifact, managedDependencyMap, localRepository, + repositories, artifactMetadataSource, null, Collections.singletonList( listener ) ); + + return new Dependencies( project, listener, null ); + } + private static String createId( String groupId, String artifactId, String version ) { return groupId + ":" + artifactId + ":" + version; @@ -245,6 +323,11 @@ public class ShowArtifactAction return dependencies; } + public List getDependencyTree() + { + return dependencyTree; + } + public String getGroupId() { return groupId; @@ -324,21 +407,6 @@ public class ShowArtifactAction return classifier; } - private static class Ver - { - private int buildNumber; - - private int major; - - private int minor; - - private int incremental; - - private String qualifier; - - - } - public void addVersion( String version ) { // We use DefaultArtifactVersion to get the correct sorting order later, however it does not have 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 73f3fd3dc..60aa8ada9 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 @@ -61,6 +61,11 @@ public class RepositoryActionMapper return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" + params.remove( "version" ) + "/dependedonby"; } + else if ( "showArtifactDependencyTree".equals( actionMapping.getName() ) ) + { + return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" + + params.remove( "version" ) + "/dependencyTree"; + } else if ( "proxy".equals( actionMapping.getName() ) ) { return PROXY_PREFIX + params.remove( "path" ); @@ -118,6 +123,10 @@ public class RepositoryActionMapper { return new ActionMapping( "showArtifactDependees", "/", "", params ); } + else if ( "dependencyTree".equals( parts[3] ) ) + { + return new ActionMapping( "showArtifactDependencyTree", "/", "", params ); + } } } } diff --git a/archiva-webapp/src/main/resources/xwork.xml b/archiva-webapp/src/main/resources/xwork.xml index 4b5cda060..c2bb8b421 100644 --- a/archiva-webapp/src/main/resources/xwork.xml +++ b/archiva-webapp/src/main/resources/xwork.xml @@ -133,6 +133,10 @@ <action name="showArtifactDependees" class="showArtifactAction" method="dependees"> <result>/WEB-INF/jsp/showArtifact.jsp</result> </action> + + <action name="showArtifactDependencyTree" class="showArtifactAction" method="dependencyTree"> + <result>/WEB-INF/jsp/showArtifact.jsp</result> + </action> <action name="proxy" class="proxyAction"> <result type="stream"> diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/dependencyTree.jspf b/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/dependencyTree.jspf new file mode 100644 index 000000000..a86b779a3 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/dependencyTree.jspf @@ -0,0 +1,54 @@ +<%-- + ~ 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 prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %> + + +<ul> + <c:set var="prevDepth" value="1"/> + <ww:set name="dependencyTree" value="dependencyTree"/> + <c:forEach items="${dependencyTree}" var="node"> + <c:choose> + <c:when test="${node.depth < prevDepth}"> + </ul> + <li> + </c:when> + <c:when test="${node.depth > prevDepth}"> + <ul> + <li> + </c:when> + <c:otherwise> + <li> + </c:otherwise> + </c:choose> + <c:set var="url"> + <ww:url action="showArtifact" namespace="/"> + <ww:param name="groupId" value="%{'${node.artifact.groupId}'}"/> + <ww:param name="artifactId" value="%{'${node.artifact.artifactId}'}"/> + <ww:param name="version" value="%{'${node.artifact.version}'}"/> + </ww:url> + </c:set> + <a href="${url}"> + <%-- TODO! show this like the other dependencies: g / g1 / g2 / artifactId / version --%> + <c:out value="${node.artifact.dependencyConflictId}"/> + </a> + </li> + <c:set var="prevDepth" value="${node.depth}" /> + </c:forEach> +</ul> +
\ 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 d05ce8586..2747ab0b7 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp @@ -103,6 +103,14 @@ </c:set> <my:currentWWUrl url="${url}">Dependencies</my:currentWWUrl> <c:set var="url"> + <ww:url action="showArtifactDependencyTree"> + <ww:param name="groupId" value="%{groupId}"/> + <ww:param name="artifactId" value="%{artifactId}"/> + <ww:param name="version" value="%{version}"/> + </ww:url> + </c:set> + <my:currentWWUrl url="${url}">Dependency Tree</my:currentWWUrl> + <c:set var="url"> <ww:url action="showArtifactDependees"> <ww:param name="groupId" value="%{groupId}"/> <ww:param name="artifactId" value="%{artifactId}"/> @@ -123,6 +131,9 @@ <c:when test="${dependencies != null}"> <%@ include file="/WEB-INF/jsp/include/artifactDependencies.jspf" %> </c:when> + <c:when test="${dependencyTree != null}"> + <%@ include file="/WEB-INF/jsp/include/dependencyTree.jspf" %> + </c:when> <c:otherwise> <%@ include file="/WEB-INF/jsp/include/artifactInfo.jspf" %> </c:otherwise> |