diff --git a/plugins/scanners/scancode/src/main/kotlin/ScanCodeResultModel.kt b/plugins/scanners/scancode/src/main/kotlin/ScanCodeResultModel.kt index 988c7c131112c..8dd890891c1ef 100644 --- a/plugins/scanners/scancode/src/main/kotlin/ScanCodeResultModel.kt +++ b/plugins/scanners/scancode/src/main/kotlin/ScanCodeResultModel.kt @@ -158,6 +158,7 @@ sealed interface LicenseEntry { override val startLine: Int, override val endLine: Int, override val licenseExpression: String, + val spdxLicenseExpression: String? = null, // This might be missing in JSON. val fromFile: String? = null // This might be missing in JSON. ) : LicenseEntry } diff --git a/plugins/scanners/scancode/src/main/kotlin/ScanCodeResultModelMapper.kt b/plugins/scanners/scancode/src/main/kotlin/ScanCodeResultModelMapper.kt index 366e6c0062b3c..c12ab11dfa086 100644 --- a/plugins/scanners/scancode/src/main/kotlin/ScanCodeResultModelMapper.kt +++ b/plugins/scanners/scancode/src/main/kotlin/ScanCodeResultModelMapper.kt @@ -111,7 +111,12 @@ fun ScanCodeResult.toScanSummary(preferFileLicense: Boolean = false): ScanSummar } else { licenses.mapTo(licenseFindings) { license -> // ScanCode uses its own license keys as identifiers in license expressions. - val spdxLicenseExpression = license.licenseExpression.mapLicense(scanCodeKeyToSpdxIdMappings) + val spdxLicenseExpression = when { + license is LicenseEntry.Version3 && license.spdxLicenseExpression != null -> { + license.spdxLicenseExpression + } + else -> license.licenseExpression.mapLicense(scanCodeKeyToSpdxIdMappings) + } LicenseFinding( license = spdxLicenseExpression, diff --git a/plugins/scanners/scancode/src/test/kotlin/ScanCodeResultParserTest.kt b/plugins/scanners/scancode/src/test/kotlin/ScanCodeResultParserTest.kt index 34f9f0b798128..e55c939b58e0e 100644 --- a/plugins/scanners/scancode/src/test/kotlin/ScanCodeResultParserTest.kt +++ b/plugins/scanners/scancode/src/test/kotlin/ScanCodeResultParserTest.kt @@ -166,7 +166,7 @@ class ScanCodeResultParserTest : FreeSpec({ score = 96.69f ), LicenseFinding( - license = "LGPL-2.1-only AND gpl-2.0 AND gpl-3.0", + license = "LGPL-2.1-only AND GPL-2.0-only AND GPL-3.0-only", location = TextLocation("COPYING", 52, 55), score = 100.0f ),