Skip to content

Commit

Permalink
Exit code update
Browse files Browse the repository at this point in the history
  • Loading branch information
Viji committed Aug 6, 2024
1 parent d7ed7f1 commit 554eb9f
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/ArtifactoryUploader/PackageUploadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ public static async Task UploadingThePackages(List<ComponentsToArtifactory> comp
if (SetWarningCode)
{
CommonHelper.PublishFilesToArtifact();
Environment.Exit(2);
Environment.ExitCode = 2;
Logger.Debug("Setting ExitCode to 2");
}

Expand Down
2 changes: 1 addition & 1 deletion src/ArtifactoryUploader/PackageUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static async Task UploadPackageToArtifactory(CommonAppSettings appSetting
if (uploaderKpiData.PackagesNotUploadedDueToError > 0 || uploaderKpiData.PackagesNotExistingInRemoteCache > 0)
{
CommonHelper.PublishFilesToArtifact();
Environment.Exit(2);
Environment.ExitCode = 2;
Logger.Debug("Setting ExitCode to 2");
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/LCT.Common/CommonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static void WriteComponentsWithoutDownloadURLToKpi(List<ComparisonBomData
{
Logger.Logger.Log(null, Level.Alert, "Action Item required by the user:\n", null);
PublishFilesToArtifact();
Environment.Exit(2);
Environment.ExitCode = 2;
}

if (componentInfo.Count > 0)
Expand Down Expand Up @@ -204,7 +204,7 @@ public static void WriteComponentsNotLinkedListInConsole(List<Components> compon
if (components.Count > 0)
{
PublishFilesToArtifact();
Environment.Exit(2);
Environment.ExitCode = 2;
Logger.Logger.Log(null, Level.Alert, "* Components Not linked to project :", null);
Logger.Logger.Log(null, Level.Alert, " Can be linked manually OR Check the Logs AND RE-Run", null);
Logger.Logger.Log(null, Level.Alert, $"{"=",5}{string.Join("", Enumerable.Repeat("=", 98)),5}", null);
Expand Down
15 changes: 10 additions & 5 deletions src/LCT.Common/FileOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ public Bom CombineComponentsFromExistingBOM(Bom components, string filePath)
}
catch (IOException e)
{
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error($"Error:Invalid path entered,Please check if the comparison BOM path entered is correct", e);
}
catch (UnauthorizedAccessException e)
{
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error($"Error:Invalid path entered,Please check if the comparison BOM path entered is correct", e);
}
return comparisonData;
Expand Down Expand Up @@ -225,17 +227,20 @@ private static void BackupTheGivenFile(string folderPath, string fileName)
catch (IOException ex)
{
Logger.Error($"Error occurred while generating backup BOM file", ex);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
}
catch (NotSupportedException ex)
{
Logger.Error($"Error occurred while generating backup BOM file", ex);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
}
catch (UnauthorizedAccessException ex)
{
Logger.Error($"Error occurred while generating backup BOM file", ex);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/LCT.Common/FolderAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ public bool CopyToTargetDirectory(string sourceDirectory, string targetDirectory
catch (IOException ex)
{
isCopied = false;
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error("FolderAction.CopyToTargetDirectory():", ex);
}
catch (SecurityException ex)
{
isCopied = false;
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error("FolderAction.CopyToTargetDirectory():", ex);
}

Expand Down
1 change: 0 additions & 1 deletion src/LCT.Common/Logging/Log4net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public static void Init(string logFileName, string logFolder, bool verbose)
{
LoggerRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(LoggerRepository, new FileInfo(GetDefaultLogConfigFile()));
string outPath = Directory.GetParent(Directory.GetCurrentDirectory()).FullName;
string logPath = CatoolLogPath = Path.Combine(CatoolCurrentDirectory, logFolder, logFileName);

if (LoggerRepository is Hierarchy rootRepo)
Expand Down
1 change: 0 additions & 1 deletion src/LCT.PackageIdentifier/BomHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ public async Task<List<AqlResult>> GetListOfComponentsFromRepo(string[] repoList
return aqlResultList;
}


#endregion
}
}
9 changes: 6 additions & 3 deletions src/LCT.PackageIdentifier/ConanProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,20 @@ private static List<Component> ParsePackageLockJson(string filepath, ref List<De
}
catch (JsonReaderException ex)
{
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error($"ParsePackageFile():", ex);
}
catch (IOException ex)
{
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error($"ParsePackageFile():", ex);
}
catch (SecurityException ex)
{
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error($"ParsePackageFile():", ex);
}

Expand Down
9 changes: 6 additions & 3 deletions src/LCT.PackageIdentifier/NpmProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,20 @@ public List<Component> ParsePackageLockJson(string filepath, CommonAppSettings a
}
catch (JsonReaderException ex)
{
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error($"ParsePackageFile():", ex);
}
catch (IOException ex)
{
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error($"ParsePackageFile():", ex);
}
catch (SecurityException ex)
{
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error($"ParsePackageFile():", ex);
}

Expand Down
3 changes: 2 additions & 1 deletion src/LCT.SW360PackageCreator/ComponentCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ private void AddReleaseIdToLink(ComparisonBomData item, string releaseIdToLink)
}
else
{
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Fatal($"Linking release to the project is failed. " +
$"Release version - {item.Version} not found under this component - {item.Name}. ");
Logger.Error($"Linking release to the project is failed. " +
Expand Down
3 changes: 2 additions & 1 deletion src/LCT.SW360PackageCreator/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ string IRepository.IdentifyRepoURLForGit(string url, string componentName)
}
catch (ArgumentOutOfRangeException ex)
{
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error($"Repository.IdentifyRepoURLForGitHub():{componentName}-{url}", ex);
}

Expand Down
6 changes: 4 additions & 2 deletions src/LCT.Services/Sw360CommonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,14 @@ public async Task<string> GetReleaseIdByComponentId(string componentId, string c
catch (HttpRequestException e)
{
Logger.Error("GetReleaseIdByComponentId():", e);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
}
catch (AggregateException e)
{
Logger.Error("GetReleaseIdByComponentId():", e);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
}

return releaseId;
Expand Down
45 changes: 30 additions & 15 deletions src/LCT.Services/Sw360CreatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public async Task<ComponentCreateStatus> CreateComponentBasesOFswComaprisonBOM(
{
componentCreateStatus.IsCreated = false;
componentCreateStatus.ReleaseStatus.IsCreated = false;
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Debug($"CreateComponent():Component Name -{componentInfo.Name}- " +
$"response status code-{response.StatusCode} and reason pharase-{response.ReasonPhrase}");
Logger.Error($"CreateComponent():Component Name -{componentInfo.Name}- " +
Expand All @@ -96,7 +97,8 @@ public async Task<ComponentCreateStatus> CreateComponentBasesOFswComaprisonBOM(
catch (HttpRequestException e)
{
Logger.Error($"CreateComponent():", e);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
componentCreateStatus.IsCreated = false;
componentCreateStatus.ReleaseStatus.IsCreated = false;
}
Expand Down Expand Up @@ -179,7 +181,8 @@ public async Task<ReleaseCreateStatus> CreateReleaseForComponent(ComparisonBomDa
else
{
createStatus.IsCreated = false;
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Debug($"CreateReleaseForComponent():Component Name -{componentInfo.Name}{componentInfo.Version}- " +
$"response status code-{response.StatusCode} and reason pharase-{response.ReasonPhrase}");
Logger.Error($"CreateReleaseForComponent():Component Name -{componentInfo.Name}{componentInfo.Version}- " +
Expand All @@ -192,7 +195,8 @@ public async Task<ReleaseCreateStatus> CreateReleaseForComponent(ComparisonBomDa
catch (HttpRequestException e)
{
Logger.Error($"CreateReleaseForComponent():", e);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
createStatus.IsCreated = false;
}
return createStatus;
Expand Down Expand Up @@ -301,7 +305,8 @@ public async Task<bool> LinkReleasesToProject(List<ReleaseLinked> releasesTobeLi
var response = await m_SW360ApiCommunicationFacade.LinkReleasesToProject(content, sw360ProjectId);
if (!response.IsSuccessStatusCode)
{
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error($"LinkReleasesToProject() : Linking releases to project Id {sw360ProjectId} is failed.");
return false;
}
Expand All @@ -310,13 +315,15 @@ public async Task<bool> LinkReleasesToProject(List<ReleaseLinked> releasesTobeLi
catch (HttpRequestException ex)
{
Logger.Error($"LinkReleasesToProject():", ex);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
return false;
}
catch (AggregateException ex)
{
Logger.Error($"LinkReleasesToProject():", ex);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
return false;
}
}
Expand All @@ -332,7 +339,8 @@ public async Task<string> GetReleaseIDofComponent(string componentName, string c
catch (HttpRequestException e)
{
Logger.Error("GetReleaseIDofComponent():", e);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
}

if (string.IsNullOrEmpty(releaseIdOfComponent))
Expand All @@ -354,7 +362,8 @@ public async Task<string> GetReleaseIdByName(string componentName, string compon
catch (HttpRequestException e)
{
Logger.Error("GetReleaseIdByName():", e);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
}

if (string.IsNullOrEmpty(releaseid))
Expand Down Expand Up @@ -402,12 +411,14 @@ public async Task<string> GetComponentId(string componentName)
catch (HttpRequestException e)
{
Logger.Error($"GetComponentId():", e);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
}
catch (AggregateException e)
{
Logger.Error($"GetComponentId():", e);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
}
return ComponentId;
}
Expand Down Expand Up @@ -463,13 +474,15 @@ public async Task<bool> UpdatePurlIdForExistingComponent(ComparisonBomData cbomD
catch (HttpRequestException ex)
{
Logger.Error($"UpdateExternalIdForRelease(): {ex}");
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
return false;
}
catch (AggregateException ex)
{
Logger.Error($"UpdateExternalIdForRelease(): {ex}");
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
return false;
}
}
Expand Down Expand Up @@ -574,13 +587,15 @@ public async Task<bool> UpdatePurlIdForExistingRelease(ComparisonBomData cbomDat
catch (HttpRequestException ex)
{
Logger.Error($"UpdateExternalIdForRelease(): {ex}");
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
return false;
}
catch (AggregateException ex)
{
Logger.Error($"UpdateExternalIdForRelease(): {ex}");
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
return false;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/LCT.Services/Sw360ProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ public async Task<string> GetProjectNameByProjectIDFromSW360(string projectId, s
{
Logger.Error($"Failed to connect SW360 : {ex.Message}");
Logger.Debug($"GetProjectNameByProjectIDFromSW360()", ex);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
}
catch (AggregateException ex)
{
Logger.Error($"Failed to connect SW360 : {ex.Message}");
Logger.Debug($"GetProjectNameByProjectIDFromSW360()", ex);
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
}

return sw360ProjectName;
Expand Down
9 changes: 6 additions & 3 deletions src/LCT.Services/Sw360Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public async Task<ReleasesInfo> GetReleaseDataOfComponent(string releaseLink)
}
catch (AggregateException e)
{
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error($"GetComponentsClearingStatus():", e);
}

Expand All @@ -127,7 +128,8 @@ public async Task<HttpResponseMessage> GetReleaseInfoByReleaseId(string releaseL
}
catch (HttpRequestException ex)
{
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error($"GetReleaseInfoByReleaseId():", ex);
}

Expand Down Expand Up @@ -364,7 +366,8 @@ private async Task<IList<Sw360Components>> GetAvailableComponenentsListFromSw360
}
catch (HttpRequestException ex)
{
CommonHelper.CallEnvironmentExit(-1);
CommonHelper.PublishFilesToArtifact();
Environment.ExitCode = -1;
Logger.Error($"GetAvailableComponenentsListFromSw360():", ex);
}
return componentsList;
Expand Down

0 comments on commit 554eb9f

Please sign in to comment.