Skip to content

Commit f014d7c

Browse files
authored
fix: license_url not serialised in XML output #179 (#180)
Signed-off-by: Paul Horton <[email protected]>
1 parent 670bde4 commit f014d7c

File tree

7 files changed

+40
-8
lines changed

7 files changed

+40
-8
lines changed

cyclonedx/model/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ def __hash__(self) -> int:
376376
return hash(self._uri)
377377

378378
def __repr__(self) -> str:
379+
return f'<XsUri {self._uri}>'
380+
381+
def __str__(self) -> str:
379382
return self._uri
380383

381384

cyclonedx/output/xml.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,9 @@ def _add_licenses_to_element(self, licenses: Set[LicenseChoice], parent_element:
356356
license_text_e_attrs['encoding'] = license_.license.text.encoding.value
357357
ElementTree.SubElement(license_e, 'text',
358358
license_text_e_attrs).text = license_.license.text.content
359+
if license_.license.url:
360+
ElementTree.SubElement(license_e, 'url').text = str(license_.license.url)
359361

360-
ElementTree.SubElement(license_e, 'text').text = license_.license.id
361362
license_output = True
362363
else:
363364
if self.license_supports_expression():

tests/data.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
from packageurl import PackageURL
2525

2626
from cyclonedx.model import AttachedText, DataClassification, DataFlow, Encoding, ExternalReference, \
27-
ExternalReferenceType, HashType, LicenseChoice, Note, NoteText, OrganizationalContact, OrganizationalEntity, \
28-
Property, Tool, XsUri
27+
ExternalReferenceType, HashType, LicenseChoice, License, Note, NoteText, OrganizationalContact, \
28+
OrganizationalEntity, Property, Tool, XsUri
2929
from cyclonedx.model.bom import Bom
3030
from cyclonedx.model.component import Commit, Component, ComponentEvidence, ComponentType, Copyright, Patch, \
3131
PatchClassification, Pedigree, Swid, ComponentScope
@@ -166,7 +166,11 @@ def get_bom_just_complete_metadata() -> Bom:
166166
)
167167
bom.metadata.manufacture = get_org_entity_1()
168168
bom.metadata.supplier = get_org_entity_2()
169-
bom.metadata.licenses = [LicenseChoice(license_expression='Commercial')]
169+
bom.metadata.licenses = [LicenseChoice(license_=License(
170+
spdx_license_id='Apache-2.0', license_text=AttachedText(
171+
content='VGVzdCBjb250ZW50IC0gdGhpcyBpcyBub3QgdGhlIEFwYWNoZSAyLjAgbGljZW5zZSE=', encoding=Encoding.BASE_64
172+
), license_url=XsUri('https://www.apache.org/licenses/LICENSE-2.0.txt')
173+
))]
170174
bom.metadata.properties = get_properties_1()
171175
return bom
172176

tests/fixtures/json/1.3/bom_with_full_metadata.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,15 @@
6262
},
6363
"licenses": [
6464
{
65-
"expression": "Commercial"
65+
"license": {
66+
"id": "Apache-2.0",
67+
"text": {
68+
"contentType": "text/plain",
69+
"encoding": "base64",
70+
"content": "VGVzdCBjb250ZW50IC0gdGhpcyBpcyBub3QgdGhlIEFwYWNoZSAyLjAgbGljZW5zZSE="
71+
},
72+
"url": "https://www.apache.org/licenses/LICENSE-2.0.txt"
73+
}
6674
}
6775
],
6876
"properties": [

tests/fixtures/json/1.4/bom_with_full_metadata.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@
9696
},
9797
"licenses": [
9898
{
99-
"expression": "Commercial"
99+
"license": {
100+
"id": "Apache-2.0",
101+
"text": {
102+
"contentType": "text/plain",
103+
"encoding": "base64",
104+
"content": "VGVzdCBjb250ZW50IC0gdGhpcyBpcyBub3QgdGhlIEFwYWNoZSAyLjAgbGljZW5zZSE="
105+
},
106+
"url": "https://www.apache.org/licenses/LICENSE-2.0.txt"
107+
}
100108
}
101109
],
102110
"properties": [

tests/fixtures/xml/1.3/bom_with_full_metadata.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@
4747
</contact>
4848
</supplier>
4949
<licenses>
50-
<expression>Commercial</expression>
50+
<license>
51+
<id>Apache-2.0</id>
52+
<text content-type="text/plain" encoding="base64">VGVzdCBjb250ZW50IC0gdGhpcyBpcyBub3QgdGhlIEFwYWNoZSAyLjAgbGljZW5zZSE=</text>
53+
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
54+
</license>
5155
</licenses>
5256
<properties>
5357
<property name="key1">val1</property>

tests/fixtures/xml/1.4/bom_with_full_metadata.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@
7373
</contact>
7474
</supplier>
7575
<licenses>
76-
<expression>Commercial</expression>
76+
<license>
77+
<id>Apache-2.0</id>
78+
<text content-type="text/plain" encoding="base64">VGVzdCBjb250ZW50IC0gdGhpcyBpcyBub3QgdGhlIEFwYWNoZSAyLjAgbGljZW5zZSE=</text>
79+
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
80+
</license>
7781
</licenses>
7882
<properties>
7983
<property name="key1">val1</property>

0 commit comments

Comments
 (0)