Skip to content

Commit

Permalink
add exclude components in tool output bom and remove from sw360 clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
Viji committed Dec 20, 2024
1 parent 8f68d69 commit 490452a
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/LCT.Common.UTests/CommonHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void RemoveExcludedComponents_PassingList_ReturnSuccess()
list.Add("Debian:Debian");

//Act
List<Component> result = CommonHelper.RemoveExcludedComponents(ComponentsForBom, list, ref noOfExcludedComponents);
List<Component> result = CommonHelper.FlagExcludedComponentsAsInternal(ComponentsForBom, list, ref noOfExcludedComponents);

//Assert
Assert.IsTrue(result.Count > 0);
Expand All @@ -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");
Expand Down Expand Up @@ -273,7 +273,7 @@ public void RemoveExcludedComponents_WhenExcludedComponentMatches_ReturnsExclude
int noOfExcludedComponents = 0;

// Act
List<Component> result = CommonHelper.RemoveExcludedComponents(componentList, excludedComponents, ref noOfExcludedComponents);
List<Component> result = CommonHelper.FlagExcludedComponentsAsInternal(componentList, excludedComponents, ref noOfExcludedComponents);

// Assert
Assert.AreEqual(1, result.Count);
Expand All @@ -296,7 +296,7 @@ public void RemoveExcludedComponents_WhenExcludedComponentDoesNotMatch_ReturnsOr
int noOfExcludedComponents = 0;

// Act
List<Component> result = CommonHelper.RemoveExcludedComponents(componentList, excludedComponents, ref noOfExcludedComponents);
List<Component> result = CommonHelper.FlagExcludedComponentsAsInternal(componentList, excludedComponents, ref noOfExcludedComponents);

// Assert
Assert.AreEqual(3, result.Count);
Expand Down
14 changes: 12 additions & 2 deletions src/LCT.Common/CommonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public static bool IsAzureDevOpsDebugEnabled()
return false;
}

public static List<Component> RemoveExcludedComponents(List<Component> ComponentList, List<string> ExcludedComponents, ref int noOfExcludedComponents)
public static List<Component> FlagExcludedComponentsAsInternal(List<Component> ComponentList, List<string> ExcludedComponents, ref int noOfExcludedComponents)
{
// find the excluded components in the identified list of components
List<Component> ExcludedList = new List<Component>();
foreach (string excludedComponent in ExcludedComponents)
{
Expand All @@ -54,11 +55,20 @@ public static List<Component> RemoveExcludedComponents(List<Component> 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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/LCT.PackageIdentifier/AlpineProcesser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/LCT.PackageIdentifier/BomValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static async Task<int> ValidateAppSettings(CommonAppSettings appSettings,
return -1;
}
else
{
{
appSettings.SW360ProjectName = sw360ProjectName;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/LCT.PackageIdentifier/ConanProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion src/LCT.PackageIdentifier/CycloneBomProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/LCT.PackageIdentifier/DebianProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/LCT.PackageIdentifier/MavenProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 14 additions & 7 deletions src/LCT.PackageIdentifier/NpmProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public List<Component> 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;

}
Expand Down Expand Up @@ -374,13 +374,20 @@ public async Task<ComponentIdentification> 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);
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -606,7 +613,7 @@ private static List<Component> RemoveBundledComponentFromList(List<BundledCompon

private static bool IsInternalNpmComponent(
List<AqlResult> aqlResultList, Component component, IBomHelper bomHelper)
{
{
string jfrogcomponentName = $"{component.Name}-{component.Version}.tgz";
if (aqlResultList.Exists(
x => x.Name.Equals(jfrogcomponentName, StringComparison.OrdinalIgnoreCase)))
Expand Down
2 changes: 1 addition & 1 deletion src/LCT.PackageIdentifier/NugetProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/LCT.PackageIdentifier/PythonProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 490452a

Please sign in to comment.