Skip to content

Commit

Permalink
fix(reporter): Do not take blank license texts
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sschuberth committed Dec 8, 2023
1 parent ce6839d commit 6a7d63d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions reporter/src/main/kotlin/LicenseTextProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

0 comments on commit 6a7d63d

Please sign in to comment.