From 4f0deeb78b84cdf35f639882a30974b144707bb3 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 22 Mar 2012 17:53:03 +0000 Subject: [PATCH] fix dependency tree calculation git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1303924 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva/rest/api/model/TreeEntry.java | 18 ++++++- .../rest/services/DefaultBrowseService.java | 53 ++++++++----------- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/TreeEntry.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/TreeEntry.java index 6ed3b2f3a..0ac2713af 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/TreeEntry.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/TreeEntry.java @@ -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 childs = new ArrayList(); - 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; + } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java index 59a922b98..74328d93b 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java @@ -510,12 +510,17 @@ public class DefaultBrowseService private static class TreeDependencyNodeVisitor implements DependencyNodeVisitor { + final List treeEntries; private TreeEntry currentEntry; + private DependencyNode firstNode; + + boolean firstChild = true; + private TreeDependencyNodeVisitor( List 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 ) ) ); - } - } - - if ( !node.getChildren().isEmpty() ) - { - for ( DependencyNode dependencyNode : (List) 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; - } - } + currentEntry.getParent().getChilds().add( currentEntry ); } - return true; } public boolean endVisit( DependencyNode node ) { - firstNode = null; + /* + if ( node.getChildren().isEmpty() ) + { + currentEntry = currentEntry.getParent(); + } + else + { + + } */ + currentEntry = currentEntry.getParent(); + firstChild = false; return true; } -- 2.39.5