From dcd3b192646c4bbf89c128b9334e1c03523201be Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Wed, 8 Nov 2023 13:50:31 +0100 Subject: [PATCH] feat(helper-cli): Re-filter scan summary by VCS path Analog to [1], re-filter all scan results by VCS path, so that the effect of narrowing down a VCS path via a package curation is reflected in the output of `ListLicensesCommand`. [1]: https://github.com/oss-review-toolkit/ort/commit/2ec49c792ef6c3afe4c6ca5127737b1eb6d08555 Signed-off-by: Frank Viernau --- helper-cli/src/main/kotlin/utils/Extensions.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/helper-cli/src/main/kotlin/utils/Extensions.kt b/helper-cli/src/main/kotlin/utils/Extensions.kt index 219690f05dc2f..1eafd86ed6409 100644 --- a/helper-cli/src/main/kotlin/utils/Extensions.kt +++ b/helper-cli/src/main/kotlin/utils/Extensions.kt @@ -66,6 +66,7 @@ import org.ossreviewtoolkit.model.readValue import org.ossreviewtoolkit.model.utils.FindingCurationMatcher import org.ossreviewtoolkit.model.utils.PackageConfigurationProvider import org.ossreviewtoolkit.model.utils.createLicenseInfoResolver +import org.ossreviewtoolkit.model.utils.filterByVcsPath import org.ossreviewtoolkit.model.writeValue import org.ossreviewtoolkit.model.yamlMapper import org.ossreviewtoolkit.utils.common.safeMkdirs @@ -179,7 +180,13 @@ internal fun OrtResult.getLicenseFindingsById( packageConfigurationProvider.getPackageConfigurations(id, provenance).flatMap { it.licenseFindingCurations } } - getScanResultsForId(id).forEach { scanResult -> + getScanResultsForId(id).map { + // If a VCS path curation has been applied after the scanning stage, it is possible to apply that + // curation without re-scanning in case the new VCS path is a subdirectory of the scanned VCS path. + // So, filter by VCS path to enable the user to see the effect on the detected license with a shorter + // turn around time / without re-scanning. + it.filterByVcsPath(getPackage(id)?.metadata?.vcsProcessed?.path.orEmpty()) + }.forEach { scanResult -> val findingsForProvenance = result.getOrPut(scanResult.provenance) { mutableMapOf() } scanResult.summary.licenseFindings.let { findings ->