From ff12c08f7412c4a753f89fc7c0385cde2c98f022 Mon Sep 17 00:00:00 2001 From: Chalapala RaghavendraReddy Date: Tue, 6 Aug 2024 14:18:47 +0530 Subject: [PATCH] Bug fix for metadata --- .../CycloneBomProcessorTests.cs | 4 +- .../CycloneBomProcessor.cs | 69 +++++++++---------- .../Debian/CCTComparisonBOMDebianInitial.json | 22 ------ 3 files changed, 33 insertions(+), 62 deletions(-) diff --git a/src/LCT.PackageIdentifier.UTest/CycloneBomProcessorTests.cs b/src/LCT.PackageIdentifier.UTest/CycloneBomProcessorTests.cs index 100169b2..5c6455ab 100644 --- a/src/LCT.PackageIdentifier.UTest/CycloneBomProcessorTests.cs +++ b/src/LCT.PackageIdentifier.UTest/CycloneBomProcessorTests.cs @@ -99,8 +99,8 @@ public void SetMetadataInComparisonBOM_GivenBOMWithMetadata_AddsNewMetadataInfoI Bom files = CycloneBomProcessor.SetMetadataInComparisonBOM(bom, appSettings, projectReleases, caToolInformation); //Assert - Assert.That(tools.Name, Is.EqualTo(files.Metadata.Tools[1].Name), "Returns bom with metadata tools"); - Assert.That(SiemensSBOM.Name, Is.EqualTo(files.Metadata.Tools[2].Name), "Returns bom with metadata tools"); + Assert.That(tools.Name, Is.EqualTo(files.Metadata.Tools[0].Name), "Returns bom with metadata tools"); + Assert.That(SiemensSBOM.Name, Is.EqualTo(files.Metadata.Tools[1].Name), "Returns bom with metadata tools"); Assert.That(component.Name, Is.EqualTo(files.Metadata.Component.Name), "Returns bom with metadata component "); Assert.That(component.Version, Is.EqualTo(files.Metadata.Component.Version), "Returns bom with metadata component "); Assert.That(component.Type, Is.EqualTo(files.Metadata.Component.Type), "Returns bom with metadata component "); diff --git a/src/LCT.PackageIdentifier/CycloneBomProcessor.cs b/src/LCT.PackageIdentifier/CycloneBomProcessor.cs index 2f601a1a..16651214 100644 --- a/src/LCT.PackageIdentifier/CycloneBomProcessor.cs +++ b/src/LCT.PackageIdentifier/CycloneBomProcessor.cs @@ -26,60 +26,53 @@ public static Bom SetMetadataInComparisonBOM(Bom bom, CatoolInfo caToolInformation) { Logger.Debug("Starting to add metadata info into the BOM"); - List tools = new List(); - List components = new List(); - List properties = new(); - Tool tool = new Tool + Metadata metadata = new Metadata { - Name = "Clearing Automation Tool", - Version = caToolInformation.CatoolVersion, - Vendor = "Siemens AG", - ExternalReferences = new List() { new ExternalReference { Url = "https://github.com/siemens/continuous-clearing", Type = ExternalReference.ExternalReferenceType.Website } } - + Tools = new List(), + Properties = new List() }; - tools.Add(tool); - Tool SiemensSBOM = new Tool - { - Name = "Siemens SBOM", - Version = "2.0.0", - Vendor = "Siemens AG", - ExternalReferences = new List() { new ExternalReference { Url = "https://sbom.siemens.io/", Type = ExternalReference.ExternalReferenceType.Website } } - }; - tools.Add(SiemensSBOM); + + SetMetaDataToolsValues(metadata, caToolInformation); + Component component = new Component { Name = appSettings.SW360ProjectName, Version = projectReleases.Version, Type = Component.Classification.Application }; - components.Add(component); + metadata.Component = component; - if (bom.Metadata != null) - { - bom.Metadata.Tools.AddRange(tools); - bom.Metadata.Component = bom.Metadata.Component ?? new Component(); - bom.Metadata.Component.Name = component.Name; - bom.Metadata.Component.Version = component.Version; - bom.Metadata.Component.Type = component.Type; - } - else - { - bom.Metadata = new Metadata - { - Tools = tools, - Component = component, - }; - } - Property projectType = new() + Property projectType = new Property { Name = "siemens:profile", Value = "clearing" }; - bom.Metadata.Properties = properties; - bom.Metadata.Properties.Add(projectType); + metadata.Properties.Add(projectType); + + bom.Metadata = metadata; return bom; } + public static void SetMetaDataToolsValues(Metadata metadata, CatoolInfo caToolInformation) + { + Tool tool = new Tool + { + Name = "Clearing Automation Tool", + Version = caToolInformation.CatoolVersion, + Vendor = "Siemens AG", + ExternalReferences = new List() { new ExternalReference { Url = "https://github.com/siemens/continuous-clearing", Type = ExternalReference.ExternalReferenceType.Website } } + }; + metadata.Tools.Add(tool); + + Tool SiemensSBOM = new Tool + { + Name = "Siemens SBOM", + Version = "2.0.0", + Vendor = "Siemens AG", + ExternalReferences = new List() { new ExternalReference { Url = "https://sbom.siemens.io/", Type = ExternalReference.ExternalReferenceType.Website } } + }; + metadata.Tools.Add(SiemensSBOM); + } public static void SetProperties(CommonAppSettings appSettings, Component component, ref List componentForBOM, string repo = "Not Found in JFrogRepo") { List propList = new(); diff --git a/src/SW360IntegrationTest/PackageCreatorTestFiles/Debian/CCTComparisonBOMDebianInitial.json b/src/SW360IntegrationTest/PackageCreatorTestFiles/Debian/CCTComparisonBOMDebianInitial.json index 958fc349..fc1db315 100644 --- a/src/SW360IntegrationTest/PackageCreatorTestFiles/Debian/CCTComparisonBOMDebianInitial.json +++ b/src/SW360IntegrationTest/PackageCreatorTestFiles/Debian/CCTComparisonBOMDebianInitial.json @@ -6,28 +6,6 @@ "metadata": { "timestamp": "2024-07-06T14:57:50Z", "tools": [ - { - "vendor": "Siemens AG", - "name": "Clearing Automation Tool", - "version": "6.1.0", - "externalReferences": [ - { - "url": "https://github.com/siemens/continuous-clearing", - "type": "website" - } - ] - }, - { - "vendor": "Siemens AG", - "name": "Siemens SBOM", - "version": "2.0.0", - "externalReferences": [ - { - "url": "https://sbom.siemens.io/", - "type": "website" - } - ] - }, { "vendor": "Siemens AG", "name": "Clearing Automation Tool",