belingueres commented on code in PR #281:
URL: https://github.com/apache/maven/pull/281#discussion_r3942372768


##########
impl/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java:
##########
@@ -132,6 +187,97 @@ public static void toArtifacts(
         }
     }
 
+    private static void toArtifactsBFS(

Review Comment:
   I left only one now



##########
impl/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java:
##########
@@ -132,6 +187,97 @@ public static void toArtifacts(
         }
     }
 
+    private static void toArtifactsBFS(
+            Collection<org.apache.maven.artifact.Artifact> artifacts,
+            Collection<? extends DependencyNode> nodes,
+            List<String> trail,
+            DependencyFilter filter) {
+        Map<Integer, List<org.apache.maven.artifact.Artifact>> 
artifactsByDepth = new TreeMap<>();
+
+        List<org.apache.maven.artifact.Artifact> firstLevelArtifacts = new 
ArrayList<>(nodes.size());
+        // we know there are at least direct dependencies
+        artifactsByDepth.put(1, firstLevelArtifacts);
+
+        toArtifactsBFS(artifactsByDepth, 1, nodes, trail, filter);
+
+        // list of artifacts ordered by depth level
+        for (List<org.apache.maven.artifact.Artifact> artifactsInDepth : 
artifactsByDepth.values()) {
+            artifacts.addAll(artifactsInDepth);
+        }
+    }
+
+    private static void toArtifactsBFS(
+            Map<Integer, List<org.apache.maven.artifact.Artifact>> 
artifactsByDepth,
+            int currentDepth,
+            Collection<? extends DependencyNode> nodes,
+            List<String> trail,
+            DependencyFilter filter) {
+        for (DependencyNode node : nodes) {
+            org.apache.maven.artifact.Artifact artifact = 
toArtifact(node.getDependency());
+
+            List<String> nodeTrail = new ArrayList<>(trail.size() + 1);
+            nodeTrail.addAll(trail);
+            nodeTrail.add(artifact.getId());
+
+            if (filter == null || filter.accept(node, 
Collections.emptyList())) {
+                artifact.setDependencyTrail(nodeTrail);
+
+                // add artifact in the list of the current depth
+                List<org.apache.maven.artifact.Artifact> artifactsCurrentDepth 
= artifactsByDepth.get(currentDepth);
+                if (artifactsCurrentDepth == null) {
+                    artifactsCurrentDepth = new ArrayList<>();
+                    artifactsByDepth.put(currentDepth, artifactsCurrentDepth);
+                }
+                artifactsCurrentDepth.add(artifact);
+            }
+
+            toArtifactsBFS(artifactsByDepth, currentDepth + 1, 
node.getChildren(), nodeTrail, filter);
+        }
+    }
+
+    public static void toArtifactsBFS2(

Review Comment:
   fixed to private



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to