Skip to content

Commit 37ba9e9

Browse files
Sonarcube issues fix
1 parent efef9ff commit 37ba9e9

File tree

3 files changed

+61
-89
lines changed

3 files changed

+61
-89
lines changed

src/LCT.SW360PackageCreator/AlpinePackageDownloader.cs

+23-38
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public async Task<string> DownloadPackage(ComparisonBomData component, string lo
4242

4343
private static void CopyBuildFilesFromSourceRepo(string localPathforDownload, ComparisonBomData component, string sourceData, string localPathforSourceRepo)
4444
{
45-
if (sourceData!=null)
45+
if (sourceData != null)
4646
{
4747
string[] filenameList = sourceData.Split("\n");
4848
foreach (var name in filenameList)
@@ -58,7 +58,7 @@ private static void CopyBuildFilesFromSourceRepo(string localPathforDownload, Co
5858
}
5959
}
6060
}
61-
61+
6262
}
6363

6464
private static string GetCurrentDownloadFolderPath(string localPathforDownload, ComparisonBomData component)
@@ -97,10 +97,9 @@ private static async Task<string> DownloadTarFileAndGetPath(ComparisonBomData co
9797

9898
return downloadPath;
9999
}
100-
private static string ApplyPatchFilesToSourceCode(string downloadPath, string sourceData, string localPathforSourceRepo, ComparisonBomData component, string localPathforDownload)
100+
private static void ApplyPatchFilesToSourceCode(string downloadPath, string sourceData, string localPathforSourceRepo, ComparisonBomData component, string localPathforDownload)
101101
{
102102
string[] buildFilesList = sourceData.Split("\n");
103-
string directoryPath = string.Empty;
104103
string sourceCodezippedFolder = string.Empty;
105104

106105
if (sourceData.Contains(".patch") && (downloadPath.EndsWith(".gz") || downloadPath.EndsWith(".bz2")))
@@ -113,20 +112,17 @@ private static string ApplyPatchFilesToSourceCode(string downloadPath, string so
113112
sourceCodezippedFolder = directoriesOfSourceFolder[0];
114113
if (sourceData.Contains(".patch"))
115114
{
116-
var process = new Process
117-
{
118-
StartInfo = new ProcessStartInfo()
119-
{
120-
CreateNoWindow = true,
121-
FileName = "git",
122-
Arguments = "init",
123-
WorkingDirectory = sourceCodezippedFolder,
124-
}
125-
};
126-
process.Start();
127-
process.WaitForExit();
128-
}
115+
Process p = new Process();
116+
117+
p.StartInfo.CreateNoWindow = true;
118+
p.StartInfo.FileName = "git";
119+
p.StartInfo.Arguments = "init";
120+
p.StartInfo.WorkingDirectory = sourceCodezippedFolder;
129121

122+
p.Start();
123+
p.WaitForExit();
124+
125+
}
130126
foreach (var fileNames in buildFilesList)
131127
{
132128
var fileName = fileNames.Trim();
@@ -152,12 +148,7 @@ private static string ApplyPatchFilesToSourceCode(string downloadPath, string so
152148
Logger.Debug(ex.ToString());
153149
}
154150
}
155-
if (!sourceData.Contains(".patch"))
156-
{
157-
directoryPath = downloadPath;
158-
}
159151

160-
return directoryPath;
161152
}
162153

163154

@@ -178,7 +169,7 @@ public static void PackageFolderUnGzip(string localPathforDownload, ComparisonBo
178169
using (Stream sourceStream = new BZip2InputStream(tarFileInfo.OpenRead()))
179170
{
180171

181-
using (TarArchive tarArchive = TarArchive.CreateInputTarArchive(sourceStream,null))
172+
using (TarArchive tarArchive = TarArchive.CreateInputTarArchive(sourceStream, null))
182173
{
183174
tarArchive.ExtractContents(targetDirectory.FullName);
184175
}
@@ -215,14 +206,12 @@ public static void PackageFolderUnGzip(string localPathforDownload, ComparisonBo
215206

216207
public static string PackageFolderGzip(string localPathforDownload, ComparisonBomData component, string sourceCodezippedFolder)
217208
{
218-
219-
220209
string tarArchivePath;
221210
if (Directory.GetDirectories(localPathforDownload).Length != 0)
222211
{
223212

224213
var tempFolder = Directory.CreateDirectory($"{Directory.GetParent(Directory.GetCurrentDirectory())}\\ClearingTool\\DownloadedFiles\\SourceCodeZipped\\{component.Name}\\--{DateTime.Now.ToString("yyyyMMddHHmmss")}\\");
225-
tarArchivePath = tempFolder + (component.Name + "_" + component.Version) +".tar.gz";
214+
tarArchivePath = tempFolder + (component.Name + "_" + component.Version) + ".tar.gz";
226215
var InputDirectory = localPathforDownload;
227216
var OutputFilename = tarArchivePath;
228217
using Stream zipStream = new FileStream(System.IO.Path.GetFullPath(OutputFilename), FileMode.Create, FileAccess.Write);
@@ -257,18 +246,14 @@ private static string GetCorrectFileExtension(string sourceURL)
257246

258247
private static void ApplyPatchsToSourceCode(string patchFileFolder, string sourceCodezippedFolder)
259248
{
260-
var process = new Process
261-
{
262-
StartInfo = new ProcessStartInfo()
263-
{
264-
CreateNoWindow = true,
265-
FileName = "git",
266-
Arguments = $"apply" + " " + patchFileFolder,
267-
WorkingDirectory = sourceCodezippedFolder,
268-
}
269-
};
270-
process.Start();
271-
process.WaitForExit();
249+
Process p = new Process();
250+
p.StartInfo.CreateNoWindow = true;
251+
p.StartInfo.FileName = "git";
252+
p.StartInfo.Arguments = $"apply" + " " + patchFileFolder;
253+
p.StartInfo.WorkingDirectory = sourceCodezippedFolder;
254+
255+
p.Start();
256+
p.WaitForExit();
272257
}
273258
}
274259
}

src/LCT.SW360PackageCreator/CreatorHelper.cs

+4-9
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ public async Task<List<ComparisonBomData>> SetContentsForComparisonBOM(List<Comp
221221
mapper.DownloadUrl = item.DownloadUrl;
222222
mapper.ComponentStatus = GetComponentAvailabilityStatus(componentsAvailableInSw360, item);
223223
mapper.ReleaseStatus = IsReleaseAvailable(item.Name, item.Version, item.ReleaseExternalId);
224+
mapper.AlpineSource = item.AlpineSourceData;
224225
if (!string.IsNullOrEmpty(item.ReleaseExternalId) && item.ReleaseExternalId.Contains(Dataconstant.PurlCheck()["DEBIAN"]))
225226
{
226227
if ((string.IsNullOrEmpty(item.SourceUrl) || item.SourceUrl == Dataconstant.SourceUrlNotFound) && !string.IsNullOrEmpty(releasesInfo.SourceCodeDownloadUrl))
@@ -236,16 +237,10 @@ public async Task<List<ComparisonBomData>> SetContentsForComparisonBOM(List<Comp
236237
mapper.DownloadUrl = GetMavenDownloadUrl(mapper, item, releasesInfo);
237238
}
238239
else if (!string.IsNullOrEmpty(item.ReleaseExternalId) &&
239-
(item.ReleaseExternalId.Contains(Dataconstant.PurlCheck()["PYTHON"]) || item.ReleaseExternalId.Contains(Dataconstant.PurlCheck()["CONAN"])))
240+
(item.ReleaseExternalId.Contains(Dataconstant.PurlCheck()["PYTHON"]) || item.ReleaseExternalId.Contains(Dataconstant.PurlCheck()["CONAN"]) || item.ReleaseExternalId.Contains(Dataconstant.PurlCheck()["ALPINE"])))
240241
{
241-
mapper.DownloadUrl = mapper.SourceUrl;
242-
243-
}
244-
else if (!string.IsNullOrEmpty(item.ReleaseExternalId) && item.ReleaseExternalId.Contains(Dataconstant.PurlCheck()["ALPINE"]))
245-
{
246-
mapper.DownloadUrl = mapper.SourceUrl;
247-
mapper.AlpineSource = item.AlpineSourceData;
248-
}
242+
mapper.DownloadUrl = mapper.SourceUrl;
243+
}
249244
else
250245
{
251246
mapper.DownloadUrl = GetComponentDownloadUrl(mapper, item, repo, releasesInfo);

src/LCT.SW360PackageCreator/URLHelper.cs

+34-42
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public async Task<Components> GetSourceUrlForAlpinePackage(string componentName,
8787
componentsData.ReleaseExternalId = GetReleaseExternalIdForAlpine(alpinePackSourceDetails.Name, alpinePackSourceDetails.Version);
8888
componentsData.ComponentExternalId = GetComponentExternalIdForAlpine(alpinePackSourceDetails.Name);
8989
componentsData.SourceUrl = string.IsNullOrEmpty(alpinePackSourceDetails.SourceUrl) ? Dataconstant.SourceUrlNotFound : alpinePackSourceDetails.SourceUrl;
90-
componentsData.DownloadUrl = componentsData.SourceUrl.Equals(Dataconstant.SourceUrlNotFound) ? Dataconstant.DownloadUrlNotFound : componentsData.SourceUrl;
90+
componentsData.DownloadUrl = componentsData.SourceUrl.Equals(Dataconstant.SourceUrlNotFound) ? Dataconstant.DownloadUrlNotFound : componentsData.SourceUrl;
9191
}
9292
catch (IOException ex)
9393
{
@@ -117,7 +117,7 @@ private static Task<AlpinePackage> GetAlpineSourceUrl(string name, string versio
117117
if (File.Exists(pkgFilePath))
118118
{
119119
var sourceData = GetSourceFromAPKBUILD(localPathforSourceRepo, name);
120-
sourceURLDetails.SourceDataForAlpine=sourceData;
120+
sourceURLDetails.SourceDataForAlpine = sourceData;
121121
var sourceUrl = GetSourceUrlForAlpine(pkgFilePath, sourceData);
122122
if (sourceUrl.EndsWith(FileConstant.TargzFileExtension) || sourceUrl.EndsWith(FileConstant.XzFileExtension) || sourceUrl.EndsWith(FileConstant.TgzFileExtension) || sourceUrl.EndsWith(FileConstant.Bz2FileExtension))
123123
{
@@ -261,34 +261,28 @@ private static void CloneSource(string localPathforSourceRepo, string alpineDist
261261
{
262262
foreach (string command in gitCommands)
263263
{
264-
var process = new Process
265-
{
266-
StartInfo = new ProcessStartInfo()
267-
{
268-
CreateNoWindow = true,
269-
FileName = "git",
270-
Arguments = command,
271-
WorkingDirectory = localPathforSourceRepo,
272-
}
273-
};
274-
process.Start();
275-
process.WaitForExit();
264+
Process p = new Process();
265+
p.StartInfo.CreateNoWindow = true;
266+
p.StartInfo.FileName = "git";
267+
p.StartInfo.Arguments = command;
268+
p.StartInfo.WorkingDirectory = localPathforSourceRepo;
269+
270+
p.Start();
271+
p.WaitForExit();
272+
p.WaitForExit();
273+
276274
}
277275
}
278276
else
279277
{
280-
var process = new Process
281-
{
282-
StartInfo = new ProcessStartInfo()
283-
{
284-
CreateNoWindow = true,
285-
FileName = "git",
286-
Arguments = gitCommands[1],
287-
WorkingDirectory = localPathforSourceRepo,
288-
}
289-
};
290-
process.Start();
291-
process.WaitForExit();
278+
Process p = new Process();
279+
p.StartInfo.CreateNoWindow = true;
280+
p.StartInfo.FileName = "git";
281+
p.StartInfo.Arguments = gitCommands[1];
282+
p.StartInfo.WorkingDirectory = localPathforSourceRepo;
283+
284+
p.Start();
285+
p.WaitForExit();
292286
}
293287
if (Directory.Exists(fullPath))
294288
{
@@ -299,18 +293,16 @@ private static void CloneSource(string localPathforSourceRepo, string alpineDist
299293

300294
private static void CheckoutDistro(string alpineDistro, string fullPath)
301295
{
302-
var process = new Process
303-
{
304-
StartInfo = new ProcessStartInfo()
305-
{
306-
CreateNoWindow = true,
307-
FileName = "git",
308-
Arguments = $"checkout" + " " + alpineDistro,
309-
WorkingDirectory = fullPath,
310-
}
311-
};
312-
process.Start();
313-
process.WaitForExit();
296+
297+
Process p = new Process();
298+
p.StartInfo.CreateNoWindow = true;
299+
p.StartInfo.FileName = "git";
300+
p.StartInfo.Arguments = $"checkout" + " " + alpineDistro;
301+
p.StartInfo.WorkingDirectory = fullPath;
302+
303+
p.Start();
304+
p.WaitForExit();
305+
314306
}
315307

316308
private static List<string> GetGitCloneCommands()
@@ -432,14 +424,14 @@ public string GetSourceUrlForNpmPackage(string componentName, string version)
432424
/// <param name="componentName"></param>
433425
/// <param name="version"></param>
434426
/// <returns>string</returns>
435-
public async Task<string> GetSourceUrlForConanPackage(string componentName, string componenVersion)
427+
public async Task<string> GetSourceUrlForConanPackage(string componentName, string componenVersion)
436428
{
437429

438430
var downLoadUrl = $"{CommonAppSettings.SourceURLConan}" + componentName + "/all/conandata.yml";
439431
var deserializer = new DeserializerBuilder().WithNamingConvention(UnderscoredNamingConvention.Instance).Build();
440432
string componentSrcURL = string.Empty;
441-
Sources packageSourcesInfo=new Sources();
442-
using (HttpClient _httpClient=new HttpClient())
433+
Sources packageSourcesInfo = new Sources();
434+
using (HttpClient _httpClient = new HttpClient())
443435
{
444436
try
445437
{
@@ -467,7 +459,7 @@ public async Task<string> GetSourceUrlForConanPackage(string componentName, stri
467459
$"Exclude if it is an internal component or manually update the SRC url");
468460
Logger.Debug($"GetSourceUrlForConanPackage()", ex);
469461
}
470-
catch(YamlException ex)
462+
catch (YamlException ex)
471463
{
472464
Logger.Warn($"Identification of SRC url failed for {componentName}, " +
473465
$"Exclude if it is an internal component or manually update the SRC url");

0 commit comments

Comments
 (0)