diff --git a/src/LCT.Common.UTests/CommonHelperTest.cs b/src/LCT.Common.UTests/CommonHelperTest.cs index 2c8e68ea..2df2dca0 100644 --- a/src/LCT.Common.UTests/CommonHelperTest.cs +++ b/src/LCT.Common.UTests/CommonHelperTest.cs @@ -43,7 +43,7 @@ public void RemoveExcludedComponents_PassingList_ReturnSuccess() list.Add("Debian:Debian"); //Act - List result = CommonHelper.RemoveExcludedComponents(ComponentsForBom, list, ref noOfExcludedComponents); + List result = CommonHelper.FlagExcludedComponentsAsInternal(ComponentsForBom, list, ref noOfExcludedComponents); //Assert Assert.IsTrue(result.Count > 0); @@ -66,7 +66,7 @@ public void RemoveMultipleExcludedComponents_ReturnSuccess() list.Add("Newton:3.1.3"); //Act - CommonHelper.RemoveExcludedComponents(ComponentsForBom, list, ref noOfExcludedComponents); + CommonHelper.FlagExcludedComponentsAsInternal(ComponentsForBom, list, ref noOfExcludedComponents); //Assert Assert.That(noOfExcludedComponents, Is.EqualTo(4), "Returns the count of excluded components"); @@ -273,7 +273,7 @@ public void RemoveExcludedComponents_WhenExcludedComponentMatches_ReturnsExclude int noOfExcludedComponents = 0; // Act - List result = CommonHelper.RemoveExcludedComponents(componentList, excludedComponents, ref noOfExcludedComponents); + List result = CommonHelper.FlagExcludedComponentsAsInternal(componentList, excludedComponents, ref noOfExcludedComponents); // Assert Assert.AreEqual(1, result.Count); @@ -296,7 +296,7 @@ public void RemoveExcludedComponents_WhenExcludedComponentDoesNotMatch_ReturnsOr int noOfExcludedComponents = 0; // Act - List result = CommonHelper.RemoveExcludedComponents(componentList, excludedComponents, ref noOfExcludedComponents); + List result = CommonHelper.FlagExcludedComponentsAsInternal(componentList, excludedComponents, ref noOfExcludedComponents); // Assert Assert.AreEqual(3, result.Count); diff --git a/src/LCT.Common/CommonHelper.cs b/src/LCT.Common/CommonHelper.cs index cd528f17..9987546f 100644 --- a/src/LCT.Common/CommonHelper.cs +++ b/src/LCT.Common/CommonHelper.cs @@ -37,8 +37,9 @@ public static bool IsAzureDevOpsDebugEnabled() return false; } - public static List RemoveExcludedComponents(List ComponentList, List ExcludedComponents, ref int noOfExcludedComponents) + public static List FlagExcludedComponentsAsInternal(List ComponentList, List ExcludedComponents, ref int noOfExcludedComponents) { + // find the excluded components in the identified list of components List ExcludedList = new List(); foreach (string excludedComponent in ExcludedComponents) { @@ -54,11 +55,20 @@ public static List RemoveExcludedComponents(List Component (component.Version.ToLowerInvariant().Contains(excludedcomponent[1].ToLowerInvariant()) || excludedcomponent[1].ToLowerInvariant() == "*")) { noOfExcludedComponents++; + + // flag excluded component as internal 20:12:2024 + Property property = new Property(); + property.Name = Dataconstant.Cdx_IsInternal; + property.Value = "true"; + if (!component.Properties.Exists(x => x.Name.Equals(property.Name))) + { + component.Properties.Add(property); + } + ExcludedList.Add(component); } } } - ComponentList.RemoveAll(item => ExcludedList.Contains(item)); return ComponentList; } diff --git a/src/LCT.PackageIdentifier/AlpineProcesser.cs b/src/LCT.PackageIdentifier/AlpineProcesser.cs index 9607d14d..66eeddbc 100644 --- a/src/LCT.PackageIdentifier/AlpineProcesser.cs +++ b/src/LCT.PackageIdentifier/AlpineProcesser.cs @@ -79,7 +79,7 @@ public static Bom RemoveExcludedComponents(CommonAppSettings appSettings, Bom cy int noOfExcludedComponents = 0; if (appSettings.Alpine.ExcludedComponents != null) { - componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.Alpine.ExcludedComponents, ref noOfExcludedComponents); + componentForBOM = CommonHelper.FlagExcludedComponentsAsInternal(componentForBOM, appSettings.Alpine.ExcludedComponents, ref noOfExcludedComponents); dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents; diff --git a/src/LCT.PackageIdentifier/BomValidator.cs b/src/LCT.PackageIdentifier/BomValidator.cs index af87aeb3..51663705 100644 --- a/src/LCT.PackageIdentifier/BomValidator.cs +++ b/src/LCT.PackageIdentifier/BomValidator.cs @@ -36,7 +36,7 @@ public static async Task ValidateAppSettings(CommonAppSettings appSettings, return -1; } else - { + { appSettings.SW360ProjectName = sw360ProjectName; } return 0; diff --git a/src/LCT.PackageIdentifier/ConanProcessor.cs b/src/LCT.PackageIdentifier/ConanProcessor.cs index 936da4a4..7747bca0 100644 --- a/src/LCT.PackageIdentifier/ConanProcessor.cs +++ b/src/LCT.PackageIdentifier/ConanProcessor.cs @@ -528,7 +528,7 @@ private static Bom RemoveExcludedComponents(CommonAppSettings appSettings, Bom c int noOfExcludedComponents = 0; if (appSettings.Conan.ExcludedComponents != null) { - componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.Conan.ExcludedComponents, ref noOfExcludedComponents); + componentForBOM = CommonHelper.FlagExcludedComponentsAsInternal(componentForBOM, appSettings.Conan.ExcludedComponents, ref noOfExcludedComponents); dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents; } diff --git a/src/LCT.PackageIdentifier/CycloneBomProcessor.cs b/src/LCT.PackageIdentifier/CycloneBomProcessor.cs index 16651214..4f4933c3 100644 --- a/src/LCT.PackageIdentifier/CycloneBomProcessor.cs +++ b/src/LCT.PackageIdentifier/CycloneBomProcessor.cs @@ -120,7 +120,10 @@ public static void SetProperties(CommonAppSettings appSettings, Component compon Name = Dataconstant.Cdx_JfrogRepoPath, Value = Dataconstant.JfrogRepoPathNotFound }; - component.Properties.Add(internalType); + if (!component.Properties.Exists(x => x.Name.Equals(internalType.Name))) + { + component.Properties.Add(internalType); + } component.Properties.Add(artifactoryrepo); component.Properties.Add(projectType); component.Properties.Add(isDevelopment); diff --git a/src/LCT.PackageIdentifier/DebianProcessor.cs b/src/LCT.PackageIdentifier/DebianProcessor.cs index f4dccba7..5f762373 100644 --- a/src/LCT.PackageIdentifier/DebianProcessor.cs +++ b/src/LCT.PackageIdentifier/DebianProcessor.cs @@ -114,7 +114,7 @@ public static Bom RemoveExcludedComponents(CommonAppSettings appSettings, Bom cy int noOfExcludedComponents = 0; if (appSettings.Debian.ExcludedComponents != null) { - componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.Debian.ExcludedComponents, ref noOfExcludedComponents); + componentForBOM = CommonHelper.FlagExcludedComponentsAsInternal(componentForBOM, appSettings.Debian.ExcludedComponents, ref noOfExcludedComponents); dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents; } diff --git a/src/LCT.PackageIdentifier/MavenProcessor.cs b/src/LCT.PackageIdentifier/MavenProcessor.cs index 511fdea7..d86a6fcb 100644 --- a/src/LCT.PackageIdentifier/MavenProcessor.cs +++ b/src/LCT.PackageIdentifier/MavenProcessor.cs @@ -99,7 +99,7 @@ public Bom ParsePackageFile(CommonAppSettings appSettings) if (appSettings.Maven.ExcludedComponents != null) { - componentsForBOM = CommonHelper.RemoveExcludedComponents(componentsForBOM, appSettings.Maven.ExcludedComponents, ref noOfExcludedComponents); + componentsForBOM = CommonHelper.FlagExcludedComponentsAsInternal(componentsForBOM, appSettings.Maven.ExcludedComponents, ref noOfExcludedComponents); dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentsForBOM, dependenciesForBOM); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents; } diff --git a/src/LCT.PackageIdentifier/NpmProcessor.cs b/src/LCT.PackageIdentifier/NpmProcessor.cs index d269025b..7be7a522 100644 --- a/src/LCT.PackageIdentifier/NpmProcessor.cs +++ b/src/LCT.PackageIdentifier/NpmProcessor.cs @@ -108,7 +108,7 @@ public List ParsePackageLockJson(string filepath, CommonAppSettings a if (appSettings.Npm.ExcludedComponents != null) { - lstComponentForBOM = CommonHelper.RemoveExcludedComponents(lstComponentForBOM, appSettings.Npm.ExcludedComponents, ref noOfExcludedComponents); + lstComponentForBOM = CommonHelper.FlagExcludedComponentsAsInternal(lstComponentForBOM, appSettings.Npm.ExcludedComponents, ref noOfExcludedComponents); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents; } @@ -374,13 +374,20 @@ public async Task IdentificationOfInternalComponents( { internalComponents.Add(currentIterationItem); isInternal.Value = "true"; + if (!component.Properties.Exists(x => x.Name.Equals(isInternal.Name))) + { + currentIterationItem.Properties.Add(isInternal); + } } - else - { - isInternal.Value = "false"; + else { + if (!component.Properties.Exists(x => x.Name.Equals(isInternal.Name))) + { + currentIterationItem.Properties.Add(isInternal); + } } - currentIterationItem.Properties.Add(isInternal); + + internalComponentStatusUpdatedList.Add(currentIterationItem); } @@ -457,7 +464,7 @@ public static Bom RemoveExcludedComponents(CommonAppSettings appSettings, Bom cy int noOfExcludedComponents = 0; if (appSettings.Npm.ExcludedComponents != null) { - componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.Npm.ExcludedComponents, ref noOfExcludedComponents); + componentForBOM = CommonHelper.FlagExcludedComponentsAsInternal(componentForBOM, appSettings.Npm.ExcludedComponents, ref noOfExcludedComponents); dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents; @@ -606,7 +613,7 @@ private static List RemoveBundledComponentFromList(List aqlResultList, Component component, IBomHelper bomHelper) - { + { string jfrogcomponentName = $"{component.Name}-{component.Version}.tgz"; if (aqlResultList.Exists( x => x.Name.Equals(jfrogcomponentName, StringComparison.OrdinalIgnoreCase))) diff --git a/src/LCT.PackageIdentifier/NugetProcessor.cs b/src/LCT.PackageIdentifier/NugetProcessor.cs index a3450ec0..e46c7b45 100644 --- a/src/LCT.PackageIdentifier/NugetProcessor.cs +++ b/src/LCT.PackageIdentifier/NugetProcessor.cs @@ -394,7 +394,7 @@ public static Bom RemoveExcludedComponents(CommonAppSettings appSettings, Bom cy int noOfExcludedComponents = 0; if (appSettings.Nuget.ExcludedComponents != null) { - componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.Nuget.ExcludedComponents, ref noOfExcludedComponents); + componentForBOM = CommonHelper.FlagExcludedComponentsAsInternal(componentForBOM, appSettings.Nuget.ExcludedComponents, ref noOfExcludedComponents); dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents; diff --git a/src/LCT.PackageIdentifier/PythonProcessor.cs b/src/LCT.PackageIdentifier/PythonProcessor.cs index 2daadc33..1b1dc533 100644 --- a/src/LCT.PackageIdentifier/PythonProcessor.cs +++ b/src/LCT.PackageIdentifier/PythonProcessor.cs @@ -304,7 +304,7 @@ private static Bom RemoveExcludedComponents(CommonAppSettings appSettings, int noOfExcludedComponents = 0; if (appSettings.Python.ExcludedComponents != null) { - componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.Python.ExcludedComponents, ref noOfExcludedComponents); + componentForBOM = CommonHelper.FlagExcludedComponentsAsInternal(componentForBOM, appSettings.Python.ExcludedComponents, ref noOfExcludedComponents); dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents;