Skip to content

Commit d09abc9

Browse files
Updated code changes
1 parent d593780 commit d09abc9

10 files changed

+70
-66
lines changed

src/LCT.PackageIdentifier/AlpineProcesser.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public static Bom RemoveExcludedComponents(CommonAppSettings appSettings, Bom cy
8080
List<Component> componentForBOM = cycloneDXBOM.Components.ToList();
8181
List<Dependency> dependenciesForBOM = cycloneDXBOM.Dependencies?.ToList() ?? new List<Dependency>();
8282
int noOfExcludedComponents = 0;
83-
if (appSettings.SW360.ExcludeComponents != null)
83+
if (appSettings?.SW360?.ExcludeComponents != null)
8484
{
85-
componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.SW360.ExcludeComponents, ref noOfExcludedComponents);
85+
componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings?.SW360?.ExcludeComponents, ref noOfExcludedComponents);
8686
dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM);
8787
BomCreator.bomKpiData.ComponentsExcludedSW360 += noOfExcludedComponents;
8888

src/LCT.PackageIdentifier/ConanProcessor.cs

+11-10
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,12 @@ public static bool IsDevDependency(ConanPackage component, List<string> buildNod
216216
private static void CreateFileForMultipleVersions(List<Component> componentsWithMultipleVersions, CommonAppSettings appSettings)
217217
{
218218
MultipleVersions multipleVersions = new MultipleVersions();
219-
IFileOperations fileOperations = new FileOperations();
220-
string bomFullPath= $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_Bom.cdx.json";
219+
IFileOperations fileOperations = new FileOperations();
220+
string defaultProjectName = CommonIdentiferHelper.GetDefaultProjectName(appSettings);
221+
string bomFullPath= $"{appSettings.Directory.OutputFolder}\\{defaultProjectName}_Bom.cdx.json";
221222

222-
string filename = $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}";
223-
if (!File.Exists(filename))
223+
string filePath = $"{appSettings.Directory.OutputFolder}\\{defaultProjectName}_{FileConstant.multipleversionsFileName}";
224+
if (!File.Exists(filePath))
224225
{
225226
multipleVersions.Conan = new List<MultipleVersionValues>();
226227
foreach (var conanPackage in componentsWithMultipleVersions)
@@ -232,12 +233,12 @@ private static void CreateFileForMultipleVersions(List<Component> componentsWith
232233
jsonComponents.PackageFoundIn = conanPackage.Description;
233234
multipleVersions.Conan.Add(jsonComponents);
234235
}
235-
fileOperations.WriteContentToMultipleVersionsFile(multipleVersions, appSettings.Directory.OutputFolder, FileConstant.multipleversionsFileName, appSettings.SW360.ProjectName);
236-
Logger.Warn($"\nTotal Multiple versions detected {multipleVersions.Conan.Count} and details can be found at {appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}\n");
236+
fileOperations.WriteContentToMultipleVersionsFile(multipleVersions, appSettings.Directory.OutputFolder, FileConstant.multipleversionsFileName, defaultProjectName);
237+
Logger.Warn($"\nTotal Multiple versions detected {multipleVersions.Conan.Count} and details can be found at {filePath}\n");
237238
}
238239
else
239240
{
240-
string json = File.ReadAllText(filename);
241+
string json = File.ReadAllText(filePath);
241242
MultipleVersions myDeserializedClass = JsonConvert.DeserializeObject<MultipleVersions>(json);
242243
List<MultipleVersionValues> conanComponents = new List<MultipleVersionValues>();
243244
foreach (var conanPackage in componentsWithMultipleVersions)
@@ -252,8 +253,8 @@ private static void CreateFileForMultipleVersions(List<Component> componentsWith
252253
}
253254
myDeserializedClass.Conan = conanComponents;
254255

255-
fileOperations.WriteContentToMultipleVersionsFile(myDeserializedClass, appSettings.Directory.OutputFolder, FileConstant.multipleversionsFileName, appSettings.SW360.ProjectName);
256-
Logger.Warn($"\nTotal Multiple versions detected {conanComponents.Count} and details can be found at {appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}\n");
256+
fileOperations.WriteContentToMultipleVersionsFile(myDeserializedClass, appSettings.Directory.OutputFolder, FileConstant.multipleversionsFileName, defaultProjectName);
257+
Logger.Warn($"\nTotal Multiple versions detected {conanComponents.Count} and details can be found at {filePath}\n");
257258
}
258259
}
259260
private void ParsingInputFileForBOM(CommonAppSettings appSettings, ref Bom bom)
@@ -558,7 +559,7 @@ private static Bom RemoveExcludedComponents(CommonAppSettings appSettings, Bom c
558559
List<Component> componentForBOM = cycloneDXBOM.Components.ToList();
559560
List<Dependency> dependenciesForBOM = cycloneDXBOM.Dependencies?.ToList() ?? new List<Dependency>();
560561
int noOfExcludedComponents = 0;
561-
if (appSettings.SW360.ExcludeComponents != null)
562+
if (appSettings?.SW360?.ExcludeComponents != null)
562563
{
563564
componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.SW360.ExcludeComponents, ref noOfExcludedComponents);
564565
dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM);

src/LCT.PackageIdentifier/CycloneBomProcessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static Bom SetMetadataInComparisonBOM(Bom bom,
3636

3737
Component component = new Component
3838
{
39-
Name = appSettings.SW360.ProjectName,
39+
Name = appSettings?.SW360?.ProjectName,
4040
Version = projectReleases.Version,
4141
Type = Component.Classification.Application
4242
};

src/LCT.PackageIdentifier/DebianProcessor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ public static Bom RemoveExcludedComponents(CommonAppSettings appSettings, Bom cy
107107
List<Component> componentForBOM = cycloneDXBOM.Components.ToList();
108108
List<Dependency> dependenciesForBOM = cycloneDXBOM.Dependencies?.ToList() ?? new List<Dependency>();
109109
int noOfExcludedComponents = 0;
110-
if (appSettings.SW360.ExcludeComponents != null)
110+
if (appSettings?.SW360?.ExcludeComponents != null)
111111
{
112-
componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.SW360.ExcludeComponents, ref noOfExcludedComponents);
112+
componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings?.SW360?.ExcludeComponents, ref noOfExcludedComponents);
113113
dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM);
114114
BomCreator.bomKpiData.ComponentsExcludedSW360 += noOfExcludedComponents;
115115
}

src/LCT.PackageIdentifier/DisplayInformation.cs

+24-25
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ public static string DisplayIncludeFiles(CommonAppSettings appSettings)
1919
string totalString = string.Empty;
2020
var includeMappings = new Dictionary<string, Func<IEnumerable<string>>>(StringComparer.OrdinalIgnoreCase)
2121
{
22-
{ "NPM", () => appSettings.Npm.Include },
23-
{ "NUGET", () => appSettings.Nuget.Include },
24-
{ "MAVEN", () => appSettings.Maven.Include },
25-
{ "DEBIAN", () => appSettings.Debian.Include },
26-
{ "POETRY", () => appSettings.Poetry.Include },
27-
{ "CONAN", () => appSettings.Conan.Include },
28-
{ "ALPINE", () => appSettings.Alpine.Include }
22+
{ "NPM", () => appSettings?.Npm?.Include },
23+
{ "NUGET", () => appSettings?.Nuget?.Include },
24+
{ "MAVEN", () => appSettings?.Maven?.Include },
25+
{ "DEBIAN", () => appSettings?.Debian?.Include },
26+
{ "POETRY", () => appSettings?.Poetry?.Include },
27+
{ "CONAN", () => appSettings?.Conan?.Include },
28+
{ "ALPINE", () => appSettings?.Alpine?.Include }
2929
};
3030

3131
if (includeMappings.TryGetValue(appSettings.ProjectType, out var getIncludeList))
@@ -48,13 +48,13 @@ public static string DisplayExcludeFiles(CommonAppSettings appSettings)
4848
string totalString = string.Empty;
4949
var excludeMappings = new Dictionary<string, Func<IEnumerable<string>>>(StringComparer.OrdinalIgnoreCase)
5050
{
51-
{ "NPM", () => appSettings.Npm.Exclude },
52-
{ "NUGET", () => appSettings.Nuget.Exclude },
53-
{ "MAVEN", () => appSettings.Maven.Exclude },
54-
{ "DEBIAN", () => appSettings.Debian.Exclude },
55-
{ "POETRY", () => appSettings.Poetry.Exclude },
56-
{ "CONAN", () => appSettings.Conan.Exclude },
57-
{ "ALPINE", () => appSettings.Alpine.Exclude }
51+
{ "NPM", () => appSettings?.Npm?.Exclude },
52+
{ "NUGET", () => appSettings?.Nuget?.Exclude },
53+
{ "MAVEN", () => appSettings?.Maven?.Exclude },
54+
{ "DEBIAN", () => appSettings?.Debian?.Exclude },
55+
{ "POETRY", () => appSettings?.Poetry?.Exclude },
56+
{ "CONAN", () => appSettings?.Conan?.Exclude },
57+
{ "ALPINE", () => appSettings?.Alpine?.Exclude }
5858
};
5959

6060
if (excludeMappings.TryGetValue(appSettings.ProjectType, out var getExcludeList))
@@ -77,9 +77,9 @@ public static string DisplayExcludeComponents(CommonAppSettings appSettings)
7777
{
7878

7979
string totalString = string.Empty;
80-
if (appSettings.SW360.ExcludeComponents != null)
80+
if (appSettings?.SW360?.ExcludeComponents != null)
8181
{
82-
totalString = string.Join(",", appSettings.SW360.ExcludeComponents?.ToList());
82+
totalString = string.Join(",", appSettings?.SW360?.ExcludeComponents?.ToList());
8383
}
8484
return totalString;
8585
}
@@ -90,13 +90,13 @@ public static string GetInternalRepolist(CommonAppSettings appSettings)
9090

9191
var repoMapping = new Dictionary<string, Func<IEnumerable<string>>>(StringComparer.OrdinalIgnoreCase)
9292
{
93-
{ "NPM", () => appSettings.Npm?.Artifactory.InternalRepos },
94-
{ "NUGET", () => appSettings.Nuget?.Artifactory.InternalRepos },
95-
{ "MAVEN", () => appSettings.Maven?.Artifactory.InternalRepos },
96-
{ "DEBIAN", () => appSettings.Debian?.Artifactory.InternalRepos },
97-
{ "POETRY", () => appSettings.Poetry?.Artifactory.InternalRepos },
98-
{ "CONAN", () => appSettings.Conan?.Artifactory.InternalRepos },
99-
{ "ALPINE", () => appSettings.Alpine?.Artifactory.InternalRepos }
93+
{ "NPM", () => appSettings?.Npm?.Artifactory.InternalRepos },
94+
{ "NUGET", () => appSettings?.Nuget?.Artifactory.InternalRepos },
95+
{ "MAVEN", () => appSettings?.Maven?.Artifactory.InternalRepos },
96+
{ "DEBIAN", () => appSettings?.Debian?.Artifactory.InternalRepos },
97+
{ "POETRY", () => appSettings?.Poetry?.Artifactory.InternalRepos },
98+
{ "CONAN", () => appSettings?.Conan?.Artifactory.InternalRepos },
99+
{ "ALPINE", () => appSettings?.Alpine?.Artifactory.InternalRepos }
100100
};
101101

102102
if (repoMapping.TryGetValue(appSettings.ProjectType, out var getRepos))
@@ -132,8 +132,7 @@ public static void LogInputParameters(CatoolInfo caToolInformation, CommonAppSet
132132
}
133133

134134
logMessage += $"ProjectType\t\t --> {appSettings.ProjectType}\n\t" +
135-
$"LogFolderPath\t\t --> {Log4Net.CatoolLogPath}\n\t" +
136-
135+
$"LogFolderPath\t\t --> {Log4Net.CatoolLogPath}\n\t" +
137136
$"Include\t\t\t --> {listOfInclude}\n\t" +
138137
$"Exclude\t\t\t --> {listOfExclude}\n\t" +
139138
$"ExcludeComponents\t --> {listOfExcludeComponents}\n";

src/LCT.PackageIdentifier/MavenProcessor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ public Bom ParsePackageFile(CommonAppSettings appSettings)
9797
BomCreator.bomKpiData.DuplicateComponents = totalComponentsIdentified - componentsForBOM.Count;
9898

9999

100-
if (appSettings.SW360.ExcludeComponents != null)
100+
if (appSettings?.SW360?.ExcludeComponents != null)
101101
{
102-
componentsForBOM = CommonHelper.RemoveExcludedComponents(componentsForBOM, appSettings.SW360.ExcludeComponents, ref noOfExcludedComponents);
102+
componentsForBOM = CommonHelper.RemoveExcludedComponents(componentsForBOM, appSettings?.SW360?.ExcludeComponents, ref noOfExcludedComponents);
103103
dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentsForBOM, dependenciesForBOM);
104104
BomCreator.bomKpiData.ComponentsExcludedSW360 += noOfExcludedComponents;
105105
}

src/LCT.PackageIdentifier/NpmProcessor.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public List<Component> ParsePackageLockJson(string filepath, CommonAppSettings a
109109
}
110110
}
111111

112-
if (appSettings.SW360.ExcludeComponents != null)
112+
if (appSettings?.SW360?.ExcludeComponents != null)
113113
{
114114
lstComponentForBOM = CommonHelper.RemoveExcludedComponents(lstComponentForBOM, appSettings.SW360.ExcludeComponents, ref noOfExcludedComponents);
115115
BomCreator.bomKpiData.ComponentsExcludedSW360 += noOfExcludedComponents;
@@ -155,10 +155,10 @@ private static void CreateFileForMultipleVersions(List<Component> componentsWith
155155
{
156156
MultipleVersions multipleVersions = new MultipleVersions();
157157
IFileOperations fileOperations = new FileOperations();
158-
159-
string bomFullPath = $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_Bom.cdx.json";
160-
string filename = $"{appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}";
161-
if (!File.Exists(filename))
158+
string defaultProjectName = CommonIdentiferHelper.GetDefaultProjectName(appSettings);
159+
string bomFullPath = $"{appSettings.Directory.OutputFolder}\\{defaultProjectName}_Bom.cdx.json";
160+
string filePath = $"{appSettings.Directory.OutputFolder}\\{defaultProjectName}_{FileConstant.multipleversionsFileName}";
161+
if (!File.Exists(filePath))
162162
{
163163
multipleVersions.Npm = new List<MultipleVersionValues>();
164164
foreach (var npmpackage in componentsWithMultipleVersions)
@@ -170,12 +170,12 @@ private static void CreateFileForMultipleVersions(List<Component> componentsWith
170170
jsonComponents.PackageFoundIn = npmpackage.Description;
171171
multipleVersions.Npm.Add(jsonComponents);
172172
}
173-
fileOperations.WriteContentToMultipleVersionsFile(multipleVersions, appSettings.Directory.OutputFolder, FileConstant.multipleversionsFileName, appSettings.SW360.ProjectName);
174-
Logger.Warn($"\nTotal Multiple versions detected {multipleVersions.Npm.Count} and details can be found at {appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}\n");
173+
fileOperations.WriteContentToMultipleVersionsFile(multipleVersions, appSettings.Directory.OutputFolder, FileConstant.multipleversionsFileName, defaultProjectName);
174+
Logger.Warn($"\nTotal Multiple versions detected {multipleVersions.Npm.Count} and details can be found at {filePath}\n");
175175
}
176176
else
177177
{
178-
string json = File.ReadAllText(filename);
178+
string json = File.ReadAllText(filePath);
179179
MultipleVersions myDeserializedClass = JsonConvert.DeserializeObject<MultipleVersions>(json);
180180
List<MultipleVersionValues> npmComponents = new List<MultipleVersionValues>();
181181
foreach (var npmpackage in componentsWithMultipleVersions)
@@ -189,8 +189,8 @@ private static void CreateFileForMultipleVersions(List<Component> componentsWith
189189
}
190190
myDeserializedClass.Npm = npmComponents;
191191

192-
fileOperations.WriteContentToMultipleVersionsFile(myDeserializedClass, appSettings.Directory.OutputFolder, FileConstant.multipleversionsFileName, appSettings.SW360.ProjectName);
193-
Logger.Warn($"\nTotal Multiple versions detected {npmComponents.Count} and details can be found at {appSettings.Directory.OutputFolder}\\{appSettings.SW360.ProjectName}_{FileConstant.multipleversionsFileName}\n");
192+
fileOperations.WriteContentToMultipleVersionsFile(myDeserializedClass, appSettings.Directory.OutputFolder, FileConstant.multipleversionsFileName, defaultProjectName);
193+
Logger.Warn($"\nTotal Multiple versions detected {npmComponents.Count} and details can be found at {filePath}\n");
194194
}
195195
}
196196

@@ -504,7 +504,7 @@ public static Bom RemoveExcludedComponents(CommonAppSettings appSettings, Bom cy
504504
List<Component> componentForBOM = cycloneDXBOM.Components.ToList();
505505
List<Dependency> dependenciesForBOM = cycloneDXBOM.Dependencies?.ToList() ?? new List<Dependency>();
506506
int noOfExcludedComponents = 0;
507-
if (appSettings.SW360.ExcludeComponents != null)
507+
if (appSettings?.SW360?.ExcludeComponents != null)
508508
{
509509
componentForBOM = CommonHelper.RemoveExcludedComponents(componentForBOM, appSettings.SW360.ExcludeComponents, ref noOfExcludedComponents);
510510
dependenciesForBOM = CommonHelper.RemoveInvalidDependenciesAndReferences(componentForBOM, dependenciesForBOM);

0 commit comments

Comments
 (0)