Skip to content

Commit

Permalink
fix(model): Add a heuristic to get the manager in dependency graphs
Browse files Browse the repository at this point in the history
This is a prerequisite for being able to use `GradleInspector` in
package manager dependencies, as done by `Pub`.

Adjust a test accordingly to avoid [type, type-1] managers to both
manage "type" projects.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Sep 5, 2024
1 parent dabcd27 commit 04b0356
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions analyzer/src/test/kotlin/AnalyzerResultBuilderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ class AnalyzerResultBuilderTest : WordSpec() {
)

val project = Project.EMPTY.copy(
id = Identifier("type", "namespace", "project", "version"),
id = project2.id,
scopeDependencies = setOf(scope),
definitionFilePath = "project"
definitionFilePath = project2.definitionFilePath
)

val projectAnalyzerResult = ProjectAnalyzerResult(
Expand Down
13 changes: 11 additions & 2 deletions model/src/main/kotlin/DependencyGraphNavigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,18 @@ class DependencyGraphNavigator(
override fun scopeNames(project: Project): Set<String> = project.scopeNames.orEmpty()

override fun directDependencies(project: Project, scopeName: String): Sequence<DependencyNode> {
val graph = graphForManager(project.id.type)
// TODO: Relax the assumption that package manager name 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) }

val manager = requireNotNull(managers.singleOrNull()) {
"All of the $managers managers are able to manage '${project.id.type}' projects. Please enable only one " +
"of them."
}

val graph = graphForManager(manager)
val rootDependencies = graph.scopes[DependencyGraph.qualifyScope(project, scopeName)].orEmpty().map { root ->
referenceFor(project.id.type, root)
referenceFor(manager, root)
}

return dependenciesSequence(graph, rootDependencies)
Expand Down

0 comments on commit 04b0356

Please sign in to comment.