Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add exclude components in tool output bom and remove from sw360 clearing #223

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/LCT.Common.UTests/CommonHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace LCT.Common.UTest
[TestFixture]
public class CommonHelperTest
{

[Test]
public void WriteComponentsNotLinkedListInConsole_PassingList_ReturnSuccess()
{
Expand All @@ -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,11 +273,11 @@ 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);
Assert.IsFalse(result.Any(c => c.Name == "Component1" && c.Version == "1.0"));
Assert.AreEqual(3, result.Count);
Assert.IsTrue(result.Any(c => c.Name == "Component1" && c.Version == "1.0"));
Assert.IsTrue(result.Any(c => c.Name == "Component3" && c.Version == "3.0"));
Assert.AreEqual(2, noOfExcludedComponents);
}
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
19 changes: 17 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,25 @@ 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 != null
&& !component.Properties.Exists(x => x.Name.Equals(property.Name)))
{
component.Properties.Add(property);
}
else
{
component.Properties = [property];
}

ExcludedList.Add(component);
}
}
}
ComponentList.RemoveAll(item => ExcludedList.Contains(item));
return ComponentList;
}

Expand Down
10 changes: 5 additions & 5 deletions src/LCT.PackageIdentifier.UTest/ConanParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void ParseLockFile_GivenAInputFilePath_ReturnDevDependentComp()
public void ParseLockFile_GivenAInputFilePathExcludeComponent_ReturnComponentCount()
{
//Arrange
int totalComponentsAfterExclusion = 15;
int totalComponentsAfterExclusion = 17;
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string outFolder = Path.GetDirectoryName(exePath);
string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles";
Expand All @@ -113,14 +113,14 @@ public void ParseLockFile_GivenAInputFilePathExcludeComponent_ReturnComponentCou
Bom listofcomponents = new ConanProcessor(cycloneDXBomParser.Object).ParsePackageFile(appSettings);

//Assert
Assert.That(totalComponentsAfterExclusion, Is.EqualTo(listofcomponents.Components.Count), "Checks if the excluded components have been removed");
Assert.That(totalComponentsAfterExclusion, Is.EqualTo(listofcomponents.Components.Count), "Checks if the excluded components have not been removed");
}

[TestCase]
public void IsDevDependent_GivenListOfDevComponents_ReturnsSuccess()
{
//Arrange
var conanPackage = new ConanPackage() {Id = "10"};
var conanPackage = new ConanPackage() { Id = "10" };
var buildNodeIds = new List<string> { "10", "11", "12" };
var noOfDevDependent = 0;
//Act
Expand All @@ -135,13 +135,13 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData_Succes
{
// Arrange
Component component = new Component()
{
{
Name = "securitycommunicationmanager",
Description = string.Empty,
Version = "2.6.5",
Purl = "pkg:conan/[email protected]"
};

var components = new List<Component>() { component };
ComponentIdentification componentIdentification = new() { comparisonBOMData = components };
string[] repoList = { "internalrepo1", "internalrepo2" };
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
Loading