From 9754855642ec7a8563afb9ff41b8bb6516935653 Mon Sep 17 00:00:00 2001
From: Chalapala RaghavendraReddy <raghavendrareddy.chalapala@siemens.com>
Date: Sun, 12 Jan 2025 08:45:52 +0530
Subject: [PATCH] Changes for multipleversions

---
 src/LCT.PackageIdentifier/ConanProcessor.cs | 11 +++++++++--
 src/LCT.PackageIdentifier/NpmProcessor.cs   |  9 ++++++++-
 src/LCT.PackageIdentifier/NugetProcessor.cs |  9 ++++++++-
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/LCT.PackageIdentifier/ConanProcessor.cs b/src/LCT.PackageIdentifier/ConanProcessor.cs
index 4f03622c..51b78a42 100644
--- a/src/LCT.PackageIdentifier/ConanProcessor.cs
+++ b/src/LCT.PackageIdentifier/ConanProcessor.cs
@@ -219,13 +219,20 @@ private static void CreateFileForMultipleVersions(List<Component> componentsWith
         {
             MultipleVersions multipleVersions = new MultipleVersions();
             IFileOperations fileOperations = new FileOperations();
+            string bomFileName = $"{appSettings.SW360.ProjectName}_Bom.cdx.json";
+            string outputFolderPath = appSettings.Directory.OutputFolder;
+            string[] files = System.IO.Directory.GetFiles(outputFolderPath);
+
+            bool fileExists = files.Length > 0 && files.Any(file => Path.GetFileName(file).Equals(bomFileName, StringComparison.OrdinalIgnoreCase));
+            string bomFullPath= $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_Bom.cdx.json";
+
             string filename = $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}";
-            if (string.IsNullOrEmpty(appSettings.Directory.OutputFolder) || (!File.Exists(filename)))
+            if (fileExists || (!File.Exists(filename)))
             {
                 multipleVersions.Conan = new List<MultipleVersionValues>();
                 foreach (var conanPackage in componentsWithMultipleVersions)
                 {
-                 
+                    conanPackage.Description = !string.IsNullOrEmpty(bomFullPath) ? bomFullPath : conanPackage.Description;
                     MultipleVersionValues jsonComponents = new MultipleVersionValues();
                     jsonComponents.ComponentName = conanPackage.Name;
                     jsonComponents.ComponentVersion = conanPackage.Version;
diff --git a/src/LCT.PackageIdentifier/NpmProcessor.cs b/src/LCT.PackageIdentifier/NpmProcessor.cs
index 0782395b..0aa8798a 100644
--- a/src/LCT.PackageIdentifier/NpmProcessor.cs
+++ b/src/LCT.PackageIdentifier/NpmProcessor.cs
@@ -153,12 +153,19 @@ private static void CreateFileForMultipleVersions(List<Component> componentsWith
         {
             MultipleVersions multipleVersions = new MultipleVersions();
             IFileOperations fileOperations = new FileOperations();
+            string bomFileName = $"{appSettings.SW360.ProjectName}_Bom.cdx.json";
+            string outputFolderPath = appSettings.Directory.OutputFolder;
+            string[] files = System.IO.Directory.GetFiles(outputFolderPath);
+
+            bool fileExists = files.Length > 0 && files.Any(file => Path.GetFileName(file).Equals(bomFileName, StringComparison.OrdinalIgnoreCase));
+            string bomFullPath = $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_Bom.cdx.json";
             string filename = $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}";
-            if (string.IsNullOrEmpty(appSettings.Directory.OutputFolder) || (!File.Exists(filename)))
+            if (fileExists || (!File.Exists(filename)))
             {
                 multipleVersions.Npm = new List<MultipleVersionValues>();
                 foreach (var npmpackage in componentsWithMultipleVersions)
                 {
+                    npmpackage.Description = !string.IsNullOrEmpty(bomFullPath) ? bomFullPath : npmpackage.Description;
                     MultipleVersionValues jsonComponents = new MultipleVersionValues();
                     jsonComponents.ComponentName = npmpackage.Name;
                     jsonComponents.ComponentVersion = npmpackage.Version;
diff --git a/src/LCT.PackageIdentifier/NugetProcessor.cs b/src/LCT.PackageIdentifier/NugetProcessor.cs
index 6e9b4467..90ff1a1b 100644
--- a/src/LCT.PackageIdentifier/NugetProcessor.cs
+++ b/src/LCT.PackageIdentifier/NugetProcessor.cs
@@ -542,12 +542,19 @@ private static void CreateFileForMultipleVersions(List<Component> componentsWith
         {
             MultipleVersions multipleVersions = new MultipleVersions();
             IFileOperations fileOperations = new FileOperations();
+            string bomFileName = $"{appSettings.SW360.ProjectName}_Bom.cdx.json";
+            string outputFolderPath = appSettings.Directory.OutputFolder;
+            string[] files = System.IO.Directory.GetFiles(outputFolderPath);
+
+            bool fileExists = files.Length > 0 && files.Any(file => Path.GetFileName(file).Equals(bomFileName, StringComparison.OrdinalIgnoreCase));
+            string bomFullPath = $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_Bom.cdx.json";
             string filename = $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}";
-            if (string.IsNullOrEmpty(appSettings.Directory.OutputFolder) || (!File.Exists(filename)))
+            if (fileExists || (!File.Exists(filename)))
             {
                 multipleVersions.Nuget = new List<MultipleVersionValues>();
                 foreach (var nugetPackage in componentsWithMultipleVersions)
                 {
+                    nugetPackage.Description = !string.IsNullOrEmpty(bomFullPath) ? bomFullPath : nugetPackage.Description;
                     MultipleVersionValues jsonComponents = new MultipleVersionValues();
                     jsonComponents.ComponentName = nugetPackage.Name;
                     jsonComponents.ComponentVersion = nugetPackage.Version;