From a0b8f9dac149666e5ee14c4bada5756c3adba7f7 Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Tue, 17 Oct 2023 14:23:46 +0200 Subject: [PATCH] fix: break infinite recursion in renderTreeNode (#33) * can be reproduced with libraryDependencies += "io.grpc" % "grpc-core" % "1.58.0" * break cycle by tracking parents --- .gitignore | 1 + .../paradox/dependencies/DependenciesDirective.scala | 9 +++++---- src/sbt-test/dependencies/happy-path/build.sbt | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index b6449cf..7580e05 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ project/plugins/project/ .history .cache .lib/ +.bsp ### Scala template *.class diff --git a/src/main/scala/com/lightbend/paradox/dependencies/DependenciesDirective.scala b/src/main/scala/com/lightbend/paradox/dependencies/DependenciesDirective.scala index 665c04b..2de5482 100644 --- a/src/main/scala/com/lightbend/paradox/dependencies/DependenciesDirective.scala +++ b/src/main/scala/com/lightbend/paradox/dependencies/DependenciesDirective.scala @@ -79,12 +79,13 @@ class DependenciesDirective(showLicenses: Boolean)(projectIdToDependencies: Stri r <- graph.roots d <- children(graph, r) } - renderTreeNode(p, graph, d) + renderTreeNode(p, graph, d, Set.empty) p.print("").println() } - private def renderTreeNode(p: Printer, graph: ModuleGraph, n: Module): Unit = - if (n.evictedByVersion.isEmpty) { + private def renderTreeNode(p: Printer, graph: ModuleGraph, n: Module, parents: Set[Module]): Unit = + // avoid cycles by checking if in parents + if (n.evictedByVersion.isEmpty && !parents.contains(n)) { val moduleId = n.id val name = moduleId.name p.println() @@ -99,7 +100,7 @@ class DependenciesDirective(showLicenses: Boolean)(projectIdToDependencies: Stri n.license.foreach(l => p.print(" ").print(l)) if (children(graph, n).nonEmpty) { p.indent(4) - children(graph, n).foreach(renderTreeNode(p, graph, _)) + children(graph, n).foreach(renderTreeNode(p, graph, _, parents + n)) p.indent(-4) } } diff --git a/src/sbt-test/dependencies/happy-path/build.sbt b/src/sbt-test/dependencies/happy-path/build.sbt index 3609016..b2af704 100644 --- a/src/sbt-test/dependencies/happy-path/build.sbt +++ b/src/sbt-test/dependencies/happy-path/build.sbt @@ -1,4 +1,6 @@ enablePlugins(ParadoxPlugin) paradoxTheme := None -libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.5.17" +//libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.5.17" + +libraryDependencies += "io.grpc" % "grpc-core" % "1.58.0"