Skip to content

Commit c56ec83

Browse files
authored
docs(example): showcase LicenseChoiceFactory (#428)
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent dc43959 commit c56ec83

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

examples/build_and_serialize.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
1-
from cyclonedx.factory.license import LicenseFactory
2-
from cyclonedx.model import LicenseChoice, OrganizationalEntity, XsUri
1+
from cyclonedx.factory.license import LicenseChoiceFactory, LicenseFactory
2+
from cyclonedx.model import OrganizationalEntity, XsUri
33
from cyclonedx.model.bom import Bom
44
from cyclonedx.model.component import Component, ComponentType
55
from cyclonedx.output.json import JsonV1Dot4
66
from cyclonedx.output.xml import XmlV1Dot4
77
from packageurl import PackageURL
88

9-
lFac = LicenseFactory()
9+
lc_factory = LicenseChoiceFactory(license_factory=LicenseFactory())
1010

1111
# region build the BOM
1212

1313
bom = Bom()
1414
bom.metadata.component = rootComponent = Component(
1515
name='myApp',
1616
type=ComponentType.APPLICATION,
17-
licenses=[LicenseChoice(license=lFac.make_from_string('MIT'))],
17+
licenses=[lc_factory.make_from_string('MIT')],
1818
bom_ref='myApp',
1919
)
2020

21-
component = Component(
21+
component1 = Component(
2222
type=ComponentType.LIBRARY,
2323
name='some-component',
2424
group='acme',
2525
version='1.33.7-beta.1',
26-
licenses=[LicenseChoice(license=lFac.make_from_string('(c) 2021 Acme inc.'))],
26+
licenses=[lc_factory.make_from_string('(c) 2021 Acme inc.')],
2727
supplier=OrganizationalEntity(
2828
name='Acme Inc',
2929
urls=[XsUri('https://www.acme.org')]
3030
),
3131
bom_ref='[email protected]',
3232
purl=PackageURL('generic', 'acme', 'some-component', '1.33.7-beta.1')
3333
)
34+
bom.components.add(component1)
35+
bom.register_dependency(rootComponent, [component1])
3436

35-
bom.components.add(component)
36-
bom.register_dependency(rootComponent, [component])
37+
component2 = Component(
38+
type=ComponentType.LIBRARY,
39+
name='some-library',
40+
licenses=[lc_factory.make_from_string('GPL-3.0-only WITH Classpath-exception-2.0')]
41+
)
42+
bom.components.add(component2)
43+
bom.register_dependency(component1, [component2])
3744

3845
# endregion build the BOM
3946

0 commit comments

Comments
 (0)