]> source.dussan.org Git - archiva.git/commitdiff
fix dependency tree calculation
authorOlivier Lamy <olamy@apache.org>
Thu, 22 Mar 2012 17:53:03 +0000 (17:53 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 22 Mar 2012 17:53:03 +0000 (17:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1303924 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/TreeEntry.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java

index 6ed3b2f3a620eadd25589e20d639d7ff6a26d9f7..0ac2713afd1e6b94067d4f01fc003bcd1f2ab2be 100644 (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;
+    }
 }
index 59a922b98b56ae7815200f8f0d4b012c44abcf10..74328d93b0546227415c4620a3f25dd02bd3ea6f 100644 (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 ) ) );
-                }
-            }
-
-            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;
-                    }
-                }
+                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;
         }