Skip to content

Add "rename-entity" command: rewrite a bom-ref and its back-references - #509

Open
jimklimov wants to merge 2 commits into
CycloneDX:mainfrom
jimklimov:rename-entity-command
Open

jimklimov wants to merge 2 commits into
CycloneDX:mainfrom
jimklimov:rename-entity-command

Conversation

@jimklimov

Copy link
Copy Markdown
Contributor

What

Adds a cyclonedx rename-entity command: rewrites a bom-ref and every back-reference to it
(Metadata.Component, Components, Services, Dependencies, Compositions, Vulnerabilities,
Annotations) throughout a document in one pass, via Bom.RenameRef(). Includes regression tests
(RenameEntityTests.cs).

Why

This is #396 (which itself revived #346) done again: #346 was merged without tests and then reverted
before the v0.26.0 release (commit 91cf6c6) because the library didn't yet expose the primitives it
needed; #396 stalled waiting on the library-side BomEntity family and metadata-update methods.

Both of those are now in cyclonedx-dotnet-library#446
(BomRefWalker, Bom.RenameRef), which this PR depends on — it won't build against the currently
published library until that merges and releases. Supersedes #396; closing that in favor of this PR.

Independent of the other CLI PRs in this batch (touches only RenameEntityCommand(Options).cs and
Program.cs, no shared files) — can merge in any order relative to them, once the library dependency
lands.

Adds a "rename-entity" command that renames a bom-ref and every
back-reference to it throughout a BOM document, built on the
library's new BomRefWalker-based Bom.RenameRef(old, new) API. Follows
current System.CommandLine conventions
(System.CommandLine.NamingConventionBinder, not the older
System.CommandLine.Invocation namespace) and matches Convert/
MergeCommand's internal (not public) visibility.

Verified end-to-end against a real fixture: renaming a component's
bom-ref correctly rewrites both the dependsOn back-reference and the
dependency's own ref entry, and stamps fresh SerialNumber/Timestamp/
Tools metadata via BomMetadataUpdate/BomMetadataReferThisToolkit.

Wired into Program.cs (alphabetical position, between Merge and Sign),
guarded by #if NET8_0_OR_GREATER to match the library capability it
depends on.

Signed-off-by: Jim Klimov <jimklimov@gmail.com>
Follows MergeTests.cs conventions: direct handler call, TempDirectory,
Snapshooter with serialNumber/timestamp stripped (plus the tools list,
whose contents are build/environment-specific -- assembly versions and
"testhost" vs. the real CLI name under `dotnet test`). Covers a JSON
and an XML output round-trip of the rewrite-identifier-and-back-refs
case, plus a no-op case when the requested old-ref isn't present.

Full suite: 132 passed / 0 failed (129 pre-existing + 3 new).

Signed-off-by: Jim Klimov <jimklimov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant