Skip to content

Commit

Permalink
fix: Handle multiple licenses (fixes #45)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyharrison committed Dec 2, 2024
1 parent b057a6f commit cf63c26
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib4sbom/spdx/spdx_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,22 @@ def generateTagPackageDetails(
"PackageLicenseConcluded",
self.license_ident(package_info["licenseconcluded"]),
)
if "licenselist" in package_info:
# Handle multiple licenses from a CycloneDX SBOM
license_expression = ""
for license in package_info["licenselist"]:
if "id" in license:
license_expression = license_expression + license['id'] + " AND "
# Remove extraneous " AND "
license_expression = license_expression[:-4]
self.generateTag(
"PackageLicenseDeclared",
license_expression
)
self.generateTag(
"PackageLicenseConcluded",
license_expression
)
if "licensecomments" in package_info:
self.generateTag(
"PackageLicenseComments",
Expand Down Expand Up @@ -406,6 +422,16 @@ def generateJSONPackageDetails(
component["licenseDeclared"] = self.license_ident(
package_info["licensedeclared"]
)
if "licenselist" in package_info:
# Handle multiple licenses from a CycloneDX SBOM
license_expression = ""
for license in package_info["licenselist"]:
if "id" in license:
license_expression = license_expression + license['id'] + " AND "
# Remove extraneous " AND "
license_expression = license_expression[:-4]
component["licenseDeclared"]= license_expression
component["licenseConcluded"]= license_expression
if "licensecomments" in package_info:
component["licenseComments"] = package_info["licensecomments"]
if files_analysed:
Expand Down

0 comments on commit cf63c26

Please sign in to comment.