Skip to content

Commit

Permalink
fix(analyzer): Maintain package manager names as keys in the graph
Browse files Browse the repository at this point in the history
A key in the dependency graphs map corresponds to the name of the
package manager that determined the `DependencyGraph` value. The
previous implementation of `resolvePackageManagerDependencies()` broke
with that convention by using the name for the type of project instead.
Fix that by maintaining the original keys and just mapping the values.

This also fixes a bug with issues of a `DependencyReference` previously
being dropped: `package3` is the 0th entry in `dependencies2` who's
reference `depRef3` has `issue5` attached.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Oct 2, 2024
1 parent 5fe6981 commit a45a530
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions analyzer/src/main/kotlin/AnalyzerResultBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,20 @@ private fun AnalyzerResult.resolvePackageManagerDependencies(): AnalyzerResult {
val handler = PackageManagerDependencyHandler(this)
val navigator = DependencyGraphNavigator(dependencyGraphs)

val graphs = projects.groupBy { it.id.type }.entries.associate { (type, projectsForType) ->
val graphs = dependencyGraphs.mapValues { (packageManagerName, graph) ->
val builder = DependencyGraphBuilder(handler)

projectsForType.forEach { project ->
project.scopeNames?.forEach { scopeName ->
val qualifiedScopeName = DependencyGraph.qualifyScope(project, scopeName)
navigator.directDependencies(project, scopeName).forEach { node ->
handler.resolvePackageManagerDependency(node).forEach {
builder.addDependency(qualifiedScopeName, it)
}
graph.scopes.forEach { (scopeName, rootIndices) ->
navigator.dependenciesAccessor(packageManagerName, graph, rootIndices).forEach { node ->
handler.resolvePackageManagerDependency(node).forEach {
builder.addDependency(scopeName, it)
}
}
}

// Package managers that do not use the dependency graph representation might not have a check implemented to
// verify that packages exist for all dependencies, so the reference check needs to be disabled here.
type to builder.build(checkReferences = false)
builder.build(checkReferences = false)
}

return copy(dependencyGraphs = graphs)
Expand Down
2 changes: 1 addition & 1 deletion analyzer/src/test/kotlin/AnalyzerResultBuilderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class AnalyzerResultBuilderTest : WordSpec() {

analyzerResult.getAllIssues() should containExactly(
package1.id to setOf(issue1),
package3.id to setOf(issue2),
package3.id to setOf(issue2, issue5),
project1.id to setOf(issue3, issue4),
project2.id to setOf(issue4)
)
Expand Down

0 comments on commit a45a530

Please sign in to comment.