Skip to content

Commit d3f74a6

Browse files
Updated code changes
1 parent c28e0b5 commit d3f74a6

23 files changed

+150
-81
lines changed

src/LCT.Common.UTests/CommonHelperTest.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,20 @@ public void RemoveMultipleExcludedComponents_ReturnSuccess()
5959
ComponentsForBom.Add(new Component() { Name = "Debian", Version = "3.1.2" });
6060
ComponentsForBom.Add(new Component() { Name = "Newton", Version = "3.1.3" });
6161
ComponentsForBom.Add(new Component() { Name = "Log4t", Version = "3.1.4" });
62+
ComponentsForBom.Add(new Component() { Name = "Log4t", Version = "3.1.5",Purl= "pkg:npm/foobar@12.3.1" });
63+
ComponentsForBom.Add(new Component() { Name = "Log4t", Version = "3.1.5", Purl = "pkg:npm/foobar@12.3.2" });
6264
int noOfExcludedComponents = 0;
6365

6466
List<string> list = new List<string>();
6567
list.Add("Debian:*");
6668
list.Add("Newton:3.1.3");
69+
list.Add("pkg:npm/foobar@12.3.1");
6770

6871
//Act
6972
CommonHelper.RemoveExcludedComponents(ComponentsForBom, list, ref noOfExcludedComponents);
7073

7174
//Assert
72-
Assert.That(noOfExcludedComponents, Is.EqualTo(4), "Returns the count of excluded components");
75+
Assert.That(noOfExcludedComponents, Is.EqualTo(5), "Returns the count of excluded components");
7376

7477
}
7578

src/LCT.Common.UTests/FolderActionTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public void CopyToTargetDirectory_PassingDirsWithFiles_ReturnSuccess()
7474
{
7575
//Arrange
7676
string sourcePath = $"{Path.GetTempPath()}\\SampleFolder";
77-
Directory.CreateDirectory(sourcePath);
78-
Directory.CreateDirectory(sourcePath +"\\SampleSubFolder");
77+
System.IO.Directory.CreateDirectory(sourcePath);
78+
System.IO.Directory.CreateDirectory(sourcePath +"\\SampleSubFolder");
7979
File.WriteAllText(sourcePath + "\\Sample.txt", "");
8080
string targetPath = $"{Path.GetTempPath()}/targetPath/";
8181
var folderAction = new FolderAction();

src/LCT.Common/CommonAppSettings.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace LCT.Common
2121
public class CommonAppSettings
2222
{
2323
private readonly IFolderAction folderAction;
24-
private readonly IFileOperations _fileOperations;
24+
private readonly IFileOperations fileOperations;
2525

2626
public static string PackageUrlApi { get; set; } = $"https://www.nuget.org/api/v2/package/";
2727
public static string SourceURLNugetApi { get; set; } = $"https://api.nuget.org/v3-flatcontainer/";
@@ -37,18 +37,18 @@ public class CommonAppSettings
3737
public CommonAppSettings()
3838
{
3939
folderAction = new FolderAction();
40-
_fileOperations = new FileOperations();
41-
Directory = new Directory(folderAction, _fileOperations);
40+
fileOperations = new FileOperations();
41+
Directory = new Directory(folderAction, fileOperations);
4242
}
4343

44-
public CommonAppSettings(IFolderAction iFolderAction, IFileOperations fileOperations)
44+
public CommonAppSettings(IFolderAction iFolderAction, IFileOperations ifileOperations)
4545
{
4646
folderAction = iFolderAction;
47-
_fileOperations = fileOperations;
48-
Directory = new Directory(folderAction, _fileOperations);
47+
fileOperations = ifileOperations;
48+
Directory = new Directory(folderAction, fileOperations);
4949
}
5050

51-
public int TimeOut { get; set; } = 400;
51+
public int TimeOut { get; set; } = 200;
5252
public string ProjectType
5353
{
5454
get
@@ -211,14 +211,14 @@ public string Token
211211
public class Directory
212212
{
213213
private readonly IFolderAction folderAction;
214-
private readonly IFileOperations _fileOperations;
214+
private readonly IFileOperations fileOperations;
215215
private string m_InputFolder;
216216
private string m_OutputFolder;
217217

218218
public Directory(IFolderAction folderAction, IFileOperations fileOperations)
219219
{
220220
this.folderAction = folderAction;
221-
this._fileOperations = fileOperations;
221+
this.fileOperations = fileOperations;
222222
}
223223
public string InputFolder
224224
{
@@ -234,6 +234,12 @@ public string InputFolder
234234
folderAction.ValidateFolderPath(value);
235235
m_InputFolder = value;
236236
}
237+
else if (AppDomain.CurrentDomain.FriendlyName.Contains("SW360PackageCreator") ||
238+
AppDomain.CurrentDomain.FriendlyName.Contains("ArtifactoryUploader"))
239+
{
240+
fileOperations.ValidateFilePath(value);
241+
m_InputFolder = value;
242+
}
237243
}
238244
}
239245

src/LCT.Common/CommonHelper.cs

Lines changed: 99 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,8 @@ public static List<Component> RemoveExcludedComponents(List<Component> Component
4343
List<string> ExcludedComponentsFromPurl = ExcludedComponents?.Where(ec => ec.StartsWith("pkg:")).ToList();
4444
List<string> otherExcludedComponents = ExcludedComponents?.Where(ec => !ec.StartsWith("pkg:")).ToList();
4545

46-
foreach (string excludedComponent in ExcludedComponentsFromPurl)
47-
{
48-
foreach (var component in ComponentList)
49-
{
50-
if (component.Purl != null && component.Purl.Equals(excludedComponent, StringComparison.OrdinalIgnoreCase))
51-
{
52-
noOfExcludedComponents++;
53-
ExcludedList.Add(component);
54-
}
55-
}
56-
}
57-
foreach (string excludedComponent in otherExcludedComponents)
58-
{
59-
string[] excludedcomponent = excludedComponent.ToLower().Split(':');
60-
foreach (var component in ComponentList)
61-
{
62-
string name = component.Name;
63-
if (!string.IsNullOrEmpty(component.Group) && (component.Group != component.Name))
64-
{
65-
name = $"{component.Group}/{component.Name}";
66-
}
67-
if (excludedcomponent.Length > 0 && (Regex.IsMatch(name.ToLowerInvariant(), WildcardToRegex(excludedcomponent[0].ToLowerInvariant()))) &&
68-
(component.Version.ToLowerInvariant().Contains(excludedcomponent[1].ToLowerInvariant()) || excludedcomponent[1].ToLowerInvariant() == "*"))
69-
{
70-
noOfExcludedComponents++;
71-
ExcludedList.Add(component);
72-
}
73-
}
74-
}
46+
ExcludedList.AddRange(RemoveExcludedComponentsFromPurl(ComponentList, ExcludedComponentsFromPurl, ref noOfExcludedComponents));
47+
ExcludedList.AddRange(RemoveOtherExcludedComponents(ComponentList, otherExcludedComponents, ref noOfExcludedComponents));
7548
ComponentList.RemoveAll(item => ExcludedList.Contains(item));
7649
return ComponentList;
7750
}
@@ -302,6 +275,59 @@ public static void PublishFilesToArtifact()
302275
artifactPublisher.UploadLogs();
303276
artifactPublisher.UploadBom();
304277
}
278+
public static string[] GetRepoList(CommonAppSettings appSettings)
279+
{
280+
string[] repoList = null;
281+
282+
if (appSettings.ProjectType.Equals("CONAN", StringComparison.InvariantCultureIgnoreCase))
283+
{
284+
repoList = (appSettings.Conan?.Artifactory.InternalRepos ?? Array.Empty<string>())
285+
.Concat(appSettings.Conan?.Artifactory.DevRepos ?? Array.Empty<string>())
286+
.Concat(appSettings.Conan?.Artifactory.RemoteRepos ?? Array.Empty<string>())
287+
.Concat(appSettings.Conan?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty<string>())
288+
.ToArray();
289+
}else if (appSettings.ProjectType.Equals("NPM", StringComparison.InvariantCultureIgnoreCase))
290+
{
291+
repoList = (appSettings.Npm?.Artifactory.InternalRepos ?? Array.Empty<string>())
292+
.Concat(appSettings.Npm?.Artifactory.DevRepos ?? Array.Empty<string>())
293+
.Concat(appSettings.Npm?.Artifactory.RemoteRepos ?? Array.Empty<string>())
294+
.Concat(appSettings.Npm?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty<string>())
295+
.ToArray();
296+
}
297+
else if (appSettings.ProjectType.Equals("NUGET", StringComparison.InvariantCultureIgnoreCase))
298+
{
299+
repoList = (appSettings.Nuget?.Artifactory.InternalRepos ?? Array.Empty<string>())
300+
.Concat(appSettings.Nuget?.Artifactory.DevRepos ?? Array.Empty<string>())
301+
.Concat(appSettings.Nuget?.Artifactory.RemoteRepos ?? Array.Empty<string>())
302+
.Concat(appSettings.Nuget?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty<string>())
303+
.ToArray();
304+
}
305+
else if (appSettings.ProjectType.Equals("POETRY", StringComparison.InvariantCultureIgnoreCase))
306+
{
307+
repoList = (appSettings.Poetry?.Artifactory.InternalRepos ?? Array.Empty<string>())
308+
.Concat(appSettings.Poetry?.Artifactory.DevRepos ?? Array.Empty<string>())
309+
.Concat(appSettings.Poetry?.Artifactory.RemoteRepos ?? Array.Empty<string>())
310+
.Concat(appSettings.Poetry?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty<string>())
311+
.ToArray();
312+
}
313+
else if (appSettings.ProjectType.Equals("DEBIAN", StringComparison.InvariantCultureIgnoreCase))
314+
{
315+
repoList = (appSettings.Debian?.Artifactory.InternalRepos ?? Array.Empty<string>())
316+
.Concat(appSettings.Debian?.Artifactory.DevRepos ?? Array.Empty<string>())
317+
.Concat(appSettings.Debian?.Artifactory.RemoteRepos ?? Array.Empty<string>())
318+
.Concat(appSettings.Debian?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty<string>())
319+
.ToArray();
320+
}
321+
else if (appSettings.ProjectType.Equals("MAVEN", StringComparison.InvariantCultureIgnoreCase))
322+
{
323+
repoList = (appSettings.Maven?.Artifactory.InternalRepos ?? Array.Empty<string>())
324+
.Concat(appSettings.Maven?.Artifactory.DevRepos ?? Array.Empty<string>())
325+
.Concat(appSettings.Maven?.Artifactory.RemoteRepos ?? Array.Empty<string>())
326+
.Concat(appSettings.Maven?.Artifactory.ThirdPartyRepos?.Select(repo => repo.Name) ?? Array.Empty<string>())
327+
.ToArray();
328+
}
329+
return repoList;
330+
}
305331

306332
#endregion
307333

@@ -316,6 +342,50 @@ private static string Sw360URL(string sw360Env, string releaseId)
316342
string sw360URL = $"{sw360Env}{"/group/guest/components/-/component/release/detailRelease/"}{releaseId}";
317343
return sw360URL;
318344
}
345+
private static List<Component> RemoveExcludedComponentsFromPurl(List<Component> ComponentList, List<string> ExcludedComponentsFromPurl, ref int noOfExcludedComponents)
346+
{
347+
List<Component> ExcludedList = new List<Component>();
348+
349+
foreach (string excludedComponent in ExcludedComponentsFromPurl)
350+
{
351+
foreach (var component in ComponentList)
352+
{
353+
if (component.Purl != null && component.Purl.Equals(excludedComponent, StringComparison.OrdinalIgnoreCase))
354+
{
355+
noOfExcludedComponents++;
356+
ExcludedList.Add(component);
357+
}
358+
}
359+
}
360+
361+
return ExcludedList;
362+
}
363+
364+
private static List<Component> RemoveOtherExcludedComponents(List<Component> ComponentList, List<string> otherExcludedComponents, ref int noOfExcludedComponents)
365+
{
366+
List<Component> ExcludedList = new List<Component>();
367+
368+
foreach (string excludedComponent in otherExcludedComponents)
369+
{
370+
string[] excludedcomponent = excludedComponent.ToLower().Split(':');
371+
foreach (var component in ComponentList)
372+
{
373+
string name = component.Name;
374+
if (!string.IsNullOrEmpty(component.Group) && (component.Group != component.Name))
375+
{
376+
name = $"{component.Group}/{component.Name}";
377+
}
378+
if (excludedcomponent.Length > 0 && (Regex.IsMatch(name.ToLowerInvariant(), WildcardToRegex(excludedcomponent[0].ToLowerInvariant()))) &&
379+
(component.Version.ToLowerInvariant().Contains(excludedcomponent[1].ToLowerInvariant()) || excludedcomponent[1].ToLowerInvariant() == "*"))
380+
{
381+
noOfExcludedComponents++;
382+
ExcludedList.Add(component);
383+
}
384+
}
385+
}
386+
387+
return ExcludedList;
388+
}
319389
#endregion
320390
}
321391
}

src/LCT.PackageIdentifier.UTest/BomHelperUnitTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,15 @@ public async Task GetRepoDetails_GivenProjectTypeAsNpm_ReturnsListOFComponents()
265265
Key = "npm.version",
266266
Value = "1"
267267
};
268-
List<AqlProperty> propertys = new List<AqlProperty> { npmNameProperty, npmVersionProperty };
268+
List<AqlProperty> npmAqlProperties = new List<AqlProperty> { npmNameProperty, npmVersionProperty };
269269
List<AqlResult> aqlResultList = new()
270270
{
271271
new()
272272
{
273273
Path="test/test",
274274
Name="Test-1.tgz",
275275
Repo="remote",
276-
Properties=propertys,
276+
Properties=npmAqlProperties,
277277
MD5="7654345676543",
278278
SHA256="65434567",
279279
SHA1="765434567654"

src/LCT.PackageIdentifier.UTest/ConanParserTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully()
203203
IFileOperations fileOperations = new FileOperations();
204204
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
205205
{
206+
ProjectType = "Conan",
206207
SW360 = new SW360(),
207208
Conan = new Config
208209
{
@@ -255,6 +256,7 @@ public async Task GetArtifactoryRepoName_Conan_ReturnsNotFound_ReturnsFailure()
255256
IFileOperations fileOperations = new FileOperations();
256257
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
257258
{
259+
ProjectType="Conan",
258260
SW360 = new SW360(),
259261
Conan = new Config
260262
{

src/LCT.PackageIdentifier.UTest/MavenParserTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully()
313313
IFileOperations fileOperations = new FileOperations();
314314
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
315315
{
316+
ProjectType = "Maven",
316317
SW360 = new SW360(),
317318
Maven = new Config
318319
{
@@ -364,6 +365,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData2_SuccessFully(
364365
IFileOperations fileOperations = new FileOperations();
365366
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
366367
{
368+
ProjectType = "Maven",
367369
SW360 = new SW360(),
368370
Maven = new Config
369371
{

src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully()
326326
IFileOperations fileOperations = new FileOperations();
327327
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
328328
{
329+
ProjectType = "NPM",
329330
SW360 = new SW360(),
330331
Npm = new Config
331332
{
@@ -390,6 +391,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData2_SuccessFully(
390391
IFileOperations fileOperations = new FileOperations();
391392
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
392393
{
394+
ProjectType = "NPM",
393395
SW360 = new SW360(),
394396
Npm = new Config
395397
{

src/LCT.PackageIdentifier.UTest/NugetParserTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully()
751751
IFileOperations fileOperations = new FileOperations();
752752
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
753753
{
754+
ProjectType = "NUGET",
754755
SW360 = new SW360(),
755756
Nuget = new Config
756757
{
@@ -802,6 +803,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_Nuget_ReturnsWithData2_Success
802803
IFileOperations fileOperations = new FileOperations();
803804
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
804805
{
806+
ProjectType = "NUGET",
805807
SW360 = new SW360(),
806808
Nuget = new Config
807809
{
@@ -853,6 +855,7 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_SuccessFully()
853855
IFileOperations fileOperations = new FileOperations();
854856
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
855857
{
858+
ProjectType = "NUGET",
856859
SW360 = new SW360(),
857860
Nuget = new Config
858861
{
@@ -904,6 +907,7 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_ReturnsFailure()
904907
IFileOperations fileOperations = new FileOperations();
905908
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
906909
{
910+
ProjectType = "NUGET",
907911
SW360 = new SW360(),
908912
Nuget = new Config
909913
{
@@ -955,6 +959,7 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_ReturnsSuccess()
955959
IFileOperations fileOperations = new FileOperations();
956960
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
957961
{
962+
ProjectType = "NUGET",
958963
SW360 = new SW360(),
959964
Nuget = new Config
960965
{
@@ -1007,6 +1012,7 @@ public async Task GetArtifactoryRepoName_Nuget_ReturnsNotFound_ReturnsFailure()
10071012
IFileOperations fileOperations = new FileOperations();
10081013
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
10091014
{
1015+
ProjectType = "NUGET",
10101016
SW360 = new SW360(),
10111017
Nuget = new Config
10121018
{

src/LCT.PackageIdentifier.UTest/PythonParserTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ public async Task GetJfrogRepoDetailsOfAComponentForPython_ReturnsWithData_Succe
359359
IFileOperations fileOperations = new FileOperations();
360360
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
361361
{
362+
ProjectType = "POETRY",
362363
SW360 = new SW360(),
363364
Poetry = new Config
364365
{
@@ -422,6 +423,7 @@ public async Task GetJfrogRepoDetailsOfAComponentForPython_ReturnsWithData2_Succ
422423
IFileOperations fileOperations = new FileOperations();
423424
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
424425
{
426+
ProjectType = "POETRY",
425427
SW360 = new SW360(),
426428
Poetry = new Config
427429
{

0 commit comments

Comments
 (0)