From 752d992fe4fa6bd3bbd6ec699ba965896d79f4ad Mon Sep 17 00:00:00 2001 From: Chalapala RaghavendraReddy Date: Sat, 11 Jan 2025 12:30:45 +0530 Subject: [PATCH 01/10] Updated new appsettings and UT and IT --- src/LCT.Common.UTests/Log4NetTests.cs | 2 +- src/LCT.Common/CommonAppSettings.cs | 261 +++++++---------- src/LCT.Common/CommonHelper.cs | 16 +- src/LCT.Common/Constants/Dataconstant.cs | 2 +- src/LCT.Common/FolderAction.cs | 4 +- src/LCT.Common/Model/Config.cs | 29 +- src/LCT.Common/SettingsManager.cs | 66 ++++- src/LCT.Common/appSettings.json | 271 ++++++++++++------ .../AlpineParserTests.cs | 93 ++++-- .../BomHelperUnitTests.cs | 154 +++++++--- .../BomValidatorUnitTests.cs | 48 +++- .../ConanParserTests.cs | 111 ++++--- .../CycloneBomProcessorTests.cs | 10 +- .../DebianParserTests.cs | 84 ++++-- .../MavenParserTests.cs | 146 ++++++++-- .../NPMParserTests.cs | 105 ++++--- .../NpmProcessorUTest.cs | 74 ++++- .../NugetParserTests.cs | 207 ++++++++++--- .../PythonParserTests.cs | 182 ++++++++---- .../SBomTemplateTests.cs | 2 +- src/LCT.PackageIdentifier/AlpineProcesser.cs | 31 +- src/LCT.PackageIdentifier/BomCreator.cs | 30 +- src/LCT.PackageIdentifier/BomValidator.cs | 6 +- src/LCT.PackageIdentifier/ConanProcessor.cs | 69 +++-- .../CycloneBomProcessor.cs | 2 +- src/LCT.PackageIdentifier/DebianProcessor.cs | 51 ++-- src/LCT.PackageIdentifier/MavenProcessor.cs | 52 ++-- src/LCT.PackageIdentifier/NpmProcessor.cs | 71 +++-- src/LCT.PackageIdentifier/NugetProcessor.cs | 73 ++--- src/LCT.PackageIdentifier/Program.cs | 127 ++++---- src/LCT.PackageIdentifier/PythonProcessor.cs | 56 ++-- src/LCT.PackageIdentifier/Scanner.cs | 4 +- src/LCT.Services/Sw360Service.cs | 2 +- .../Conan/PackageIdentifierInitialConan.cs | 3 +- .../Debian/PackageIdentifierInitialDebian.cs | 3 +- .../Maven/PackageIdentifierInitialMaven.cs | 3 +- .../NPM/PackageIdentifierInitial.cs | 3 +- .../ComponentCreatorNugetTemplate.cs | 1 - .../PackageIdentifierNugetTemplate.cs | 1 - .../Nuget/PackageIdentifierInitialNuget.cs | 3 +- .../Python/PackageIdentifierInitialPython.cs | 3 +- src/TestUtilities/TestConstant.cs | 63 ++-- src/TestUtilities/TestParam.cs | 2 +- 43 files changed, 1641 insertions(+), 885 deletions(-) diff --git a/src/LCT.Common.UTests/Log4NetTests.cs b/src/LCT.Common.UTests/Log4NetTests.cs index 46c15667..26273f85 100644 --- a/src/LCT.Common.UTests/Log4NetTests.cs +++ b/src/LCT.Common.UTests/Log4NetTests.cs @@ -196,7 +196,7 @@ public void ActivateFileAppender_LogPathIsNull_ShouldNotSetFileAndNotActivateOpt { // Arrange bool verbose = true; - string? logPath = null; + string logPath = null; IAppender[] appenders = [new RollingFileAppender()]; // Act diff --git a/src/LCT.Common/CommonAppSettings.cs b/src/LCT.Common/CommonAppSettings.cs index ca386ce9..fd97f43f 100644 --- a/src/LCT.Common/CommonAppSettings.cs +++ b/src/LCT.Common/CommonAppSettings.cs @@ -1,5 +1,5 @@ // -------------------------------------------------------------------------------------------------------------------- -// SPDX-FileCopyrightText: 2024 Siemens AG +// SPDX-FileCopyrightText: 2025 Siemens AG // // SPDX-License-Identifier: MIT // -------------------------------------------------------------------------------------------------------------------- @@ -8,6 +8,7 @@ using LCT.Common.Interface; using LCT.Common.Model; using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; @@ -30,104 +31,55 @@ public class CommonAppSettings public static string PyPiURL { get; set; } = $"https://pypi.org/pypi/"; public static string SourceURLConan { get; set; } = "https://raw.githubusercontent.com/conan-io/conan-center-index/master/recipes/"; public static string AlpineAportsGitURL { get; set; } = $"https://gitlab.alpinelinux.org/alpine/aports.git"; + + private string m_ProjectType; + private string m_LogFolderPath; public CommonAppSettings() { folderAction = new FolderAction(); _fileOperations = new FileOperations(); + Directory = new Directory(folderAction, _fileOperations); } - public CommonAppSettings(IFolderAction iFolderAction) + public CommonAppSettings(IFolderAction iFolderAction, IFileOperations fileOperations) { folderAction = iFolderAction; + _fileOperations = fileOperations; + Directory = new Directory(folderAction, _fileOperations); } - private string m_PackageFilePath; - private string m_BomFolderPath; - private string m_Sw360Token; - private string m_SW360ProjectName; - private string m_SW360ProjectID; - private string m_ProjectType; - private string m_ArtifactoryApiKey; - private string m_SW360URL; - private string m_BomFilePath; - private string m_LogFolderPath; - private string m_FOSSURL; - private string m_ArtifactoryUser; - private string m_CycloneDxSBomTemplatePath; - - - public bool RemoveDevDependency { get; set; } = true; - public string SW360AuthTokenType { get; set; } = "Bearer"; - public string JFrogApi { get; set; } - public int TimeOut { get; set; } = 200; - public Config Npm { get; set; } - public Config Nuget { get; set; } - - public Config Maven { get; set; } - public Config Debian { get; set; } - public Config Python { get; set; } - public Config Conan { get; set; } - public Config Alpine { get; set; } - public string CaVersion { get; set; } - public string CycloneDxSBomTemplatePath { get; set; } - public string[] InternalRepoList { get; set; } = Array.Empty(); - public bool EnableFossTrigger { get; set; } = true; - public string JfrogNpmSrcRepo { get; set; } - public string Mode { get; set; } = string.Empty; - - - public string SW360URL + public int TimeOut { get; set; } = 400; + public string ProjectType { get { - return m_SW360URL; + return m_ProjectType; } set { - if (string.IsNullOrEmpty(value)) - { - throw new ArgumentNullException($"Provide a sw360 url - {value}"); - } - else - { - m_SW360URL = value.TrimEnd(Dataconstant.ForwardSlash); - } + CommonHelper.CheckNullOrEmpty(nameof(ProjectType), value); + m_ProjectType = value; } } - - public string IdentifierBomFilePath + public bool MultipleProjectType { get; set; } = false; + public SW360 SW360 { get; set; } + public Directory Directory { get; set; } + public Jfrog Jfrog { get; set; } + public Config Npm { get; set; } + public Config Nuget { get; set; } + public Config Maven { get; set; } + public Config Debian { get; set; } + public Config Alpine { get; set; } + public Config Poetry { get; set; } + public Config Conan { get; set; } + public string Mode { get; set; } = string.Empty; + public bool IsTestMode { get { - return m_BomFilePath; - } - set - { - if (!AppDomain.CurrentDomain.FriendlyName.Contains("SW360PackageCreator") && - !AppDomain.CurrentDomain.FriendlyName.Contains("ArtifactoryUploader") && - !string.IsNullOrEmpty(value)) - { - _fileOperations.ValidateFilePath(value); - m_BomFilePath = value; - } + return string.Compare(Mode, "test", true) == 0; } - } - public string PackageFilePath - { - get - { - return m_PackageFilePath; - } - set - { - if (!AppDomain.CurrentDomain.FriendlyName.Contains("SW360PackageCreator") && - !AppDomain.CurrentDomain.FriendlyName.Contains("ArtifactoryUploader")) - { - folderAction.ValidateFolderPath(value); - m_PackageFilePath = value; - } - } } public string LogFolderPath @@ -142,103 +94,77 @@ public string LogFolderPath m_LogFolderPath = value; } } - - public string BomFolderPath + } + public class SW360 + { + private string m_URL; + private string m_Token; + private string m_ProjectName; + private string m_ProjectID; + public string URL { get { - return m_BomFolderPath; + return m_URL; } set { - try + if (string.IsNullOrEmpty(value)) { - m_BomFolderPath = value; - folderAction.ValidateFolderPath(value); + throw new ArgumentNullException($"Provide a sw360 url - {value}"); } - catch (DirectoryNotFoundException) + else { - Directory.CreateDirectory(m_BomFolderPath); + m_URL = value.TrimEnd(Dataconstant.ForwardSlash); } } } - - public string Sw360Token + public string ProjectName { get { - return m_Sw360Token; + return m_ProjectName; } set { - CommonHelper.CheckNullOrEmpty(nameof(Sw360Token), value); - m_Sw360Token = value; + CommonHelper.CheckNullOrEmpty(nameof(ProjectName), value); + m_ProjectName = value; } } - - public string SW360ProjectName + public string ProjectID { get { - return m_SW360ProjectName; + return m_ProjectID; } set { - CommonHelper.CheckNullOrEmpty(nameof(SW360ProjectName), value); - m_SW360ProjectName = value; + CommonHelper.CheckNullOrEmpty(nameof(ProjectID), value); + m_ProjectID = value; } } - - public string SW360ProjectID + public string AuthTokenType { get; set; } = "Bearer"; + public string Token { get { - return m_SW360ProjectID; + return m_Token; } set { - CommonHelper.CheckNullOrEmpty(nameof(SW360ProjectID), value); - m_SW360ProjectID = value; - } - } - - public string ProjectType - { - get - { - return m_ProjectType; - } - set - { - CommonHelper.CheckNullOrEmpty(nameof(ProjectType), value); - m_ProjectType = value; - } - } - - public string ArtifactoryUploadApiKey - { - get - { - return m_ArtifactoryApiKey; - } - set - { - CommonHelper.CheckNullOrEmpty(nameof(ArtifactoryUploadApiKey), value); - m_ArtifactoryApiKey = value; - } - - } - - public bool IsTestMode - { - get - { - return string.Compare(Mode, "test", true) == 0; + CommonHelper.CheckNullOrEmpty(nameof(Token), value); + m_Token = value; } - } + public Fossology Fossology { get; set; } + public bool IgnoreDevDependency { get; set; } = true; + public List ExcludeComponents { get; set; } - public string Fossologyurl + } + public class Fossology + { + private string m_FOSSURL; + public string URL { get { @@ -259,51 +185,78 @@ public string Fossologyurl } } } + public bool EnableTrigger { get; set; } + } + + public class Jfrog + { + private string m_Token; - public string BomFilePath + public string URL { get; set; } + public string Token { get { - return m_BomFilePath; + return m_Token; } set { - if (!AppDomain.CurrentDomain.FriendlyName.Contains("PackageIdentifier")) - { - m_BomFilePath = value; - _fileOperations.ValidateFilePath(m_BomFilePath); - } + CommonHelper.CheckNullOrEmpty(nameof(Token), value); + m_Token = value; } } - public string SBomTemplatePath + public bool DryRun { get; set; } = false; + } + public class Directory + { + private readonly IFolderAction folderAction; + private readonly IFileOperations _fileOperations; + private string m_InputFolder; + private string m_OutputFolder; + + public Directory(IFolderAction folderAction, IFileOperations fileOperations) + { + this.folderAction = folderAction; + this._fileOperations = fileOperations; + } + public string InputFolder { get { - return m_CycloneDxSBomTemplatePath; + return m_InputFolder; } set { - m_CycloneDxSBomTemplatePath = value; - _fileOperations.ValidateFilePath(m_CycloneDxSBomTemplatePath); + if (!AppDomain.CurrentDomain.FriendlyName.Contains("SW360PackageCreator") && + !AppDomain.CurrentDomain.FriendlyName.Contains("ArtifactoryUploader")) + { + folderAction.ValidateFolderPath(value); + m_InputFolder = value; + } } } - public string ArtifactoryUploadUser + public string OutputFolder { get { - return m_ArtifactoryUser; + return m_OutputFolder; } set { - CommonHelper.CheckNullOrEmpty(nameof(ArtifactoryUploadUser), value); - m_ArtifactoryUser = value; + try + { + m_OutputFolder = value; + folderAction.ValidateFolderPath(value); + } + catch (DirectoryNotFoundException) + { + System.IO.Directory.CreateDirectory(m_OutputFolder); + } } - } - public bool Release { get; set; } = false; - } + } diff --git a/src/LCT.Common/CommonHelper.cs b/src/LCT.Common/CommonHelper.cs index cd528f17..c2534772 100644 --- a/src/LCT.Common/CommonHelper.cs +++ b/src/LCT.Common/CommonHelper.cs @@ -40,7 +40,21 @@ public static bool IsAzureDevOpsDebugEnabled() public static List RemoveExcludedComponents(List ComponentList, List ExcludedComponents, ref int noOfExcludedComponents) { List ExcludedList = new List(); - foreach (string excludedComponent in ExcludedComponents) + List ExcludedComponentsFromPurl = ExcludedComponents?.Where(ec => ec.StartsWith("pkg:")).ToList(); + List otherExcludedComponents = ExcludedComponents?.Where(ec => !ec.StartsWith("pkg:")).ToList(); + + foreach (string excludedComponent in ExcludedComponentsFromPurl) + { + foreach (var component in ComponentList) + { + if (component.Purl != null && component.Purl.Equals(excludedComponent, StringComparison.OrdinalIgnoreCase)) + { + noOfExcludedComponents++; + ExcludedList.Add(component); + } + } + } + foreach (string excludedComponent in otherExcludedComponents) { string[] excludedcomponent = excludedComponent.ToLower().Split(':'); foreach (var component in ComponentList) diff --git a/src/LCT.Common/Constants/Dataconstant.cs b/src/LCT.Common/Constants/Dataconstant.cs index ace66df6..01700b3b 100644 --- a/src/LCT.Common/Constants/Dataconstant.cs +++ b/src/LCT.Common/Constants/Dataconstant.cs @@ -21,7 +21,7 @@ public static class Dataconstant {"NUGET", "pkg:nuget"}, {"DEBIAN", "pkg:deb/debian"}, {"MAVEN", "pkg:maven"}, - {"PYTHON", "pkg:pypi"}, + {"POETRY", "pkg:pypi"}, {"CONAN", "pkg:conan"}, {"ALPINE", "pkg:apk/alpine"}, }; diff --git a/src/LCT.Common/FolderAction.cs b/src/LCT.Common/FolderAction.cs index 733cc158..79d2d6df 100644 --- a/src/LCT.Common/FolderAction.cs +++ b/src/LCT.Common/FolderAction.cs @@ -69,7 +69,7 @@ public void ValidateFolderPath(string folderPath) throw new ArgumentException($"Invalid value for folderPath -{folderPath}"); } - if (!Directory.Exists(folderPath)) + if (!System.IO.Directory.Exists(folderPath)) { throw new DirectoryNotFoundException($"Invalid folder path -{folderPath}"); } @@ -124,7 +124,7 @@ private static void CopyAll(DirectoryInfo source, DirectoryInfo target) try { - Directory.CreateDirectory(target.FullName); + System.IO.Directory.CreateDirectory(target.FullName); // Copy each file into the new directory. foreach (FileInfo fi in source.GetFiles()) diff --git a/src/LCT.Common/Model/Config.cs b/src/LCT.Common/Model/Config.cs index 96d9cb60..a1a63ab7 100644 --- a/src/LCT.Common/Model/Config.cs +++ b/src/LCT.Common/Model/Config.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System; namespace LCT.Common.Model { @@ -17,17 +18,21 @@ public class Config { public string[] Include { get; set; } public string[] Exclude { get; set; } - public List ExcludedComponents { get; set; } - public string[] JfrogNpmRepoList { get; set; } - public string[] JfrogNugetRepoList { get; set; } - public string[] JfrogMavenRepoList { get; set; } - public string[] JfrogDebianRepoList { get; set; } - public string[] JfrogPythonRepoList { get; set; } - public string[] JfrogConanRepoList { get; set; } - public string JfrogThirdPartyDestRepoName { get; set; } - public string JfrogInternalDestRepoName { get; set; } - public string JfrogDevDestRepoName { get; set; } - public string[] DevDependentScopeList { get; set; } - + public Artifactory Artifactory { get; set; } + public string ReleaseRepo { get; set; } + public string DevDepRepo { get; set; } + + } + public class Artifactory + { + public List ThirdPartyRepos { get; set; } + public string[] InternalRepos { get; set; } = Array.Empty(); + public string[] DevRepos { get; set; } + public string[] RemoteRepos { get; set; } + } + public class ThirdPartyRepo + { + public string Name { get; set; } + public bool Upload { get; set; } } } diff --git a/src/LCT.Common/SettingsManager.cs b/src/LCT.Common/SettingsManager.cs index 40046248..95415ff6 100644 --- a/src/LCT.Common/SettingsManager.cs +++ b/src/LCT.Common/SettingsManager.cs @@ -121,17 +121,24 @@ public void CheckRequiredArgsToRun(CommonAppSettings appSettings, string current { //Required parameters to run Package Identifier List identifierReqParameters = new List() - { - "SW360ProjectID", - "Sw360Token", - "SW360URL", - "JFrogApi", - "PackageFilePath", - "BomFolderPath", - "ArtifactoryUploadApiKey", - "InternalRepoList", - "ProjectType" - }; + { + "SW360.ProjectID", + "SW360.Token", + "Jfrog.Token", + "SW360.URL", + "Jfrog.URL", + "Directory.InputFolder", + "Directory.OutputFolder", + "ProjectType" + }; + //Check if ProjectType contains a value and add InternalRepos key accordingly + if (!string.IsNullOrWhiteSpace(appSettings.ProjectType)) + { + if (!appSettings.ProjectType.Equals("ALPINE", StringComparison.InvariantCultureIgnoreCase)) + { + identifierReqParameters.Add($"{appSettings.ProjectType}.Artifactory.InternalRepos"); + } + } CheckForMissingParameter(appSettings, properties, identifierReqParameters); } else if (currentExe == "Creator") @@ -165,11 +172,42 @@ private static void CheckForMissingParameter(CommonAppSettings appSettings, Prop foreach (string key in reqParameters) { - string value = properties.First(x => x.Name == key)?.GetValue(appSettings)?.ToString(); + string[] parts = key.Split('.'); + object currentObject = appSettings; + PropertyInfo property = null; + + foreach (string part in parts) + { + if (currentObject == null) + { + break; + } + + property = currentObject.GetType().GetProperty(part); + currentObject = property?.GetValue(currentObject); + } - if (string.IsNullOrWhiteSpace(value)) + if (currentObject is Array array) + { + if (array.Length == 0 || string.IsNullOrWhiteSpace(array.GetValue(0)?.ToString())) + { + missingParameters.Append(key + "\n"); + } + } + else if (currentObject is IList list) + { + if (list.Count == 0 || string.IsNullOrWhiteSpace(list[0]?.ToString())) + { + missingParameters.Append(key + "\n"); + } + } + else { - missingParameters.Append(key + "\n"); + string value = currentObject?.ToString(); + if (string.IsNullOrWhiteSpace(value)) + { + missingParameters.Append(key + "\n"); + } } } diff --git a/src/LCT.Common/appSettings.json b/src/LCT.Common/appSettings.json index f3aa2960..596792f5 100644 --- a/src/LCT.Common/appSettings.json +++ b/src/LCT.Common/appSettings.json @@ -1,113 +1,214 @@ // -------------------------------------------------------------------------------------------------------------------- -// SPDX-FileCopyrightText: 2024 Siemens AG +// SPDX-FileCopyrightText: 2025 Siemens AG // // SPDX-License-Identifier: MIT // -------------------------------------------------------------------------------------------------------------------- { - "CaVersion": "", - "TimeOut": 200, + "TimeOut": 400, "ProjectType": "", - "SW360ProjectName": "", - "SW360ProjectID": "", - "Sw360AuthTokenType": "Bearer", - "Sw360Token": "", - "SW360URL": "", - "Fossologyurl": "", - "JFrogApi": "", - "PackageFilePath": "/PathToInputDirectory", //For Docker run set as /mnt/Input - "BomFolderPath": "/PathToOutputDirectory", //For Docker run set as /mnt/Output - "BomFilePath": "/PathToOutputDirectory/_Bom.cdx.json", - //IdentifierBomFilePath : For multiple project type - "IdentifierBomFilePath": "", - //CycloneDxBomFilePath: For Providing Customer maintained SBOM as input.Can be used along with Packagefilepath or individually - "CycloneDxSBomTemplatePath": "", - "ArtifactoryUploadApiKey": "", //This should be Jfrog Ref Token - "ArtifactoryUploadUser": "", //This should be Jfrog user name & it is optional - "Release": false, - "RemoveDevDependency": true, - "EnableFossTrigger": true, - "InternalRepoList": [ - "", //This should be the internal repo names in JFrog for NPM - "" //This should be the internal repo names in JFrog for Nuget - ], + "MultipleProjectType": false, + "SW360": { + "URL": "", + "ProjectName": "", + "ProjectID": "", + "AuthTokenType": "", + "Token": "", + "Fossology": { + "URL": "", + "EnableTrigger": true + }, + "IgnoreDevDependency": true, + //Examples pkg:npm/foobar@12.3.1 or foobar:12.3.1,foobar:12.*,foobar:* + "ExcludeComponents": [] + }, + "Directory": { + "InputFolder": "/PathToInputDirectory", //Input File path. For Docker run set as /mnt/Input + "OutputFolder": "/PathToOutputDirectory", //Output Bom Folder path. For Docker run set as /mnt/Output + "BomFilePath": "", //For multiple project type + "CycloneDxSBomTemplatePath": "" //CycloneDxBomFilePath: For Providing Customer maintained SBOM as input.Can be used along with Packagefilepath or individually + }, + "Jfrog": { + "URL": "", + "Token": "", + "DryRun": false + }, "Npm": { - "Include": [ "p*-lock.json", "*.cdx.json" ], - "Exclude": [ "node_modules" ], - "JfrogNpmRepoList": [ - "", //This is a mirror repo for npm registry in JFrog - "", //This should be the release repo in JFrog - "" //This should be the development dependency repo in JFrog + "Include": [ + "p*-lock.json", + "*.cdx.json" + ], + "Exclude": [ + "node_modules" ], - "JfrogThirdPartyDestRepoName": "", - "JfrogInternalDestRepoName": "", - "JfrogDevDestRepoName": "", - "ExcludedComponents": [] + "Artifactory": { + "ThirdPartyRepos": [ + { + "Name": "", + "Upload": true + } + ], + "InternalRepos": [ + "" + ], + "DevRepos": [ + "" + ], + "RemoteRepos": [ + "" + ] + }, + "ReleaseRepo": "", + "DevDepRepo": "" }, "Nuget": { - "Include": [ "packages.config", "p*.assets.json", "*.cdx.json" ], - "Exclude": [], - "JfrogNugetRepoList": [ - "", //This is a mirror repo for nuget.org in JFrog - "", //This should be the release repo in JFrog - "" //This should be the development dependency repo in JFrog + "Include": [ + "packages.config", + "p*.assets.json", + "*.cdx.json" ], - "JfrogThirdPartyDestRepoName": "", - "JfrogInternalDestRepoName": "", - "JfrogDevDestRepoName": "", - "ExcludedComponents": [] + "Exclude": [], + "Artifactory": { + "ThirdPartyRepos": [ + { + "Name": "", + "Upload": true + } + ], + "InternalRepos": [], //Insert Nuget Internal Repo Name + "DevRepos": [ + "" + ], + "RemoteRepos": [ + "" + ] + }, + "ReleaseRepo": "", + "DevDepRepo": "" }, "Maven": { - "Include": [ "*.cdx.json" ], - "Exclude": [], - "JfrogMavenRepoList": [ - "", //This is a mirror repo for repo.maven in JFrog - "", //This should be the release repo.maven in JFrog - "" //This should be the development dependency repo in JFrog + "Include": [ + "*.cdx.json" ], - "JfrogThirdPartyDestRepoName": "", - "JfrogInternalDestRepoName": "", - "JfrogDevDestRepoName": "", - "DevDependentScopeList": [ "test" ], - "ExcludedComponents": [] + "Exclude": [], + "Artifactory": { + "ThirdPartyRepos": [ + { + "Name": "", + "Upload": true + } + ], + "InternalRepos": [], //Insert Maven Internal Repo Name + "DevRepos": [ + "" + ], + "RemoteRepos": [ + "" + ] + }, + "ReleaseRepo": "", + "DevDepRepo": "" }, "Debian": { - "Include": [ "*.cdx.json" ], - "Exclude": [], - "JfrogDebianRepoList": [ - "" //This is a mirror repo for debian registry in JFrog + "Include": [ + "*.cdx.json" ], - "ExcludedComponents": [] + "Exclude": [], + "Artifactory": { + "ThirdPartyRepos": [ + { + "Name": "", + "Upload": true + } + ], + "InternalRepos": [ + "" + ], + "DevRepos": [ + "" + ], + "RemoteRepos": [ + "" + ] + }, + "ReleaseRepo": "", + "DevDepRepo": "" }, "Alpine": { - "Include": [ "*.cdx.json" ], + "Include": [ + "*.cdx.json" + ], "Exclude": [], - "ExcludedComponents": [] + "Artifactory": { + "ThirdPartyRepos": [ + { + "Name": "", + "Upload": true + } + ], + "InternalRepos": [ + "" + ], + "DevRepos": [ + "" + ], + "RemoteRepos": [ + "" + ] + }, + "ReleaseRepo": "", + "DevDepRepo": "" }, - "Python": { - "Include": [ "poetry.lock", "*.cdx.json" ], - "Exclude": [], - "JfrogPythonRepoList": [ - "", //This is a mirror repo for pypi in JFrog - "", //This should be the release pypi in JFrog - "" //This should be the development dependency repo in JFrog + "Poetry": { + "Include": [ + "poetry.lock", + "*.cdx.json" ], - "JfrogThirdPartyDestRepoName": "", - "JfrogInternalDestRepoName": "", - "JfrogDevDestRepoName": "", - "ExcludedComponents": [] + "Exclude": [], + "Artifactory": { + "ThirdPartyRepos": [ + { + "Name": "", + "Upload": true + } + ], + "InternalRepos": [ + "" + ], + "DevRepos": [ + "" + ], + "RemoteRepos": [ + "" + ] + }, + "ReleaseRepo": "", + "DevDepRepo": "" }, "Conan": { - "Include": [ "conan.lock" ], - "Exclude": [], - "JfrogConanRepoList": [ - "", //This is a mirror repo for conan in JFrog - "", //This should be the release repo in JFrog - "" //This should be the development dependency repo in JFrog + "Include": [ + "conan.lock", + "*.cdx.json" ], - "JfrogThirdPartyDestRepoName": "", - "JfrogInternalDestRepoName": "", - "JfrogDevDestRepoName": "", - "ExcludedComponents": [] + "Exclude": [], + "Artifactory": { + "ThirdPartyRepos": [ + { + "Name": "", + "Upload": true + } + ], + "InternalRepos": [ + "" + ], + "DevRepos": [ + "" + ], + "RemoteRepos": [ + "" + ] + }, + "ReleaseRepo": "", + "DevDepRepo": "" } } diff --git a/src/LCT.PackageIdentifier.UTest/AlpineParserTests.cs b/src/LCT.PackageIdentifier.UTest/AlpineParserTests.cs index d049e268..81d413ab 100644 --- a/src/LCT.PackageIdentifier.UTest/AlpineParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/AlpineParserTests.cs @@ -12,6 +12,7 @@ using LCT.Common.Constants; using Moq; using System.Collections.Generic; +using LCT.Common.Interface; namespace LCT.PackageIdentifier.UTest { @@ -40,14 +41,20 @@ public void ParsePackageConfig_GivenAMultipleInputFilePath_ReturnsCounts() int expectednoofcomponents = 2; string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); - + string[] Includes = { "*_Alpine.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { ProjectType = "ALPINE", - RemoveDevDependency = true, Alpine = new Config() { Include = Includes }, - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -67,12 +74,18 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsCounts() string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "CycloneDX_Alpine.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", + ProjectType = "ALPINE", - RemoveDevDependency = true, - Alpine = new Config() { Include = Includes } + Alpine = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -90,15 +103,19 @@ public void ParsePackageConfig_GivenMultipleInputFiles_ReturnsCountOfDuplicates( int duplicateComponents = 2; string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); - - string[] Includes = { "*_Alpine.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() - { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", + string[] Includes = { "*_Alpine.cdx.json" }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { ProjectType = "ALPINE", - RemoveDevDependency = true, - Alpine = new Config() { Include = Includes } + Alpine = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -118,12 +135,17 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsSourceDetails() string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "AlpineSourceDetails_Cyclonedx.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() - { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { ProjectType = "ALPINE", - RemoveDevDependency = true, - Alpine = new Config() { Include = Includes } + Alpine = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -144,13 +166,17 @@ public void ParsePackageConfig_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTo string[] Includes = { "CycloneDX_Alpine.cdx.json", "SBOMTemplate_Alpine.cdx.json" }; string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; - CommonAppSettings appSettings = new CommonAppSettings() - { - PackageFilePath = packagefilepath, - ProjectType = "ALPINE", - RemoveDevDependency = true, + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + ProjectType = "ALPINE", Alpine = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_AlpineCATemplate.cdx.json" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles", + } }; //Act @@ -170,13 +196,18 @@ public void ParsePackageConfig_GivenAInputFilePathAlongWithSBOMTemplate_ReturnUp string[] Includes = { "CycloneDX_Alpine.cdx.json", "SBOMTemplate_Alpine.cdx.json" }; string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, - ProjectType = "ALPINE", - RemoveDevDependency = true, + + ProjectType = "ALPINE", Alpine = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOMTemplate_Alpine.cdx.json", + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath + } }; //Act diff --git a/src/LCT.PackageIdentifier.UTest/BomHelperUnitTests.cs b/src/LCT.PackageIdentifier.UTest/BomHelperUnitTests.cs index 3a0b8f4a..4d566e1e 100644 --- a/src/LCT.PackageIdentifier.UTest/BomHelperUnitTests.cs +++ b/src/LCT.PackageIdentifier.UTest/BomHelperUnitTests.cs @@ -17,6 +17,7 @@ using LCT.Common.Model; using LCT.Services.Interface; using LCT.APICommunications.Model.AQL; +using LCT.Common.Interface; namespace LCT.PackageIdentifier.UTest { @@ -177,15 +178,23 @@ public async Task GetRepoDetails_GivenProjectTypeAsDebian_ReturnsListOFComponent } }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ArtifactoryUploadApiKey = "testvalue", ProjectType = "DEBIAN", - Debian = new Config() + Debian = new Config { - JfrogDebianRepoList = new string[] { "here" } + Artifactory = new Artifactory + { + RemoteRepos = new string[] { "here" } + } }, - JFrogApi = "https://jfrogapi" + Jfrog = new Jfrog + { + Token = "testvalue", + URL = "https://jfrogapi" + } }; List aqlResultList = new() { @@ -227,16 +236,36 @@ public async Task GetRepoDetails_GivenProjectTypeAsNpm_ReturnsListOFComponents() } }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ArtifactoryUploadApiKey = "testvalue", ProjectType = "NPM", - Debian = new Config() + Npm = new Config { - JfrogDebianRepoList = new string[] { "here" } + Artifactory = new Artifactory + { + RemoteRepos = new string[] { "here" } + } }, - JFrogApi = "https://jfrogapi" + Jfrog = new Jfrog + { + Token = "testvalue", + URL = "https://jfrogapi" + } }; + AqlProperty npmNameProperty = new AqlProperty + { + Key = "npm.name", + Value = "Test" + }; + + AqlProperty npmVersionProperty = new AqlProperty + { + Key = "npm.version", + Value = "1" + }; + List propertys = new List { npmNameProperty, npmVersionProperty }; List aqlResultList = new() { new() @@ -244,6 +273,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsNpm_ReturnsListOFComponents() Path="test/test", Name="Test-1.tgz", Repo="remote", + Properties=propertys, MD5="7654345676543", SHA256="65434567", SHA1="765434567654" @@ -252,10 +282,10 @@ public async Task GetRepoDetails_GivenProjectTypeAsNpm_ReturnsListOFComponents() mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(lstComponentForBOM); Mock cycloneDXBomParser = new Mock(); - IParser parser = new DebianProcessor(cycloneDXBomParser.Object); + IParser parser = new NpmProcessor(cycloneDXBomParser.Object); Mock jFrogService = new Mock(); Mock bomHelper = new Mock(); - bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny(), It.IsAny())).ReturnsAsync(aqlResultList); + bomHelper.Setup(x => x.GetNpmListOfComponentsFromRepo(It.IsAny(), It.IsAny())).ReturnsAsync(aqlResultList); //Act var expected = await parser.GetJfrogRepoDetailsOfAComponent(lstComponentForBOM, appSettings, jFrogService.Object, bomHelper.Object); @@ -277,15 +307,23 @@ public async Task GetRepoDetails_GivenProjectTypeAsNuget_ReturnsListOFComponents } }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ArtifactoryUploadApiKey = "testvalue", - ProjectType = "NUGET", - Debian = new Config() + ProjectType = "Nuget", + Nuget = new Config { - JfrogDebianRepoList = new string[] { "here" } + Artifactory = new Artifactory + { + RemoteRepos = new string[] { "here" } + } }, - JFrogApi = "https://jfrogapi" + Jfrog = new Jfrog + { + Token = "testvalue", + URL = "https://jfrogapi" + } }; List aqlResultList = new() { @@ -302,7 +340,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsNuget_ReturnsListOFComponents mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(lstComponentForBOM); Mock cycloneDXBomParser = new Mock(); - IParser parser = new DebianProcessor(cycloneDXBomParser.Object); + IParser parser = new NugetProcessor(cycloneDXBomParser.Object); Mock jFrogService = new Mock(); Mock bomHelper = new Mock(); bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny(), It.IsAny())).ReturnsAsync(aqlResultList); @@ -327,16 +365,36 @@ public async Task GetRepoDetails_GivenProjectTypeAsPython_ReturnsListOFComponent } }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ArtifactoryUploadApiKey = "testvalue", - ProjectType = "PYTHON", - Debian = new Config() + ProjectType = "POETRY", + Poetry = new Config { - JfrogDebianRepoList = new string[] { "here" } + Artifactory = new Artifactory + { + RemoteRepos = new string[] { "here" } + } }, - JFrogApi = "https://jfrogapi" + Jfrog = new Jfrog + { + Token = "testvalue", + URL = "https://jfrogapi" + } + }; + AqlProperty pypiNameProperty = new AqlProperty + { + Key = "pypi.normalized.name", + Value = "Test" }; + + AqlProperty pypiVersionProperty = new AqlProperty + { + Key = "pypi.version", + Value = "1" + }; + List propertys = new List { pypiNameProperty, pypiVersionProperty }; List aqlResultList = new() { new() @@ -344,18 +402,20 @@ public async Task GetRepoDetails_GivenProjectTypeAsPython_ReturnsListOFComponent Path="test/test", Name="Test-1.whl", Repo="remote", + Properties=propertys, MD5="7654345676543", SHA256="65434567", SHA1="765434567654" + } }; mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(lstComponentForBOM); Mock cycloneDXBomParser = new Mock(); - IParser parser = new DebianProcessor(cycloneDXBomParser.Object); + IParser parser = new PythonProcessor(cycloneDXBomParser.Object); Mock jFrogService = new Mock(); Mock bomHelper = new Mock(); - bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny(), It.IsAny())).ReturnsAsync(aqlResultList); + bomHelper.Setup(x => x.GetPypiListOfComponentsFromRepo(It.IsAny(), It.IsAny())).ReturnsAsync(aqlResultList); //Act var expected = await parser.GetJfrogRepoDetailsOfAComponent(lstComponentForBOM, appSettings, jFrogService.Object, bomHelper.Object); @@ -377,15 +437,23 @@ public async Task GetRepoDetails_GivenProjectTypeAsConan_ReturnsListOFComponents } }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ArtifactoryUploadApiKey = "testvalue", ProjectType = "Conan", - Debian = new Config() + Conan = new Config { - JfrogDebianRepoList = new string[] { "here" } + Artifactory = new Artifactory + { + RemoteRepos = new string[] { "here" } + } }, - JFrogApi = "https://jfrogapi" + Jfrog = new Jfrog + { + Token = "testvalue", + URL = "https://jfrogapi" + } }; List aqlResultList = new() { @@ -402,7 +470,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsConan_ReturnsListOFComponents mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(lstComponentForBOM); Mock cycloneDXBomParser = new Mock(); - IParser parser = new DebianProcessor(cycloneDXBomParser.Object); + IParser parser = new ConanProcessor(cycloneDXBomParser.Object); Mock jFrogService = new Mock(); Mock bomHelper = new Mock(); bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny(), It.IsAny())).ReturnsAsync(aqlResultList); @@ -427,15 +495,23 @@ public async Task GetRepoDetails_GivenProjectTypeAsMaven_ReturnsListOFComponents } }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ArtifactoryUploadApiKey = "testvalue", ProjectType = "MAVEN", - Debian = new Config() + Maven = new Config { - JfrogDebianRepoList = new string[] { "here" } + Artifactory = new Artifactory + { + RemoteRepos = new string[] { "here" } + } }, - JFrogApi = "https://jfrogapi" + Jfrog = new Jfrog + { + Token = "testvalue", + URL = "https://jfrogapi" + } }; List aqlResultList = new() { @@ -452,7 +528,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsMaven_ReturnsListOFComponents mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(lstComponentForBOM); Mock cycloneDXBomParser = new Mock(); - IParser parser = new DebianProcessor(cycloneDXBomParser.Object); + IParser parser = new MavenProcessor(cycloneDXBomParser.Object); Mock jFrogService = new Mock(); Mock bomHelper = new Mock(); bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny(), It.IsAny())).ReturnsAsync(aqlResultList); diff --git a/src/LCT.PackageIdentifier.UTest/BomValidatorUnitTests.cs b/src/LCT.PackageIdentifier.UTest/BomValidatorUnitTests.cs index 21e5886e..8683180c 100644 --- a/src/LCT.PackageIdentifier.UTest/BomValidatorUnitTests.cs +++ b/src/LCT.PackageIdentifier.UTest/BomValidatorUnitTests.cs @@ -30,10 +30,9 @@ public async Task ValidateAppSettings_ProvidedProjectID_ReturnsProjectName() //Arrange string projectName = "Test"; ProjectReleases projectReleases = new ProjectReleases(); - var CommonAppSettings = new CommonAppSettings(mockIFolderAction.Object) - { - SW360ProjectName = "Test" - }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny(), It.IsAny(), projectReleases)) .ReturnsAsync(projectName); @@ -44,8 +43,14 @@ public async Task ValidateAppSettings_ProvidedProjectID_ReturnsProjectName() mockIFolderAction.Setup(x => x.ValidateFolderPath(It.IsAny())) .Callback((string message) => { }) .Verifiable(); - CommonAppSettings.PackageFilePath = ""; - + var CommonAppSettings = new CommonAppSettings(mockIFolderAction.Object, mockIFileOperations.Object) + { + SW360 = new SW360() { ProjectName = "Test" }, + Directory = new LCT.Common.Directory(mockIFolderAction.Object, mockIFileOperations.Object) + { + InputFolder = "" + } + }; //Act await BomValidator.ValidateAppSettings(CommonAppSettings, mockISw360ProjectService.Object, projectReleases); @@ -60,10 +65,9 @@ public Task ValidateAppSettings_ProvidedProjectID_ReturnsInvalidDataException() //Arrange string projectName = null; ProjectReleases projectReleases = new ProjectReleases(); - var CommonAppSettings = new CommonAppSettings(mockIFolderAction.Object) - { - SW360ProjectName = "Test" - }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny(), It.IsAny(),projectReleases)) .ReturnsAsync(projectName); @@ -75,6 +79,14 @@ public Task ValidateAppSettings_ProvidedProjectID_ReturnsInvalidDataException() .Callback((string message) => { }) .Verifiable(); + var CommonAppSettings = new CommonAppSettings(mockIFolderAction.Object, mockIFileOperations.Object) + { + SW360 = new SW360() { ProjectName = "Test" }, + Directory = new LCT.Common.Directory(mockIFolderAction.Object, mockIFileOperations.Object) + { + InputFolder = "" + } + }; //Act && Assert Assert.ThrowsAsync(async () => await BomValidator.ValidateAppSettings(CommonAppSettings, mockISw360ProjectService.Object, projectReleases)); return Task.CompletedTask; @@ -87,10 +99,7 @@ public async Task ValidateAppSettings_ProvidedProjectID_EndsTheApplicationOnClos string projectName = "Test"; ProjectReleases projectReleases = new ProjectReleases(); projectReleases.clearingState = "CLOSED"; - var CommonAppSettings = new CommonAppSettings(mockIFolderAction.Object) - { - SW360ProjectName = "Test" - }; + mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny(), It.IsAny(), projectReleases)) .ReturnsAsync(projectName); @@ -101,7 +110,16 @@ public async Task ValidateAppSettings_ProvidedProjectID_EndsTheApplicationOnClos mockIFolderAction.Setup(x => x.ValidateFolderPath(It.IsAny())) .Callback((string message) => { }) .Verifiable(); - CommonAppSettings.PackageFilePath = ""; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + var CommonAppSettings = new CommonAppSettings(mockIFolderAction.Object, mockIFileOperations.Object) + { + SW360 = new SW360() { ProjectName = "Test" }, + Directory = new LCT.Common.Directory(mockIFolderAction.Object, mockIFileOperations.Object) + { + InputFolder = "" + } + }; //Act await BomValidator.ValidateAppSettings(CommonAppSettings, mockISw360ProjectService.Object, projectReleases); diff --git a/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs b/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs index 5f747fcb..5d6ba2a2 100644 --- a/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs @@ -7,6 +7,7 @@ using CycloneDX.Models; using LCT.APICommunications.Model.AQL; using LCT.Common; +using LCT.Common.Interface; using LCT.Common.Model; using LCT.PackageIdentifier; using LCT.PackageIdentifier.Interface; @@ -33,16 +34,18 @@ public void ParseLockFile_GivenAInputFilePath_ReturnsSuccess() string outFolder = Path.GetDirectoryName(exePath); string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; - string[] Includes = { "conan.lock" }; - Config config = new Config() - { - Include = Includes - }; + string[] Includes = { "conan.lock" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, - Conan = config + Conan = new Config() { Include = Includes }, + SW360 = new SW360(), + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath + } }; Mock cycloneDXBomParser = new Mock(); @@ -64,15 +67,17 @@ public void ParseLockFile_GivenAInputFilePath_ReturnDevDependentComp() string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; string[] Includes = { "conan.lock" }; - Config config = new Config() - { - Include = Includes - }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, - Conan = config + Conan = new Config() { Include = Includes }, + SW360 = new SW360(), + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath + } }; Mock cycloneDXBomParser = new Mock(); @@ -96,16 +101,16 @@ public void ParseLockFile_GivenAInputFilePathExcludeComponent_ReturnComponentCou string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; string[] Includes = { "conan.lock" }; - Config config = new Config() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - Include = Includes, - ExcludedComponents = new List { "openldap:2.6.4-shared-ossl3.1", "libcurl:7.87.0-shared-ossl3.1" } - }; - - CommonAppSettings appSettings = new CommonAppSettings() - { - PackageFilePath = packagefilepath, - Conan = config + Conan = new Config() { Include = Includes }, + SW360 = new SW360() { ExcludeComponents = ["openldap:2.6.4-shared-ossl3.1", "libcurl:7.87.0-shared-ossl3.1"] }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath + } }; Mock cycloneDXBomParser = new Mock(); @@ -145,7 +150,19 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData_Succes var components = new List() { component }; ComponentIdentification componentIdentification = new() { comparisonBOMData = components }; string[] repoList = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = repoList }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Conan = new Config + { + Artifactory = new Artifactory + { + InternalRepos = repoList + } + } + }; AqlResult aqlResult = new() { @@ -182,8 +199,19 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully() }; var components = new List() { component }; string[] repoList = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Conan = new LCT.Common.Model.Config() { JfrogConanRepoList = repoList }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Conan = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = repoList + } + } + }; AqlResult aqlResult = new() { Name = "index.json", @@ -223,8 +251,19 @@ public async Task GetArtifactoryRepoName_Conan_ReturnsNotFound_ReturnsFailure() }; var components = new List() { component }; string[] repoList = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Conan = new LCT.Common.Model.Config() { JfrogConanRepoList = repoList }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Conan = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = repoList + } + } + }; AqlResult aqlResult = new() { Name = "index.json", @@ -263,13 +302,17 @@ public void ParsePackageConfig_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTo string[] Includes = { "SBOM_ConanCATemplate.cdx.json" }; string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, - ProjectType = "CONAN", - RemoveDevDependency = true, + ProjectType = "CONAN", Conan = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_ConanCATemplate.cdx.json" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act diff --git a/src/LCT.PackageIdentifier.UTest/CycloneBomProcessorTests.cs b/src/LCT.PackageIdentifier.UTest/CycloneBomProcessorTests.cs index f65bb176..495857e6 100644 --- a/src/LCT.PackageIdentifier.UTest/CycloneBomProcessorTests.cs +++ b/src/LCT.PackageIdentifier.UTest/CycloneBomProcessorTests.cs @@ -36,8 +36,10 @@ public void SetMetadataInComparisonBOM_GivenBOMWithEmptyMetadata_FillsInMetadata }; CommonAppSettings appSettings = new CommonAppSettings() { - CaVersion = "1.2.3" + SW360 = new() + }; + projectReleases.Version = "1.2.3"; CatoolInfo caToolInformation = new CatoolInfo() { CatoolVersion = "6.0.0", CatoolRunningLocation="" }; //Act Bom files = CycloneBomProcessor.SetMetadataInComparisonBOM(bom, appSettings, projectReleases, caToolInformation); @@ -70,9 +72,9 @@ public void SetMetadataInComparisonBOM_GivenBOMWithMetadata_AddsNewMetadataInfoI }; CommonAppSettings appSettings = new CommonAppSettings() { - CaVersion = "1.2.3", - SW360ProjectName = "Test", + SW360 = new() { ProjectName = "Test" } }; + projectReleases.Version = "1.2.3"; Tool tools = new Tool() { @@ -88,7 +90,7 @@ public void SetMetadataInComparisonBOM_GivenBOMWithMetadata_AddsNewMetadataInfoI }; Component component = new Component { - Name = appSettings.SW360ProjectName, + Name = appSettings.SW360.ProjectName, Version = projectReleases.Version, Type = Component.Classification.Application }; diff --git a/src/LCT.PackageIdentifier.UTest/DebianParserTests.cs b/src/LCT.PackageIdentifier.UTest/DebianParserTests.cs index e9511f29..ff4433b6 100644 --- a/src/LCT.PackageIdentifier.UTest/DebianParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/DebianParserTests.cs @@ -16,6 +16,7 @@ using LCT.PackageIdentifier.Interface; using LCT.Services.Interface; using LCT.APICommunications.Model.AQL; +using LCT.Common.Interface; namespace LCT.PackageIdentifier.UTest { @@ -127,12 +128,17 @@ public void ParsePackageConfig_GivenAMultipleInputFilePath_ReturnsCounts() string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "*_Debian.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ProjectType = "DEBIAN", - RemoveDevDependency = true, + ProjectType = "DEBIAN", Debian = new Config() { Include = Includes }, - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -153,12 +159,18 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsCounts() string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "CycloneDX_Debian.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", ProjectType = "DEBIAN", - RemoveDevDependency = true, - Debian = new Config() { Include = Includes } + Debian = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -177,12 +189,17 @@ public void ParsePackageConfig_GivenMultipleInputFiles_ReturnsCountOfDuplicates( string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "*_Debian.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", ProjectType = "DEBIAN", - RemoveDevDependency = true, - Debian = new Config() { Include = Includes } + Debian = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -201,12 +218,17 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsSourceDetails() string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "SourceDetails_Cyclonedx.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", ProjectType = "DEBIAN", - RemoveDevDependency = true, - Debian = new Config() { Include = Includes } + Debian = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -226,13 +248,18 @@ public void ParsePackageConfig_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTo string[] Includes = { "CycloneDX_Debian.cdx.json", "SBOMTemplate_Debian.cdx.json" }; string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, - ProjectType = "DEBIAN", - RemoveDevDependency = true, + ProjectType = "DEBIAN", Debian = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_DebianCATemplate.cdx.json" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath, + + } }; //Act @@ -251,13 +278,18 @@ public void ParsePackageConfig_GivenAInputFilePathAlongWithSBOMTemplate_ReturnUp string[] Includes = { "CycloneDX_Debian.cdx.json", "SBOMTemplate_Debian.cdx.json" }; string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, - ProjectType = "DEBIAN", - RemoveDevDependency = true, + ProjectType = "DEBIAN", Debian = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOMTemplate_Debian.cdx.json", + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath, + + } }; //Act diff --git a/src/LCT.PackageIdentifier.UTest/MavenParserTests.cs b/src/LCT.PackageIdentifier.UTest/MavenParserTests.cs index c9c7ebc2..8d1ae589 100644 --- a/src/LCT.PackageIdentifier.UTest/MavenParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/MavenParserTests.cs @@ -17,6 +17,7 @@ using Moq; using System.Threading.Tasks; using LCT.Common.Constants; +using LCT.Common.Interface; namespace LCT.PackageIdentifier.UTest { @@ -121,12 +122,17 @@ public void ParsePackageFile_PackageLockWithDuplicateComponents_ReturnsCountOfDu string[] Includes = { "*_Maven.cdx.json" }; string[] Excludes = { "lol" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = filepath, - ProjectType = "MAVEN", - RemoveDevDependency = true, - Maven = new Config() { Include = Includes, Exclude = Excludes } + ProjectType = "MAVEN", + Maven = new Config() { Include = Includes, Exclude = Excludes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath + } }; Mock cycloneDXBomParser = new Mock(); MavenProcessor MavenProcessor = new MavenProcessor(cycloneDXBomParser.Object); @@ -152,7 +158,19 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData_Succes var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Maven = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { @@ -189,7 +207,19 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData2_Succe var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Maven = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { @@ -228,7 +258,19 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData3_Succe var components = new List() { component1 }; ComponentIdentification componentIdentification = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Maven = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { @@ -267,8 +309,19 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully() }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Maven = new Config() { JfrogMavenRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Maven = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common-1.0.0.tgz", @@ -307,8 +360,19 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData2_SuccessFully( }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Maven = new Config() { JfrogMavenRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Maven = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common-1.0.0.tgz", @@ -344,12 +408,17 @@ public void DevDependencyIdentificationLogic_ReturnsCountOfDevDependentcomponent string[] Includes = { "*.cdx.json" }; string[] Excludes = { "lol" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = filepath, ProjectType = "MAVEN", - RemoveDevDependency = true, - Maven = new Config() { Include = Includes, Exclude = Excludes } + Maven = new Config() { Include = Includes, Exclude = Excludes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath + } }; Mock cycloneDXBomParser = new Mock(); MavenProcessor MavenProcessor = new MavenProcessor(cycloneDXBomParser.Object); @@ -371,12 +440,17 @@ public void DevDependencyIdentificationLogic_ReturnsCountOfComponents_WithoutDev string[] Includes = { "*.cdx.json" }; string[] Excludes = { "lol" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = filepath, ProjectType = "MAVEN", - RemoveDevDependency = true, - Maven = new Config() { Include = Includes, Exclude = Excludes } + Maven = new Config() { Include = Includes, Exclude = Excludes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath + } }; Mock cycloneDXBomParser = new Mock(); MavenProcessor MavenProcessor = new MavenProcessor(cycloneDXBomParser.Object); @@ -400,13 +474,18 @@ public void ParsePackageFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTota string[] Includes = { "CycloneDX_Maven.cdx.json", "SBOMTemplate_Maven.cdx.json" }; string[] Excludes = { "lol" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = filepath, ProjectType = "MAVEN", - RemoveDevDependency = true, Maven = new Config() { Include = Includes, Exclude = Excludes }, - CycloneDxSBomTemplatePath = filepath + "\\SBOMTemplates\\SBOM_MavenCATemplate.cdx.json" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath, + + } }; Mock cycloneDXBomParser = new Mock(); MavenProcessor MavenProcessor = new MavenProcessor(cycloneDXBomParser.Object); @@ -429,13 +508,18 @@ public void ParsePackageFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnUpda string[] Includes = { "CycloneDX_Maven.cdx.json" }; string[] Excludes = { "lol" }; - CommonAppSettings appSettings = new CommonAppSettings() - { - PackageFilePath = filepath, - ProjectType = "MAVEN", - RemoveDevDependency = true, - Maven = new Config() { Include = Includes, Exclude = Excludes }, - CycloneDxSBomTemplatePath = filepath + "\\SBOMTemplates\\SBOMTemplate_Maven.cdx.json" + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + ProjectType = "MAVEN", + Maven = new Config() { Include = Includes, Exclude = Excludes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath, + + } }; Mock cycloneDXBomParser = new Mock(); MavenProcessor MavenProcessor = new MavenProcessor(cycloneDXBomParser.Object); diff --git a/src/LCT.PackageIdentifier.UTest/NPMParserTests.cs b/src/LCT.PackageIdentifier.UTest/NPMParserTests.cs index 4d63d7c3..1b10a71f 100644 --- a/src/LCT.PackageIdentifier.UTest/NPMParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/NPMParserTests.cs @@ -13,6 +13,7 @@ using CycloneDX.Models; using LCT.Common.Constants; using Moq; +using LCT.Common.Interface; namespace LCT.PackageIdentifier.UTest { @@ -30,13 +31,18 @@ public void ParsePackageFile_PackageLockWithDuplicateComponents_ReturnsCountOfDu string[] Includes = { "p*-lock.json" }; string[] Excludes = { "node_modules" }; - CommonAppSettings appSettings = new CommonAppSettings() - { - BomFolderPath = outFolder, - PackageFilePath = filepath, + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { ProjectType = "NPM", - RemoveDevDependency = true, - Npm = new Config() { Include = Includes, Exclude = Excludes } + Npm = new Config() { Include = Includes, Exclude = Excludes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath, + OutputFolder = outFolder + } }; Mock cycloneDXBomParser = new Mock(); @@ -59,13 +65,18 @@ public void ParsePackageFile_PackageLockWithangular16_ReturnsCountOfComponents() string[] Includes = { "p*-lock16.json" }; string[] Excludes = { "node_modules" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - BomFolderPath = outFolder, - PackageFilePath = filepath, ProjectType = "NPM", - RemoveDevDependency = true, - Npm = new Config() { Include = Includes, Exclude = Excludes } + Npm = new Config() { Include = Includes, Exclude = Excludes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath, + OutputFolder = outFolder + } }; Mock cycloneDXBomParser = new Mock(); NpmProcessor NpmProcessor = new NpmProcessor(cycloneDXBomParser.Object); @@ -89,14 +100,19 @@ public void ParsePackageFile_PackageLockWithoutDuplicateComponents_ReturnsCountZ string[] Includes = { "p*-lock.json" }; string[] Excludes = { "node_modules" }; BomKpiData bomKpiData = new BomKpiData(); - CommonAppSettings appSettings = new CommonAppSettings() - { - BomFolderPath= outFolder, - PackageFilePath = filepath, - ProjectType = "NPM", - RemoveDevDependency = true, - Npm = new Config() { Include = Includes, Exclude = Excludes } + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + ProjectType = "NPM", + Npm = new Config() { Include = Includes, Exclude = Excludes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = filepath, + OutputFolder = outFolder + } }; @@ -120,13 +136,18 @@ public void ParseCycloneDXFile_GivenMultipleInputFiles_ReturnsCounts() Mock cycloneDXBomParser = new Mock(); NpmProcessor npmProcessor = new NpmProcessor(cycloneDXBomParser.Object); string[] Includes = { "*_NPM.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() - { - BomFolderPath = outFolder, - PackageFilePath = outFolder + @"\PackageIdentifierUTTestFiles", + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { ProjectType = "NPM", - RemoveDevDependency = true, - Npm = new Config() { Include = Includes } + Npm = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = outFolder + @"\PackageIdentifierUTTestFiles", + OutputFolder = outFolder + } }; //Act @@ -148,14 +169,19 @@ public void ParseCycloneDXFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTo string[] Includes = { "CycloneDX2_NPM.cdx.json", "SBOMTemplate_Npm.cdx.json" }; string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; - CommonAppSettings appSettings = new CommonAppSettings() - { - BomFolderPath = outFolder, - PackageFilePath = packagefilepath, - ProjectType = "NPM", - RemoveDevDependency = true, + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + ProjectType = "NPM", Npm = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_NpmCATemplate.cdx.json" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath, + OutputFolder = outFolder, + + } }; //Act @@ -176,14 +202,19 @@ public void ParseCycloneDXFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnUp string[] Includes = { "CycloneDX2_NPM.cdx.json" }; string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - BomFolderPath = outFolder, - PackageFilePath = packagefilepath, - ProjectType = "NPM", - RemoveDevDependency = true, + ProjectType = "NPM", Npm = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOMTemplate_Npm.cdx.json" + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath, + OutputFolder = outFolder, + + } }; //Act diff --git a/src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs b/src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs index 6211fe2d..9b1ec3a9 100644 --- a/src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs +++ b/src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs @@ -8,6 +8,8 @@ using LCT.APICommunications.Model.AQL; using LCT.Common; using LCT.Common.Constants; +using LCT.Common.Interface; +using LCT.Common.Model; using LCT.PackageIdentifier.Interface; using LCT.PackageIdentifier.Model; using LCT.Services.Interface; @@ -133,7 +135,19 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData_Succes var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Npm = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlProperty npmNameProperty = new AqlProperty { Key = "npm.name", @@ -182,7 +196,19 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData2_Succe var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Npm = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlProperty npmNameProperty = new AqlProperty { Key = "npm.name", @@ -233,7 +259,19 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData3_Succe var components = new List() { component1 }; ComponentIdentification componentIdentification = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo1" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Npm = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlProperty npmNameProperty = new AqlProperty { Key = "npm.name", @@ -284,8 +322,19 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully() }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo1" }; - CommonAppSettings appSettings = new(); - appSettings.Npm = new Common.Model.Config() { JfrogNpmRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Npm = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlProperty npmNameProperty = new AqlProperty { Key = "npm.name", @@ -337,8 +386,19 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData2_SuccessFully( }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Npm = new Common.Model.Config() { JfrogNpmRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Npm = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlProperty npmNameProperty = new AqlProperty { Key = "npm.name", diff --git a/src/LCT.PackageIdentifier.UTest/NugetParserTests.cs b/src/LCT.PackageIdentifier.UTest/NugetParserTests.cs index cb9488db..f1811a0a 100644 --- a/src/LCT.PackageIdentifier.UTest/NugetParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/NugetParserTests.cs @@ -20,6 +20,7 @@ using System.Threading.Tasks; using System.Linq; using LCT.Common.Constants; +using LCT.Common.Interface; namespace LCT.PackageIdentifier.UTest { @@ -401,9 +402,16 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsSuccess() string outFolder = Path.GetDirectoryName(exePath); string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles\packages.config"; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = outFolder + @"\PackageIdentifierUTTestFiles" + Nuget = new Config(), + SW360 = new SW360(), + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = outFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -514,15 +522,21 @@ public void Parsecsproj_GivenXMLFile_ReturnsSuccess() string outFolder = Path.GetDirectoryName(exePath); string csprojfilepath = outFolder + @"\PackageIdentifierUTTestFiles"; string[] Excludes = null; - CommonAppSettings CommonAppSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings commonAppSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = csprojfilepath, - Nuget = new Config() { Exclude = Excludes } + Nuget = new Config() { Exclude = Excludes }, + SW360 = new SW360(), + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = csprojfilepath + } }; int devDependent = 0; //Act - List referenceDetails = NugetProcessor.Parsecsproj(CommonAppSettings); + List referenceDetails = NugetProcessor.Parsecsproj(commonAppSettings); foreach (var item in referenceDetails) { if (item.Private) @@ -546,14 +560,21 @@ public void RemoveExcludedComponents_ReturnsUpdatedBom() Bom bom = new Bom(); bom.Components = new List(); - CommonAppSettings CommonAppSettings = new CommonAppSettings() + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings commonAppSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = csprojfilepath, - Nuget = new Config() { Exclude = Excludes, ExcludedComponents = new List() } + Nuget = new Config() { Exclude = Excludes }, + SW360 = new SW360() { ExcludeComponents = new List() }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = csprojfilepath + } }; //Act - Bom updatedBom = NugetProcessor.RemoveExcludedComponents(CommonAppSettings, bom); + Bom updatedBom = NugetProcessor.RemoveExcludedComponents(commonAppSettings, bom); //Assert Assert.AreEqual(0, updatedBom.Components.Count, "Zero component exculded"); @@ -572,7 +593,19 @@ public async Task IdentificationOfInternalComponents_Nuget_ReturnsComponentData_ var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo1" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { @@ -610,7 +643,19 @@ public async Task IdentificationOfInternalComponents_Nuget_ReturnsComponentData2 var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { @@ -649,7 +694,19 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData3_Succe var components = new List() { component1 }; ComponentIdentification componentIdentification = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { @@ -689,8 +746,20 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully() }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr }; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common-1.0.0.nupkg", @@ -729,8 +798,19 @@ public async Task GetJfrogRepoDetailsOfAComponent_Nuget_ReturnsWithData2_Success }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common-1.0.0.nupkg", @@ -769,8 +849,19 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_SuccessFully() }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common-1.0.0.nupkg", @@ -809,8 +900,19 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_ReturnsFailure() }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animation-test-1.0.0.nupkg", @@ -849,8 +951,19 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_ReturnsSuccess() }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animations-common.1.0.0.nupkg", @@ -890,8 +1003,19 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsNotFound_ReturnsFailure() }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Nuget = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlResult aqlResult = new() { Name = "animation-common.1.0.0.nupkg", @@ -928,15 +1052,16 @@ public void ParseProjectAssetFile_GivenAInputFilePath_ReturnsSuccess() string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; string[] Includes = { "project.assets.json" }; - Config config = new Config() - { - Include = Includes - }; - - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, - Nuget = config + Nuget = new Config() { Include = Includes }, + SW360 = new SW360(), + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath + } }; Mock cycloneDXBomParser = new Mock(); @@ -958,15 +1083,17 @@ public void ParseProjectAssetFile_GivenAInputFilePath_ReturnDevDependentComp() string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles"; string[] Includes = { "project.assets.json" }; - Config config = new Config() - { - Include = Includes - }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, - Nuget = config + Nuget = new Config() { Include = Includes }, + SW360 = new SW360(), + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath + } }; Mock cycloneDXBomParser = new Mock(); diff --git a/src/LCT.PackageIdentifier.UTest/PythonParserTests.cs b/src/LCT.PackageIdentifier.UTest/PythonParserTests.cs index 489af68c..2f7d586e 100644 --- a/src/LCT.PackageIdentifier.UTest/PythonParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/PythonParserTests.cs @@ -18,6 +18,7 @@ using Moq; using System.Collections.Generic; using System.Threading.Tasks; +using LCT.Common.Interface; namespace LCT.PackageIdentifier.UTest { @@ -45,12 +46,17 @@ public void ParseCycloneDXFile_GivenAMultipleInputFilePath_ReturnsCounts() string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "*_Python.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - ProjectType = "PYTHON", - RemoveDevDependency = true, - Python = new Config() { Include = Includes }, - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles" + ProjectType = "POETRY", + Poetry = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -69,12 +75,17 @@ public void ParseCycloneDXFile_GivenAInputFilePath_ReturnsCounts() string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "CycloneDX_Python.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", - ProjectType = "PYTHON", - RemoveDevDependency = true, - Python = new Config() { Include = Includes } + ProjectType = "POETRY", + Poetry = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -92,21 +103,20 @@ public void ParseCycloneDXFile_GivenAInputFilePathExcludeOneComponent_ReturnsCou string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "CycloneDX_Python.cdx.json" }; - Config config = new Config() + List excludeComponents = ["attrs:22.2.0"]; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - Include = Includes, - ExcludedComponents = new List() - { - "attrs:22.2.0" + ProjectType = "POETRY", + Poetry = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true, ExcludeComponents = excludeComponents }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" } }; - CommonAppSettings appSettings = new CommonAppSettings() - { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", - ProjectType = "PYTHON", - RemoveDevDependency = true, - Python = config - }; //Act Bom listofcomponents = pythonProcessor.ParsePackageFile(appSettings); @@ -123,12 +133,18 @@ public void ParseCycloneDXFile_GivenMultipleInputFiles_ReturnsCountOfDuplicates( string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); string[] Includes = { "*_Python.cdx.json" }; - CommonAppSettings appSettings = new CommonAppSettings() + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles", - ProjectType = "PYTHON", - RemoveDevDependency = true, - Python = new Config() { Include = Includes } + ProjectType = "POETRY", + Poetry = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" + } }; //Act @@ -148,13 +164,18 @@ public void ParseCycloneDXFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTo string[] Includes = { "CycloneDX_Python.cdx.json", "SBOMTemplate_Python.cdx.json" }; string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, - ProjectType = "PYTHON", - RemoveDevDependency = true, - Python = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_PythonCATemplate.cdx.json" + ProjectType = "Poetry", + Poetry = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles", + + } }; //Act @@ -173,13 +194,18 @@ public void ParseCycloneDXFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnUp string[] Includes = { "CycloneDX_Python.cdx.json", "SBOMTemplate_Python.cdx.json" }; string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles"; - CommonAppSettings appSettings = new CommonAppSettings() + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { - PackageFilePath = packagefilepath, - ProjectType = "PYTHON", - RemoveDevDependency = true, - Python = new Config() { Include = Includes }, - CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOMTemplate_Python.cdx.json" + ProjectType = "Poetry", + Poetry = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = packagefilepath, + + } }; //Act @@ -203,7 +229,19 @@ public async Task IdentificationOfInternalComponents_Python_ReturnsComponentData var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Poetry = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlProperty pypiNameProperty = new AqlProperty { Key = "pypi.normalized.name", @@ -254,7 +292,19 @@ public async Task IdentificationOfInternalComponents_Python_ReturnsComponentData var components = new List() { component1 }; ComponentIdentification component = new() { comparisonBOMData = components }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new() { InternalRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Poetry = new Config + { + Artifactory = new Artifactory + { + InternalRepos = reooListArr + } + } + }; AqlProperty pypiNameProperty = new AqlProperty { Key = "pypi.normalized.name", @@ -305,8 +355,19 @@ public async Task GetJfrogRepoDetailsOfAComponentForPython_ReturnsWithData_Succe }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Python = new Config() { JfrogPythonRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Poetry = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlProperty pypiNameProperty = new AqlProperty { Key = "pypi.normalized.name", @@ -357,8 +418,19 @@ public async Task GetJfrogRepoDetailsOfAComponentForPython_ReturnsWithData2_Succ }; var components = new List() { component1 }; string[] reooListArr = { "internalrepo1", "internalrepo2" }; - CommonAppSettings appSettings = new(); - appSettings.Python = new Config() { JfrogPythonRepoList = reooListArr }; + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + SW360 = new SW360(), + Poetry = new Config + { + Artifactory = new Artifactory + { + RemoteRepos = reooListArr + } + } + }; AqlProperty pypiNameProperty = new AqlProperty { Key = "pypi.normalized.name", @@ -419,13 +491,19 @@ public void ExtractDetailsForPoetryLockfile_GivenAInputFilePath_ReturnsCounts() //Arrange string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string OutFolder = Path.GetDirectoryName(exePath); - string[] Includes = { "poetry.lock" }; - CommonAppSettings appSettings = new CommonAppSettings() - { - PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles\PythonTestProject", - ProjectType = "PYTHON", - RemoveDevDependency = true, - Python = new Config() { Include = Includes } + string[] Includes = { "poetry.lock" }; + + IFolderAction folderAction = new FolderAction(); + IFileOperations fileOperations = new FileOperations(); + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) + { + ProjectType = "Poetry", + Poetry = new Config() { Include = Includes }, + SW360 = new SW360() { IgnoreDevDependency = true }, + Directory = new LCT.Common.Directory(folderAction, fileOperations) + { + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles\PythonTestProject" + } }; //Act diff --git a/src/LCT.PackageIdentifier.UTest/SBomTemplateTests.cs b/src/LCT.PackageIdentifier.UTest/SBomTemplateTests.cs index 4a71de7a..07c308b3 100644 --- a/src/LCT.PackageIdentifier.UTest/SBomTemplateTests.cs +++ b/src/LCT.PackageIdentifier.UTest/SBomTemplateTests.cs @@ -139,7 +139,7 @@ public void AddComponentDetails_InputTemplateDetails_ReturnsTemplateWithDetailsu SbomTemplate.AddComponentDetails(componentsForBOM, templateDetails); //Assert - Assert.That(BomCreator.bomKpiData.ComponentsUpdatedFromSBOMTemplateFile, Is.EqualTo(3)); + Assert.That(BomCreator.bomKpiData.ComponentsUpdatedFromSBOMTemplateFile, Is.EqualTo(1)); } } } diff --git a/src/LCT.PackageIdentifier/AlpineProcesser.cs b/src/LCT.PackageIdentifier/AlpineProcesser.cs index 9607d14d..38f4daa5 100644 --- a/src/LCT.PackageIdentifier/AlpineProcesser.cs +++ b/src/LCT.PackageIdentifier/AlpineProcesser.cs @@ -42,12 +42,23 @@ public Bom ParsePackageFile(CommonAppSettings appSettings) List listComponentForBOM; List dependenciesForBOM = new(); - configFiles = FolderScanner.FileScanner(appSettings.PackageFilePath, appSettings.Alpine); + configFiles = FolderScanner.FileScanner(appSettings.Directory.InputFolder, appSettings.Alpine); foreach (string filepath in configFiles) { - Logger.Debug($"ParsePackageFile():FileName: " + filepath); - listofComponents.AddRange(ParseCycloneDX(filepath, dependenciesForBOM)); + if (filepath.EndsWith(FileConstant.SBOMTemplateFileExtension)) + { + Bom templateDetails; + templateDetails = CycloneDXBomParser.ExtractSBOMDetailsFromTemplate(_cycloneDXBomParser.ParseCycloneDXBom(filepath)); + CycloneDXBomParser.CheckValidComponentsForProjectType(templateDetails.Components, appSettings.ProjectType); + //Adding Template Component Details & MetaData + SbomTemplate.AddComponentDetails(bom.Components, templateDetails); + } + else + { + Logger.Debug($"ParsePackageFile():FileName: " + filepath); + listofComponents.AddRange(ParseCycloneDX(filepath, dependenciesForBOM)); + } } int initialCount = listofComponents.Count; @@ -57,15 +68,7 @@ public Bom ParsePackageFile(CommonAppSettings appSettings) bom.Components = listComponentForBOM; bom.Dependencies = dependenciesForBOM; - - if (File.Exists(appSettings.CycloneDxSBomTemplatePath) && appSettings.CycloneDxSBomTemplatePath.EndsWith(FileConstant.SBOMTemplateFileExtension)) - { - Bom templateDetails; - templateDetails = CycloneDXBomParser.ExtractSBOMDetailsFromTemplate(_cycloneDXBomParser.ParseCycloneDXBom(appSettings.CycloneDxSBomTemplatePath)); - CycloneDXBomParser.CheckValidComponentsForProjectType(templateDetails.Components, appSettings.ProjectType); - //Adding Template Component Details & MetaData - SbomTemplate.AddComponentDetails(bom.Components, templateDetails); - } + bom = RemoveExcludedComponents(appSettings, bom); bom.Dependencies = bom.Dependencies?.GroupBy(x => new { x.Ref }).Select(y => y.First()).ToList(); @@ -77,9 +80,9 @@ public static Bom RemoveExcludedComponents(CommonAppSettings appSettings, Bom cy List componentForBOM = cycloneDXBOM.Components.ToList(); List dependenciesForBOM = cycloneDXBOM.Dependencies?.ToList() ?? new List(); int noOfExcludedComponents = 0; - if (appSettings.Alpine.ExcludedComponents != null) + if (appSettings.SW360.ExcludeComponents != null) { - componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.Alpine.ExcludedComponents, ref noOfExcludedComponents); + componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.SW360.ExcludeComponents, ref noOfExcludedComponents); dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents; diff --git a/src/LCT.PackageIdentifier/BomCreator.cs b/src/LCT.PackageIdentifier/BomCreator.cs index a2a0666a..b5e4049a 100644 --- a/src/LCT.PackageIdentifier/BomCreator.cs +++ b/src/LCT.PackageIdentifier/BomCreator.cs @@ -17,12 +17,16 @@ using log4net.Core; using System; using System.Collections.Generic; +using System.Linq; using System.Net; using System.Net.Http; using System.Reflection; using System.Threading.Tasks; +using System.IO; + namespace LCT.PackageIdentifier + { /// /// BomCreator model @@ -74,12 +78,12 @@ public async Task GenerateBom(CommonAppSettings appSettings, Program.BomStopWatch?.Stop(); bomKpiData.TimeTakenByBomCreator = Program.BomStopWatch == null ? 0 : TimeSpan.FromMilliseconds(Program.BomStopWatch.ElapsedMilliseconds).TotalSeconds; - fileOperations.WriteContentToFile(bomKpiData, appSettings.BomFolderPath, - FileConstant.BomKpiDataFileName, appSettings.SW360ProjectName); + fileOperations.WriteContentToFile(bomKpiData, appSettings.Directory.OutputFolder, + FileConstant.BomKpiDataFileName, appSettings.SW360.ProjectName); // Writes Project Summary Url on CLI - string projectURL = bomHelper.GetProjectSummaryLink(appSettings.SW360ProjectID, appSettings.SW360URL); - bomKpiData.ProjectSummaryLink = $"Link to the summary page of the configurred project:{appSettings.SW360ProjectName} => {projectURL}\n"; + string projectURL = bomHelper.GetProjectSummaryLink(appSettings.SW360.ProjectID, appSettings.SW360.URL); + bomKpiData.ProjectSummaryLink = $"Link to the summary page of the configurred project:{appSettings.SW360.ProjectName} => {projectURL}\n"; // Writes kpi info to console table bomKpiData.InternalComponents = componentData.internalComponents != null ? componentData.internalComponents.Count : 0; @@ -99,18 +103,24 @@ private static void WritecontentsToBOM(CommonAppSettings appSettings, BomKpiData private static void WriteContentToCycloneDxBOM(CommonAppSettings appSettings, Bom listOfComponentsToBom, ref BomKpiData bomKpiData) { 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)); - if (string.IsNullOrEmpty(appSettings.IdentifierBomFilePath)) + if (fileExists && appSettings.MultipleProjectType) { + string existingFilePath = files.FirstOrDefault(file => Path.GetFileName(file).Equals(bomFileName, StringComparison.OrdinalIgnoreCase)); + listOfComponentsToBom = fileOperations.CombineComponentsFromExistingBOM(listOfComponentsToBom, existingFilePath); + bomKpiData.ComponentsInComparisonBOM = listOfComponentsToBom.Components.Count; string formattedString = CommonHelper.AddSpecificValuesToBOMFormat(listOfComponentsToBom); - fileOperations.WriteContentToOutputBomFile(formattedString, appSettings.BomFolderPath, FileConstant.BomFileName, appSettings.SW360ProjectName); + fileOperations.WriteContentToOutputBomFile(formattedString, outputFolderPath, FileConstant.BomFileName, appSettings.SW360.ProjectName); } else { - listOfComponentsToBom = fileOperations.CombineComponentsFromExistingBOM(listOfComponentsToBom, appSettings.IdentifierBomFilePath); - bomKpiData.ComponentsInComparisonBOM = listOfComponentsToBom.Components.Count; string formattedString = CommonHelper.AddSpecificValuesToBOMFormat(listOfComponentsToBom); - fileOperations.WriteContentToOutputBomFile(formattedString, appSettings.BomFolderPath, FileConstant.BomFileName, appSettings.SW360ProjectName); + fileOperations.WriteContentToOutputBomFile(formattedString, outputFolderPath, FileConstant.BomFileName, appSettings.SW360.ProjectName); } } @@ -136,7 +146,7 @@ private async Task CallPackageParser(CommonAppSettings appSettings) case "ALPINE": parser = new AlpineProcessor(CycloneDXBomParser); return await ComponentIdentification(appSettings, parser); - case "PYTHON": + case "POETRY": parser = new PythonProcessor(CycloneDXBomParser); return await ComponentIdentification(appSettings, parser); case "CONAN": diff --git a/src/LCT.PackageIdentifier/BomValidator.cs b/src/LCT.PackageIdentifier/BomValidator.cs index af87aeb3..74a75548 100644 --- a/src/LCT.PackageIdentifier/BomValidator.cs +++ b/src/LCT.PackageIdentifier/BomValidator.cs @@ -23,11 +23,11 @@ public static class BomValidator static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public static async Task ValidateAppSettings(CommonAppSettings appSettings, ISw360ProjectService bomService, ProjectReleases projectReleases) { - string sw360ProjectName = await bomService.GetProjectNameByProjectIDFromSW360(appSettings.SW360ProjectID, appSettings.SW360ProjectName,projectReleases); + string sw360ProjectName = await bomService.GetProjectNameByProjectIDFromSW360(appSettings.SW360.ProjectID, appSettings.SW360.ProjectName,projectReleases); if (string.IsNullOrEmpty(sw360ProjectName)) { - throw new InvalidDataException($"Invalid Project Id - {appSettings.SW360ProjectID}"); + throw new InvalidDataException($"Invalid Project Id - {appSettings.SW360.ProjectID}"); } else if (projectReleases?.clearingState == "CLOSED") { @@ -37,7 +37,7 @@ public static async Task ValidateAppSettings(CommonAppSettings appSettings, } else { - appSettings.SW360ProjectName = sw360ProjectName; + appSettings.SW360.ProjectName = sw360ProjectName; } return 0; } diff --git a/src/LCT.PackageIdentifier/ConanProcessor.cs b/src/LCT.PackageIdentifier/ConanProcessor.cs index 7cb5a1d6..4f03622c 100644 --- a/src/LCT.PackageIdentifier/ConanProcessor.cs +++ b/src/LCT.PackageIdentifier/ConanProcessor.cs @@ -75,7 +75,7 @@ public async Task IdentificationOfInternalComponents(Co { // get the component list from Jfrog for given repository List aqlResultList = - await bomhelper.GetListOfComponentsFromRepo(appSettings.InternalRepoList, jFrogService); + await bomhelper.GetListOfComponentsFromRepo(appSettings.Conan.Artifactory.InternalRepos, jFrogService); // find the components in the list of internal components List internalComponents = new List(); @@ -118,7 +118,11 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List()) + .Concat(appSettings.Conan?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Conan?.Artifactory.RemoteRepos ?? Array.Empty()) + .Concat(appSettings.Conan?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) + .ToArray(); List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); @@ -133,15 +137,22 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List componentsWith { MultipleVersions multipleVersions = new MultipleVersions(); IFileOperations fileOperations = new FileOperations(); - string filename = $"{appSettings.BomFolderPath}\\{appSettings.SW360ProjectName}_{FileConstant.multipleversionsFileName}"; - if (string.IsNullOrEmpty(appSettings.IdentifierBomFilePath) || (!File.Exists(filename))) + string filename = $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}"; + if (string.IsNullOrEmpty(appSettings.Directory.OutputFolder) || (!File.Exists(filename))) { multipleVersions.Conan = new List(); foreach (var conanPackage in componentsWithMultipleVersions) { - conanPackage.Description = !string.IsNullOrEmpty(appSettings.CycloneDxSBomTemplatePath) ? appSettings.CycloneDxSBomTemplatePath : conanPackage.Description; - + MultipleVersionValues jsonComponents = new MultipleVersionValues(); jsonComponents.ComponentName = conanPackage.Name; jsonComponents.ComponentVersion = conanPackage.Version; jsonComponents.PackageFoundIn = conanPackage.Description; multipleVersions.Conan.Add(jsonComponents); } - fileOperations.WriteContentToMultipleVersionsFile(multipleVersions, appSettings.BomFolderPath, FileConstant.multipleversionsFileName, appSettings.SW360ProjectName); - Logger.Warn($"\nTotal Multiple versions detected {multipleVersions.Conan.Count} and details can be found at {appSettings.BomFolderPath}\\{appSettings.SW360ProjectName}_{FileConstant.multipleversionsFileName}\n"); + fileOperations.WriteContentToMultipleVersionsFile(multipleVersions, appSettings.Directory.OutputFolder, FileConstant.multipleversionsFileName, appSettings.SW360.ProjectName); + Logger.Warn($"\nTotal Multiple versions detected {multipleVersions.Conan.Count} and details can be found at {appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}\n"); } else { @@ -232,8 +242,7 @@ private static void CreateFileForMultipleVersions(List componentsWith List conanComponents = new List(); foreach (var conanPackage in componentsWithMultipleVersions) { - conanPackage.Description = !string.IsNullOrEmpty(appSettings.CycloneDxSBomTemplatePath) ? appSettings.CycloneDxSBomTemplatePath : conanPackage.Description; - + MultipleVersionValues jsonComponents = new MultipleVersionValues(); jsonComponents.ComponentName = conanPackage.Name; jsonComponents.ComponentVersion = conanPackage.Version; @@ -243,8 +252,8 @@ private static void CreateFileForMultipleVersions(List componentsWith } myDeserializedClass.Conan = conanComponents; - fileOperations.WriteContentToMultipleVersionsFile(myDeserializedClass, appSettings.BomFolderPath, FileConstant.multipleversionsFileName, appSettings.SW360ProjectName); - Logger.Warn($"\nTotal Multiple versions detected {conanComponents.Count} and details can be found at {appSettings.BomFolderPath}\\{appSettings.SW360ProjectName}_{FileConstant.multipleversionsFileName}\n"); + fileOperations.WriteContentToMultipleVersionsFile(myDeserializedClass, appSettings.Directory.OutputFolder, FileConstant.multipleversionsFileName, appSettings.SW360.ProjectName); + Logger.Warn($"\nTotal Multiple versions detected {conanComponents.Count} and details can be found at {appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}\n"); } } private void ParsingInputFileForBOM(CommonAppSettings appSettings, ref Bom bom) @@ -252,7 +261,7 @@ private void ParsingInputFileForBOM(CommonAppSettings appSettings, ref Bom bom) List configFiles; List dependencies = new List(); List componentsForBOM = new List(); - configFiles = FolderScanner.FileScanner(appSettings.PackageFilePath, appSettings.Conan); + configFiles = FolderScanner.FileScanner(appSettings.Directory.InputFolder, appSettings.Conan); foreach (string filepath in configFiles) { @@ -272,6 +281,15 @@ private void ParsingInputFileForBOM(CommonAppSettings appSettings, ref Bom bom) GetDetailsforManuallyAddedComp(bom.Components); componentsForBOM.AddRange(bom.Components); } + else if (filepath.EndsWith(FileConstant.SBOMTemplateFileExtension)) + { + Bom templateDetails; + templateDetails = ExtractSBOMDetailsFromTemplate( + _cycloneDXBomParser.ParseCycloneDXBom(filepath)); + CheckValidComponentsForProjectType(templateDetails.Components, appSettings.ProjectType); + SbomTemplate.AddComponentDetails(bom.Components, templateDetails); + + } } int initialCount = componentsForBOM.Count; @@ -289,16 +307,7 @@ private void ParsingInputFileForBOM(CommonAppSettings appSettings, ref Bom bom) bom.Dependencies = dependencies; } - if (File.Exists(appSettings.CycloneDxSBomTemplatePath) - && appSettings.CycloneDxSBomTemplatePath.EndsWith(FileConstant.SBOMTemplateFileExtension)) - { - //Adding Template Component Details - Bom templateDetails; - templateDetails = ExtractSBOMDetailsFromTemplate( - _cycloneDXBomParser.ParseCycloneDXBom(appSettings.CycloneDxSBomTemplatePath)); - CheckValidComponentsForProjectType(templateDetails.Components, appSettings.ProjectType); - SbomTemplate.AddComponentDetails(bom.Components, templateDetails); - } + bom = RemoveExcludedComponents(appSettings, bom); bom.Dependencies = bom.Dependencies?.GroupBy(x => new { x.Ref }).Select(y => y.First()).ToList(); @@ -543,9 +552,9 @@ private static Bom RemoveExcludedComponents(CommonAppSettings appSettings, Bom c List componentForBOM = cycloneDXBOM.Components.ToList(); List dependenciesForBOM = cycloneDXBOM.Dependencies?.ToList() ?? new List(); int noOfExcludedComponents = 0; - if (appSettings.Conan.ExcludedComponents != null) + if (appSettings.SW360.ExcludeComponents != null) { - componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.Conan.ExcludedComponents, ref noOfExcludedComponents); + componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.SW360.ExcludeComponents, 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..47060997 100644 --- a/src/LCT.PackageIdentifier/CycloneBomProcessor.cs +++ b/src/LCT.PackageIdentifier/CycloneBomProcessor.cs @@ -36,7 +36,7 @@ public static Bom SetMetadataInComparisonBOM(Bom bom, Component component = new Component { - Name = appSettings.SW360ProjectName, + Name = appSettings.SW360.ProjectName, Version = projectReleases.Version, Type = Component.Classification.Application }; diff --git a/src/LCT.PackageIdentifier/DebianProcessor.cs b/src/LCT.PackageIdentifier/DebianProcessor.cs index cdd58cea..2a79ad1c 100644 --- a/src/LCT.PackageIdentifier/DebianProcessor.cs +++ b/src/LCT.PackageIdentifier/DebianProcessor.cs @@ -47,11 +47,19 @@ public Bom ParsePackageFile(CommonAppSettings appSettings) Bom bom = new Bom(); List listComponentForBOM; - configFiles = FolderScanner.FileScanner(appSettings.PackageFilePath, appSettings.Debian); + configFiles = FolderScanner.FileScanner(appSettings.Directory.InputFolder, appSettings.Debian); foreach (string filepath in configFiles) { - if (!filepath.EndsWith(FileConstant.SBOMTemplateFileExtension)) + if (filepath.EndsWith(FileConstant.SBOMTemplateFileExtension)) + { + Bom templateDetails; + templateDetails = CycloneDXBomParser.ExtractSBOMDetailsFromTemplate(_cycloneDXBomParser.ParseCycloneDXBom(filepath)); + CycloneDXBomParser.CheckValidComponentsForProjectType(templateDetails.Components, appSettings.ProjectType); + //Adding Template Component Details & MetaData + SbomTemplate.AddComponentDetails(bom.Components, templateDetails); + } + else { Logger.Debug($"ParsePackageFile():FileName: " + filepath); var list = ParseCycloneDX(filepath, ref bom); @@ -65,14 +73,7 @@ public Bom ParsePackageFile(CommonAppSettings appSettings) BomCreator.bomKpiData.DuplicateComponents = initialCount - listComponentForBOM.Count; bom.Components = listComponentForBOM; - if (File.Exists(appSettings.CycloneDxSBomTemplatePath) && appSettings.CycloneDxSBomTemplatePath.EndsWith(FileConstant.SBOMTemplateFileExtension)) - { - Bom templateDetails; - templateDetails = CycloneDXBomParser.ExtractSBOMDetailsFromTemplate(_cycloneDXBomParser.ParseCycloneDXBom(appSettings.CycloneDxSBomTemplatePath)); - CycloneDXBomParser.CheckValidComponentsForProjectType(templateDetails.Components, appSettings.ProjectType); - //Adding Template Component Details & MetaData - SbomTemplate.AddComponentDetails(bom.Components, templateDetails); - } + bom = RemoveExcludedComponents(appSettings, bom); bom.Dependencies = bom.Dependencies?.GroupBy(x => new { x.Ref }).Select(y => y.First()).ToList(); @@ -112,9 +113,9 @@ public static Bom RemoveExcludedComponents(CommonAppSettings appSettings, Bom cy List componentForBOM = cycloneDXBOM.Components.ToList(); List dependenciesForBOM = cycloneDXBOM.Dependencies?.ToList() ?? new List(); int noOfExcludedComponents = 0; - if (appSettings.Debian.ExcludedComponents != null) + if (appSettings.SW360.ExcludeComponents != null) { - componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.Debian.ExcludedComponents, ref noOfExcludedComponents); + componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.SW360.ExcludeComponents, ref noOfExcludedComponents); dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents; } @@ -128,7 +129,11 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List()) + .Concat(appSettings.Debian?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Debian?.Artifactory.RemoteRepos ?? Array.Empty()) + .Concat(appSettings.Debian?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) + .ToArray(); List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); @@ -145,15 +150,23 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List IdentificationOfInternalComponents(Co { // get the component list from Jfrog for given repo List aqlResultList = - await bomhelper.GetListOfComponentsFromRepo(appSettings.InternalRepoList, jFrogService); + await bomhelper.GetListOfComponentsFromRepo(appSettings.Debian.Artifactory.InternalRepos, jFrogService); // find the components in the list of internal components List internalComponents = new List(); diff --git a/src/LCT.PackageIdentifier/MavenProcessor.cs b/src/LCT.PackageIdentifier/MavenProcessor.cs index 21506a65..ca802474 100644 --- a/src/LCT.PackageIdentifier/MavenProcessor.cs +++ b/src/LCT.PackageIdentifier/MavenProcessor.cs @@ -42,11 +42,19 @@ public Bom ParsePackageFile(CommonAppSettings appSettings) List dependenciesForBOM = new(); List configFiles; - configFiles = FolderScanner.FileScanner(appSettings.PackageFilePath, appSettings.Maven); + configFiles = FolderScanner.FileScanner(appSettings.Directory.InputFolder, appSettings.Maven); foreach (string filepath in configFiles) { - if (!filepath.EndsWith(FileConstant.SBOMTemplateFileExtension)) + if (filepath.EndsWith(FileConstant.SBOMTemplateFileExtension)) + { + //Adding Template Component Details + Bom templateDetails; + templateDetails = ExtractSBOMDetailsFromTemplate(_cycloneDXBomParser.ParseCycloneDXBom(filepath)); + CheckValidComponentsForProjectType(templateDetails.Components, appSettings.ProjectType); + SbomTemplate.AddComponentDetails(componentsForBOM, templateDetails); + } + else { Bom bomList = ParseCycloneDXBom(filepath); if (bomList?.Components != null) @@ -74,15 +82,7 @@ public Bom ParsePackageFile(CommonAppSettings appSettings) } } } - - if (File.Exists(appSettings.CycloneDxSBomTemplatePath) && appSettings.CycloneDxSBomTemplatePath.EndsWith(FileConstant.SBOMTemplateFileExtension)) - { - //Adding Template Component Details - Bom templateDetails; - templateDetails = ExtractSBOMDetailsFromTemplate(_cycloneDXBomParser.ParseCycloneDXBom(appSettings.CycloneDxSBomTemplatePath)); - CheckValidComponentsForProjectType(templateDetails.Components, appSettings.ProjectType); - SbomTemplate.AddComponentDetails(componentsForBOM, templateDetails); - } + //checking Dev dependency DevDependencyIdentificationLogic(componentsForBOM, componentsToBOM, ref ListOfComponents); @@ -97,9 +97,9 @@ public Bom ParsePackageFile(CommonAppSettings appSettings) BomCreator.bomKpiData.DuplicateComponents = totalComponentsIdentified - componentsForBOM.Count; - if (appSettings.Maven.ExcludedComponents != null) + if (appSettings.SW360.ExcludeComponents != null) { - componentsForBOM = CommonHelper.RemoveExcludedComponents(componentsForBOM, appSettings.Maven.ExcludedComponents, ref noOfExcludedComponents); + componentsForBOM = CommonHelper.RemoveExcludedComponents(componentsForBOM, appSettings.SW360.ExcludeComponents, ref noOfExcludedComponents); dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentsForBOM, dependenciesForBOM); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents; } @@ -207,7 +207,11 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List()) + .Concat(appSettings.Maven?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Maven?.Artifactory.RemoteRepos ?? Array.Empty()) + .Concat(appSettings.Maven?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) + .ToArray(); List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); @@ -225,15 +229,23 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List IdentificationOfInternalComponents( { // get the component list from Jfrog for given repo - List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(appSettings.InternalRepoList, jFrogService); + List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(appSettings.Maven.Artifactory.InternalRepos, jFrogService); // find the components in the list of internal components List internalComponents = new List(); diff --git a/src/LCT.PackageIdentifier/NpmProcessor.cs b/src/LCT.PackageIdentifier/NpmProcessor.cs index 6587c177..0782395b 100644 --- a/src/LCT.PackageIdentifier/NpmProcessor.cs +++ b/src/LCT.PackageIdentifier/NpmProcessor.cs @@ -107,9 +107,9 @@ public List ParsePackageLockJson(string filepath, CommonAppSettings a } } - if (appSettings.Npm.ExcludedComponents != null) + if (appSettings.SW360.ExcludeComponents != null) { - lstComponentForBOM = CommonHelper.RemoveExcludedComponents(lstComponentForBOM, appSettings.Npm.ExcludedComponents, ref noOfExcludedComponents); + lstComponentForBOM = CommonHelper.RemoveExcludedComponents(lstComponentForBOM, appSettings.SW360.ExcludeComponents, ref noOfExcludedComponents); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents; } @@ -153,22 +153,20 @@ private static void CreateFileForMultipleVersions(List componentsWith { MultipleVersions multipleVersions = new MultipleVersions(); IFileOperations fileOperations = new FileOperations(); - string filename = $"{appSettings.BomFolderPath}\\{appSettings.SW360ProjectName}_{FileConstant.multipleversionsFileName}"; - if (string.IsNullOrEmpty(appSettings.IdentifierBomFilePath) || (!File.Exists(filename))) + string filename = $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}"; + if (string.IsNullOrEmpty(appSettings.Directory.OutputFolder) || (!File.Exists(filename))) { multipleVersions.Npm = new List(); foreach (var npmpackage in componentsWithMultipleVersions) { - npmpackage.Description = !string.IsNullOrEmpty(appSettings.CycloneDxSBomTemplatePath) ? appSettings.CycloneDxSBomTemplatePath : npmpackage.Description; - MultipleVersionValues jsonComponents = new MultipleVersionValues(); jsonComponents.ComponentName = npmpackage.Name; jsonComponents.ComponentVersion = npmpackage.Version; jsonComponents.PackageFoundIn = npmpackage.Description; multipleVersions.Npm.Add(jsonComponents); } - fileOperations.WriteContentToMultipleVersionsFile(multipleVersions, appSettings.BomFolderPath, FileConstant.multipleversionsFileName, appSettings.SW360ProjectName); - Logger.Warn($"\nTotal Multiple versions detected {multipleVersions.Npm.Count} and details can be found at {appSettings.BomFolderPath}\\{appSettings.SW360ProjectName}_{FileConstant.multipleversionsFileName}\n"); + fileOperations.WriteContentToMultipleVersionsFile(multipleVersions, appSettings.Directory.OutputFolder, FileConstant.multipleversionsFileName, appSettings.SW360.ProjectName); + Logger.Warn($"\nTotal Multiple versions detected {multipleVersions.Npm.Count} and details can be found at {appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}\n"); } else { @@ -177,8 +175,6 @@ private static void CreateFileForMultipleVersions(List componentsWith List npmComponents = new List(); foreach (var npmpackage in componentsWithMultipleVersions) { - npmpackage.Description = !string.IsNullOrEmpty(appSettings.CycloneDxSBomTemplatePath) ? appSettings.CycloneDxSBomTemplatePath : npmpackage.Description; - MultipleVersionValues jsonComponents = new MultipleVersionValues(); jsonComponents.ComponentName = npmpackage.Name; jsonComponents.ComponentVersion = npmpackage.Version; @@ -188,8 +184,8 @@ private static void CreateFileForMultipleVersions(List componentsWith } myDeserializedClass.Npm = npmComponents; - fileOperations.WriteContentToMultipleVersionsFile(myDeserializedClass, appSettings.BomFolderPath, FileConstant.multipleversionsFileName, appSettings.SW360ProjectName); - Logger.Warn($"\nTotal Multiple versions detected {npmComponents.Count} and details can be found at {appSettings.BomFolderPath}\\{appSettings.SW360ProjectName}_{FileConstant.multipleversionsFileName}\n"); + fileOperations.WriteContentToMultipleVersionsFile(myDeserializedClass, appSettings.Directory.OutputFolder, FileConstant.multipleversionsFileName, appSettings.SW360.ProjectName); + Logger.Warn($"\nTotal Multiple versions detected {npmComponents.Count} and details can be found at {appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}\n"); } } @@ -363,7 +359,7 @@ public async Task IdentificationOfInternalComponents( { // get the component list from Jfrog for given repo List aqlResultList = - await bomhelper.GetNpmListOfComponentsFromRepo(appSettings.InternalRepoList, jFrogService); + await bomhelper.GetNpmListOfComponentsFromRepo(appSettings.Npm.Artifactory.InternalRepos, jFrogService); // find the components in the list of internal components List internalComponents = new List(); @@ -405,7 +401,11 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List()) + .Concat(appSettings.Npm?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Npm?.Artifactory.RemoteRepos ?? Array.Empty()) + .Concat(appSettings.Npm?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) + .ToArray(); List aqlResultList = await bomhelper.GetNpmListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; @@ -424,15 +424,24 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List componentForBOM = cycloneDXBOM.Components.ToList(); List dependenciesForBOM = cycloneDXBOM.Dependencies?.ToList() ?? new List(); int noOfExcludedComponents = 0; - if (appSettings.Npm.ExcludedComponents != null) + if (appSettings.SW360.ExcludeComponents != null) { - componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.Npm.ExcludedComponents, ref noOfExcludedComponents); + componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.SW360.ExcludeComponents, ref noOfExcludedComponents); dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents; @@ -500,7 +509,7 @@ public static Bom RemoveExcludedComponents(CommonAppSettings appSettings, Bom cy private void ParsingInputFileForBOM(CommonAppSettings appSettings, ref List componentsForBOM, ref Bom bom, ref List dependencies) { List configFiles; - configFiles = FolderScanner.FileScanner(appSettings.PackageFilePath, appSettings.Npm); + configFiles = FolderScanner.FileScanner(appSettings.Directory.InputFolder, appSettings.Npm); foreach (string filepath in configFiles) { @@ -508,7 +517,15 @@ private void ParsingInputFileForBOM(CommonAppSettings appSettings, ref List> GetJfrogRepoDetailsOfAComponent(List()) + .Concat(appSettings.Nuget?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Nuget?.Artifactory.RemoteRepos ?? Array.Empty()) + .Concat(appSettings.Nuget?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) + .ToArray(); List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); @@ -232,15 +236,22 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List IdentificationOfInternalComponents( { // get the component list from Jfrog for given repo - List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(appSettings.InternalRepoList, jFrogService); + List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(appSettings.Nuget.Artifactory.InternalRepos, jFrogService); // find the components in the list of internal components List internalComponents = new List(); @@ -408,9 +419,9 @@ public static Bom RemoveExcludedComponents(CommonAppSettings appSettings, Bom cy List componentForBOM = cycloneDXBOM.Components.ToList(); List dependenciesForBOM = cycloneDXBOM.Dependencies?.ToList() ?? new List(); int noOfExcludedComponents = 0; - if (appSettings.Nuget.ExcludedComponents != null) + if (appSettings.SW360.ExcludeComponents != null) { - componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.Nuget.ExcludedComponents, ref noOfExcludedComponents); + componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.SW360.ExcludeComponents, ref noOfExcludedComponents); dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents; @@ -432,14 +443,23 @@ private void ParsingInputFileForBOM(CommonAppSettings appSettings, List dependencies = new List(); int totalComponentsIdentified = 0; - configFiles = FolderScanner.FileScanner(appSettings.PackageFilePath, appSettings.Nuget); + configFiles = FolderScanner.FileScanner(appSettings.Directory.InputFolder, appSettings.Nuget); foreach (string filepath in configFiles) { Logger.Debug($"ParsingInputFileForBOM():FileName: " + filepath); if (filepath.EndsWith(FileConstant.CycloneDXFileExtension)) { - if (!filepath.EndsWith(FileConstant.SBOMTemplateFileExtension)) + if (filepath.EndsWith(FileConstant.SBOMTemplateFileExtension)) + { + Bom templateDetails; + templateDetails = CycloneDXBomParser.ExtractSBOMDetailsFromTemplate( + _cycloneDXBomParser.ParseCycloneDXBom(filepath)); + CycloneDXBomParser.CheckValidComponentsForProjectType( + templateDetails.Components, appSettings.ProjectType); + SbomTemplate.AddComponentDetails(bom.Components, templateDetails); + } + else { Logger.Debug($"ParsingInputFileForBOM():Found as CycloneDXFile"); bom = _cycloneDXBomParser.ParseCycloneDXBom(filepath); @@ -485,18 +505,7 @@ private void ParsingInputFileForBOM(CommonAppSettings appSettings, BomCreator.bomKpiData.DevDependentComponents = listComponentForBOM.Count(s => s.Properties[0].Value == "true"); bom.Components = listComponentForBOM; - - if (File.Exists(appSettings.CycloneDxSBomTemplatePath) - && appSettings.CycloneDxSBomTemplatePath.EndsWith(FileConstant.SBOMTemplateFileExtension)) - { - //Adding Template Component Details - Bom templateDetails; - templateDetails = CycloneDXBomParser.ExtractSBOMDetailsFromTemplate( - _cycloneDXBomParser.ParseCycloneDXBom(appSettings.CycloneDxSBomTemplatePath)); - CycloneDXBomParser.CheckValidComponentsForProjectType( - templateDetails.Components, appSettings.ProjectType); - SbomTemplate.AddComponentDetails(bom.Components, templateDetails); - } + bom = RemoveExcludedComponents(appSettings, bom); @@ -533,22 +542,20 @@ private static void CreateFileForMultipleVersions(List componentsWith { MultipleVersions multipleVersions = new MultipleVersions(); IFileOperations fileOperations = new FileOperations(); - string filename = $"{appSettings.BomFolderPath}\\{appSettings.SW360ProjectName}_{FileConstant.multipleversionsFileName}"; - if (string.IsNullOrEmpty(appSettings.IdentifierBomFilePath) || (!File.Exists(filename))) + string filename = $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}"; + if (string.IsNullOrEmpty(appSettings.Directory.OutputFolder) || (!File.Exists(filename))) { multipleVersions.Nuget = new List(); foreach (var nugetPackage in componentsWithMultipleVersions) { - nugetPackage.Description = !string.IsNullOrEmpty(appSettings.CycloneDxSBomTemplatePath) ? appSettings.CycloneDxSBomTemplatePath : nugetPackage.Description; - MultipleVersionValues jsonComponents = new MultipleVersionValues(); jsonComponents.ComponentName = nugetPackage.Name; jsonComponents.ComponentVersion = nugetPackage.Version; jsonComponents.PackageFoundIn = nugetPackage.Description; multipleVersions.Nuget.Add(jsonComponents); } - fileOperations.WriteContentToMultipleVersionsFile(multipleVersions, appSettings.BomFolderPath, FileConstant.multipleversionsFileName, appSettings.SW360ProjectName); - Logger.Warn($"\nTotal Multiple versions detected {multipleVersions.Nuget.Count} and details can be found at {appSettings.BomFolderPath}\\{appSettings.SW360ProjectName}_{FileConstant.multipleversionsFileName}\n"); + fileOperations.WriteContentToMultipleVersionsFile(multipleVersions, appSettings.Directory.OutputFolder, FileConstant.multipleversionsFileName, appSettings.SW360.ProjectName); + Logger.Warn($"\nTotal Multiple versions detected {multipleVersions.Nuget.Count} and details can be found at {appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}\n"); } else { @@ -557,8 +564,6 @@ private static void CreateFileForMultipleVersions(List componentsWith List nugetComponents = new List(); foreach (var nugetPackage in componentsWithMultipleVersions) { - nugetPackage.Description = !string.IsNullOrEmpty(appSettings.CycloneDxSBomTemplatePath) ? appSettings.CycloneDxSBomTemplatePath : nugetPackage.Description; - MultipleVersionValues jsonComponents = new MultipleVersionValues(); jsonComponents.ComponentName = nugetPackage.Name; jsonComponents.ComponentVersion = nugetPackage.Version; @@ -568,8 +573,8 @@ private static void CreateFileForMultipleVersions(List componentsWith } myDeserializedClass.Nuget = nugetComponents; - fileOperations.WriteContentToMultipleVersionsFile(myDeserializedClass, appSettings.BomFolderPath, FileConstant.multipleversionsFileName, appSettings.SW360ProjectName); - Logger.Warn($"\nTotal Multiple versions detected {nugetComponents.Count} and details can be found at {appSettings.BomFolderPath}\\{appSettings.SW360ProjectName}_{FileConstant.multipleversionsFileName}\n"); + fileOperations.WriteContentToMultipleVersionsFile(myDeserializedClass, appSettings.Directory.OutputFolder, FileConstant.multipleversionsFileName, appSettings.SW360.ProjectName); + Logger.Warn($"\nTotal Multiple versions detected {nugetComponents.Count} and details can be found at {appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}\n"); } } @@ -685,7 +690,7 @@ private static void CheckForMultipleVersions(CommonAppSettings appSettings, List private static List GetValidCsprojfile(CommonAppSettings appSettings) { List allFoundCsprojFiles = new List(); - string[] foundCsprojFiles = Directory.GetFiles(appSettings.PackageFilePath, "*.csproj", SearchOption.AllDirectories); + string[] foundCsprojFiles = System.IO.Directory.GetFiles(appSettings.Directory.InputFolder, "*.csproj", SearchOption.AllDirectories); if (foundCsprojFiles != null) { foreach (string csprojFile in foundCsprojFiles) diff --git a/src/LCT.PackageIdentifier/Program.cs b/src/LCT.PackageIdentifier/Program.cs index 67a6d500..04037c52 100644 --- a/src/LCT.PackageIdentifier/Program.cs +++ b/src/LCT.PackageIdentifier/Program.cs @@ -26,6 +26,8 @@ using LCT.APICommunications.Model; using System.Linq; using System.Diagnostics.CodeAnalysis; +using Tommy; +using System.Collections.Generic; namespace LCT.PackageIdentifier @@ -55,7 +57,7 @@ static async Task Main(string[] args) ProjectReleases projectReleases = new ProjectReleases(); // do not change the order of getting ca tool information CatoolInfo caToolInformation = GetCatoolVersionFromProjectfile(); - Log4Net.CatoolCurrentDirectory = Directory.GetParent(caToolInformation.CatoolRunningLocation).FullName; + Log4Net.CatoolCurrentDirectory = System.IO.Directory.GetParent(caToolInformation.CatoolRunningLocation).FullName; string FolderPath = LogFolderInitialisation(appSettings); settingsManager.CheckRequiredArgsToRun(appSettings, "Identifer"); @@ -75,23 +77,18 @@ static async Task Main(string[] args) await ValidateAppsettingsFile(appSettings, projectReleases); string listOfInlude = DisplayInclude(appSettings); string listOfExclude = DisplayExclude(appSettings); - string listOfExcludeComponents = DisplayExcludeComponents(appSettings); - string listOfInternalRepoList = string.Empty; - if (appSettings.InternalRepoList != null) - { - listOfInternalRepoList = string.Join(",", appSettings.InternalRepoList?.ToList()); - } + string listOfExcludeComponents = DisplayExcludeComponents(appSettings); + string listOfInternalRepoList = GetInternalRepolist(appSettings); Logger.Logger.Log(null, Level.Notice, $"Input Parameters used in Package Identifier:\n\t" + $"CaToolVersion\t\t --> {caToolInformation.CatoolVersion}\n\t" + $"CaToolRunningPath\t --> {caToolInformation.CatoolRunningLocation}\n\t" + - $"PackageFilePath\t\t --> {appSettings.PackageFilePath}\n\t" + - $"BomFolderPath\t\t --> {appSettings.BomFolderPath}\n\t" + - $"SBOMTemplateFilePath\t --> {appSettings.CycloneDxSBomTemplatePath}\n\t" + - $"SW360Url\t\t --> {appSettings.SW360URL}\n\t" + - $"SW360AuthTokenType\t --> {appSettings.SW360AuthTokenType}\n\t" + - $"SW360ProjectName\t --> {appSettings.SW360ProjectName}\n\t" + - $"SW360ProjectID\t\t --> {appSettings.SW360ProjectID}\n\t" + + $"PackageFilePath\t\t --> {appSettings.Directory.InputFolder}\n\t" + + $"BomFolderPath\t\t --> {appSettings.Directory.OutputFolder}\n\t" + + $"SW360Url\t\t --> {appSettings.SW360.URL}\n\t" + + $"SW360AuthTokenType\t --> {appSettings.SW360.AuthTokenType}\n\t" + + $"SW360ProjectName\t --> {appSettings.SW360.ProjectName}\n\t" + + $"SW360ProjectID\t\t --> {appSettings.SW360.ProjectID}\n\t" + $"ProjectType\t\t --> {appSettings.ProjectType}\n\t" + $"LogFolderPath\t\t --> {Log4Net.CatoolLogPath}\n\t" + $"InternalRepoList\t --> {listOfInternalRepoList}\n\t" + @@ -134,10 +131,10 @@ private static IJFrogService GetJfrogService(CommonAppSettings appSettings) { ArtifactoryCredentials artifactoryUpload = new ArtifactoryCredentials() { - ApiKey = appSettings.ArtifactoryUploadApiKey + ApiKey = appSettings.Jfrog.Token, }; IJfrogAqlApiCommunication jfrogAqlApiCommunication = - new JfrogAqlApiCommunication(appSettings.JFrogApi, artifactoryUpload, appSettings.TimeOut); + new JfrogAqlApiCommunication(appSettings.Jfrog.URL, artifactoryUpload, appSettings.TimeOut); IJfrogAqlApiCommunicationFacade jFrogApiCommunicationFacade = new JfrogAqlApiCommunicationFacade(jfrogAqlApiCommunication); IJFrogService jFrogService = new JFrogService(jFrogApiCommunicationFacade); @@ -148,9 +145,9 @@ private static async Task ValidateAppsettingsFile(CommonAppSettings appSettings, { SW360ConnectionSettings sw360ConnectionSettings = new SW360ConnectionSettings() { - SW360URL = appSettings.SW360URL, - SW360AuthTokenType = appSettings.SW360AuthTokenType, - Sw360Token = appSettings.Sw360Token, + SW360URL = appSettings.SW360.URL, + SW360AuthTokenType = appSettings.SW360.AuthTokenType, + Sw360Token = appSettings.SW360.Token, IsTestMode = appSettings.IsTestMode, Timeout = appSettings.TimeOut }; @@ -191,10 +188,10 @@ private static string DisplayInclude(CommonAppSettings appSettings) } return totalString; - case "PYTHON": - if (appSettings.Python.Include != null) + case "POETRY": + if (appSettings.Poetry.Include != null) { - totalString = string.Join(",", appSettings.Python.Include?.ToList()); + totalString = string.Join(",", appSettings.Poetry.Include?.ToList()); } return totalString; case "CONAN": @@ -245,10 +242,10 @@ private static string DisplayExclude(CommonAppSettings appSettings) totalString = string.Join(",", appSettings.Debian.Exclude?.ToList()); } return totalString; - case "PYTHON": - if (appSettings.Python.Exclude != null) + case "POETRY": + if (appSettings.Poetry.Exclude != null) { - totalString = string.Join(",", appSettings.Python.Exclude?.ToList()); + totalString = string.Join(",", appSettings.Poetry.Exclude?.ToList()); } return totalString; case "CONAN": @@ -274,58 +271,44 @@ private static string DisplayExcludeComponents(CommonAppSettings appSettings) { string totalString = string.Empty; - switch (appSettings.ProjectType.ToUpperInvariant()) + if (appSettings.SW360.ExcludeComponents != null) { - case "NPM": - if (appSettings.Npm.ExcludedComponents != null) - { - totalString = string.Join(",", appSettings.Npm.ExcludedComponents?.ToList()); - } - return totalString; - case "NUGET": - if (appSettings.Nuget.ExcludedComponents != null) - { - totalString = string.Join(",", appSettings.Nuget.ExcludedComponents?.ToList()); - } - return totalString; - case "MAVEN": - if (appSettings.Maven.ExcludedComponents != null) - { - totalString = string.Join(",", appSettings.Maven.ExcludedComponents?.ToList()); - } - return totalString; - case "DEBIAN": - if (appSettings.Debian.ExcludedComponents != null) - { - totalString = string.Join(",", appSettings.Debian.ExcludedComponents?.ToList()); - } - - return totalString; - case "PYTHON": - if (appSettings.Python.ExcludedComponents != null) - { - totalString = string.Join(",", appSettings.Python.ExcludedComponents?.ToList()); - } - return totalString; - case "CONAN": - if (appSettings.Conan.ExcludedComponents != null) - { - totalString = string.Join(",", appSettings.Conan.ExcludedComponents?.ToList()); - } - return totalString; - case "ALPINE": - if (appSettings.Alpine.Include != null) - { - totalString = string.Join(",", appSettings.Alpine.Include?.ToList()); - } - return totalString; - default: - Logger.Error($"Invalid ProjectType - {appSettings.ProjectType}"); - break; + totalString = string.Join(",", appSettings.SW360.ExcludeComponents?.ToList()); } return totalString; } + private static string GetInternalRepolist(CommonAppSettings appSettings) + { + string listOfInternalRepoList = string.Empty; + + var repoMapping = new Dictionary>>(StringComparer.OrdinalIgnoreCase) + { + { "NPM", () => appSettings.Npm?.Artifactory.InternalRepos }, + { "NUGET", () => appSettings.Nuget?.Artifactory.InternalRepos }, + { "MAVEN", () => appSettings.Maven?.Artifactory.InternalRepos }, + { "DEBIAN", () => appSettings.Debian?.Artifactory.InternalRepos }, + { "POETRY", () => appSettings.Poetry?.Artifactory.InternalRepos }, + { "CONAN", () => appSettings.Conan?.Artifactory.InternalRepos }, + { "ALPINE", () => appSettings.Alpine?.Artifactory.InternalRepos } + }; + + if (repoMapping.TryGetValue(appSettings.ProjectType, out var getRepos)) + { + var repos = getRepos(); + if (repos != null) + { + listOfInternalRepoList = string.Join(",", repos); + } + } + else + { + Logger.Error($"Invalid ProjectType - {appSettings.ProjectType}"); + } + + return listOfInternalRepoList; + } + private static string LogFolderInitialisation(CommonAppSettings appSettings) { string FolderPath; diff --git a/src/LCT.PackageIdentifier/PythonProcessor.cs b/src/LCT.PackageIdentifier/PythonProcessor.cs index 0c966472..0d9d51d9 100644 --- a/src/LCT.PackageIdentifier/PythonProcessor.cs +++ b/src/LCT.PackageIdentifier/PythonProcessor.cs @@ -39,12 +39,12 @@ public PythonProcessor(ICycloneDXBomParser cycloneDXBomParser) public Bom ParsePackageFile(CommonAppSettings appSettings) { - List configFiles = FolderScanner.FileScanner(appSettings.PackageFilePath, appSettings.Python); + List configFiles = FolderScanner.FileScanner(appSettings.Directory.InputFolder, appSettings.Poetry); List listofComponents = new List(); Bom bom = new Bom(); List listComponentForBOM; List dependencies = new List(); - + Bom templateDetails = new Bom(); foreach (string config in configFiles) { if (config.ToLower().EndsWith("poetry.lock")) @@ -55,15 +55,14 @@ public Bom ParsePackageFile(CommonAppSettings appSettings) { listofComponents.AddRange(ExtractDetailsFromJson(config, appSettings, ref dependencies)); } + else if (config.EndsWith(FileConstant.SBOMTemplateFileExtension)) + { + templateDetails = CycloneDXBomParser.ExtractSBOMDetailsFromTemplate(_cycloneDXBomParser.ParseCycloneDXBom(config)); + CycloneDXBomParser.CheckValidComponentsForProjectType(templateDetails.Components, appSettings.ProjectType); + } } - - Bom templateDetails = new Bom(); - if (File.Exists(appSettings.CycloneDxSBomTemplatePath) - && appSettings.CycloneDxSBomTemplatePath.EndsWith(FileConstant.SBOMTemplateFileExtension)) - { - templateDetails = CycloneDXBomParser.ExtractSBOMDetailsFromTemplate(_cycloneDXBomParser.ParseCycloneDXBom(appSettings.CycloneDxSBomTemplatePath)); - CycloneDXBomParser.CheckValidComponentsForProjectType(templateDetails.Components, appSettings.ProjectType); - } + + int initialCount = listofComponents.Count; GetDistinctComponentList(ref listofComponents); @@ -129,7 +128,7 @@ private static List GetPackagesFromTOMLFile(string filePath, List { Name = node["name"].ToString(), Version = node["version"].ToString(), - PurlID = Dataconstant.PurlCheck()["PYTHON"] + "/" + node["name"].ToString() + "@" + node["version"].ToString(), + PurlID = Dataconstant.PurlCheck()["POETRY"] + "/" + node["name"].ToString() + "@" + node["version"].ToString(), // By Default Tommy.TomlLazy is coming instead of Null or empty Isdevdependent = (node["category"].ToString() != "main" && node["category"].ToString() != "Tommy.TomlLazy"), FoundType = Dataconstant.Discovered @@ -179,11 +178,11 @@ private static string FormRefFromNodeDetails(KeyValuePair valu if (string.IsNullOrEmpty(value)) { - return Dataconstant.PurlCheck()["PYTHON"] + "/" + valuePair.Key + "@" + "*"; + return Dataconstant.PurlCheck()["POETRY"] + "/" + valuePair.Key + "@" + "*"; } else { - return Dataconstant.PurlCheck()["PYTHON"] + "/" + valuePair.Key + "@" + value; + return Dataconstant.PurlCheck()["POETRY"] + "/" + valuePair.Key + "@" + value; } } @@ -203,7 +202,7 @@ private List ExtractDetailsFromJson(string filePath, CommonAppSet PurlID = componentsInfo.Purl, }; - if (!string.IsNullOrEmpty(componentsInfo.Name) && !string.IsNullOrEmpty(componentsInfo.Version) && !string.IsNullOrEmpty(componentsInfo.Purl) && componentsInfo.Purl.Contains(Dataconstant.PurlCheck()["PYTHON"])) + if (!string.IsNullOrEmpty(componentsInfo.Name) && !string.IsNullOrEmpty(componentsInfo.Version) && !string.IsNullOrEmpty(componentsInfo.Purl) && componentsInfo.Purl.Contains(Dataconstant.PurlCheck()["POETRY"])) { BomCreator.bomKpiData.DebianComponents++; PythonPackages.Add(package); @@ -238,7 +237,7 @@ private static string GetReleaseExternalId(string name, string version) version = WebUtility.UrlEncode(version); version = version.Replace("%3A", ":"); - return $"{Dataconstant.PurlCheck()["PYTHON"]}{Dataconstant.ForwardSlash}{name}@{version}"; + return $"{Dataconstant.PurlCheck()["POETRY"]}{Dataconstant.ForwardSlash}{name}@{version}"; } private static List FormComponentReleaseExternalID(List listOfComponents) @@ -302,9 +301,9 @@ private static Bom RemoveExcludedComponents(CommonAppSettings appSettings, List componentForBOM = cycloneDXBOM.Components.ToList(); List dependenciesForBOM = cycloneDXBOM.Dependencies?.ToList() ?? new List(); int noOfExcludedComponents = 0; - if (appSettings.Python.ExcludedComponents != null) + if (appSettings.SW360.ExcludeComponents != null) { - componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.Python.ExcludedComponents, ref noOfExcludedComponents); + componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.SW360.ExcludeComponents, ref noOfExcludedComponents); dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM); BomCreator.bomKpiData.ComponentsExcluded += noOfExcludedComponents; @@ -318,7 +317,7 @@ public async Task IdentificationOfInternalComponents(Co { // get the component list from Jfrog for given repo List aqlResultList = - await bomhelper.GetPypiListOfComponentsFromRepo(appSettings.InternalRepoList, jFrogService); + await bomhelper.GetPypiListOfComponentsFromRepo(appSettings.Poetry.Artifactory.InternalRepos, jFrogService); // find the components in the list of internal components List internalComponents = new List(); @@ -383,7 +382,11 @@ private static string GetJfrogNameOfPypiComponent(string name, string version, L public async Task> GetJfrogRepoDetailsOfAComponent(List componentsForBOM, CommonAppSettings appSettings, IJFrogService jFrogService, IBomHelper bomhelper) { // get the component list from Jfrog for given repo + internal repo - string[] repoList = appSettings.InternalRepoList.Concat(appSettings.Python?.JfrogPythonRepoList).ToArray(); + string[] repoList = (appSettings.Poetry?.Artifactory.InternalRepos ?? Array.Empty()) + .Concat(appSettings.Poetry?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Poetry?.Artifactory.RemoteRepos ?? Array.Empty()) + .Concat(appSettings.Poetry?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) + .ToArray(); List aqlResultList = await bomhelper.GetPypiListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); @@ -400,15 +403,22 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List FileScanner(string rootPath, Config config) throw new ArgumentException($"Invalid value for the {nameof(rootPath)} - {rootPath}"); } - if (!Directory.Exists(rootPath)) + if (!System.IO.Directory.Exists(rootPath)) { Logger.Error("Root path does not exist.Provide a valid path"); throw new DirectoryNotFoundException($"The {nameof(rootPath)} is not found at this path" + @@ -52,7 +52,7 @@ public static List FileScanner(string rootPath, Config config) Logger.Logger.Log(null, Level.Notice, $"Directory Location: Packages are read from the below locations:", null); foreach (string includePattern in config.Include) { - foundConfigFiles = Directory.GetFiles(rootPath, includePattern, SearchOption.AllDirectories); + foundConfigFiles = System.IO.Directory.GetFiles(rootPath, includePattern, SearchOption.AllDirectories); if (foundConfigFiles != null && foundConfigFiles.Length > 0) { diff --git a/src/LCT.Services/Sw360Service.cs b/src/LCT.Services/Sw360Service.cs index 3a03999f..c25b1b39 100644 --- a/src/LCT.Services/Sw360Service.cs +++ b/src/LCT.Services/Sw360Service.cs @@ -231,7 +231,7 @@ public string DownloadReleaseSourceCode(string fileName, string version, Sw360At { string filePath = $"{Path.GetTempPath()}ClearingTool\\DownloadedFiles/{attachmentHash.SW360AttachmentName}"; fileName = $"{filePath}"; - Directory.CreateDirectory(Path.GetDirectoryName(filePath)); + System.IO.Directory.CreateDirectory(Path.GetDirectoryName(filePath)); if (File.Exists(filePath)) { diff --git a/src/SW360IntegrationTest/Conan/PackageIdentifierInitialConan.cs b/src/SW360IntegrationTest/Conan/PackageIdentifierInitialConan.cs index 9b95d40d..56cafb21 100644 --- a/src/SW360IntegrationTest/Conan/PackageIdentifierInitialConan.cs +++ b/src/SW360IntegrationTest/Conan/PackageIdentifierInitialConan.cs @@ -42,7 +42,8 @@ public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess() TestConstant.SW360ProjectName, testParameters.SW360ProjectName, TestConstant.JFrogApiURL, testParameters.JfrogApi, TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey, - TestConstant.ProjectType,"CONAN", + TestConstant.JfrogConanInternalRepo,"Conan.test", + TestConstant.ProjectType,"Conan", TestConstant.Mode,""}), "Test to run Package Identifier EXE execution"); } diff --git a/src/SW360IntegrationTest/Debian/PackageIdentifierInitialDebian.cs b/src/SW360IntegrationTest/Debian/PackageIdentifierInitialDebian.cs index 12a23580..8e592c7d 100644 --- a/src/SW360IntegrationTest/Debian/PackageIdentifierInitialDebian.cs +++ b/src/SW360IntegrationTest/Debian/PackageIdentifierInitialDebian.cs @@ -52,7 +52,8 @@ public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess() TestConstant.SW360ProjectName, testParameters.SW360ProjectName, TestConstant.JFrogApiURL, testParameters.JfrogApi, TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey, - TestConstant.ProjectType,"DEBIAN", + TestConstant.JfrogDebianInternalRepo,"Debian.test", + TestConstant.ProjectType,"Debian", TestConstant.Mode,""}), "Test to run Package Identifier EXE execution"); } diff --git a/src/SW360IntegrationTest/Maven/PackageIdentifierInitialMaven.cs b/src/SW360IntegrationTest/Maven/PackageIdentifierInitialMaven.cs index dd23bc01..b64d712c 100644 --- a/src/SW360IntegrationTest/Maven/PackageIdentifierInitialMaven.cs +++ b/src/SW360IntegrationTest/Maven/PackageIdentifierInitialMaven.cs @@ -50,7 +50,8 @@ public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess() TestConstant.SW360ProjectName, testParameters.SW360ProjectName, TestConstant.JFrogApiURL, testParameters.JfrogApi, TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey, - TestConstant.ProjectType,"MAVEN", + TestConstant.JfrogMavenInternalRepo,"Maven.test", + TestConstant.ProjectType,"Maven", TestConstant.Mode,""}), "Test to run Package Identifier EXE execution"); } diff --git a/src/SW360IntegrationTest/NPM/PackageIdentifierInitial.cs b/src/SW360IntegrationTest/NPM/PackageIdentifierInitial.cs index d632d6d6..f18820b1 100644 --- a/src/SW360IntegrationTest/NPM/PackageIdentifierInitial.cs +++ b/src/SW360IntegrationTest/NPM/PackageIdentifierInitial.cs @@ -50,7 +50,8 @@ public void TestBOMCreatorexe() TestConstant.SW360ProjectName, testParameters.SW360ProjectName, TestConstant.JFrogApiURL, testParameters.JfrogApi, TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey, - TestConstant.ProjectType, "NPM", + TestConstant.JfrogNpmInternalRepo,"Npm.test", + TestConstant.ProjectType, "Npm", TestConstant.Mode,""}), "Test to run Package Identifier EXE execution"); } diff --git a/src/SW360IntegrationTest/Nuget/NugetTemplate/ComponentCreatorNugetTemplate.cs b/src/SW360IntegrationTest/Nuget/NugetTemplate/ComponentCreatorNugetTemplate.cs index 2676c74f..5851b94a 100644 --- a/src/SW360IntegrationTest/Nuget/NugetTemplate/ComponentCreatorNugetTemplate.cs +++ b/src/SW360IntegrationTest/Nuget/NugetTemplate/ComponentCreatorNugetTemplate.cs @@ -48,7 +48,6 @@ public void Setup() TestConstant.JFrogApiURL, testParameters.JfrogApi, TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey, TestConstant.ProjectType,"NUGET", - TestConstant.CycloneDxSBomTemplatePath,sbomTemplatePath, TestConstant.Mode,""}); } } diff --git a/src/SW360IntegrationTest/Nuget/NugetTemplate/PackageIdentifierNugetTemplate.cs b/src/SW360IntegrationTest/Nuget/NugetTemplate/PackageIdentifierNugetTemplate.cs index a89b3772..445cd9b8 100644 --- a/src/SW360IntegrationTest/Nuget/NugetTemplate/PackageIdentifierNugetTemplate.cs +++ b/src/SW360IntegrationTest/Nuget/NugetTemplate/PackageIdentifierNugetTemplate.cs @@ -52,7 +52,6 @@ public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess() TestConstant.JFrogApiURL, testParameters.JfrogApi, TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey, TestConstant.ProjectType,"NUGET", - TestConstant.CycloneDxSBomTemplatePath,sbomTemplatePath, TestConstant.Mode,""}), "Test to run Package Identifier EXE execution"); } diff --git a/src/SW360IntegrationTest/Nuget/PackageIdentifierInitialNuget.cs b/src/SW360IntegrationTest/Nuget/PackageIdentifierInitialNuget.cs index 32af3cc7..bdec145d 100644 --- a/src/SW360IntegrationTest/Nuget/PackageIdentifierInitialNuget.cs +++ b/src/SW360IntegrationTest/Nuget/PackageIdentifierInitialNuget.cs @@ -50,7 +50,8 @@ public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess() TestConstant.SW360ProjectName, testParameters.SW360ProjectName, TestConstant.JFrogApiURL, testParameters.JfrogApi, TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey, - TestConstant.ProjectType,"NUGET", + TestConstant.JfrogNugetInternalRepo,"Nuget.test", + TestConstant.ProjectType,"Nuget", TestConstant.Mode,""}), "Test to run Package Identifier EXE execution"); } diff --git a/src/SW360IntegrationTest/Python/PackageIdentifierInitialPython.cs b/src/SW360IntegrationTest/Python/PackageIdentifierInitialPython.cs index 17b9d6e1..8aa5c467 100644 --- a/src/SW360IntegrationTest/Python/PackageIdentifierInitialPython.cs +++ b/src/SW360IntegrationTest/Python/PackageIdentifierInitialPython.cs @@ -50,7 +50,8 @@ public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess() TestConstant.SW360ProjectName, testParameters.SW360ProjectName, TestConstant.JFrogApiURL, testParameters.JfrogApi, TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey, - TestConstant.ProjectType,"PYTHON", + TestConstant.JfrogPoetryInternalRepo,"Pypi.test", + TestConstant.ProjectType,"Poetry", TestConstant.Mode,""}), "Test to run Package Identifier EXE execution"); } diff --git a/src/TestUtilities/TestConstant.cs b/src/TestUtilities/TestConstant.cs index 7f1a49da..cd341091 100644 --- a/src/TestUtilities/TestConstant.cs +++ b/src/TestUtilities/TestConstant.cs @@ -26,46 +26,51 @@ public static class TestConstant public const string componentNameUrl = "?name="; - public const string PackageFilePath = "--packageFilePath"; - public const string BomFolderPath = "--bomFolderPath"; - public const string Sw360Token = "--sw360Token"; - public const string BomFilePath = "--bomFilePath"; - public const string SW360URL = "--sW360URL"; - public const string FossologyURL = "--fossologyURL"; - public const string SW360AuthTokenType = "--sW360AuthTokenType"; - public const string SW360ProjectName = "--sW360ProjectName"; - public const string SW360ProjectID = "--sW360ProjectID"; - public const string ProjectType = "--projectType"; - public const string RemoveDevDependency = "--removeDevDependency"; + public const string PackageFilePath = "--Directory:InputFolder"; + public const string BomFolderPath = "--Directory:OutputFolder"; + public const string Sw360Token = "--SW360:Token"; + public const string BomFilePath = "--Directory:BomFilePath"; + public const string SW360URL = "--SW360:URL"; + public const string FossologyURL = "--Fossology:URL"; + public const string SW360AuthTokenType = "--SW360:AuthTokenType"; + public const string SW360ProjectName = "--SW360:ProjectName"; + public const string SW360ProjectID = "--SW360:ProjectID"; + public const string ProjectType = "--ProjectType"; + public const string RemoveDevDependency = "--SW360:IgnoreDevDependency"; public const string Mode = "--Mode"; public const string JFrog_API_Header = "X-JFrog-Art-Api"; public const string Email = "Email"; + public const string ArtifactoryKey = "--Jfrog:Token"; public const string ArtifactoryUser = "--artifactoryuploaduser"; - public const string ArtifactoryKey = "--artifactoryuploadapikey"; - public const string JfrogNpmThirdPartyDestRepoName = "--npm:JfrogThirdPartyDestRepoName "; - public const string JfrogNpmInternalDestRepoName = "--npm:JfrogInternalDestRepoName "; - public const string JfrogNpmDevDestRepoName = "--npm:JfrogDevDestRepoName "; + public const string JfrogNpmThirdPartyDestRepoName = "--Npm:Artifactory:ThirdPartyRepos:0:Name"; + public const string JfrogNpmInternalRepo = "--Npm:Artifactory:InternalRepos:0"; + public const string JfrogNpmInternalDestRepoName = "--Npm:ReleaseRepo "; + public const string JfrogNpmDevDestRepoName = "--Npm:DevDepRepo "; - public const string JfrogMavenThirdPartyDestRepoName = "--maven:JfrogThirdPartyDestRepoName "; - public const string JfrogMavenInternalDestRepoName = "--maven:JfrogInternalDestRepoName "; - public const string JfrogMavenDevDestRepoName = "--maven:JfrogDevDestRepoName "; + public const string JfrogMavenThirdPartyDestRepoName = "--Maven:Artifactory:ThirdPartyRepos:0:Name"; + public const string JfrogMavenInternalRepo = "--Maven:Artifactory:InternalRepos:0"; + public const string JfrogMavenInternalDestRepoName = "--Maven:ReleaseRepo "; + public const string JfrogMavenDevDestRepoName = "--Maven:DevDepRepo "; - public const string JfrogNugetThirdPartyDestRepoName = "--nuget:JfrogThirdPartyDestRepoName "; - public const string JfrogNugetInternalDestRepoName = "--nuget:JfrogInternalDestRepoName "; - public const string JfrogNugetDevDestRepoName = "--nuget:JfrogDevDestRepoName "; + public const string JfrogNugetThirdPartyDestRepoName = "--Nuget:Artifactory:ThirdPartyRepos:0:Name"; + public const string JfrogNugetInternalRepo = "--Nuget:Artifactory:InternalRepos:0"; + public const string JfrogNugetInternalDestRepoName = "--Nuget:ReleaseRepo "; + public const string JfrogNugetDevDestRepoName = "--Nuget:DevDepRepo "; - public const string JfrogPythonThirdPartyDestRepoName = "--python:JfrogThirdPartyDestRepoName "; - public const string JfrogPythonInternalDestRepoName = "--python:JfrogInternalDestRepoName "; - public const string JfrogPythonDevDestRepoName = "--python:JfrogDevDestRepoName "; + public const string JfrogPythonThirdPartyDestRepoName = "--Poetry:Artifactory:ThirdPartyRepos:0:Name"; + public const string JfrogPoetryInternalRepo = "--Poetry:Artifactory:InternalRepos:0"; + public const string JfrogPythonInternalDestRepoName = "--Poetry:ReleaseRepo "; + public const string JfrogPythonDevDestRepoName = "--Poetry:DevDepRepo "; - public const string JfrogConanThirdPartyDestRepoName = "--conan:JfrogThirdPartyDestRepoName "; - public const string JfrogConanInternalDestRepoName = "--conan:JfrogInternalDestRepoName "; - public const string JfrogConanDevDestRepoName = "--conan:JfrogDevDestRepoName "; + public const string JfrogConanThirdPartyDestRepoName = "--Conan:Artifactory:ThirdPartyRepos:0:Name"; + public const string JfrogConanInternalRepo = "--Conan:Artifactory:InternalRepos:0"; + public const string JfrogConanInternalDestRepoName = "--Conan:ReleaseRepo "; + public const string JfrogConanDevDestRepoName = "--Conan:DevDepRepo "; + public const string JfrogDebianInternalRepo = "--Debian:Artifactory:InternalRepos:0"; public const string NuspecMode = "--NuspecMode"; - public const string JFrogApiURL = "--JFrogApi"; - public const string CycloneDxSBomTemplatePath = "--cycloneDxSBomTemplatePath"; + public const string JFrogApiURL = "--JFrog:URL"; public const string Release = "--release"; } } diff --git a/src/TestUtilities/TestParam.cs b/src/TestUtilities/TestParam.cs index 05648096..f72acad8 100644 --- a/src/TestUtilities/TestParam.cs +++ b/src/TestUtilities/TestParam.cs @@ -38,7 +38,7 @@ public TestParam() FossUrl = s_Config["FossologyURL"]; SW360ProjectName = s_Config["SW360ProjectName"]; SW360ProjectID = s_Config["SW360ProjectID"]; - ProjectType = "NPM"; + ProjectType = "Conan"; RemoveDevDependency = s_Config["RemoveDevDependency"]; ArtifactoryUploadUser = s_Config["ArtifactoryUploadUser"]; ArtifactoryUploadApiKey = s_Config["ArtifactoryUploadApiKey"]; From 9754855642ec7a8563afb9ff41b8bb6516935653 Mon Sep 17 00:00:00 2001 From: Chalapala RaghavendraReddy Date: Sun, 12 Jan 2025 08:45:52 +0530 Subject: [PATCH 02/10] 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 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(); 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 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(); 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 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(); 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; From aa0a194506dac59405da0b25ccebc38159867a9a Mon Sep 17 00:00:00 2001 From: Chalapala RaghavendraReddy Date: Sun, 12 Jan 2025 23:18:02 +0530 Subject: [PATCH 03/10] removed unused parameters --- src/LCT.Common/appSettings.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/LCT.Common/appSettings.json b/src/LCT.Common/appSettings.json index 596792f5..70ac5a75 100644 --- a/src/LCT.Common/appSettings.json +++ b/src/LCT.Common/appSettings.json @@ -24,9 +24,7 @@ }, "Directory": { "InputFolder": "/PathToInputDirectory", //Input File path. For Docker run set as /mnt/Input - "OutputFolder": "/PathToOutputDirectory", //Output Bom Folder path. For Docker run set as /mnt/Output - "BomFilePath": "", //For multiple project type - "CycloneDxSBomTemplatePath": "" //CycloneDxBomFilePath: For Providing Customer maintained SBOM as input.Can be used along with Packagefilepath or individually + "OutputFolder": "/PathToOutputDirectory" //Output Bom Folder path. For Docker run set as /mnt/Output }, "Jfrog": { "URL": "", From 74b15a2d7b9efedf3407bf1546aea101bf228db6 Mon Sep 17 00:00:00 2001 From: Chalapala RaghavendraReddy Date: Mon, 13 Jan 2025 09:44:44 +0530 Subject: [PATCH 04/10] updated code --- src/LCT.PackageIdentifier/ConanProcessor.cs | 9 ++------- src/LCT.PackageIdentifier/NpmProcessor.cs | 8 ++------ src/LCT.PackageIdentifier/NugetProcessor.cs | 8 ++------ 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/LCT.PackageIdentifier/ConanProcessor.cs b/src/LCT.PackageIdentifier/ConanProcessor.cs index 51b78a42..2f2a1d73 100644 --- a/src/LCT.PackageIdentifier/ConanProcessor.cs +++ b/src/LCT.PackageIdentifier/ConanProcessor.cs @@ -218,16 +218,11 @@ public static bool IsDevDependency(ConanPackage component, List buildNod private static void CreateFileForMultipleVersions(List componentsWithMultipleVersions, CommonAppSettings appSettings) { 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)); + IFileOperations fileOperations = new FileOperations(); string bomFullPath= $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_Bom.cdx.json"; string filename = $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}"; - if (fileExists || (!File.Exists(filename))) + if (!File.Exists(filename)) { multipleVersions.Conan = new List(); foreach (var conanPackage in componentsWithMultipleVersions) diff --git a/src/LCT.PackageIdentifier/NpmProcessor.cs b/src/LCT.PackageIdentifier/NpmProcessor.cs index 0aa8798a..e99e4d6d 100644 --- a/src/LCT.PackageIdentifier/NpmProcessor.cs +++ b/src/LCT.PackageIdentifier/NpmProcessor.cs @@ -153,14 +153,10 @@ private static void CreateFileForMultipleVersions(List 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 (fileExists || (!File.Exists(filename))) + if (!File.Exists(filename)) { multipleVersions.Npm = new List(); foreach (var npmpackage in componentsWithMultipleVersions) diff --git a/src/LCT.PackageIdentifier/NugetProcessor.cs b/src/LCT.PackageIdentifier/NugetProcessor.cs index 90ff1a1b..51127a92 100644 --- a/src/LCT.PackageIdentifier/NugetProcessor.cs +++ b/src/LCT.PackageIdentifier/NugetProcessor.cs @@ -542,14 +542,10 @@ private static void CreateFileForMultipleVersions(List 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 (fileExists || (!File.Exists(filename))) + if (!File.Exists(filename)) { multipleVersions.Nuget = new List(); foreach (var nugetPackage in componentsWithMultipleVersions) From 07471ea305a7b7f1864b500391c59ff8b1c7bcff Mon Sep 17 00:00:00 2001 From: Chalapala RaghavendraReddy Date: Mon, 13 Jan 2025 09:54:41 +0530 Subject: [PATCH 05/10] Updated changes --- src/LCT.Common/SettingsManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LCT.Common/SettingsManager.cs b/src/LCT.Common/SettingsManager.cs index 95415ff6..8c80c726 100644 --- a/src/LCT.Common/SettingsManager.cs +++ b/src/LCT.Common/SettingsManager.cs @@ -183,7 +183,7 @@ private static void CheckForMissingParameter(CommonAppSettings appSettings, Prop break; } - property = currentObject.GetType().GetProperty(part); + property = currentObject.GetType().GetProperty(part, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); currentObject = property?.GetValue(currentObject); } From c28e0b5213e362c298a8de3af23fdad578bcbeb4 Mon Sep 17 00:00:00 2001 From: Chalapala RaghavendraReddy Date: Wed, 15 Jan 2025 10:02:37 +0530 Subject: [PATCH 06/10] updated code --- src/LCT.PackageIdentifier.UTest/SBomTemplateTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LCT.PackageIdentifier.UTest/SBomTemplateTests.cs b/src/LCT.PackageIdentifier.UTest/SBomTemplateTests.cs index 07c308b3..4a71de7a 100644 --- a/src/LCT.PackageIdentifier.UTest/SBomTemplateTests.cs +++ b/src/LCT.PackageIdentifier.UTest/SBomTemplateTests.cs @@ -139,7 +139,7 @@ public void AddComponentDetails_InputTemplateDetails_ReturnsTemplateWithDetailsu SbomTemplate.AddComponentDetails(componentsForBOM, templateDetails); //Assert - Assert.That(BomCreator.bomKpiData.ComponentsUpdatedFromSBOMTemplateFile, Is.EqualTo(1)); + Assert.That(BomCreator.bomKpiData.ComponentsUpdatedFromSBOMTemplateFile, Is.EqualTo(3)); } } } From d3f74a6c0ba647f30cdfb8b74e7c89d0951d4b47 Mon Sep 17 00:00:00 2001 From: Chalapala RaghavendraReddy Date: Fri, 17 Jan 2025 12:06:17 +0530 Subject: [PATCH 07/10] Updated code changes --- src/LCT.Common.UTests/CommonHelperTest.cs | 5 +- src/LCT.Common.UTests/FolderActionTest.cs | 4 +- src/LCT.Common/CommonAppSettings.cs | 24 ++-- src/LCT.Common/CommonHelper.cs | 128 ++++++++++++++---- .../BomHelperUnitTests.cs | 4 +- .../ConanParserTests.cs | 2 + .../MavenParserTests.cs | 2 + .../NpmProcessorUTest.cs | 2 + .../NugetParserTests.cs | 6 + .../PythonParserTests.cs | 2 + src/LCT.PackageIdentifier/ConanProcessor.cs | 8 +- src/LCT.PackageIdentifier/DebianProcessor.cs | 6 +- src/LCT.PackageIdentifier/MavenProcessor.cs | 6 +- src/LCT.PackageIdentifier/NpmProcessor.cs | 6 +- src/LCT.PackageIdentifier/NugetProcessor.cs | 6 +- src/LCT.PackageIdentifier/PythonProcessor.cs | 6 +- .../Conan/PackageIdentifierInitialConan.cs | 2 +- .../Debian/PackageIdentifierInitialDebian.cs | 2 +- .../Maven/PackageIdentifierInitialMaven.cs | 2 +- .../NPM/PackageIdentifierInitial.cs | 2 +- .../Nuget/PackageIdentifierInitialNuget.cs | 2 +- .../Python/PackageIdentifierInitialPython.cs | 2 +- src/TestUtilities/TestParam.cs | 2 +- 23 files changed, 150 insertions(+), 81 deletions(-) diff --git a/src/LCT.Common.UTests/CommonHelperTest.cs b/src/LCT.Common.UTests/CommonHelperTest.cs index 2c8e68ea..8cd6ed21 100644 --- a/src/LCT.Common.UTests/CommonHelperTest.cs +++ b/src/LCT.Common.UTests/CommonHelperTest.cs @@ -59,17 +59,20 @@ public void RemoveMultipleExcludedComponents_ReturnSuccess() ComponentsForBom.Add(new Component() { Name = "Debian", Version = "3.1.2" }); ComponentsForBom.Add(new Component() { Name = "Newton", Version = "3.1.3" }); ComponentsForBom.Add(new Component() { Name = "Log4t", Version = "3.1.4" }); + ComponentsForBom.Add(new Component() { Name = "Log4t", Version = "3.1.5",Purl= "pkg:npm/foobar@12.3.1" }); + ComponentsForBom.Add(new Component() { Name = "Log4t", Version = "3.1.5", Purl = "pkg:npm/foobar@12.3.2" }); int noOfExcludedComponents = 0; List list = new List(); list.Add("Debian:*"); list.Add("Newton:3.1.3"); + list.Add("pkg:npm/foobar@12.3.1"); //Act CommonHelper.RemoveExcludedComponents(ComponentsForBom, list, ref noOfExcludedComponents); //Assert - Assert.That(noOfExcludedComponents, Is.EqualTo(4), "Returns the count of excluded components"); + Assert.That(noOfExcludedComponents, Is.EqualTo(5), "Returns the count of excluded components"); } diff --git a/src/LCT.Common.UTests/FolderActionTest.cs b/src/LCT.Common.UTests/FolderActionTest.cs index 9bebfe0e..2ed870af 100644 --- a/src/LCT.Common.UTests/FolderActionTest.cs +++ b/src/LCT.Common.UTests/FolderActionTest.cs @@ -74,8 +74,8 @@ public void CopyToTargetDirectory_PassingDirsWithFiles_ReturnSuccess() { //Arrange string sourcePath = $"{Path.GetTempPath()}\\SampleFolder"; - Directory.CreateDirectory(sourcePath); - Directory.CreateDirectory(sourcePath +"\\SampleSubFolder"); + System.IO.Directory.CreateDirectory(sourcePath); + System.IO.Directory.CreateDirectory(sourcePath +"\\SampleSubFolder"); File.WriteAllText(sourcePath + "\\Sample.txt", ""); string targetPath = $"{Path.GetTempPath()}/targetPath/"; var folderAction = new FolderAction(); diff --git a/src/LCT.Common/CommonAppSettings.cs b/src/LCT.Common/CommonAppSettings.cs index fd97f43f..efa2f639 100644 --- a/src/LCT.Common/CommonAppSettings.cs +++ b/src/LCT.Common/CommonAppSettings.cs @@ -21,7 +21,7 @@ namespace LCT.Common public class CommonAppSettings { private readonly IFolderAction folderAction; - private readonly IFileOperations _fileOperations; + private readonly IFileOperations fileOperations; public static string PackageUrlApi { get; set; } = $"https://www.nuget.org/api/v2/package/"; public static string SourceURLNugetApi { get; set; } = $"https://api.nuget.org/v3-flatcontainer/"; @@ -37,18 +37,18 @@ public class CommonAppSettings public CommonAppSettings() { folderAction = new FolderAction(); - _fileOperations = new FileOperations(); - Directory = new Directory(folderAction, _fileOperations); + fileOperations = new FileOperations(); + Directory = new Directory(folderAction, fileOperations); } - public CommonAppSettings(IFolderAction iFolderAction, IFileOperations fileOperations) + public CommonAppSettings(IFolderAction iFolderAction, IFileOperations ifileOperations) { folderAction = iFolderAction; - _fileOperations = fileOperations; - Directory = new Directory(folderAction, _fileOperations); + fileOperations = ifileOperations; + Directory = new Directory(folderAction, fileOperations); } - public int TimeOut { get; set; } = 400; + public int TimeOut { get; set; } = 200; public string ProjectType { get @@ -211,14 +211,14 @@ public string Token public class Directory { private readonly IFolderAction folderAction; - private readonly IFileOperations _fileOperations; + private readonly IFileOperations fileOperations; private string m_InputFolder; private string m_OutputFolder; public Directory(IFolderAction folderAction, IFileOperations fileOperations) { this.folderAction = folderAction; - this._fileOperations = fileOperations; + this.fileOperations = fileOperations; } public string InputFolder { @@ -234,6 +234,12 @@ public string InputFolder folderAction.ValidateFolderPath(value); m_InputFolder = value; } + else if (AppDomain.CurrentDomain.FriendlyName.Contains("SW360PackageCreator") || + AppDomain.CurrentDomain.FriendlyName.Contains("ArtifactoryUploader")) + { + fileOperations.ValidateFilePath(value); + m_InputFolder = value; + } } } diff --git a/src/LCT.Common/CommonHelper.cs b/src/LCT.Common/CommonHelper.cs index c2534772..ed5e0b2f 100644 --- a/src/LCT.Common/CommonHelper.cs +++ b/src/LCT.Common/CommonHelper.cs @@ -43,35 +43,8 @@ public static List RemoveExcludedComponents(List Component List ExcludedComponentsFromPurl = ExcludedComponents?.Where(ec => ec.StartsWith("pkg:")).ToList(); List otherExcludedComponents = ExcludedComponents?.Where(ec => !ec.StartsWith("pkg:")).ToList(); - foreach (string excludedComponent in ExcludedComponentsFromPurl) - { - foreach (var component in ComponentList) - { - if (component.Purl != null && component.Purl.Equals(excludedComponent, StringComparison.OrdinalIgnoreCase)) - { - noOfExcludedComponents++; - ExcludedList.Add(component); - } - } - } - foreach (string excludedComponent in otherExcludedComponents) - { - string[] excludedcomponent = excludedComponent.ToLower().Split(':'); - foreach (var component in ComponentList) - { - string name = component.Name; - if (!string.IsNullOrEmpty(component.Group) && (component.Group != component.Name)) - { - name = $"{component.Group}/{component.Name}"; - } - if (excludedcomponent.Length > 0 && (Regex.IsMatch(name.ToLowerInvariant(), WildcardToRegex(excludedcomponent[0].ToLowerInvariant()))) && - (component.Version.ToLowerInvariant().Contains(excludedcomponent[1].ToLowerInvariant()) || excludedcomponent[1].ToLowerInvariant() == "*")) - { - noOfExcludedComponents++; - ExcludedList.Add(component); - } - } - } + ExcludedList.AddRange(RemoveExcludedComponentsFromPurl(ComponentList, ExcludedComponentsFromPurl, ref noOfExcludedComponents)); + ExcludedList.AddRange(RemoveOtherExcludedComponents(ComponentList, otherExcludedComponents, ref noOfExcludedComponents)); ComponentList.RemoveAll(item => ExcludedList.Contains(item)); return ComponentList; } @@ -302,6 +275,59 @@ public static void PublishFilesToArtifact() artifactPublisher.UploadLogs(); artifactPublisher.UploadBom(); } + public static string[] GetRepoList(CommonAppSettings appSettings) + { + string[] repoList = null; + + if (appSettings.ProjectType.Equals("CONAN", StringComparison.InvariantCultureIgnoreCase)) + { + repoList = (appSettings.Conan?.Artifactory.InternalRepos ?? Array.Empty()) + .Concat(appSettings.Conan?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Conan?.Artifactory.RemoteRepos ?? Array.Empty()) + .Concat(appSettings.Conan?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) + .ToArray(); + }else if (appSettings.ProjectType.Equals("NPM", StringComparison.InvariantCultureIgnoreCase)) + { + repoList = (appSettings.Npm?.Artifactory.InternalRepos ?? Array.Empty()) + .Concat(appSettings.Npm?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Npm?.Artifactory.RemoteRepos ?? Array.Empty()) + .Concat(appSettings.Npm?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) + .ToArray(); + } + else if (appSettings.ProjectType.Equals("NUGET", StringComparison.InvariantCultureIgnoreCase)) + { + repoList = (appSettings.Nuget?.Artifactory.InternalRepos ?? Array.Empty()) + .Concat(appSettings.Nuget?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Nuget?.Artifactory.RemoteRepos ?? Array.Empty()) + .Concat(appSettings.Nuget?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) + .ToArray(); + } + else if (appSettings.ProjectType.Equals("POETRY", StringComparison.InvariantCultureIgnoreCase)) + { + repoList = (appSettings.Poetry?.Artifactory.InternalRepos ?? Array.Empty()) + .Concat(appSettings.Poetry?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Poetry?.Artifactory.RemoteRepos ?? Array.Empty()) + .Concat(appSettings.Poetry?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) + .ToArray(); + } + else if (appSettings.ProjectType.Equals("DEBIAN", StringComparison.InvariantCultureIgnoreCase)) + { + repoList = (appSettings.Debian?.Artifactory.InternalRepos ?? Array.Empty()) + .Concat(appSettings.Debian?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Debian?.Artifactory.RemoteRepos ?? Array.Empty()) + .Concat(appSettings.Debian?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) + .ToArray(); + } + else if (appSettings.ProjectType.Equals("MAVEN", StringComparison.InvariantCultureIgnoreCase)) + { + repoList = (appSettings.Maven?.Artifactory.InternalRepos ?? Array.Empty()) + .Concat(appSettings.Maven?.Artifactory.DevRepos ?? Array.Empty()) + .Concat(appSettings.Maven?.Artifactory.RemoteRepos ?? Array.Empty()) + .Concat(appSettings.Maven?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) + .ToArray(); + } + return repoList; + } #endregion @@ -316,6 +342,50 @@ private static string Sw360URL(string sw360Env, string releaseId) string sw360URL = $"{sw360Env}{"/group/guest/components/-/component/release/detailRelease/"}{releaseId}"; return sw360URL; } + private static List RemoveExcludedComponentsFromPurl(List ComponentList, List ExcludedComponentsFromPurl, ref int noOfExcludedComponents) + { + List ExcludedList = new List(); + + foreach (string excludedComponent in ExcludedComponentsFromPurl) + { + foreach (var component in ComponentList) + { + if (component.Purl != null && component.Purl.Equals(excludedComponent, StringComparison.OrdinalIgnoreCase)) + { + noOfExcludedComponents++; + ExcludedList.Add(component); + } + } + } + + return ExcludedList; + } + + private static List RemoveOtherExcludedComponents(List ComponentList, List otherExcludedComponents, ref int noOfExcludedComponents) + { + List ExcludedList = new List(); + + foreach (string excludedComponent in otherExcludedComponents) + { + string[] excludedcomponent = excludedComponent.ToLower().Split(':'); + foreach (var component in ComponentList) + { + string name = component.Name; + if (!string.IsNullOrEmpty(component.Group) && (component.Group != component.Name)) + { + name = $"{component.Group}/{component.Name}"; + } + if (excludedcomponent.Length > 0 && (Regex.IsMatch(name.ToLowerInvariant(), WildcardToRegex(excludedcomponent[0].ToLowerInvariant()))) && + (component.Version.ToLowerInvariant().Contains(excludedcomponent[1].ToLowerInvariant()) || excludedcomponent[1].ToLowerInvariant() == "*")) + { + noOfExcludedComponents++; + ExcludedList.Add(component); + } + } + } + + return ExcludedList; + } #endregion } } diff --git a/src/LCT.PackageIdentifier.UTest/BomHelperUnitTests.cs b/src/LCT.PackageIdentifier.UTest/BomHelperUnitTests.cs index 4d566e1e..953d08fb 100644 --- a/src/LCT.PackageIdentifier.UTest/BomHelperUnitTests.cs +++ b/src/LCT.PackageIdentifier.UTest/BomHelperUnitTests.cs @@ -265,7 +265,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsNpm_ReturnsListOFComponents() Key = "npm.version", Value = "1" }; - List propertys = new List { npmNameProperty, npmVersionProperty }; + List npmAqlProperties = new List { npmNameProperty, npmVersionProperty }; List aqlResultList = new() { new() @@ -273,7 +273,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsNpm_ReturnsListOFComponents() Path="test/test", Name="Test-1.tgz", Repo="remote", - Properties=propertys, + Properties=npmAqlProperties, MD5="7654345676543", SHA256="65434567", SHA1="765434567654" diff --git a/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs b/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs index 5d6ba2a2..aeee702d 100644 --- a/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs @@ -203,6 +203,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully() IFileOperations fileOperations = new FileOperations(); CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { + ProjectType = "Conan", SW360 = new SW360(), Conan = new Config { @@ -255,6 +256,7 @@ public async Task GetArtifactoryRepoName_Conan_ReturnsNotFound_ReturnsFailure() IFileOperations fileOperations = new FileOperations(); CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { + ProjectType="Conan", SW360 = new SW360(), Conan = new Config { diff --git a/src/LCT.PackageIdentifier.UTest/MavenParserTests.cs b/src/LCT.PackageIdentifier.UTest/MavenParserTests.cs index 8d1ae589..4d2b7694 100644 --- a/src/LCT.PackageIdentifier.UTest/MavenParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/MavenParserTests.cs @@ -313,6 +313,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully() IFileOperations fileOperations = new FileOperations(); CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { + ProjectType = "Maven", SW360 = new SW360(), Maven = new Config { @@ -364,6 +365,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData2_SuccessFully( IFileOperations fileOperations = new FileOperations(); CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { + ProjectType = "Maven", SW360 = new SW360(), Maven = new Config { diff --git a/src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs b/src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs index 9b1ec3a9..ce11bde1 100644 --- a/src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs +++ b/src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs @@ -326,6 +326,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully() IFileOperations fileOperations = new FileOperations(); CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { + ProjectType = "NPM", SW360 = new SW360(), Npm = new Config { @@ -390,6 +391,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData2_SuccessFully( IFileOperations fileOperations = new FileOperations(); CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { + ProjectType = "NPM", SW360 = new SW360(), Npm = new Config { diff --git a/src/LCT.PackageIdentifier.UTest/NugetParserTests.cs b/src/LCT.PackageIdentifier.UTest/NugetParserTests.cs index f1811a0a..f2f7c1db 100644 --- a/src/LCT.PackageIdentifier.UTest/NugetParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/NugetParserTests.cs @@ -751,6 +751,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully() IFileOperations fileOperations = new FileOperations(); CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { + ProjectType = "NUGET", SW360 = new SW360(), Nuget = new Config { @@ -802,6 +803,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_Nuget_ReturnsWithData2_Success IFileOperations fileOperations = new FileOperations(); CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { + ProjectType = "NUGET", SW360 = new SW360(), Nuget = new Config { @@ -853,6 +855,7 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_SuccessFully() IFileOperations fileOperations = new FileOperations(); CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { + ProjectType = "NUGET", SW360 = new SW360(), Nuget = new Config { @@ -904,6 +907,7 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_ReturnsFailure() IFileOperations fileOperations = new FileOperations(); CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { + ProjectType = "NUGET", SW360 = new SW360(), Nuget = new Config { @@ -955,6 +959,7 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_ReturnsSuccess() IFileOperations fileOperations = new FileOperations(); CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { + ProjectType = "NUGET", SW360 = new SW360(), Nuget = new Config { @@ -1007,6 +1012,7 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsNotFound_ReturnsFailure() IFileOperations fileOperations = new FileOperations(); CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { + ProjectType = "NUGET", SW360 = new SW360(), Nuget = new Config { diff --git a/src/LCT.PackageIdentifier.UTest/PythonParserTests.cs b/src/LCT.PackageIdentifier.UTest/PythonParserTests.cs index 2f7d586e..00c27660 100644 --- a/src/LCT.PackageIdentifier.UTest/PythonParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/PythonParserTests.cs @@ -359,6 +359,7 @@ public async Task GetJfrogRepoDetailsOfAComponentForPython_ReturnsWithData_Succe IFileOperations fileOperations = new FileOperations(); CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { + ProjectType = "POETRY", SW360 = new SW360(), Poetry = new Config { @@ -422,6 +423,7 @@ public async Task GetJfrogRepoDetailsOfAComponentForPython_ReturnsWithData2_Succ IFileOperations fileOperations = new FileOperations(); CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) { + ProjectType = "POETRY", SW360 = new SW360(), Poetry = new Config { diff --git a/src/LCT.PackageIdentifier/ConanProcessor.cs b/src/LCT.PackageIdentifier/ConanProcessor.cs index 2f2a1d73..0f7fff16 100644 --- a/src/LCT.PackageIdentifier/ConanProcessor.cs +++ b/src/LCT.PackageIdentifier/ConanProcessor.cs @@ -113,16 +113,12 @@ public async Task IdentificationOfInternalComponents(Co return componentData; } - + public async Task> GetJfrogRepoDetailsOfAComponent(List componentsForBOM, CommonAppSettings appSettings, IJFrogService jFrogService, IBomHelper bomhelper) { // get the component list from Jfrog for given repo + internal repo - string[] repoList = (appSettings.Conan?.Artifactory.InternalRepos ?? Array.Empty()) - .Concat(appSettings.Conan?.Artifactory.DevRepos ?? Array.Empty()) - .Concat(appSettings.Conan?.Artifactory.RemoteRepos ?? Array.Empty()) - .Concat(appSettings.Conan?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) - .ToArray(); + string[] repoList = CommonHelper.GetRepoList(appSettings); List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); diff --git a/src/LCT.PackageIdentifier/DebianProcessor.cs b/src/LCT.PackageIdentifier/DebianProcessor.cs index 2a79ad1c..bb69e85b 100644 --- a/src/LCT.PackageIdentifier/DebianProcessor.cs +++ b/src/LCT.PackageIdentifier/DebianProcessor.cs @@ -129,11 +129,7 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List()) - .Concat(appSettings.Debian?.Artifactory.DevRepos ?? Array.Empty()) - .Concat(appSettings.Debian?.Artifactory.RemoteRepos ?? Array.Empty()) - .Concat(appSettings.Debian?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) - .ToArray(); + string[] repoList = CommonHelper.GetRepoList(appSettings); List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); diff --git a/src/LCT.PackageIdentifier/MavenProcessor.cs b/src/LCT.PackageIdentifier/MavenProcessor.cs index ca802474..15703c53 100644 --- a/src/LCT.PackageIdentifier/MavenProcessor.cs +++ b/src/LCT.PackageIdentifier/MavenProcessor.cs @@ -207,11 +207,7 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List()) - .Concat(appSettings.Maven?.Artifactory.DevRepos ?? Array.Empty()) - .Concat(appSettings.Maven?.Artifactory.RemoteRepos ?? Array.Empty()) - .Concat(appSettings.Maven?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) - .ToArray(); + string[] repoList = CommonHelper.GetRepoList(appSettings); List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); diff --git a/src/LCT.PackageIdentifier/NpmProcessor.cs b/src/LCT.PackageIdentifier/NpmProcessor.cs index e99e4d6d..bf297e7c 100644 --- a/src/LCT.PackageIdentifier/NpmProcessor.cs +++ b/src/LCT.PackageIdentifier/NpmProcessor.cs @@ -404,11 +404,7 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List()) - .Concat(appSettings.Npm?.Artifactory.DevRepos ?? Array.Empty()) - .Concat(appSettings.Npm?.Artifactory.RemoteRepos ?? Array.Empty()) - .Concat(appSettings.Npm?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) - .ToArray(); + string[] repoList = CommonHelper.GetRepoList(appSettings); List aqlResultList = await bomhelper.GetNpmListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; diff --git a/src/LCT.PackageIdentifier/NugetProcessor.cs b/src/LCT.PackageIdentifier/NugetProcessor.cs index 51127a92..7941a2e1 100644 --- a/src/LCT.PackageIdentifier/NugetProcessor.cs +++ b/src/LCT.PackageIdentifier/NugetProcessor.cs @@ -216,11 +216,7 @@ public async Task> GetJfrogRepoDetailsOfAComponent(List()) - .Concat(appSettings.Nuget?.Artifactory.DevRepos ?? Array.Empty()) - .Concat(appSettings.Nuget?.Artifactory.RemoteRepos ?? Array.Empty()) - .Concat(appSettings.Nuget?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) - .ToArray(); + string[] repoList = CommonHelper.GetRepoList(appSettings); List aqlResultList = await bomhelper.GetListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); diff --git a/src/LCT.PackageIdentifier/PythonProcessor.cs b/src/LCT.PackageIdentifier/PythonProcessor.cs index 0d9d51d9..6fcfdf17 100644 --- a/src/LCT.PackageIdentifier/PythonProcessor.cs +++ b/src/LCT.PackageIdentifier/PythonProcessor.cs @@ -382,11 +382,7 @@ private static string GetJfrogNameOfPypiComponent(string name, string version, L public async Task> GetJfrogRepoDetailsOfAComponent(List componentsForBOM, CommonAppSettings appSettings, IJFrogService jFrogService, IBomHelper bomhelper) { // get the component list from Jfrog for given repo + internal repo - string[] repoList = (appSettings.Poetry?.Artifactory.InternalRepos ?? Array.Empty()) - .Concat(appSettings.Poetry?.Artifactory.DevRepos ?? Array.Empty()) - .Concat(appSettings.Poetry?.Artifactory.RemoteRepos ?? Array.Empty()) - .Concat(appSettings.Poetry?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) - .ToArray(); + string[] repoList = CommonHelper.GetRepoList(appSettings); List aqlResultList = await bomhelper.GetPypiListOfComponentsFromRepo(repoList, jFrogService); Property projectType = new() { Name = Dataconstant.Cdx_ProjectType, Value = appSettings.ProjectType }; List modifiedBOM = new List(); diff --git a/src/SW360IntegrationTest/Conan/PackageIdentifierInitialConan.cs b/src/SW360IntegrationTest/Conan/PackageIdentifierInitialConan.cs index 56cafb21..96491b7d 100644 --- a/src/SW360IntegrationTest/Conan/PackageIdentifierInitialConan.cs +++ b/src/SW360IntegrationTest/Conan/PackageIdentifierInitialConan.cs @@ -42,7 +42,7 @@ public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess() TestConstant.SW360ProjectName, testParameters.SW360ProjectName, TestConstant.JFrogApiURL, testParameters.JfrogApi, TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey, - TestConstant.JfrogConanInternalRepo,"Conan.test", + TestConstant.JfrogConanInternalRepo,"Conan-test", TestConstant.ProjectType,"Conan", TestConstant.Mode,""}), "Test to run Package Identifier EXE execution"); diff --git a/src/SW360IntegrationTest/Debian/PackageIdentifierInitialDebian.cs b/src/SW360IntegrationTest/Debian/PackageIdentifierInitialDebian.cs index 8e592c7d..265ca623 100644 --- a/src/SW360IntegrationTest/Debian/PackageIdentifierInitialDebian.cs +++ b/src/SW360IntegrationTest/Debian/PackageIdentifierInitialDebian.cs @@ -52,7 +52,7 @@ public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess() TestConstant.SW360ProjectName, testParameters.SW360ProjectName, TestConstant.JFrogApiURL, testParameters.JfrogApi, TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey, - TestConstant.JfrogDebianInternalRepo,"Debian.test", + TestConstant.JfrogDebianInternalRepo,"Debian-test", TestConstant.ProjectType,"Debian", TestConstant.Mode,""}), "Test to run Package Identifier EXE execution"); diff --git a/src/SW360IntegrationTest/Maven/PackageIdentifierInitialMaven.cs b/src/SW360IntegrationTest/Maven/PackageIdentifierInitialMaven.cs index b64d712c..06ba4bf8 100644 --- a/src/SW360IntegrationTest/Maven/PackageIdentifierInitialMaven.cs +++ b/src/SW360IntegrationTest/Maven/PackageIdentifierInitialMaven.cs @@ -50,7 +50,7 @@ public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess() TestConstant.SW360ProjectName, testParameters.SW360ProjectName, TestConstant.JFrogApiURL, testParameters.JfrogApi, TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey, - TestConstant.JfrogMavenInternalRepo,"Maven.test", + TestConstant.JfrogMavenInternalRepo,"Maven-test", TestConstant.ProjectType,"Maven", TestConstant.Mode,""}), "Test to run Package Identifier EXE execution"); diff --git a/src/SW360IntegrationTest/NPM/PackageIdentifierInitial.cs b/src/SW360IntegrationTest/NPM/PackageIdentifierInitial.cs index f18820b1..eb2c959c 100644 --- a/src/SW360IntegrationTest/NPM/PackageIdentifierInitial.cs +++ b/src/SW360IntegrationTest/NPM/PackageIdentifierInitial.cs @@ -50,7 +50,7 @@ public void TestBOMCreatorexe() TestConstant.SW360ProjectName, testParameters.SW360ProjectName, TestConstant.JFrogApiURL, testParameters.JfrogApi, TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey, - TestConstant.JfrogNpmInternalRepo,"Npm.test", + TestConstant.JfrogNpmInternalRepo,"Npm-test", TestConstant.ProjectType, "Npm", TestConstant.Mode,""}), "Test to run Package Identifier EXE execution"); diff --git a/src/SW360IntegrationTest/Nuget/PackageIdentifierInitialNuget.cs b/src/SW360IntegrationTest/Nuget/PackageIdentifierInitialNuget.cs index bdec145d..aa2d0bc2 100644 --- a/src/SW360IntegrationTest/Nuget/PackageIdentifierInitialNuget.cs +++ b/src/SW360IntegrationTest/Nuget/PackageIdentifierInitialNuget.cs @@ -50,7 +50,7 @@ public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess() TestConstant.SW360ProjectName, testParameters.SW360ProjectName, TestConstant.JFrogApiURL, testParameters.JfrogApi, TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey, - TestConstant.JfrogNugetInternalRepo,"Nuget.test", + TestConstant.JfrogNugetInternalRepo,"Nuget-test", TestConstant.ProjectType,"Nuget", TestConstant.Mode,""}), "Test to run Package Identifier EXE execution"); diff --git a/src/SW360IntegrationTest/Python/PackageIdentifierInitialPython.cs b/src/SW360IntegrationTest/Python/PackageIdentifierInitialPython.cs index 8aa5c467..7f7c40b9 100644 --- a/src/SW360IntegrationTest/Python/PackageIdentifierInitialPython.cs +++ b/src/SW360IntegrationTest/Python/PackageIdentifierInitialPython.cs @@ -50,7 +50,7 @@ public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess() TestConstant.SW360ProjectName, testParameters.SW360ProjectName, TestConstant.JFrogApiURL, testParameters.JfrogApi, TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey, - TestConstant.JfrogPoetryInternalRepo,"Pypi.test", + TestConstant.JfrogPoetryInternalRepo,"Pypi-test", TestConstant.ProjectType,"Poetry", TestConstant.Mode,""}), "Test to run Package Identifier EXE execution"); diff --git a/src/TestUtilities/TestParam.cs b/src/TestUtilities/TestParam.cs index f72acad8..05648096 100644 --- a/src/TestUtilities/TestParam.cs +++ b/src/TestUtilities/TestParam.cs @@ -38,7 +38,7 @@ public TestParam() FossUrl = s_Config["FossologyURL"]; SW360ProjectName = s_Config["SW360ProjectName"]; SW360ProjectID = s_Config["SW360ProjectID"]; - ProjectType = "Conan"; + ProjectType = "NPM"; RemoveDevDependency = s_Config["RemoveDevDependency"]; ArtifactoryUploadUser = s_Config["ArtifactoryUploadUser"]; ArtifactoryUploadApiKey = s_Config["ArtifactoryUploadApiKey"]; From ce678b8391a4deacff784fb83425796c5125c49c Mon Sep 17 00:00:00 2001 From: Chalapala RaghavendraReddy Date: Fri, 17 Jan 2025 12:09:34 +0530 Subject: [PATCH 08/10] updated file --- src/LCT.Common.UTests/Log4NetTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LCT.Common.UTests/Log4NetTests.cs b/src/LCT.Common.UTests/Log4NetTests.cs index 26273f85..46c15667 100644 --- a/src/LCT.Common.UTests/Log4NetTests.cs +++ b/src/LCT.Common.UTests/Log4NetTests.cs @@ -196,7 +196,7 @@ public void ActivateFileAppender_LogPathIsNull_ShouldNotSetFileAndNotActivateOpt { // Arrange bool verbose = true; - string logPath = null; + string? logPath = null; IAppender[] appenders = [new RollingFileAppender()]; // Act From d2d7727c12da49ecdf04fdeaf3c4ed571f9a990c Mon Sep 17 00:00:00 2001 From: Chalapala RaghavendraReddy Date: Thu, 23 Jan 2025 09:49:40 +0530 Subject: [PATCH 09/10] updated code --- src/LCT.Common/CommonHelper.cs | 71 +++++++++++----------------------- 1 file changed, 22 insertions(+), 49 deletions(-) diff --git a/src/LCT.Common/CommonHelper.cs b/src/LCT.Common/CommonHelper.cs index ed5e0b2f..371d8388 100644 --- a/src/LCT.Common/CommonHelper.cs +++ b/src/LCT.Common/CommonHelper.cs @@ -277,58 +277,31 @@ public static void PublishFilesToArtifact() } public static string[] GetRepoList(CommonAppSettings appSettings) { - string[] repoList = null; - - if (appSettings.ProjectType.Equals("CONAN", StringComparison.InvariantCultureIgnoreCase)) - { - repoList = (appSettings.Conan?.Artifactory.InternalRepos ?? Array.Empty()) - .Concat(appSettings.Conan?.Artifactory.DevRepos ?? Array.Empty()) - .Concat(appSettings.Conan?.Artifactory.RemoteRepos ?? Array.Empty()) - .Concat(appSettings.Conan?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) - .ToArray(); - }else if (appSettings.ProjectType.Equals("NPM", StringComparison.InvariantCultureIgnoreCase)) - { - repoList = (appSettings.Npm?.Artifactory.InternalRepos ?? Array.Empty()) - .Concat(appSettings.Npm?.Artifactory.DevRepos ?? Array.Empty()) - .Concat(appSettings.Npm?.Artifactory.RemoteRepos ?? Array.Empty()) - .Concat(appSettings.Npm?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) - .ToArray(); - } - else if (appSettings.ProjectType.Equals("NUGET", StringComparison.InvariantCultureIgnoreCase)) - { - repoList = (appSettings.Nuget?.Artifactory.InternalRepos ?? Array.Empty()) - .Concat(appSettings.Nuget?.Artifactory.DevRepos ?? Array.Empty()) - .Concat(appSettings.Nuget?.Artifactory.RemoteRepos ?? Array.Empty()) - .Concat(appSettings.Nuget?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) - .ToArray(); - } - else if (appSettings.ProjectType.Equals("POETRY", StringComparison.InvariantCultureIgnoreCase)) - { - repoList = (appSettings.Poetry?.Artifactory.InternalRepos ?? Array.Empty()) - .Concat(appSettings.Poetry?.Artifactory.DevRepos ?? Array.Empty()) - .Concat(appSettings.Poetry?.Artifactory.RemoteRepos ?? Array.Empty()) - .Concat(appSettings.Poetry?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) - .ToArray(); - } - else if (appSettings.ProjectType.Equals("DEBIAN", StringComparison.InvariantCultureIgnoreCase)) - { - repoList = (appSettings.Debian?.Artifactory.InternalRepos ?? Array.Empty()) - .Concat(appSettings.Debian?.Artifactory.DevRepos ?? Array.Empty()) - .Concat(appSettings.Debian?.Artifactory.RemoteRepos ?? Array.Empty()) - .Concat(appSettings.Debian?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) - .ToArray(); - } - else if (appSettings.ProjectType.Equals("MAVEN", StringComparison.InvariantCultureIgnoreCase)) + var projectTypeMappings = new Dictionary> + { + { "CONAN", () => appSettings.Conan?.Artifactory }, + { "NPM", () => appSettings.Npm?.Artifactory }, + { "NUGET", () => appSettings.Nuget?.Artifactory }, + { "POETRY", () => appSettings.Poetry?.Artifactory }, + { "DEBIAN", () => appSettings.Debian?.Artifactory }, + { "MAVEN", () => appSettings.Maven?.Artifactory } + }; + + if (projectTypeMappings.TryGetValue(appSettings.ProjectType.ToUpperInvariant(), out var getArtifactory)) { - repoList = (appSettings.Maven?.Artifactory.InternalRepos ?? Array.Empty()) - .Concat(appSettings.Maven?.Artifactory.DevRepos ?? Array.Empty()) - .Concat(appSettings.Maven?.Artifactory.RemoteRepos ?? Array.Empty()) - .Concat(appSettings.Maven?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) - .ToArray(); + var artifactory = getArtifactory(); + if (artifactory != null) + { + return (artifactory.InternalRepos ?? Array.Empty()) + .Concat(artifactory.DevRepos ?? Array.Empty()) + .Concat(artifactory.RemoteRepos ?? Array.Empty()) + .Concat(artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty()) + .ToArray(); + } } - return repoList; - } + return Array.Empty(); + } #endregion #region private From 8370f958d83ba1fbf5e1c60465c733e3e502203d Mon Sep 17 00:00:00 2001 From: Chalapala RaghavendraReddy Date: Thu, 23 Jan 2025 13:04:54 +0530 Subject: [PATCH 10/10] updated changes --- src/LCT.PackageIdentifier/BomCreator.cs | 3 ++- src/LCT.PackageIdentifier/NugetProcessor.cs | 3 ++- src/LCT.PackageIdentifier/Program.cs | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/LCT.PackageIdentifier/BomCreator.cs b/src/LCT.PackageIdentifier/BomCreator.cs index b5e4049a..0af00137 100644 --- a/src/LCT.PackageIdentifier/BomCreator.cs +++ b/src/LCT.PackageIdentifier/BomCreator.cs @@ -23,6 +23,7 @@ using System.Reflection; using System.Threading.Tasks; using System.IO; +using Directory = System.IO.Directory; namespace LCT.PackageIdentifier @@ -105,7 +106,7 @@ private static void WriteContentToCycloneDxBOM(CommonAppSettings appSettings, Bo IFileOperations fileOperations = new FileOperations(); string bomFileName = $"{appSettings.SW360.ProjectName}_Bom.cdx.json"; string outputFolderPath = appSettings.Directory.OutputFolder; - string[] files = System.IO.Directory.GetFiles(outputFolderPath); + string[] files = Directory.GetFiles(outputFolderPath); bool fileExists = files.Length > 0 && files.Any(file => Path.GetFileName(file).Equals(bomFileName, StringComparison.OrdinalIgnoreCase)); diff --git a/src/LCT.PackageIdentifier/NugetProcessor.cs b/src/LCT.PackageIdentifier/NugetProcessor.cs index 7941a2e1..48ea732f 100644 --- a/src/LCT.PackageIdentifier/NugetProcessor.cs +++ b/src/LCT.PackageIdentifier/NugetProcessor.cs @@ -27,6 +27,7 @@ using System.Threading.Tasks; using System.Xml; using System.Xml.Linq; +using Directory = System.IO.Directory; namespace LCT.PackageIdentifier { @@ -689,7 +690,7 @@ private static void CheckForMultipleVersions(CommonAppSettings appSettings, List private static List GetValidCsprojfile(CommonAppSettings appSettings) { List allFoundCsprojFiles = new List(); - string[] foundCsprojFiles = System.IO.Directory.GetFiles(appSettings.Directory.InputFolder, "*.csproj", SearchOption.AllDirectories); + string[] foundCsprojFiles = Directory.GetFiles(appSettings.Directory.InputFolder, "*.csproj", SearchOption.AllDirectories); if (foundCsprojFiles != null) { foreach (string csprojFile in foundCsprojFiles) diff --git a/src/LCT.PackageIdentifier/Program.cs b/src/LCT.PackageIdentifier/Program.cs index 04037c52..5289703c 100644 --- a/src/LCT.PackageIdentifier/Program.cs +++ b/src/LCT.PackageIdentifier/Program.cs @@ -26,8 +26,8 @@ using LCT.APICommunications.Model; using System.Linq; using System.Diagnostics.CodeAnalysis; -using Tommy; using System.Collections.Generic; +using Directory = System.IO.Directory; namespace LCT.PackageIdentifier @@ -57,7 +57,7 @@ static async Task Main(string[] args) ProjectReleases projectReleases = new ProjectReleases(); // do not change the order of getting ca tool information CatoolInfo caToolInformation = GetCatoolVersionFromProjectfile(); - Log4Net.CatoolCurrentDirectory = System.IO.Directory.GetParent(caToolInformation.CatoolRunningLocation).FullName; + Log4Net.CatoolCurrentDirectory = Directory.GetParent(caToolInformation.CatoolRunningLocation).FullName; string FolderPath = LogFolderInitialisation(appSettings); settingsManager.CheckRequiredArgsToRun(appSettings, "Identifer");