From 339d9544371ba857577e16feba4ab1ba097bdd38 Mon Sep 17 00:00:00 2001 From: Anthony Harrison Date: Mon, 8 Aug 2022 21:59:39 +0100 Subject: [PATCH] Handle Apache 2.0 licence synoymns --- sbom4python/license.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sbom4python/license.py b/sbom4python/license.py index 3fc2767..ab4f91d 100644 --- a/sbom4python/license.py +++ b/sbom4python/license.py @@ -7,6 +7,9 @@ class LicenseScanner: + + APACHE_SYNOYMNS = ["Apache Software License", "Apache License, Version 2.0", "Apache 2.0", "Apache 2"] + def __init__(self): # Load licenses license_dir, filename = os.path.split(__file__) @@ -14,6 +17,9 @@ def __init__(self): licfile = open(license_path) self.licenses = json.load(licfile) + def check_synoymn(self, license, synoymns, value): + return value if license in synoymns else None + def find_license(self, license): # Search list of licenses to find match @@ -24,4 +30,5 @@ def find_license(self, license): return lic["licenseId"] elif lic["name"].lower() == license.lower(): return lic["licenseId"] - return default_license + license_id = self.check_synoymn(license, self.APACHE_SYNOYMNS, "Apache-2.0") + return license_id if license_id is not None else default_license