fix dependency tree calculation

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1303924 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-03-22 17:53:03 +00:00
parent e9cb197863
commit 4f0deeb78b
2 changed files with 38 additions and 33 deletions

View File

@ -18,6 +18,8 @@ package org.apache.archiva.rest.api.model;
* under the License. * under the License.
*/ */
import org.codehaus.jackson.annotate.JsonIgnore;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
@ -33,9 +35,11 @@ public class TreeEntry
private List<TreeEntry> childs = new ArrayList<TreeEntry>(); private List<TreeEntry> childs = new ArrayList<TreeEntry>();
private Artifact artifact; private Artifact artifact;
@JsonIgnore
private TreeEntry parent;
public TreeEntry() public TreeEntry()
{ {
// no op // no op
@ -66,4 +70,16 @@ public class TreeEntry
{ {
this.childs = childs; this.childs = childs;
} }
@JsonIgnore
public TreeEntry getParent()
{
return parent;
}
@JsonIgnore
public void setParent( TreeEntry parent )
{
this.parent = parent;
}
} }

View File

@ -510,12 +510,17 @@ public class DefaultBrowseService
private static class TreeDependencyNodeVisitor private static class TreeDependencyNodeVisitor
implements DependencyNodeVisitor implements DependencyNodeVisitor
{ {
final List<TreeEntry> treeEntries; final List<TreeEntry> treeEntries;
private TreeEntry currentEntry; private TreeEntry currentEntry;
private DependencyNode firstNode; private DependencyNode firstNode;
boolean firstChild = true;
private TreeDependencyNodeVisitor( List<TreeEntry> treeEntries ) private TreeDependencyNodeVisitor( List<TreeEntry> treeEntries )
{ {
this.treeEntries = treeEntries; this.treeEntries = treeEntries;
@ -523,51 +528,35 @@ public class DefaultBrowseService
public boolean visit( DependencyNode node ) public boolean visit( DependencyNode node )
{ {
TreeEntry entry = new TreeEntry( new BeanReplicator().replicateBean( node.getArtifact(), Artifact.class ) );
entry.setParent( currentEntry );
currentEntry = entry;
if ( firstNode == null ) if ( firstNode == null )
{ {
firstNode = node; firstNode = node;
}
if ( currentEntry == null )
{
currentEntry =
new TreeEntry( new BeanReplicator().replicateBean( node.getArtifact(), Artifact.class ) );
treeEntries.add( currentEntry ); treeEntries.add( currentEntry );
} }
else else
{ {
if ( node.getChildren().isEmpty() ) currentEntry.getParent().getChilds().add( currentEntry );
{
currentEntry.getChilds().add(
new TreeEntry( new BeanReplicator().replicateBean( node.getArtifact(), Artifact.class ) ) );
}
} }
if ( !node.getChildren().isEmpty() )
{
for ( DependencyNode dependencyNode : (List<DependencyNode>) node.getChildren() )
{
if ( dependencyNode.getChildren().isEmpty() )
{
this.currentEntry.getChilds().add( new TreeEntry(
new BeanReplicator().replicateBean( dependencyNode.getArtifact(), Artifact.class ) ) );
}
else
{
TreeEntry backup = this.currentEntry;
this.currentEntry = new TreeEntry(
new BeanReplicator().replicateBean( dependencyNode.getArtifact(), Artifact.class ) );
visit( dependencyNode );
this.currentEntry = backup;
}
}
}
return true; return true;
} }
public boolean endVisit( DependencyNode node ) public boolean endVisit( DependencyNode node )
{ {
firstNode = null; /*
if ( node.getChildren().isEmpty() )
{
currentEntry = currentEntry.getParent();
}
else
{
} */
currentEntry = currentEntry.getParent();
firstChild = false;
return true; return true;
} }