From 6a7d63dd6b9019a9bb978620b218655d0725aa42 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Thu, 7 Dec 2023 13:28:12 +0100 Subject: [PATCH] fix(reporter): Do not take blank license texts Recent ScanCode versions started to add a YAML front matter to license files (also see b9c038e). This means that now license files are present even in cases where ScanCode previously had no license text. Such files now only contain the YAML frontmatter, and removing the frontmatter makes them blank. Note that even online files like [1] are blank now. Avoid using such files for license texts by adding a check whether their contents are blank. This fixes an issue with the SPDX reporter which has a check that `extractedText` for a `SpdxExtractedLicenseInfo` must be non-blank. [1]: https://scancode-licensedb.aboutcode.org/generic-cla.LICENSE Signed-off-by: Sebastian Schuberth --- reporter/src/main/kotlin/LicenseTextProvider.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/reporter/src/main/kotlin/LicenseTextProvider.kt b/reporter/src/main/kotlin/LicenseTextProvider.kt index d377099b59600..313d4c2c45d54 100644 --- a/reporter/src/main/kotlin/LicenseTextProvider.kt +++ b/reporter/src/main/kotlin/LicenseTextProvider.kt @@ -26,7 +26,8 @@ interface LicenseTextProvider { /** * Return the license text for the license identified by [licenseId] or null if the license text is not available. */ - fun getLicenseText(licenseId: String): String? = getLicenseTextReader(licenseId)?.invoke() + fun getLicenseText(licenseId: String): String? = + getLicenseTextReader(licenseId)?.invoke()?.takeUnless { it.isBlank() } /** * Return a lambda that can read the license text for the license identified by [licenseId] or null if no license @@ -35,7 +36,8 @@ interface LicenseTextProvider { fun getLicenseTextReader(licenseId: String): (() -> String)? /** - * Return true if a license text for the license identified by [licenseId] is available. + * Return true if a license text for the license identified by [licenseId] is generally available. Note that this + * does not necessarily mean that the text is meaningful (i.e. non-blank). */ fun hasLicenseText(licenseId: String): Boolean = getLicenseTextReader(licenseId) != null }