From 1116fd7735bd68b79ff1df861fd90be2e94aca19 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Fri, 17 Jan 2025 19:47:28 +0100 Subject: [PATCH] chore(DependencyGraphNavigator): Avoid relying on manage name prefixes This removes the assumption that package manager names start with the name of the type of project they manage in favor of collecting all root indices for the project and ensuring that they only stem from a single project. Signed-off-by: Sebastian Schuberth --- .../src/main/kotlin/DependencyGraphNavigator.kt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/model/src/main/kotlin/DependencyGraphNavigator.kt b/model/src/main/kotlin/DependencyGraphNavigator.kt index 16bb3f143501c..6af1a4ccf8195 100644 --- a/model/src/main/kotlin/DependencyGraphNavigator.kt +++ b/model/src/main/kotlin/DependencyGraphNavigator.kt @@ -45,20 +45,19 @@ class DependencyGraphNavigator( override fun scopeNames(project: Project): Set = project.scopeNames.orEmpty() override fun directDependencies(project: Project, scopeName: String): Sequence { - // TODO: Relax this assumption that package manager names start with the name of the type of project - // they manage, for example that "GradleInspector" manages "Gradle" projects. - val managers = graphs.keys.filter { it.startsWith(project.id.type) } + // Collect all root indices for all manager whose graphs have projects of the respective type. + val rootIndicesForGraphs = graphs.mapNotNull { (manager, graph) -> + graph.scopes[DependencyGraph.qualifyScope(project, scopeName)]?.let { Triple(manager, graph, it) } + } + + if (rootIndicesForGraphs.isEmpty()) return emptySequence() - val manager = requireNotNull(managers.singleOrNull()) { + val (manager, graph, rootIndices) = requireNotNull(rootIndicesForGraphs.singleOrNull()) { + val managers = rootIndicesForGraphs.map { (manager, _, _) -> manager } "All of the $managers managers are able to manage '${project.id.type}' projects. Please enable only one " + "of them." } - val graph = requireNotNull(graphs[manager]) { - "No DependencyGraph for package manager '$manager' available." - } - - val rootIndices = graph.scopes[DependencyGraph.qualifyScope(project, scopeName)].orEmpty() return dependenciesAccessor(manager, graph, rootIndices) }