Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlatMerge should deduplicate "equivalent" entries and squash their data #245

Open
wants to merge 297 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
297 commits
Select commit Hold shift + click to select a range
815285c
CycloneDX.Core/Models/Component.cs: basic adjustment to be a BomEntit…
jimklimov Aug 9, 2023
37849b3
CycloneDX.Core/Models/Component.cs: MergeWith(): revise logging level…
jimklimov Aug 9, 2023
277d0da
CycloneDX.Core/Models/Component.cs: MergeWith(): speed-up with BomEnt…
jimklimov Aug 9, 2023
f2e83b7
CycloneDX.Core/Models/Component.cs: MergeWith(): revise logging of sk…
jimklimov Aug 9, 2023
6c3b667
CycloneDX.Core/Models/Component.cs: MergeWith(): revise logging of sk…
jimklimov Aug 9, 2023
eb51a96
CycloneDX.Core/Models/Component.cs: rearrange processing of un-set (n…
jimklimov Aug 9, 2023
a439246
CycloneDX.Core/Models/Component.cs: MergeWith(): revise logging of sk…
jimklimov Aug 9, 2023
cefd853
CycloneDX.Core/Models/Component.cs: MergeWith(): revise handling of v…
jimklimov Aug 9, 2023
1624c20
CycloneDX.Core/Models/Component.cs: MergeWith(): revise discovery of …
jimklimov Aug 9, 2023
476e0e8
Component.MergeWith() and ListMergeHelper.Merge(): use cached BomEnti…
jimklimov Aug 9, 2023
6c7795f
Component.MergeWith(): handle Enum values quickly
jimklimov Aug 9, 2023
d564eb1
Component.MergeWith(): handle Enum values even more quickly
jimklimov Aug 9, 2023
dd4f042
Component.MergeWith(): try to avoid spurious values for null (missing…
jimklimov Aug 9, 2023
49cfff7
Component.MergeWith(): keep track of BomEntity-derived classes which …
jimklimov Aug 10, 2023
c945c45
BomEntity: when tracking BomEntityListReflection[type] also leave a k…
jimklimov Aug 10, 2023
a55b30d
Component.MergeWith(): skip changes due to un-set "other" Modified pr…
jimklimov Aug 10, 2023
6ac10ba
Component.MergeWith(): skip changes due to un-set "this+other" Scope …
jimklimov Aug 10, 2023
510f4d1
Component.MergeWith(): update comments about Scope and NonNullableScope
jimklimov Aug 10, 2023
fb06139
Component.MergeWith(): interrupt list processing as soon as we have a…
jimklimov Aug 10, 2023
006811e
Component.MergeWith(): when preparing the "tmp" clone, skip "NonNulla…
jimklimov Aug 10, 2023
ac15233
Component.MergeWith(): when copying back from the "tmp" clone to "thi…
jimklimov Aug 10, 2023
9666e7a
Component.MergeWith(): leave a TODO comment for code sharing eventually
jimklimov Aug 10, 2023
9c72658
CycloneDX.Core/Json/Serializer.Serialization.cs: implement the one Se…
jimklimov Aug 10, 2023
0827020
CycloneDX.Core/Json/Serializer.Serialization.cs: comment away other i…
jimklimov Aug 10, 2023
8f1be8c
CycloneDX.Core/Json/Serializer.Serialization.cs: tidy up Serialize(Bo…
jimklimov Aug 10, 2023
5adb785
CycloneDX.Core/Json/Serializer.Serialization.cs: introduce SerializeC…
jimklimov Aug 10, 2023
ebd6fdd
BomEntity: avoid caching in KnownTypeSerializers any default implemen…
jimklimov Aug 10, 2023
e54ef7f
Component.MergeWith(): fix comparison of enums
jimklimov Aug 10, 2023
a5db319
Component.MergeWith(): optimize detection of Nullable a bit
jimklimov Aug 10, 2023
423cf2b
Component.MergeWith(): fix comparison of stubborn enums
jimklimov Aug 10, 2023
03f967a
Introduce BomEntityListMergeHelperStrategy to tweak run-time behaviors
jimklimov Aug 10, 2023
29614e0
Merge.cs: Use BomEntityListMergeHelperStrategy for quick FlatMerge() …
jimklimov Aug 10, 2023
00a8ac5
Merge.cs, BomEntity.cs: implement BomEntityListMergeHelperStrategy fo…
jimklimov Aug 10, 2023
9ff40f0
Merge.cs, BomEntity.cs: refactor BomEntityListMergeHelperStrategy for…
jimklimov Aug 10, 2023
e297e97
Merge.cs, BomEntity.cs et al: clean up commented-away experimental an…
jimklimov Aug 10, 2023
8f0bf43
Merge.cs, BomEntity.cs et al: address CI complaints (code style, etc.)
jimklimov Aug 11, 2023
684c899
BomEntity.cs: address CI complaints (protect prepared public lists an…
jimklimov Aug 11, 2023
618a90c
BomEntity.cs: address CI complaints (protect helper class public fiel…
jimklimov Aug 11, 2023
d1938c3
ListMergeHelper: update doc summary of the class
jimklimov Aug 11, 2023
aff0ea5
Validator.cs: document addDictList()
jimklimov Aug 14, 2023
11b62da
Validator.cs: check that for each "ref" pointer in the document, a ta…
jimklimov Aug 14, 2023
641f1ed
Merge branch 'validate-json-bomref' into privateBuild/20230814
jimklimov Aug 14, 2023
cde95ef
Merge.cs, Component.cs: add support for optional mergeWith() method t…
jimklimov Jul 22, 2023
4545835
Merge.cs: refactor with GetMethod() called once and using type-specif…
jimklimov Jul 26, 2023
8f7f53f
Merge.cs: ListMerge: quiesce much of debug message noise
jimklimov Jul 26, 2023
363f6f5
Component.cs: try using ListMergeHelper
jimklimov Jul 26, 2023
4c5e93d
Revert "Component.cs: try using ListMergeHelper"
jimklimov Jul 26, 2023
0a6f7ee
Component.cs: experiment more for mergeWith() to actually act
jimklimov Jul 27, 2023
37adbf7
Merge.cs, Component.cs: relegate debug trace printing to CYCLONEDX_DE…
jimklimov Jul 27, 2023
e91f16f
Component.cs: address some compiler warnings
jimklimov Jul 27, 2023
d67c320
Component.cs: clean up handling of SCOPE merging
jimklimov Jul 27, 2023
86a35e3
Merge.cs: always apply a new timestamp to freshly created "result" Bo…
jimklimov Aug 4, 2023
3f11613
Merge.cs: HierarchicalMerge(): be sure to have a non-null result.Meta…
jimklimov Aug 4, 2023
ec71bbe
Merge.cs: add logic to CleanupMetadataComponent() and CleanupEmptyLis…
jimklimov Aug 4, 2023
ce0afc6
Merge.cs: be more careful about populating metadata/component vs. com…
jimklimov Aug 4, 2023
e0c615b
Components.cs: mergeWith(): revise exception catching for NonNullable…
jimklimov Aug 4, 2023
f177609
Components.cs: mergeWith(): fix equality check for list items
jimklimov Aug 4, 2023
0b6d1ce
Revert "Components.cs: mergeWith(): revise exception catching for Non…
jimklimov Aug 6, 2023
c7af4ce
Introduce a CycloneDX.Core/Models/BomEntity.cs as a base class for sh…
jimklimov Aug 7, 2023
3ef0d36
Hash.cs: implement as a BomEntity descendant class
jimklimov Aug 7, 2023
9b4ea8b
Restore simplistic CycloneDX.Utils/Merge.cs logic for ListMergeHelper…
jimklimov Aug 7, 2023
42d96c3
Restore simplistic CycloneDX.Utils/Merge.cs logic for ListMergeHelper…
jimklimov Aug 7, 2023
8920767
Component.cs: implement as a BomEntity descendant class
jimklimov Aug 7, 2023
99b6644
CycloneDX.Utils/Merge.cs: debug trace if proceeding with legacy logic
jimklimov Aug 7, 2023
4901a93
BomUtils.cs: MergeBomEntityLists(): refactor so it builds
jimklimov Aug 7, 2023
ada2fe5
BomEntity: make exception classes public
jimklimov Aug 7, 2023
75fff60
Merge.cs: update comment
jimklimov Aug 7, 2023
ce29985
Tool.cs: subclass from BomEntity
jimklimov Aug 7, 2023
497c0a1
Move BomUtils:MergeBomEntityLists() to BomEntityListMergeHelper<T> cl…
jimklimov Aug 7, 2023
a6b1ee2
Merge.cs: unite back uses of BomEntityListMergeHelper<T> and legacy L…
jimklimov Aug 7, 2023
b934207
BomEntity.cs: refactor with SerializeEntity() helper
jimklimov Aug 9, 2023
efcd3ba
BomEntity.cs: fix SerializeEntity() to find custom serializer method …
jimklimov Aug 9, 2023
73fbb8e
BomEntity.cs: pre-cache info about custom serializer method if define…
jimklimov Aug 9, 2023
eb67d8b
BomEntity.cs: pre-cache info about Equals(), Equivalent() and MergeWi…
jimklimov Aug 9, 2023
9b78d6a
Merge.cs: ListMergeHelper: use idiomatic and more efficient typeof(T)…
jimklimov Aug 9, 2023
ae5a84b
BomEntity: forward from default Equals() and Equivalent() implems to …
jimklimov Aug 9, 2023
ce746c1
Move ListMergeHelper from Merge.cs to CycloneDX.Core so it can be sha…
jimklimov Aug 9, 2023
e2adbef
CycloneDX.Core Model classes: make them all derivates of BomEntity so…
jimklimov Aug 9, 2023
42648fd
BomEntity: forward from default Equals() and Equivalent() implems to …
jimklimov Aug 9, 2023
9484afb
BomEntity: use KnownTypeMergeWith[] from BomEntityListMergeHelper<> t…
jimklimov Aug 9, 2023
457909d
CycloneDX.Core/Models/Component.cs: basic adjustment to be a BomEntit…
jimklimov Aug 9, 2023
837bd5d
CycloneDX.Core/Models/Component.cs: MergeWith(): revise logging level…
jimklimov Aug 9, 2023
4d30059
CycloneDX.Core/Models/Component.cs: MergeWith(): speed-up with BomEnt…
jimklimov Aug 9, 2023
8801c51
CycloneDX.Core/Models/Component.cs: MergeWith(): revise logging of sk…
jimklimov Aug 9, 2023
693a8e7
CycloneDX.Core/Models/Component.cs: MergeWith(): revise logging of sk…
jimklimov Aug 9, 2023
a330604
CycloneDX.Core/Models/Component.cs: rearrange processing of un-set (n…
jimklimov Aug 9, 2023
80b8c46
CycloneDX.Core/Models/Component.cs: MergeWith(): revise logging of sk…
jimklimov Aug 9, 2023
4f19ce1
CycloneDX.Core/Models/Component.cs: MergeWith(): revise handling of v…
jimklimov Aug 9, 2023
a37a6e4
CycloneDX.Core/Models/Component.cs: MergeWith(): revise discovery of …
jimklimov Aug 9, 2023
c538a3e
Component.MergeWith() and ListMergeHelper.Merge(): use cached BomEnti…
jimklimov Aug 9, 2023
3f8b8aa
Component.MergeWith(): handle Enum values quickly
jimklimov Aug 9, 2023
fbe83b1
Component.MergeWith(): handle Enum values even more quickly
jimklimov Aug 9, 2023
51e7eac
Component.MergeWith(): try to avoid spurious values for null (missing…
jimklimov Aug 9, 2023
1c8c5a8
Component.MergeWith(): keep track of BomEntity-derived classes which …
jimklimov Aug 10, 2023
5f3b30b
BomEntity: when tracking BomEntityListReflection[type] also leave a k…
jimklimov Aug 10, 2023
c7d2f41
Component.MergeWith(): skip changes due to un-set "other" Modified pr…
jimklimov Aug 10, 2023
ddc71d2
Component.MergeWith(): skip changes due to un-set "this+other" Scope …
jimklimov Aug 10, 2023
5701a1c
Component.MergeWith(): update comments about Scope and NonNullableScope
jimklimov Aug 10, 2023
ce4df43
Component.MergeWith(): interrupt list processing as soon as we have a…
jimklimov Aug 10, 2023
993903d
Component.MergeWith(): when preparing the "tmp" clone, skip "NonNulla…
jimklimov Aug 10, 2023
f72f6b5
Component.MergeWith(): when copying back from the "tmp" clone to "thi…
jimklimov Aug 10, 2023
50dea1f
Component.MergeWith(): leave a TODO comment for code sharing eventually
jimklimov Aug 10, 2023
d93e2d2
CycloneDX.Core/Json/Serializer.Serialization.cs: implement the one Se…
jimklimov Aug 10, 2023
182b9cf
CycloneDX.Core/Json/Serializer.Serialization.cs: comment away other i…
jimklimov Aug 10, 2023
205c986
CycloneDX.Core/Json/Serializer.Serialization.cs: tidy up Serialize(Bo…
jimklimov Aug 10, 2023
ad26001
CycloneDX.Core/Json/Serializer.Serialization.cs: introduce SerializeC…
jimklimov Aug 10, 2023
a728449
BomEntity: avoid caching in KnownTypeSerializers any default implemen…
jimklimov Aug 10, 2023
3d46dbc
Component.MergeWith(): fix comparison of enums
jimklimov Aug 10, 2023
43a72f1
Component.MergeWith(): optimize detection of Nullable a bit
jimklimov Aug 10, 2023
c8b704e
Component.MergeWith(): fix comparison of stubborn enums
jimklimov Aug 10, 2023
ffb3108
Introduce BomEntityListMergeHelperStrategy to tweak run-time behaviors
jimklimov Aug 10, 2023
45c30f2
Merge.cs: Use BomEntityListMergeHelperStrategy for quick FlatMerge() …
jimklimov Aug 10, 2023
48fcc03
Merge.cs, BomEntity.cs: implement BomEntityListMergeHelperStrategy fo…
jimklimov Aug 10, 2023
483689e
Merge.cs, BomEntity.cs: refactor BomEntityListMergeHelperStrategy for…
jimklimov Aug 10, 2023
7c7aa82
Merge.cs, BomEntity.cs et al: clean up commented-away experimental an…
jimklimov Aug 10, 2023
2ee5906
Merge.cs, BomEntity.cs et al: address CI complaints (code style, etc.)
jimklimov Aug 11, 2023
d15e8ec
BomEntity.cs: address CI complaints (protect prepared public lists an…
jimklimov Aug 11, 2023
7f3837e
BomEntity.cs: address CI complaints (protect helper class public fiel…
jimklimov Aug 11, 2023
d54affe
ListMergeHelper: update doc summary of the class
jimklimov Aug 11, 2023
49fc976
Merge branch 'flatmerge-dedup-squash' into privateBuild/20230814
jimklimov Aug 14, 2023
1f4c12b
BomEntity.cs, ListMergeHelper.cs: avoid syntax that requires newer C#
jimklimov Aug 14, 2023
5e2f78e
BomEntity.cs, ListMergeHelper.cs: avoid syntax that requires newer C#
jimklimov Aug 14, 2023
44ab3a8
ListMergeHelper.cs: avoid potential null dereference in logging
jimklimov Aug 16, 2023
f8807ce
ListMergeHelper.cs: avoid potential null dereference in logging
jimklimov Aug 16, 2023
5620e17
Merge.cs: update comments
jimklimov Aug 21, 2023
5406535
Merge.cs: introduce CleanupSortLists() as last step, and ListMergeHel…
jimklimov Aug 21, 2023
c17ac40
BomEntity: PoC CompareSelector() offload into classes
jimklimov Aug 21, 2023
4e6fea6
Revert "BomEntity: PoC CompareSelector() offload into classes"
jimklimov Aug 21, 2023
880c416
Merge.cs: update comments
jimklimov Aug 21, 2023
6932232
Merge.cs: introduce CleanupSortLists() as last step, and ListMergeHel…
jimklimov Aug 21, 2023
ef320e9
Merge.cs: inject this cyclonedx-cli script into metadata/tools[]
jimklimov Aug 21, 2023
15bbfe0
BomEntityListMergeHelper: be sure to use info from list1 if it is pre…
jimklimov Aug 21, 2023
e131cd0
BomEntityListMergeHelper: be sure to use info from list1 if it is pre…
jimklimov Aug 21, 2023
48cc06f
Merge.cs: inject this cyclonedx-cli script into metadata/tools[]
jimklimov Aug 21, 2023
3044b8d
Address codacy CI warnings
jimklimov Aug 21, 2023
9049efa
Merge.cs: account different object trees which wield a "BomRef" to ma…
jimklimov Aug 21, 2023
4376167
Merge.cs: comment away INJECTED-ERROR-FOR-TESTING
jimklimov Aug 21, 2023
35bc42b
Merge.cs: account the "BomRef" of the bomSubject optionally coming fr…
jimklimov Aug 21, 2023
65e0397
BomEntity.GetHashCode(): mix length of the serialized representation …
jimklimov Aug 21, 2023
1e788f6
Merge branch 'flatmerge-dedup-squash' into privateBuild/20230821
jimklimov Aug 21, 2023
6c6cf70
Merge.cs: comment away INJECTED-ERROR-FOR-TESTING - reword for CI
jimklimov Aug 21, 2023
9946f2e
Merge.cs: comment away INJECTED-ERROR-FOR-TESTING - reword for CI
jimklimov Aug 21, 2023
922a2b3
Merge branch 'flatmerge-dedup-squash' into privateBuild/20230821
jimklimov Aug 22, 2023
5296596
Component.cs: Equivalent(): refine based on spec and practical identi…
jimklimov Aug 22, 2023
0ca4680
Component.cs: Equivalent(): refine based on spec and practical identi…
jimklimov Aug 22, 2023
b61ac44
ListMergeHelper: refactor SortBy*() methods to minimize the amount of…
jimklimov Aug 22, 2023
33a89ec
BomEntity: cache info about Sort() and Reverse() methods of construct…
jimklimov Aug 22, 2023
01c2215
BomEntity: implement a recursible static NormalizeList() to sort list…
jimklimov Aug 22, 2023
3073e00
ListMergeHelper.SortByImpl(): support calling BomEntity.NormalizeList…
jimklimov Aug 22, 2023
375a4a3
ListMergeHelper: hack around type-less SortByAscending()/SortByDescen…
jimklimov Aug 22, 2023
57d45ee
BomEntity: introduce interface IBomEntity to fiddle with inheritance
jimklimov Aug 22, 2023
2208616
BomEntity: extend KnownTypeNormalizeList detection to cover IBomEntit…
jimklimov Aug 22, 2023
157d660
BomEntity and ListMergeHelper: fix calling of NormalizeList() and bac…
jimklimov Aug 22, 2023
5ac86c1
BomEntity: create simpler NormalizeList() aliases with default settings
jimklimov Aug 22, 2023
9843d5d
Merge: simplify CleanupSortLists() by not keeping sort-filters in the…
jimklimov Aug 22, 2023
568ddc2
Drop IBomEntity as a failed and useless experiment
jimklimov Aug 22, 2023
3262d6d
ListMergeHelper: refactor SortBy*() methods to minimize the amount of…
jimklimov Aug 22, 2023
f7844dc
BomEntity: cache info about Sort() and Reverse() methods of construct…
jimklimov Aug 22, 2023
f4121e0
BomEntity: implement a recursible static NormalizeList() to sort list…
jimklimov Aug 22, 2023
9bd6c02
ListMergeHelper.SortByImpl(): support calling BomEntity.NormalizeList…
jimklimov Aug 22, 2023
2101308
ListMergeHelper: hack around type-less SortByAscending()/SortByDescen…
jimklimov Aug 22, 2023
c1cd826
BomEntity: introduce interface IBomEntity to fiddle with inheritance
jimklimov Aug 22, 2023
1550c27
BomEntity: extend KnownTypeNormalizeList detection to cover IBomEntit…
jimklimov Aug 22, 2023
e0555bf
BomEntity and ListMergeHelper: fix calling of NormalizeList() and bac…
jimklimov Aug 22, 2023
45ad014
BomEntity: create simpler NormalizeList() aliases with default settings
jimklimov Aug 22, 2023
0a101e9
Merge: simplify CleanupSortLists() by not keeping sort-filters in the…
jimklimov Aug 22, 2023
283544b
Drop IBomEntity as a failed and useless experiment
jimklimov Aug 22, 2023
06343c6
BomMerge.cs: fix codacy (bogus) warnings
jimklimov Aug 22, 2023
0641912
BomEntity: KnownEntityTypeLists[]: track BomEntity.NormalizeList() too
jimklimov Aug 23, 2023
c2c2e6f
Merge: CleanupSortLists(): make use of recursive sorting of BomEntity…
jimklimov Aug 23, 2023
a1dfacf
Merge branch 'flatmerge-dedup-squash' into privateBuild/20230821
jimklimov Aug 23, 2023
0449e94
BomEntity and derived types: extend MergeWith() API signature to hand…
jimklimov Aug 29, 2023
c5af163
BomEntityListMergeHelperStrategy: add and explain the renameConflicti…
jimklimov Aug 29, 2023
90951dd
Merge.cs: refactor with ReferThisToolkitMetadata() and update some co…
jimklimov Aug 29, 2023
ff0cff9
Bom.cs: add ability to update Bom document basic metadata (Timestamp,…
jimklimov Aug 30, 2023
4a0f409
Merge.cs: refactor away ReferThisToolkitMetadata() in favor of Bom.Bo…
jimklimov Aug 30, 2023
316098d
BomEntityListMergeHelperStrategy: add toggles to request calls to Bom…
jimklimov Aug 30, 2023
0964657
Merge.cs: refactor updates of Bom Timestamp and similar basic metadat…
jimklimov Aug 30, 2023
9b232d5
Bom.cs: add ability to update Bom document basic metadata (Timestamp,…
jimklimov Aug 30, 2023
00287b9
Merge.cs: use result.BomMetadataUpdate() and BomMetadataReferThisTool…
jimklimov Sep 13, 2023
cd750b9
Bom.cs: modernize BomMetadataReferThisToolkit() for cyclonedx-dotnet-…
jimklimov Sep 13, 2023
67c3cdb
Merge tag 'v6.0.0' into privateBuild/20230914
jimklimov Sep 13, 2023
d12445c
Bom.cs: BomMetadataUpdateSerialNumberVersion(): address static analys…
jimklimov Sep 13, 2023
8e1fc0c
Merge branch 'bom-self-metadata' into privateBuild/20230914
jimklimov Sep 13, 2023
cdbb139
Merge.cs: FlatMerge(): if we did pre-populate result...Tools[], then …
jimklimov Sep 13, 2023
9fdf96e
Merge.cs: HierarchicalMerge(): we did pre-populate result...Tools[], …
jimklimov Sep 13, 2023
14084c5
Merge remote-tracking branch 'upstream/main' into flatmerge-dedup-squash
jimklimov Sep 14, 2023
d52517d
Merge branch 'flatmerge-dedup-squash' into privateBuild/20230914
jimklimov Sep 14, 2023
2e87f5d
Bom.cs: fix compilation warnings with obsoleted Tool class
jimklimov Sep 14, 2023
d29e330
Merge.cs: fix compilation warnings with obsoleted Tool class
jimklimov Sep 14, 2023
9479e4d
Merge branch 'bom-self-metadata' into privateBuild/20230914
jimklimov Sep 14, 2023
9e3cd74
Merge branch 'flatmerge-dedup-squash' into privateBuild/20230914
jimklimov Sep 14, 2023
9e808cb
Make new classes introduced with cyclonedx-dotnet-library v6.0.0 rele…
jimklimov Sep 22, 2023
4829101
Make new classes introduced with cyclonedx-dotnet-library v6.0.0 rele…
jimklimov Sep 22, 2023
545c218
Bom: introduce GetBomRefsByContainer() and transposed GetBomRefsWithC…
jimklimov Sep 22, 2023
3a10bf9
BomEntity.cs: Introduce BomWalkResult helper class
jimklimov Sep 22, 2023
2640634
Bom.cs: moved most of BomRef discovery PoC/logic into a BomWalkResult
jimklimov Sep 29, 2023
82bef90
BomWalkResult: add SerializeBomEntity_BomRefs() helper
jimklimov Sep 25, 2023
86231b3
BomWalkResult: move big comments to SerializeBomEntity_BomRefs()
jimklimov Sep 26, 2023
e950f08
BomWalkResult: use class props for results, not PoC dicts
jimklimov Sep 26, 2023
1d3232b
BomWalkResult: SerializeBomEntity_BomRefs(): try/catch GetValue()
jimklimov Sep 25, 2023
cc59a9d
BomWalkResult: SerializeBomEntity_BomRefs(): fix naming for objType
jimklimov Sep 25, 2023
270f768
BomWalkResult: SerializeBomEntity_BomRefs(): check for "NonNullable*"…
jimklimov Sep 25, 2023
8ee6a67
BomWalkResult: SerializeBomEntity_BomRefs(): with the name check for …
jimklimov Sep 25, 2023
50e5bee
BomWalkResult: SerializeBomEntity_BomRefs(): speed up check for "bom-…
jimklimov Sep 26, 2023
260e95f
BomWalkResult: SerializeBomEntity_BomRefs(): speed up objProperties[]…
jimklimov Sep 26, 2023
28e9132
BomWalkResult: rename GetBomRefsByContainer() => GetBomRefsInContaine…
jimklimov Sep 26, 2023
d27a1a5
Merge.cs: PoC with BomWalkResult in the loop
jimklimov Sep 29, 2023
45af0d0
BomWalkResult: add poor-man's profiling
jimklimov Sep 26, 2023
1daa940
BomWalkResult: minimize lookups into dict by complex key
jimklimov Sep 26, 2023
dd90ba3
BomWalkResult: SerializeBomEntity_BomRefs(): avoid dict key lookup
jimklimov Sep 26, 2023
ef7f5c4
BomWalkResult: add a toggle for debugPerformance
jimklimov Sep 26, 2023
bf591fc
BomWalkResult: constrain evaluation of bom-ref fields to string types
jimklimov Sep 27, 2023
851c978
BomWalkResult: add tracking of "string Ref" back-links
jimklimov Sep 28, 2023
e1da8c6
BomEntity.cs: extend the family with IBomEntity* interfaces
jimklimov Sep 28, 2023
288ef31
BomWalkResult: clarify comments about ref/bomref occurences in spec
jimklimov Sep 28, 2023
3b203ff
BomWalkResult: add tracking of "List<string> Something" back-links
jimklimov Sep 29, 2023
e844169
Bom.cs: introduce an AssertThisBomWalkResult() helper
jimklimov Sep 29, 2023
686ab5d
BomWalkResult: do not constrain refs that they may not be pure whites…
jimklimov Sep 29, 2023
574cdd3
BomEntity: make sure interfaces IBomEntityWithRefType_String_BomRef a…
jimklimov Oct 4, 2023
75d3c17
BomEntity: BomWalkResult: rectify drilling into EvidenceIdentity/Tool…
jimklimov Oct 4, 2023
ee524e7
Bom.cs: implement the logic for RenameBomRef() method
jimklimov Oct 5, 2023
8045799
Mark suitable classes with IBomEntityWithRefType_String_BomRef
jimklimov Oct 5, 2023
a9d56a1
Mark suitable classes with IBomEntityWithRefLinkType_String_Ref and I…
jimklimov Oct 5, 2023
f588a4e
Implement GetRefLinkConstraints() for classes marked with IBomEntityW…
jimklimov Oct 5, 2023
e2473cc
Bom.cs, BomEntity.cs: common base-class default implementation of get…
jimklimov Oct 5, 2023
f5046ab
Bom.cs: drop commented-away code about RenameBomRef() alternative exp…
jimklimov Oct 5, 2023
8a275d4
Merge branch 'flatmerge-dedup-squash-bomwalk' as of 2023-10-05 into f…
jimklimov Oct 5, 2023
4b8e1ae
Address Codacy complaints: redundant parentheses in new Dict<...>() {…
jimklimov Oct 13, 2023
c944324
Address Codacy complaints: redundant parentheses in new List<...>() {…
jimklimov Oct 13, 2023
e6f6070
Address Codacy complaints: make use of namedObjectContainer, convert …
jimklimov Oct 13, 2023
92a5e26
Address Codacy complaints: make use of referrerModified for return va…
jimklimov Oct 13, 2023
7a49466
Address Codacy complaints: convert some properties to private with ge…
jimklimov Oct 13, 2023
0a530f3
Address Codacy complaints: code example is not commented-away code (a…
jimklimov Oct 13, 2023
a06d465
Address Codacy complaints: avoid needless cast
jimklimov Oct 13, 2023
c911bd4
BomEntity.cs: add GetRefsInContainers() for completeness (essentially…
jimklimov Oct 9, 2023
c2e850d
Address Codacy complaints: take BomWalkResult.dictBackrefs private
jimklimov Oct 13, 2023
575c505
Address Codacy complaints: take BomWalkResult.dictRefsInContainers pr…
jimklimov Oct 13, 2023
21487a0
Bom.cs: add GetRefsInContainers() for completeness
jimklimov Oct 13, 2023
590a619
Address Codacy complaints: redundant parentheses in new Dict<...>() {…
jimklimov Oct 13, 2023
16e1300
Address Codacy complaints: make use of referrerModified for return va…
jimklimov Oct 13, 2023
fe41274
Address Codacy complaints: twist back the needed assignment of debugP…
jimklimov Oct 13, 2023
e66bd4f
Address Codacy complaints: be sure to not stop the stopWatchWalkTotal…
jimklimov Oct 13, 2023
0b9fdb6
Address Codacy complaints: shut them off for debugPerformance being p…
jimklimov Oct 13, 2023
2a2b7b5
Address Codacy complaints fallout: add explicit getter/setter for Bom…
jimklimov Oct 13, 2023
86c38ce
Address Codacy complaints fallout: fix signature for Bom.GetRefsInCon…
jimklimov Oct 13, 2023
3c48440
Address Codacy complaints fallout: *public*+get/set = love: fix back …
jimklimov Oct 14, 2023
3d553e9
Component.cs: update comment
jimklimov Oct 14, 2023
5c1e10c
BomEntity.cs: BomWalkResult: update comment about performance-account…
jimklimov Oct 14, 2023
2e52406
Address Codacy complaints fallout: *public*+get/set = love: fix back …
jimklimov Oct 14, 2023
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
2 changes: 1 addition & 1 deletion src/CycloneDX.Core/BomUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,4 @@ public static void EnumerateAllServices(Bom bom, Action<Service> callback)
}
}
}
}
}
76 changes: 55 additions & 21 deletions src/CycloneDX.Core/Json/Serializer.Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ namespace CycloneDX.Json
public static partial class Serializer
{
private static JsonSerializerOptions _options = Utils.GetJsonSerializerOptions();
private static readonly JsonSerializerOptions _options_compact = new Func<JsonSerializerOptions>(() =>
{
JsonSerializerOptions opts = Utils.GetJsonSerializerOptions();
opts.AllowTrailingCommas = false;
opts.WriteIndented = false;

return opts;
}) ();

/// <summary>
/// Serializes a CycloneDX BOM writing the output to a stream.
Expand All @@ -58,34 +66,60 @@ public static string Serialize(Bom bom)
return jsonBom;
}

internal static string Serialize(Component component)
{
Contract.Requires(component != null);
return JsonSerializer.Serialize(component, _options);
}

internal static string Serialize(Dependency dependency)
{
Contract.Requires(dependency != null);
return JsonSerializer.Serialize(dependency, _options);
}

internal static string Serialize(Service service)
/// <summary>
/// Return serialization of a class derived from BomEntity
/// with common JsonSerializerOptions defined for this class.
/// </summary>
/// <param name="entity">A BomEntity-derived class</param>
/// <returns>String with JSON markup</returns>
internal static string Serialize(BomEntity entity)
{
Contract.Requires(service != null);
return JsonSerializer.Serialize(service, _options);
return Serialize(entity, _options);
}

internal static string Serialize(Tool tool)
/// <summary>
/// Return serialization of a class derived from BomEntity
/// with compact JsonSerializerOptions aimed at minimal
/// markup (harder to read for humans, less bytes to parse).
/// </summary>
/// <param name="entity">A BomEntity-derived class</param>
/// <returns>String with JSON markup</returns>
internal static string SerializeCompact(BomEntity entity)
{
Contract.Requires(tool != null);
return JsonSerializer.Serialize(tool, _options);
return Serialize(entity, _options_compact);
}

internal static string Serialize(Models.Vulnerabilities.Vulnerability vulnerability)
/// <summary>
/// Return serialization of a class derived from BomEntity
/// with caller-specified JsonSerializerOptions.
/// </summary>
/// <param name="entity">A BomEntity-derived class</param>
/// <param name="options">Options for serializer</param>
/// <returns>String with JSON markup</returns>
internal static string Serialize(BomEntity entity, JsonSerializerOptions jserOptions)
{
Contract.Requires(vulnerability != null);
return JsonSerializer.Serialize(vulnerability, _options);
Contract.Requires(entity != null);
// Default code tends to return serialization of base class
// => empty (no props in BomEntity itself) so we have to
// coerce it into seeing the object type we need to parse.
// This codepath is critical for us since serialization is
// used to compare if entities are Equal() in massive loops
// when merging Bom's. Optimizations welcome.
string res = null;
if (BomEntity.KnownEntityTypeLists.TryGetValue(entity.GetType(), out var listInfo)
&& listInfo != null && listInfo.genericType != null
&& listInfo.methodAdd != null && listInfo.methodGetItem != null
) {
var castList = Activator.CreateInstance(listInfo.genericType);
listInfo.methodAdd.Invoke(castList, new object[] { entity });
res = JsonSerializer.Serialize(listInfo.methodGetItem.Invoke(castList, new object[] { 0 }), jserOptions);
}
else
{
var castEntity = Convert.ChangeType(entity, entity.GetType());
res = JsonSerializer.Serialize(castEntity, jserOptions);
}
return res;
}
}
}
132 changes: 132 additions & 0 deletions src/CycloneDX.Core/ListMergeHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// This file is part of CycloneDX Library for .NET
//
// Licensed under the Apache License, Version 2.0 (the “License”);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an “AS IS” BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
using CycloneDX.Models;

namespace CycloneDX
{
/// <summary>
/// Allows to merge generic lists with items of specified types
/// (by default essentially adding entries which are not present
/// yet according to List.Contains() method), and calls special
/// logic for lists of BomEntry types.<br/>
///
/// Used in CycloneDX.Utils various Merge implementations as well
/// as in CycloneDX.Core BomEntity-derived classes' MergeWith().<br/>
///
/// Does not modify original lists and returns a new instance
/// with merged data. One exception is if one of the inputs is
/// null or empty - then the other object is returned.
/// </summary>
/// <typeparam name="T">Type of listed entries</typeparam>
public class ListMergeHelper<T>
{
public List<T> Merge(List<T> list1, List<T> list2)
{
return Merge(list1, list2, BomEntityListMergeHelperStrategy.Default());
}

public List<T> Merge(List<T> list1, List<T> list2, BomEntityListMergeHelperStrategy listMergeHelperStrategy)
{
if (!int.TryParse(System.Environment.GetEnvironmentVariable("CYCLONEDX_DEBUG_MERGE"), out int iDebugLevel) || iDebugLevel < 0)
{
iDebugLevel = 0;
}

// Rule out utterly empty inputs
if ((list1 is null || list1.Count < 1) && (list2 is null || list2.Count < 1))
{
if (!(list1 is null))
{
return list1;
}
if (!(list2 is null))
{
return list2;
}
return new List<T>();
}

// At least one of these entries exists, per above sanity check
if (typeof(BomEntity).IsInstanceOfType((!(list1 is null) && list1.Count > 0) ? list1[0] : list2[0]))
{
MethodInfo methodMerge = null;
Object helper;
// Use cached info where available
if (BomEntity.KnownBomEntityListMergeHelpers.TryGetValue(typeof(T), out BomEntityListMergeHelperReflection refInfo))
{
methodMerge = refInfo.methodMerge;
helper = refInfo.helperInstance;
}
else
{
// Inspired by https://stackoverflow.com/a/4661237/4715872
// to craft a List<SpecificType> "result" at run-time:
Type listHelperType = typeof(BomEntityListMergeHelper<>);
var constructedListHelperType = listHelperType.MakeGenericType(typeof(T));
helper = Activator.CreateInstance(constructedListHelperType);
// Gotta use reflection for run-time evaluated type methods:
methodMerge = constructedListHelperType.GetMethod("Merge", 0, new [] { typeof(List<T>), typeof(List<T>), typeof(BomEntityListMergeHelperStrategy) });
}

if (methodMerge != null)
{
return (List<T>)methodMerge.Invoke(helper, new object[] {list1, list2, listMergeHelperStrategy});
}
else
{
// Should not get here, but if we do - log and fall through
if (iDebugLevel >= 1)
{
Console.WriteLine($"Warning: List-Merge for BomEntity failed to find a Merge() helper method: {list1?.GetType()?.ToString()} and {list2?.GetType()?.ToString()}");
}
}
}

// Lists of legacy types (for BomEntity we use BomEntityListMergeHelper<T> class)
if (iDebugLevel >= 1)
{
Console.WriteLine($"List-Merge for legacy types: {list1?.GetType()?.ToString()} and {list2?.GetType()?.ToString()}");
}

if (list1 is null || list1.Count < 1)
{
return list2;
}
if (list2 is null || list2.Count < 1)
{
return list1;
}

var result = new List<T>(list1);

foreach (var item in list2)
{
if (!(result.Contains(item)))
{
result.Add(item);
}
}

return result;
}
}
}
2 changes: 1 addition & 1 deletion src/CycloneDX.Core/Models/AttachedText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace CycloneDX.Models
{
[ProtoContract]
public class AttachedText
public class AttachedText : BomEntity
{
[XmlAttribute("content-type")]
[ProtoMember(1)]
Expand Down
7 changes: 6 additions & 1 deletion src/CycloneDX.Core/Models/Bom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace CycloneDX.Models
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
[XmlRoot("bom", IsNullable=false)]
[ProtoContract]
public class Bom
public class Bom : BomEntity
{
[XmlIgnore]
public string BomFormat => "CycloneDX";
Expand Down Expand Up @@ -133,5 +133,10 @@ public int NonNullableVersion
[ProtoMember(10)]
public List<Vulnerabilities.Vulnerability> Vulnerabilities { get; set; }
public bool ShouldSerializeVulnerabilities() { return Vulnerabilities?.Count > 0; }

// TODO: MergeWith() might be reasonable but is currently handled
// by several strategy implementations in CycloneDX.Utils Merge.cs
// so maybe there should be sub-classes or strategy arguments or
// properties to select one of those implementations at run-time?..
}
}
Loading