Skip to content

Commit a022cda

Browse files
committed
sonar issues fix
1 parent 9c3d208 commit a022cda

File tree

7 files changed

+31
-30
lines changed

7 files changed

+31
-30
lines changed

src/ArtifactoryUploader/Constants/ArtifactoryConstant.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static class ArtifactoryConstant
1717
#region Fields
1818

1919
public const string Log4netArtifactoryUploaderConfigFileName = "log4netArtifactoryUploader.config";
20-
20+
public const string Cargo = "cargo";
2121
#endregion
2222
}
2323
}

src/ArtifactoryUploader/UploadToArtifactory.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
// Ignore Spelling: Jfrog
88

9+
using ArtifactoryUploader.Constants;
910
using CycloneDX.Models;
1011
using LCT.APICommunications;
1112
using LCT.APICommunications.Model;
@@ -36,6 +37,7 @@ public static class UploadToArtifactory
3637
private const string Conan = "CONAN";
3738
private const string Cargo = "CARGO";
3839
private const string Debian = "DEBIAN";
40+
private const string NPM = "NPM";
3941

4042
#endregion
4143

@@ -150,7 +152,7 @@ private static string GetComponentType(Component item)
150152
}
151153
if (item.Purl.Contains("npm", StringComparison.OrdinalIgnoreCase))
152154
{
153-
return "NPM";
155+
return NPM;
154156
}
155157
else if (item.Purl.Contains("nuget", StringComparison.OrdinalIgnoreCase))
156158
{
@@ -172,7 +174,7 @@ private static string GetComponentType(Component item)
172174
{
173175
return Debian;
174176
}
175-
else if (item.Purl.Contains("cargo", StringComparison.OrdinalIgnoreCase))
177+
else if (item.Purl.Contains(ArtifactoryConstant.Cargo, StringComparison.OrdinalIgnoreCase))
176178
{
177179
return Cargo;
178180
}
@@ -191,7 +193,7 @@ private static string GetComponentType(Component item)
191193
public static string GetJfrogRepPath(ComponentsToArtifactory component)
192194
{
193195
string jfrogRepPath = string.Empty;
194-
if (component.ComponentType == "NPM")
196+
if (component.ComponentType == NPM)
195197
{
196198
jfrogRepPath = $"{component.DestRepoName}/{component.Path}/{component.PypiOrNpmCompName}";
197199
}
@@ -255,7 +257,7 @@ private static string GetDestinationRepo(Component item, CommonAppSettings appSe
255257
return GetRepoName(packageType, appSettings.Conan.ReleaseRepo, appSettings.Conan.DevDepRepo, appSettings.Conan.Artifactory.ThirdPartyRepos.FirstOrDefault(x => x.Upload)?.Name);
256258
case "debian":
257259
return GetRepoName(packageType, appSettings.Debian.ReleaseRepo, appSettings.Debian.DevDepRepo, appSettings.Debian.Artifactory.ThirdPartyRepos.FirstOrDefault(x => x.Upload)?.Name);
258-
case "cargo":
260+
case ArtifactoryConstant.Cargo:
259261
return GetRepoName(packageType, appSettings.Cargo.ReleaseRepo, appSettings.Cargo.DevDepRepo, appSettings.Cargo.Artifactory.ThirdPartyRepos.FirstOrDefault(x => x.Upload)?.Name);
260262
}
261263
}
@@ -273,7 +275,7 @@ private static string GetPackagePath(ComponentsToArtifactory component, AqlResul
273275
{
274276
switch (component.ComponentType)
275277
{
276-
case "NPM":
278+
case NPM:
277279
if (aqlResult != null)
278280
{
279281
return $"{aqlResult.Path}";
@@ -317,7 +319,7 @@ private static string GetPackagePath(ComponentsToArtifactory component, AqlResul
317319
public static string GetCopyURL(ComponentsToArtifactory component)
318320
{
319321
string url = string.Empty;
320-
if (component.ComponentType == "NPM")
322+
if (component.ComponentType == NPM)
321323
{
322324
url = $"{component.JfrogApi}{ApiConstant.CopyPackageApi}{component.SrcRepoPathWithFullName}" +
323325
$"?to=/{component.DestRepoName}/{component.Path}/{component.PypiOrNpmCompName}";
@@ -371,7 +373,7 @@ public static string GetCopyURL(ComponentsToArtifactory component)
371373
public static string GetMoveURL(ComponentsToArtifactory component)
372374
{
373375
string url = string.Empty;
374-
if (component.ComponentType == "NPM")
376+
if (component.ComponentType == NPM)
375377
{
376378
url = $"{component.JfrogApi}{ApiConstant.MovePackageApi}{component.SrcRepoPathWithFullName}" +
377379
$"?to=/{component.DestRepoName}/{component.Path}/{component.PypiOrNpmCompName}";
@@ -426,7 +428,7 @@ private static string GetJfrogPackageName(ComponentsToArtifactory component)
426428
{
427429
return component.ComponentType switch
428430
{
429-
"NPM" => component.PypiOrNpmCompName,
431+
NPM => component.PypiOrNpmCompName,
430432
Nuget => $"{component.PackageName}.{component.Version}{ApiConstant.NugetExtension}",
431433
Choco => $"{component.PackageName}.{component.Version}{ApiConstant.NugetExtension}",
432434
Debian => $"{component.PackageName}_{component.Version.Replace(ApiConstant.DebianExtension, "") + "*"}",
@@ -465,7 +467,7 @@ private static void AddUnknownComponentToDisplayList(string projectType, Compone
465467
{
466468
switch (projectType)
467469
{
468-
case "NPM":
470+
case NPM:
469471
displayPackagesInfo.UnknownPackagesNpm.Add(component);
470472
break;
471473
case Nuget:
@@ -566,9 +568,9 @@ public async static Task<AqlResult> GetSrcRepoDetailsForComponent(Component item
566568
return GetArtifactoryRepoName(aqlResultList, item);
567569
}
568570
}
569-
else if (item.Purl.Contains("cargo", StringComparison.OrdinalIgnoreCase))
571+
else if (item.Purl.Contains(ArtifactoryConstant.Cargo, StringComparison.OrdinalIgnoreCase))
570572
{
571-
var aqlResultList = await GetPackageTypeBased_ListOfComponentsFromRepo(new string[] { item.Properties.Find(x => x.Name == Dataconstant.Cdx_ArtifactoryRepoName)?.Value }, JFrogService, "cargo");
573+
var aqlResultList = await GetPackageTypeBased_ListOfComponentsFromRepo(new string[] { item.Properties.Find(x => x.Name == Dataconstant.Cdx_ArtifactoryRepoName)?.Value }, JFrogService, ArtifactoryConstant.Cargo);
572574

573575
if (aqlResultList.Count > 0)
574576
{
@@ -605,7 +607,7 @@ public static async Task<List<AqlResult>> GetPackageTypeBased_ListOfComponentsFr
605607
repoCache[repo] = componentRepoData;
606608
aqlResultList.AddRange(componentRepoData);
607609
}
608-
else if (packageType == "cargo")
610+
else if (packageType == ArtifactoryConstant.Cargo)
609611
{
610612
var componentRepoData = await jFrogService.GetCargoComponentDataByRepo(repo) ?? new List<AqlResult>();
611613
repoCache[repo] = componentRepoData;
@@ -666,7 +668,7 @@ private static AqlResult GetArtifactoryRepoName(List<AqlResult> aqlResultList, C
666668
x.Properties.Any(p => p.Key == "npm.name" && p.Value == jfrogpackageName) &&
667669
x.Properties.Any(p => p.Key == "npm.version" && p.Value == component.Version));
668670
}
669-
else if (component.Purl.Contains("cargo", StringComparison.OrdinalIgnoreCase))
671+
else if (component.Purl.Contains(ArtifactoryConstant.Cargo, StringComparison.OrdinalIgnoreCase))
670672
{
671673
return aqlResultList.Find(x => x.Properties != null &&
672674
x.Properties.Any(p => p.Key == "crate.name" && p.Value == jfrogpackageName) &&

src/LCT.Common/Logging/LoggerHelper.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static class LoggerHelper
3333
private const string BlueVersionMarkup = "[blue]Version[/]";
3434
private const string GreenNameMarkup = "[green]Name[/]";
3535
private const string YellowColor = "yellow";
36+
private const string ComponentVersion = "version";
3637
private static readonly Dictionary<string, string> _colorCache = new Dictionary<string, string>();
3738
private static int _colorIndex = 0;
3839

@@ -411,7 +412,7 @@ public static void WriteComponentsNotLinkedListInConsole(List<Components> compon
411412
return;
412413
}
413414
const string Name = "Name";
414-
const string Version = "Version";
415+
const string Version = ComponentVersion;
415416

416417
if (components.Count > 0)
417418
{
@@ -448,7 +449,7 @@ public static void WriteComponentsWithoutDownloadURLToKpi(List<ComparisonBomData
448449
}
449450

450451
const string Name = "Name";
451-
const string Version = "Version";
452+
const string Version = ComponentVersion;
452453
const string URL = "SW360 Release URL";
453454
if (componentInfo.Count > 0 || lstReleaseNotCreated.Count > 0 || DuplicateComponentsByPurlId.Count > 0)
454455
{
@@ -1561,7 +1562,7 @@ public static void WriteInternalComponentsListTableToKpi(List<Component> interna
15611562
public static void WriteInternalComponentsListToKpi(List<Component> internalComponents)
15621563
{
15631564
const string Name = "Name";
1564-
const string Version = "Version";
1565+
const string Version = ComponentVersion;
15651566

15661567
if (internalComponents?.Count > 0)
15671568
{
@@ -1782,7 +1783,7 @@ private static void LogDuplicateComponentsByPurlId(List<Components> duplicateCom
17821783
string separator = new string('-', totalWidth);
17831784

17841785
Logger.Logger.Log(null, Level.Alert, border, null);
1785-
Logger.Logger.Log(null, Level.Alert, string.Format("| {0,-45} | {1,-25} | {2,-120} |", "Name", "Version", "SW360 Component URL"), null);
1786+
Logger.Logger.Log(null, Level.Alert, string.Format("| {0,-45} | {1,-25} | {2,-120} |", "Name", ComponentVersion, "SW360 Component URL"), null);
17861787
Logger.Logger.Log(null, Level.Alert, border, null);
17871788

17881789
foreach (var item in duplicateComponents)

src/LCT.PackageIdentifier/DotnetRuntimeIdentifer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ private static void WriteDetailLog(RuntimeInfo info)
378378
{
379379
Logger.ErrorFormat("Error: {0}", info.ErrorMessage);
380380
if (!string.IsNullOrEmpty(info.ErrorDetails))
381-
Logger.Error($"Details: {info.ErrorDetails}");
381+
Logger.ErrorFormat("Details: {0}", info.ErrorDetails);
382382
Logger.Debug("----- .NET Runtime Information Summary End -----");
383383
return;
384384
}

src/LCT.PackageIdentifier/NugetProcessor.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,13 +1331,12 @@ private List<string> GetUniqueTargetFrameworkKeysForConfigFile(string configFile
13311331
{
13321332
var targetFramework = target.TargetFramework;
13331333
var frameworkReferences = _frameworkPackages.GetFrameworkReferences(lockFile, target);
1334-
foreach (var framework in frameworkReferences)
1335-
{
1336-
if (!uniqueKeys.Contains(targetFramework + "-" + framework))
1337-
{
1338-
uniqueKeys.Add(targetFramework + "-" + framework);
1339-
}
1340-
}
1334+
1335+
var newKeys = frameworkReferences
1336+
.Where(framework => !uniqueKeys.Contains(targetFramework + "-" + framework))
1337+
.Select(framework => targetFramework + "-" + framework);
1338+
1339+
uniqueKeys.AddRange(newKeys);
13411340
}
13421341
}
13431342
catch (IOException ex)

src/LCT.PackageIdentifier/PemSignatureVerifier.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ public static bool ValidatePem(string documentPath, string signaturePath, string
7777
catch (FormatException ex)
7878
{
7979
Logger.DebugFormat("Error loading PEM content: {0}", ex.Message);
80-
Logger.Debug("Attempting to load as public key...");
80+
Logger.Debug("Attempting to load as public key...",ex);
8181
return ValidateSignedFileFromPublicKey(documentPath, signaturePath, pemFilePath);
8282
}
8383
//IF System.Security.Cryptography.CryptographicException is thrown, it indicates that the PEM content is not a valid certificate.
8484
catch (CryptographicException ex)
8585
{
8686
Logger.DebugFormat("Error loading as certificate: {0}", ex.Message);
87-
Logger.Debug("Attempting to load as public key...");
87+
Logger.Debug("Attempting to load as public key...",ex);
8888
return ValidateSignedFileFromPublicKey(documentPath, signaturePath, pemFilePath);
8989
}
9090
}

src/LCT.Services/Sw360CreatorService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,7 @@ public async Task<bool> LinkReleasesToProject(List<ReleaseLinked> releasesTobeLi
346346
}
347347
else
348348
{
349-
Logger.Debug("Duplicate entries found in finalReleasesToBeLinked: " + release.Name + ":" + release.ReleaseId +
350-
" , with :" + value.Name + ":" + value.ReleaseId);
349+
Logger.DebugFormat("Duplicate entries found in finalReleasesToBeLinked: {0}:{1} , with :{2}:{3}",release.Name, release.ReleaseId, value.Name, value.ReleaseId);
351350
}
352351
}
353352

0 commit comments

Comments
 (0)