Skip to content

Commit

Permalink
docs(example): showcase LicenseChoiceFactory (#428)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
  • Loading branch information
jkowalleck authored Sep 6, 2023
1 parent dc43959 commit c56ec83
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions examples/build_and_serialize.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
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

bom = Bom()
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')]
),
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

Expand Down

0 comments on commit c56ec83

Please sign in to comment.