Skip to content

Commit

Permalink
added the maintainablility and reliability issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
malavikakrishnan123 committed Feb 21, 2025
1 parent d8d0eb6 commit c817090
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
48 changes: 22 additions & 26 deletions src/LCT.PackageIdentifier/ConanProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,20 @@ private static void GetPackagesForBom(ref List<Component> lstComponentForBOM, re
throw new ArgumentNullException(nameof(nodePackages), "Dependency(requires) node name details not present in the root node.");
}

ConanPackage package = nodePackages.Where(x => x.Id == "0").FirstOrDefault();
ConanPackage package = nodePackages.FirstOrDefault(x => x.Id == "0");
List<string> directDependencies = new List<string>();
if (package != null && package.Dependencies != null) { directDependencies.AddRange(package.Dependencies); }
if (package.DevDependencies != null) { directDependencies.AddRange(package.DevDependencies); }
if (package != null)
{
if (package.Dependencies != null)
{
directDependencies.AddRange(package.Dependencies);
}
if (package.DevDependencies != null)
{
directDependencies.AddRange(package.DevDependencies);
}
}

// Ignoring the root node as it is the package information node and we are anyways considering all
// nodes in the lock file.
foreach (var component in nodePackages.Skip(1))
{
BomCreator.bomKpiData.ComponentsinPackageLockJsonFile += 1;
Expand All @@ -409,49 +416,38 @@ private static void GetPackagesForBom(ref List<Component> lstComponentForBOM, re
}

Component components = new Component();

// dev components are not ignored and added as a part of SBOM
var buildNodeIds = GetBuildNodeIds(nodePackages);
if (IsDevDependency(component, buildNodeIds, ref noOfDevDependent))
{
isdev.Value = "true";
}

string packageName = Convert.ToString(component.Reference);

if (packageName.Contains('/'))
{
components.Name = packageName.Split(new char[] { '/', '@' })[0];
components.Version = packageName.Split(new char[] { '/', '@' })[1];
var parts = packageName.Split(new char[] { '/', '@' });
components.Name = parts[0];
components.Version = parts[1];
}
else
{
components.Name = packageName;
}

Property siemensFileName = new Property()
{
Name = Dataconstant.Cdx_Siemensfilename,
Value = component.Reference
};
var isDirect = directDependencies.Contains(component.Id) ? "true" : "false";
Property siemensDirect = new Property()
{
Name = Dataconstant.Cdx_SiemensDirect,
Value = isDirect
};
components.Properties = new List<Property>
{
isdev,
new Property { Name = Dataconstant.Cdx_Siemensfilename, Value = component.Reference },
new Property { Name = Dataconstant.Cdx_SiemensDirect, Value = directDependencies.Contains(component.Id) ? "true" : "false" }
};

components.Type = Component.Classification.Library;
components.Purl = $"{ApiConstant.ConanExternalID}{components.Name}@{components.Version}";
components.BomRef = $"{ApiConstant.ConanExternalID}{components.Name}@{components.Version}";
components.Properties = new List<Property>();
components.Properties.Add(isdev);
components.Properties.Add(siemensDirect);
components.Properties.Add(siemensFileName);

lstComponentForBOM.Add(components);
}
}

private static List<string> GetBuildNodeIds(List<ConanPackage> nodePackages)
{
return nodePackages
Expand Down
2 changes: 1 addition & 1 deletion src/LCT.SW360PackageCreator/CreatorValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static async Task TriggerFossologyValidation(CommonAppSettings appSetting
else
{
int currentPage = page;
int totalPages = (int)(releaseResponse?.Page?.TotalPages ?? 0);
int totalPages = releaseResponse?.Page?.TotalPages ?? 0;
if (currentPage < totalPages - 1)
{
page = currentPage + 1;
Expand Down

0 comments on commit c817090

Please sign in to comment.