|
23 | 23 | File, |
24 | 24 | ChecksumAlgorithm, |
25 | 25 | Checksum, |
| 26 | + ExtractedLicensingInfo, |
26 | 27 | ) |
27 | 28 | from spdx_tools.common.spdx_licensing import spdx_licensing |
28 | 29 | from spdx_tools.spdx.writer.write_anything import write_file |
@@ -220,6 +221,35 @@ def generate_sbom( |
220 | 221 | packages = [] |
221 | 222 | relationships = [] |
222 | 223 | files = [] |
| 224 | + extracted_licensing_info = [] |
| 225 | + |
| 226 | + # Collect custom licenses that need to be extracted |
| 227 | + custom_licenses = set() |
| 228 | + for file_info in included_file_info.values(): |
| 229 | + lic = file_info.get("license", SpdxNoAssertion()) |
| 230 | + if not isinstance(lic, SpdxNoAssertion) and lic.startswith("LicenseRef-"): |
| 231 | + custom_licenses.add(lic) |
| 232 | + |
| 233 | + if "dependencies" in manifest: |
| 234 | + for dep in manifest["dependencies"]: |
| 235 | + lic = dep["license"] |
| 236 | + if not isinstance(lic, SpdxNoAssertion) and lic.startswith("LicenseRef-"): |
| 237 | + custom_licenses.add(lic) |
| 238 | + |
| 239 | + if "testDependencies" in manifest: |
| 240 | + for dep in manifest["testDependencies"]: |
| 241 | + lic = dep["license"] |
| 242 | + if not isinstance(lic, SpdxNoAssertion) and lic.startswith("LicenseRef-"): |
| 243 | + custom_licenses.add(lic) |
| 244 | + |
| 245 | + # Create extracted licensing info for custom licenses |
| 246 | + for custom_lic in custom_licenses: |
| 247 | + extracted_licensing_info.append( |
| 248 | + ExtractedLicensingInfo( |
| 249 | + license_id=custom_lic, |
| 250 | + extracted_text="See project repository for license details" |
| 251 | + ) |
| 252 | + ) |
223 | 253 |
|
224 | 254 | # Generate output filenames based on package info |
225 | 255 | output_files = [ |
@@ -481,6 +511,7 @@ def generate_sbom( |
481 | 511 | packages=packages, |
482 | 512 | files=files, |
483 | 513 | relationships=relationships, |
| 514 | + extracted_licensing_info=extracted_licensing_info, |
484 | 515 | ) |
485 | 516 |
|
486 | 517 | write_file(document, output_path, validate=True) |
|
0 commit comments