From 47c1c0c4da465d3f5cc1d6a9d09c6d771ea98e7c Mon Sep 17 00:00:00 2001 From: Martin Nonnenmacher Date: Fri, 8 Dec 2023 12:23:02 +0100 Subject: [PATCH] feat(cli): Improve scanner comparison in `CompareCommand` If the scanners used for the packages are different, only show the entries that actually are different, not the whole lists. Signed-off-by: Martin Nonnenmacher --- .../commands/compare/src/main/kotlin/CompareCommand.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/commands/compare/src/main/kotlin/CompareCommand.kt b/plugins/commands/compare/src/main/kotlin/CompareCommand.kt index d6b3e16c9d32c..6d7fb8c5b59c4 100644 --- a/plugins/commands/compare/src/main/kotlin/CompareCommand.kt +++ b/plugins/commands/compare/src/main/kotlin/CompareCommand.kt @@ -543,8 +543,8 @@ private fun ScannerRun?.diff(other: ScannerRun?, context: SemanticDiffContext): config = if (context.ignoreConfig) null else config.diff(other.config), provenancesA = (provenances - other.provenances).takeUnless { it.isEmpty() }, provenancesB = (other.provenances - provenances).takeUnless { it.isEmpty() }, - scannersA = scanners.takeIf { it != other.scanners }, - scannersB = other.scanners.takeIf { it != scanners }, + scannersA = scanners.diff(other.scanners).takeUnless { it.isEmpty() }, + scannersB = other.scanners.diff(scanners).takeUnless { it.isEmpty() }, filesA = if (context.ignoreFileList) null else (files - other.files).takeUnless { it.isEmpty() }, filesB = if (context.ignoreFileList) null else (other.files - files).takeUnless { it.isEmpty() }, scanResultDiff = differentResults.takeUnless { it.isEmpty() } @@ -552,6 +552,10 @@ private fun ScannerRun?.diff(other: ScannerRun?, context: SemanticDiffContext): } } +private fun Map>.diff(other: Map>): Map> { + return filter { (id, values) -> other[id] != values } +} + private fun ScannerConfiguration?.diff(other: ScannerConfiguration?): ScannerConfigurationDiff? { if (this == other) return null