Skip to content

Commit

Permalink
Update expression normalization to support LicenseRef
Browse files Browse the repository at this point in the history
  • Loading branch information
lumaxis authored Apr 17, 2024
1 parent 2534616 commit 6351e3d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 11 additions & 4 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,20 @@ function joinExpressions(expressions) {
return list.join(' AND ')
}

function normalizeLicenseExpression(licenseExpression, logger) {
if (!licenseExpression) return null
function normalizeLicenseExpression(rawLicenseExpression, logger) {
if (!rawLicenseExpression) return null

const parsed = SPDX.parse(licenseExpression || '', key => SPDX.normalizeSingle(scancodeMap.get(key) || key))
const licenseVisitor = licenseExpression => {
return scancodeMap.get(licenseExpression) || SPDX.normalizeSingle(licenseExpression)
}

// parse() checks for LicenseRef- and other special types of expressions before calling the visitor
// therefore use the mapped license expression as an argument if it was found
const mappedLicenseExpression = scancodeMap.get(rawLicenseExpression)
const parsed = SPDX.parse(mappedLicenseExpression || rawLicenseExpression || '', licenseVisitor)
const result = SPDX.stringify(parsed)

if (result === 'NOASSERTION') logger.info(`ScanCode NOASSERTION from ${licenseExpression}`)
if (result === 'NOASSERTION') logger.info(`ScanCode NOASSERTION from ${rawLicenseExpression}`)

return result
}
Expand Down
5 changes: 3 additions & 2 deletions providers/summary/scancode-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ class ScanCodeSummarizerNew {
const [firstPackage] = packages
if (!firstPackage) return null

const licenseExpression = firstPackage.declared_license_expression_spdx
|| normalizeLicenseExpression(firstPackage.declared_license_expression, this.logger)
const licenseExpression =
firstPackage.declared_license_expression_spdx ||
normalizeLicenseExpression(firstPackage.declared_license_expression, this.logger)

return licenseExpression?.includes('NOASSERTION') ? null : licenseExpression
}
Expand Down

0 comments on commit 6351e3d

Please sign in to comment.