Skip to content

Commit ec22ec6

Browse files
Add timestamp in merge command (#452)
Fixes: #438 This is an alternative to #334, but it doesn't require updates of the underlying library. It also adapts the corresponding tests. Signed-off-by: andreas hilti <[email protected]>
1 parent 2c83ca9 commit ec22ec6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/cyclonedx/Commands/MergeCommand.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ public static async Task<int> Merge(MergeCommandOptions options)
107107

108108
outputBom.Version = 1;
109109
outputBom.SerialNumber = "urn:uuid:" + System.Guid.NewGuid().ToString();
110+
if (outputBom.Metadata == null)
111+
{
112+
outputBom.Metadata = new Metadata();
113+
}
114+
if (outputBom.Metadata.Timestamp == null)
115+
{
116+
outputBom.Metadata.Timestamp = DateTime.Now;
117+
}
110118

111119
if (!outputToConsole)
112120
{

tests/cyclonedx.tests/MergeTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public async Task Merge(
7777
var bom = File.ReadAllText(fullOutputPath);
7878
bom = Regex.Replace(bom, @"\s*""serialNumber"": "".*?"",\r?\n", ""); // json
7979
bom = Regex.Replace(bom, @"\s+serialNumber="".*?""", ""); // xml
80+
bom = Regex.Replace(bom, @"\s*""timestamp"": "".*?"",\r?\n", ""); // json
81+
bom = Regex.Replace(bom, @"\s+<timestamp>.*?</timestamp>", ""); // xml
8082
Snapshot.Match(bom, SnapshotNameExtension.Create(hierarchical ? "Hierarchical" : "Flat", snapshotInputFilenames, inputFormat, outputFilename, outputFormat, outputVersion));
8183
}
8284
}

0 commit comments

Comments
 (0)