Skip to content
Merged
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
12 changes: 8 additions & 4 deletions plugins/commands/advisor/src/main/kotlin/AdvisorCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,16 @@ class AdvisorCommand : OrtCommand(
println("The advice took $duration.")

with(advisorRun.results.getVulnerabilities()) {
val totalPackageCount = ortResultOutput.getPackages(omitExcluded = true).size
val vulnerabilityCount = values.sumOf { it.size }
val includedPackages = ortResultOutput.getPackages(omitExcluded = true).map { it.metadata.id }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map returned by getVulnerabilities() contains entries for all
packages, also those that do not have any vulnerabilities.

BTW, this is something that also occurred to me in the context of #6613: The advisor's retrievePackageFindings() API definition does not make clear whether the returned map should contain entries for packages that have empty defects and vulnerabilities as part of the AdvisorResult. Should it? Just to get the AdvisorDetails and AdvisorSummary returned?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this as well, in some situations like package curations we decided that it has benefits to have explicit empty results to document that something was requested.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed as part of the Kotlin developer meeting.

val totalPackageCount = includedPackages.size
val vulnerablePackageCount = count { (id, vulnerabilities) ->
id in includedPackages && vulnerabilities.isNotEmpty()
}
val vulnerabilityCount = filterKeys { it in includedPackages }.values.sumOf { it.size }

println(
"$size of $totalPackageCount package(s) (not counting excluded ones) are vulnerable, with " +
"$vulnerabilityCount vulnerabilities in total."
"$vulnerablePackageCount of $totalPackageCount package(s) (not counting excluded ones) are " +
"vulnerable, with $vulnerabilityCount vulnerabilities in total."
)
}

Expand Down