From c56ec8395dd203ac41fa6f4c43970a50c0e80efb Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Wed, 6 Sep 2023 13:10:10 +0200 Subject: [PATCH] docs(example): showcase `LicenseChoiceFactory` (#428) Signed-off-by: Jan Kowalleck --- examples/build_and_serialize.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/build_and_serialize.py b/examples/build_and_serialize.py index 1643562c..52567e66 100644 --- a/examples/build_and_serialize.py +++ b/examples/build_and_serialize.py @@ -1,12 +1,12 @@ -from cyclonedx.factory.license import LicenseFactory -from cyclonedx.model import LicenseChoice, OrganizationalEntity, XsUri +from cyclonedx.factory.license import LicenseChoiceFactory, LicenseFactory +from cyclonedx.model import OrganizationalEntity, XsUri from cyclonedx.model.bom import Bom from cyclonedx.model.component import Component, ComponentType from cyclonedx.output.json import JsonV1Dot4 from cyclonedx.output.xml import XmlV1Dot4 from packageurl import PackageURL -lFac = LicenseFactory() +lc_factory = LicenseChoiceFactory(license_factory=LicenseFactory()) # region build the BOM @@ -14,16 +14,16 @@ bom.metadata.component = rootComponent = Component( name='myApp', type=ComponentType.APPLICATION, - licenses=[LicenseChoice(license=lFac.make_from_string('MIT'))], + licenses=[lc_factory.make_from_string('MIT')], bom_ref='myApp', ) -component = Component( +component1 = Component( type=ComponentType.LIBRARY, name='some-component', group='acme', version='1.33.7-beta.1', - licenses=[LicenseChoice(license=lFac.make_from_string('(c) 2021 Acme inc.'))], + licenses=[lc_factory.make_from_string('(c) 2021 Acme inc.')], supplier=OrganizationalEntity( name='Acme Inc', urls=[XsUri('https://www.acme.org')] @@ -31,9 +31,16 @@ bom_ref='myComponent@1.33.7-beta.1', purl=PackageURL('generic', 'acme', 'some-component', '1.33.7-beta.1') ) +bom.components.add(component1) +bom.register_dependency(rootComponent, [component1]) -bom.components.add(component) -bom.register_dependency(rootComponent, [component]) +component2 = Component( + type=ComponentType.LIBRARY, + name='some-library', + licenses=[lc_factory.make_from_string('GPL-3.0-only WITH Classpath-exception-2.0')] +) +bom.components.add(component2) +bom.register_dependency(component1, [component2]) # endregion build the BOM