Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/formattedcode/output_cyclonedx.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class CycloneDxLicenseExpression(ToDictMixin):
"""
expression: str = attr.ib(default=None)

@property
def identifier(self):
return self.expression

@classmethod
def from_package(cls, package):
"""
Expand All @@ -81,6 +85,10 @@ class CycloneDxProperty(ToDictMixin):
name: str = attr.ib()
value: str = attr.ib()

@property
def identifier(self):
return f"{self.name}-{self.value}"


@attr.s
class CycloneDxHashObject(ToDictMixin):
Expand All @@ -98,6 +106,10 @@ class CycloneDxHashObject(ToDictMixin):
alg: str = attr.ib()
content: str = attr.ib()

@property
def identifier(self):
return f"{self.alg}-{self.content}"

@classmethod
def from_package(cls, package):
"""
Expand Down Expand Up @@ -159,6 +171,10 @@ class CycloneDxExternalRef(ToDictMixin):
comment: str = attr.ib(default=None)
hashes: List[CycloneDxHashObject] = attr.ib(factory=list)

@property
def identifier(self):
return f"{self.url}-{self.type}-{self.comment}"

@classmethod
def from_package(cls, package: dict):
"""
Expand Down Expand Up @@ -290,7 +306,8 @@ def from_package(cls, package):
properties.append(
CycloneDxProperty(
name='WARNING',
value=f'WARNING: component skipped in CycloneDX output: {package!r}'
value=f'WARNING: component skipped in CycloneDX output:'
f' purl: {package["purl"]} at datafile_paths: {package["datafile_paths"]}'
)
)

Expand Down Expand Up @@ -428,8 +445,8 @@ def merge_lists(x, y):
Merge ``y`` list items in list ``x`` avoiding duplicate entries.
Return the updated ``x``.
"""
seen = set(x)
new = (i for i in y if i not in seen)
seen = set([item.identifier for item in x])
new = (item for item in y if item.identifier not in seen)
x.extend(new)
return x

Expand Down
36 changes: 36 additions & 0 deletions tests/formattedcode/data/cyclonedx/simple-icu-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"bomFormat": "CycloneDX",
"specVersion": "1.3",
"version": 1,
"components": [
{
"name": "source",
"version": null,
"bom-ref": "pkg:autotools/source",
"group": null,
"type": "library",
"scope": "required",
"copyright": null,
"author": null,
"description": null,
"purl": "pkg:autotools/source",
"hashes": [],
"licenses": [
{
"expression": "LicenseRef-scancode-unicode AND FSFUL AND (FSFUL AND LicenseRef-scancode-unicode)"
},
{
"expression": "LicenseRef-scancode-unicode"
}
],
"externalReferences": [],
"properties": [
{
"name": "WARNING",
"value": "WARNING: component skipped in CycloneDX output: purl: pkg:autotools/source at datafile_paths: ['simple-icu/source/configure']"
}
]
}
],
"dependencies": []
}
Loading