Skip to content

Commit

Permalink
Sonar Chnages
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumanth K B committed Sep 27, 2023
1 parent 7e4e7e1 commit 8a26864
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 48 deletions.
53 changes: 31 additions & 22 deletions src/LCT.PackageIdentifier/NugetDevDependencyParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static NugetDevDependencyParser Instance
}
}

public List<Container> Parse(string configFile)
public static List<Container> Parse(string configFile)
{
List<Container> containerList = new();

Expand Down Expand Up @@ -132,27 +132,8 @@ private static void ParseJsonFile(string filePath, Container container)
}
else
{
string csprojFilePath = "";
string dirName = Path.GetDirectoryName(filePath);
if (dirName.Contains("obj"))
{
dirName = dirName.Replace("obj", "");
string[] filePaths = Directory.GetFiles(dirName, "*.csproj");
csprojFilePath = filePaths.Length > 0 ? filePaths[0] : "";
}
if(!string.IsNullOrEmpty(csprojFilePath) && File.Exists(csprojFilePath))
{
Logger.Debug($"ParseJsonFile():Linux Asset FileName: " + csprojFilePath);
isTestProject = IsTestProject(csprojFilePath);
container.Name = Path.GetFileName(csprojFilePath);
Logger.Debug($"ParseJsonFile():Linux Asset File: IsTestProject: " + isTestProject);
}
else
{
Logger.Debug($"ParseJsonFile():Linux Asset FileName Not Found!! ");
isTestProject = false;
container.Name = Path.GetFileName(filePath);
}
//when it's running as container
isTestProject = ParseJsonInContainer(filePath, ref container);
}

if (isTestProject)
Expand All @@ -179,6 +160,34 @@ private static void ParseJsonFile(string filePath, Container container)
}
}

private static bool ParseJsonInContainer(string filePath, ref Container container)
{
bool isTestProject;
string csprojFilePath = "";
string dirName = Path.GetDirectoryName(filePath);
if (dirName.Contains("obj"))
{
dirName = dirName.Replace("obj", "");
string[] filePaths = Directory.GetFiles(dirName, "*.csproj");
csprojFilePath = filePaths.Length > 0 ? filePaths[0] : "";
}
if (!string.IsNullOrEmpty(csprojFilePath) && File.Exists(csprojFilePath))
{
Logger.Debug($"ParseJsonFile():Linux Asset FileName: " + csprojFilePath);
isTestProject = IsTestProject(csprojFilePath);
container.Name = Path.GetFileName(csprojFilePath);
Logger.Debug($"ParseJsonFile():Linux Asset File: IsTestProject: " + isTestProject);
}
else
{
Logger.Debug($"ParseJsonFile():Linux Asset FileName Not Found!! ");
isTestProject = false;
container.Name = Path.GetFileName(filePath);
}

return isTestProject;
}

private static void ParseLibrary(LockFileTargetLibrary library, bool isTestProject, IDictionary<string, BuildInfoComponent> components, LockFile assetFile)
{
if (library.Type.Equals("project", StringComparison.InvariantCultureIgnoreCase))
Expand Down
2 changes: 1 addition & 1 deletion src/LCT.PackageIdentifier/NugetProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ private static string ReferenceTagDetailsForPackageReference(XmlNode childNode,
private static List<NugetPackage> ParseAssetFile(string configFile)
{
NugetDevDependencyParser nugetDevDependencyParser = NugetDevDependencyParser.Instance;
List<Container> containers = nugetDevDependencyParser.Parse(configFile);
List<Container> containers = NugetDevDependencyParser.Parse(configFile);
return ConvertContainerAsNugetPackage(containers, configFile);
}

Expand Down
52 changes: 29 additions & 23 deletions src/LCT.PackageIdentifier/PythonProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using CycloneDX.Models;
using LCT.APICommunications;
using LCT.APICommunications.Model;
using LCT.APICommunications.Model.AQL;
using LCT.Common;
using LCT.Common.Constants;
Expand Down Expand Up @@ -88,7 +89,7 @@ public static List<PythonPackage> ExtractDetailsForPoetryLockfile(string filePat
PythonPackages = PoetrySetOfCmds(filePath, dependencies);
return PythonPackages;
}

private List<PythonPackage> ExtractDetailsFromJson(string filePath, CommonAppSettings appSettings, ref List<Dependency> dependencies)
{
List<PythonPackage> PythonPackages = new List<PythonPackage>();
Expand Down Expand Up @@ -328,30 +329,10 @@ private static Dependency GetDependenciesDetails(Result result, PythonPackage ma
{
var details = result.StdOut;
List<string> lines = details.Split(Environment.NewLine).ToList();
bool addDependencies = false;
List<string> dependencyList = new List<string>();

foreach (string line in lines)
{
if (line == "dependencies")
{
addDependencies = true;
continue;
}

if (addDependencies && !string.IsNullOrEmpty(line))
{
string comp = line;
comp = comp.Replace(" - ", "");
dependencyList.Add(comp.Split(" ")[0]);
}

if (string.IsNullOrEmpty(line))
addDependencies = false;
}
List<string> dependencyList = GetDetailsFromLines(lines);
dependency = GetDependencyMappings(mainComp, dependencyList, AllComps);
}
else if(result != null && result.StdOut.Contains("name"))
else if (result != null && result.StdOut.Contains("name"))
{
return new Dependency()
{
Expand All @@ -366,6 +347,31 @@ private static Dependency GetDependenciesDetails(Result result, PythonPackage ma
return dependency;
}

private static List<string> GetDetailsFromLines(List<string> lines)
{
bool addDependencies = false;
List<string> dependencyList = new List<string>();
foreach (string line in lines)
{
if (line == "dependencies")
{
addDependencies = true;
continue;
}

if (addDependencies && !string.IsNullOrEmpty(line))
{
string comp = line;
comp = comp.Replace(" - ", "");
dependencyList.Add(comp.Split(" ")[0]);
}

if (string.IsNullOrEmpty(line))
addDependencies = false;
}
return dependencyList;
}

private static Dependency GetDependencyMappings(PythonPackage mainComp, List<string> dependencyList, List<PythonPackage> AllComps)
{
List<Dependency> subDependencies = new();
Expand Down
4 changes: 2 additions & 2 deletions src/LCT.SW360PackageCreator/URLHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public async Task<string> GetSourceUrlForPythonPackage(string componentName, str
private async Task<string> GetResponseFromPyPiOrg(string componentName, string componenVersion)
{
string URL;
string result = "";
const string result = "";
try
{
URL = $"{CommonAppSettings.PyPiURL}{componentName}" +
Expand All @@ -480,7 +480,7 @@ private async Task<string> GetResponseFromPyPiOrg(string componentName, string c
return result;
}

private string GetSourceURLFromPyPiResponse(string response)
private static string GetSourceURLFromPyPiResponse(string response)
{
string SourceURL = "";

Expand Down

0 comments on commit 8a26864

Please sign in to comment.