From 19cfe2abb5ed6cef8781a2d51cd2725d679bc6c7 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Thu, 6 Jun 2024 16:19:29 +0200 Subject: [PATCH] chore(ort-utils): Warn if a mapping to an invalid license is configured Signed-off-by: Sebastian Schuberth --- .../ort/src/main/kotlin/DeclaredLicenseProcessor.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/utils/ort/src/main/kotlin/DeclaredLicenseProcessor.kt b/utils/ort/src/main/kotlin/DeclaredLicenseProcessor.kt index bcbba8a6e0097..eac916a46879a 100644 --- a/utils/ort/src/main/kotlin/DeclaredLicenseProcessor.kt +++ b/utils/ort/src/main/kotlin/DeclaredLicenseProcessor.kt @@ -92,9 +92,17 @@ object DeclaredLicenseProcessor { ?: SpdxDeclaredLicenseMapping.map(strippedLicense) ?: SpdxDeclaredLicenseMapping.map(strippedLicense.unquote()) ?: SpdxDeclaredLicenseMapping.map(strippedLicense.removePrefix(SpdxConstants.TAG).trim()) - ?: parseLicense(strippedLicense) - return mappedLicense?.normalize()?.takeIf { it.isValid() || it.toString() == SpdxConstants.NONE } + if (mappedLicense?.isValid() == false) { + logger.warn { + "Declared license '$declaredLicense' is configured to map to '$mappedLicense' which is not a valid " + + "SPDX expression." + } + } + + val processedLicense = mappedLicense ?: parseLicense(strippedLicense) + + return processedLicense?.normalize()?.takeIf { it.isValid() || it.toString() == SpdxConstants.NONE } } /**