Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AOSD transitive linking #9621

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions model/src/main/kotlin/DependencyGraphNavigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ private fun collectDependencies(
ids: MutableSet<Identifier>,
visited: MutableSet<DependencyGraphNode> = mutableSetOf()
) {
if (maxDepth != 0) {
nodes.forEach { node ->
val cursor = node as DependencyRefCursor
if (cursor.current !in visited) {
visited += cursor.current
if (matcher(node)) ids += node.id

node.visitDependencies { collectDependencies(it, maxDepth - 1, matcher, ids, visited) }
}
if (maxDepth == 0) return

nodes.forEach { node ->
val cursor = node as DependencyRefCursor
if (cursor.current !in visited) {
visited += cursor.current
if (matcher(node)) ids += node.id

node.visitDependencies { collectDependencies(it, maxDepth - 1, matcher, ids, visited) }
}
}
}
25 changes: 11 additions & 14 deletions plugins/reporters/aosd/src/main/kotlin/Aosd21Reporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private fun Map<Identifier, IndexedValue<CuratedPackage>>.toComponents(
): Set<Component> =
values.mapTo(mutableSetOf()) { (index, pkg) ->
val dependencies = input.ortResult.getDependencies(pkg.metadata.id, maxLevel = 1, omitExcluded = true)
val node = input.ortResult.dependencyNavigator.findNode(project, pkg.metadata.id)
val node = input.ortResult.dependencyNavigator.findBreadthFirst(project, pkg.metadata.id)

val nonExcludedLicenseInfo = input.licenseInfoResolver.resolveLicenseInfo(pkg.metadata.id).filterExcluded()
val relevantLicenseInfo = nonExcludedLicenseInfo.filter(LicenseView.CONCLUDED_OR_DECLARED_AND_DETECTED)
Expand Down Expand Up @@ -124,24 +124,21 @@ private fun Map<Identifier, IndexedValue<CuratedPackage>>.toComponents(
}
}

private fun DependencyNavigator.findNode(project: Project, id: Identifier): DependencyNode? {
fun traverse(node: DependencyNode): DependencyNode? {
if (node.id == id) return node
private fun DependencyNavigator.findBreadthFirst(project: Project, nodeId: Identifier): DependencyNode? {
fun Sequence<DependencyNode>.findBreadthFirst(id: Identifier): DependencyNode? {
// This also turns the sequence into a list so it can be consumed twice, see below.
val directDependencies = mapTo(mutableListOf()) { it.getStableReference() }

node.visitDependencies { dependencies ->
dependencies.forEach(::traverse)
}

return null
}
directDependencies.find { node -> node.id == id }?.also { return it }

scopeNames(project).forEach { scopeName ->
directDependencies(project, scopeName).forEach { node ->
traverse(node)?.also { return it }
return directDependencies.firstNotNullOfOrNull { node ->
node.visitDependencies { it.findBreadthFirst(id) }
}
}

return null
return scopeNames(project).asSequence().mapNotNull { scopeName ->
directDependencies(project, scopeName).findBreadthFirst(nodeId)
}.firstOrNull()
}

private fun ResolvedLicenseInfo.toSimplifiedCompoundExpression(): SpdxExpression =
Expand Down
Loading