mirror of https://github.com/apache/archiva.git
[MRM-560] Dependency Tree causes an Exception.
Prevented complete collapse of DependencyTree tab when an exception occurs. Provide more details if there was a problem creating the graph. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@588808 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
40001e82b1
commit
1b44cd6cc1
|
@ -20,6 +20,7 @@ package org.apache.maven.archiva.web.tags;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.maven.archiva.common.ArchivaException;
|
||||||
import org.apache.maven.archiva.dependency.DependencyGraphFactory;
|
import org.apache.maven.archiva.dependency.DependencyGraphFactory;
|
||||||
import org.apache.maven.archiva.dependency.graph.DependencyGraph;
|
import org.apache.maven.archiva.dependency.graph.DependencyGraph;
|
||||||
import org.apache.maven.archiva.dependency.graph.DependencyGraphBuilder;
|
import org.apache.maven.archiva.dependency.graph.DependencyGraphBuilder;
|
||||||
|
@ -31,6 +32,7 @@ import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphWalker;
|
||||||
import org.apache.maven.archiva.dependency.graph.walk.WalkDepthFirstSearch;
|
import org.apache.maven.archiva.dependency.graph.walk.WalkDepthFirstSearch;
|
||||||
import org.apache.maven.archiva.model.ArtifactReference;
|
import org.apache.maven.archiva.model.ArtifactReference;
|
||||||
import org.apache.maven.archiva.model.DependencyScope;
|
import org.apache.maven.archiva.model.DependencyScope;
|
||||||
|
import org.apache.maven.archiva.model.Keys;
|
||||||
import org.apache.maven.archiva.model.VersionedReference;
|
import org.apache.maven.archiva.model.VersionedReference;
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||||
|
@ -40,7 +42,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import javax.servlet.jsp.JspException;
|
|
||||||
import javax.servlet.jsp.PageContext;
|
import javax.servlet.jsp.PageContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,22 +114,38 @@ public class DependencyTree
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List gatherTreeList( String groupId, String artifactId, String modelVersion, String nodevar,
|
public List<TreeEntry> gatherTreeList( String groupId, String artifactId, String modelVersion, String nodevar,
|
||||||
PageContext pageContext )
|
PageContext pageContext ) throws ArchivaException
|
||||||
throws JspException
|
|
||||||
{
|
{
|
||||||
if ( StringUtils.isBlank( groupId ) )
|
if ( StringUtils.isBlank( groupId ) )
|
||||||
{
|
{
|
||||||
String emsg = "Error generating dependency tree: groupId is blank.";
|
String emsg = "Error generating dependency tree [" + Keys.toKey( groupId, artifactId, modelVersion )
|
||||||
|
+ "]: groupId is blank.";
|
||||||
getLogger().error( emsg );
|
getLogger().error( emsg );
|
||||||
throw new JspException( emsg );
|
throw new ArchivaException( emsg );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( StringUtils.isBlank( artifactId ) )
|
||||||
|
{
|
||||||
|
String emsg = "Error generating dependency tree [" + Keys.toKey( groupId, artifactId, modelVersion )
|
||||||
|
+ "]: artifactId is blank.";
|
||||||
|
getLogger().error( emsg );
|
||||||
|
throw new ArchivaException( emsg );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( StringUtils.isBlank( modelVersion ) )
|
||||||
|
{
|
||||||
|
String emsg = "Error generating dependency tree [" + Keys.toKey( groupId, artifactId, modelVersion )
|
||||||
|
+ "]: version is blank.";
|
||||||
|
getLogger().error( emsg );
|
||||||
|
throw new ArchivaException( emsg );
|
||||||
}
|
}
|
||||||
|
|
||||||
DependencyGraph graph = fetchGraph( groupId, artifactId, modelVersion );
|
DependencyGraph graph = fetchGraph( groupId, artifactId, modelVersion );
|
||||||
|
|
||||||
if ( graph == null )
|
if ( graph == null )
|
||||||
{
|
{
|
||||||
throw new JspException( "Graph is null." );
|
throw new ArchivaException( "Graph is unexpectedly null." );
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeListVisitor treeListVisitor = new TreeListVisitor();
|
TreeListVisitor treeListVisitor = new TreeListVisitor();
|
||||||
|
@ -141,22 +158,22 @@ public class DependencyTree
|
||||||
class TreeListVisitor
|
class TreeListVisitor
|
||||||
extends BaseVisitor
|
extends BaseVisitor
|
||||||
{
|
{
|
||||||
private List list;
|
private List<TreeEntry> list;
|
||||||
|
|
||||||
private int walkDepth;
|
private int walkDepth;
|
||||||
|
|
||||||
private int outputDepth;
|
private int outputDepth;
|
||||||
|
|
||||||
private Stack entryStack = new Stack();
|
private Stack<TreeEntry> entryStack = new Stack<TreeEntry>();
|
||||||
|
|
||||||
private TreeEntry currentEntry;
|
private TreeEntry currentEntry;
|
||||||
|
|
||||||
public TreeListVisitor()
|
public TreeListVisitor()
|
||||||
{
|
{
|
||||||
this.list = new ArrayList();
|
this.list = new ArrayList<TreeEntry>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getList()
|
public List<TreeEntry> getList()
|
||||||
{
|
{
|
||||||
return this.list;
|
return this.list;
|
||||||
}
|
}
|
||||||
|
@ -214,6 +231,7 @@ public class DependencyTree
|
||||||
}
|
}
|
||||||
|
|
||||||
private DependencyGraph fetchGraph( String groupId, String artifactId, String modelVersion )
|
private DependencyGraph fetchGraph( String groupId, String artifactId, String modelVersion )
|
||||||
|
throws ArchivaException
|
||||||
{
|
{
|
||||||
// TODO Cache the results to disk, in XML format, in the same place as the artifact is located.
|
// TODO Cache the results to disk, in XML format, in the same place as the artifact is located.
|
||||||
|
|
||||||
|
@ -225,13 +243,14 @@ public class DependencyTree
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DependencyGraph depGraph = graphFactory.getGraph( projectRef );
|
DependencyGraph depGraph = graphFactory.getGraph( projectRef );
|
||||||
|
|
||||||
return depGraph;
|
return depGraph;
|
||||||
}
|
}
|
||||||
catch ( GraphTaskException e )
|
catch ( GraphTaskException e )
|
||||||
{
|
{
|
||||||
getLogger().warn( "Unable to get Graph: " + e.getMessage(), e );
|
String emsg = "Unable to generate graph for [" + Keys.toKey( projectRef ) + "] : " + e.getMessage();
|
||||||
return null;
|
getLogger().warn( emsg, e );
|
||||||
|
throw new ArchivaException( emsg, e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,14 @@ package org.apache.maven.archiva.web.tags;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.collections.IteratorUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.maven.archiva.common.ArchivaException;
|
||||||
import org.apache.maven.archiva.web.tags.DependencyTree.TreeEntry;
|
import org.apache.maven.archiva.web.tags.DependencyTree.TreeEntry;
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -64,7 +67,7 @@ public class DependencyTreeTag
|
||||||
|
|
||||||
private Iterator treeIterator;
|
private Iterator treeIterator;
|
||||||
|
|
||||||
private List tree;
|
private List<TreeEntry> tree;
|
||||||
|
|
||||||
private TreeEntry currentTreeEntry;
|
private TreeEntry currentTreeEntry;
|
||||||
|
|
||||||
|
@ -125,20 +128,30 @@ public class DependencyTreeTag
|
||||||
nodevar = "node";
|
nodevar = "node";
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tree = deptree.gatherTreeList( groupId, artifactId, modelVersion, nodevar, pageContext );
|
|
||||||
|
|
||||||
if ( CollectionUtils.isEmpty( this.tree ) )
|
|
||||||
{
|
|
||||||
return SKIP_BODY;
|
|
||||||
}
|
|
||||||
|
|
||||||
treeIterator = tree.iterator();
|
|
||||||
|
|
||||||
out( "<div class=\"dependency-graph\">" );
|
out( "<div class=\"dependency-graph\">" );
|
||||||
|
try
|
||||||
currentTreeEntry = (TreeEntry) treeIterator.next();
|
{
|
||||||
out( currentTreeEntry.getPre() );
|
this.tree = deptree.gatherTreeList( groupId, artifactId, modelVersion, nodevar, pageContext );
|
||||||
exposeVariables();
|
|
||||||
|
if ( CollectionUtils.isEmpty( this.tree ) )
|
||||||
|
{
|
||||||
|
return SKIP_BODY;
|
||||||
|
}
|
||||||
|
|
||||||
|
treeIterator = tree.iterator();
|
||||||
|
|
||||||
|
currentTreeEntry = (TreeEntry) treeIterator.next();
|
||||||
|
out( currentTreeEntry.getPre() );
|
||||||
|
exposeVariables();
|
||||||
|
}
|
||||||
|
catch ( ArchivaException e )
|
||||||
|
{
|
||||||
|
treeIterator = IteratorUtils.EMPTY_LIST_ITERATOR;
|
||||||
|
|
||||||
|
out("<pre>");
|
||||||
|
e.printStackTrace( new PrintWriter( pageContext.getOut() ) );
|
||||||
|
out("</pre>");
|
||||||
|
}
|
||||||
|
|
||||||
return EVAL_BODY_INCLUDE;
|
return EVAL_BODY_INCLUDE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue