Skip to content

Commit

Permalink
chore(DependencyGraphNavigator): Avoid relying on manage name prefixes
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sschuberth committed Jan 17, 2025
1 parent e510c6f commit 1116fd7
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions model/src/main/kotlin/DependencyGraphNavigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,19 @@ class DependencyGraphNavigator(
override fun scopeNames(project: Project): Set<String> = project.scopeNames.orEmpty()

override fun directDependencies(project: Project, scopeName: String): Sequence<DependencyNode> {
// 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)
}

Expand Down

0 comments on commit 1116fd7

Please sign in to comment.