|
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 |
3 | 3 | from cyclonedx.model.bom import Bom
|
4 | 4 | from cyclonedx.model.component import Component, ComponentType
|
5 | 5 | from cyclonedx.output.json import JsonV1Dot4
|
6 | 6 | from cyclonedx.output.xml import XmlV1Dot4
|
7 | 7 | from packageurl import PackageURL
|
8 | 8 |
|
9 |
| -lFac = LicenseFactory() |
| 9 | +lc_factory = LicenseChoiceFactory(license_factory=LicenseFactory()) |
10 | 10 |
|
11 | 11 | # region build the BOM
|
12 | 12 |
|
13 | 13 | bom = Bom()
|
14 | 14 | bom.metadata.component = rootComponent = Component(
|
15 | 15 | name='myApp',
|
16 | 16 | type=ComponentType.APPLICATION,
|
17 |
| - licenses=[LicenseChoice(license=lFac.make_from_string('MIT'))], |
| 17 | + licenses=[lc_factory.make_from_string('MIT')], |
18 | 18 | bom_ref='myApp',
|
19 | 19 | )
|
20 | 20 |
|
21 |
| -component = Component( |
| 21 | +component1 = Component( |
22 | 22 | type=ComponentType.LIBRARY,
|
23 | 23 | name='some-component',
|
24 | 24 | group='acme',
|
25 | 25 | 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.')], |
27 | 27 | supplier=OrganizationalEntity(
|
28 | 28 | name='Acme Inc',
|
29 | 29 | urls=[XsUri('https://www.acme.org')]
|
30 | 30 | ),
|
31 | 31 |
|
32 | 32 | purl=PackageURL('generic', 'acme', 'some-component', '1.33.7-beta.1')
|
33 | 33 | )
|
| 34 | +bom.components.add(component1) |
| 35 | +bom.register_dependency(rootComponent, [component1]) |
34 | 36 |
|
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]) |
37 | 44 |
|
38 | 45 | # endregion build the BOM
|
39 | 46 |
|
|
0 commit comments