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.
*/
import org.codehaus.jackson.annotate.JsonIgnore;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.ArrayList;
@ -33,9 +35,11 @@ public class TreeEntry
private List<TreeEntry> childs = new ArrayList<TreeEntry>();
private Artifact artifact;
@JsonIgnore
private TreeEntry parent;
public TreeEntry()
{
// no op
@ -66,4 +70,16 @@ public class TreeEntry
{
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
implements DependencyNodeVisitor
{
final List<TreeEntry> treeEntries;
private TreeEntry currentEntry;
private DependencyNode firstNode;
boolean firstChild = true;
private TreeDependencyNodeVisitor( List<TreeEntry> treeEntries )
{
this.treeEntries = treeEntries;
@ -523,51 +528,35 @@ public class DefaultBrowseService
public boolean visit( DependencyNode node )
{
TreeEntry entry = new TreeEntry( new BeanReplicator().replicateBean( node.getArtifact(), Artifact.class ) );
entry.setParent( currentEntry );
currentEntry = entry;
if ( firstNode == null )
{
firstNode = node;
}
if ( currentEntry == null )
{
currentEntry =
new TreeEntry( new BeanReplicator().replicateBean( node.getArtifact(), Artifact.class ) );
treeEntries.add( currentEntry );
}
else
{
if ( node.getChildren().isEmpty() )
{
currentEntry.getChilds().add(
new TreeEntry( new BeanReplicator().replicateBean( node.getArtifact(), Artifact.class ) ) );
}
currentEntry.getParent().getChilds().add( currentEntry );
}
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;
}
public boolean endVisit( DependencyNode node )
{
firstNode = null;
/*
if ( node.getChildren().isEmpty() )
{
currentEntry = currentEntry.getParent();
}
else
{
} */
currentEntry = currentEntry.getParent();
firstChild = false;
return true;
}