diff --git a/src/ArtifactoryUploader/Program.cs b/src/ArtifactoryUploader/Program.cs index 7a69617d..5c362835 100644 --- a/src/ArtifactoryUploader/Program.cs +++ b/src/ArtifactoryUploader/Program.cs @@ -42,10 +42,13 @@ static async Task Main(string[] args) ISettingsManager settingsManager = new SettingsManager(); CommonAppSettings appSettings = settingsManager.ReadConfiguration(args, FileConstant.appSettingFileName); + CatoolInfo caToolInformation = GetCatoolVersionFromProjectfile(); + + Log4Net.CatoolCurrentDirectory = Directory.GetParent(caToolInformation.CatoolRunningLocation).FullName; + string FolderPath = InitiateLogger(appSettings); settingsManager.CheckRequiredArgsToRun(appSettings, "Uploader"); - CatoolInfo caToolVersion = GetCatoolVersionFromProjectfile(); Logger.Logger.Log(null, Level.Notice, $"\n====================<<<<< Artifactory Uploader >>>>>====================", null); Logger.Logger.Log(null, Level.Notice, $"\nStart of Artifactory Uploader execution: {DateTime.Now}", null); @@ -57,8 +60,8 @@ static async Task Main(string[] args) Logger.Logger.Log(null, Level.Info, $"Input Parameters used in Artifactory Uploader:\n\t", null); Logger.Logger.Log(null, Level.Notice, $"\tBomFilePath:\t\t {appSettings.BomFilePath}\n\t" + - $"CaToolVersion\t\t --> {caToolVersion.CatoolVersion}\n\t" + - $"CaToolRunningPath\t --> {caToolVersion.CatoolRunningLocation}\n\t" + + $"CaToolVersion\t\t --> {caToolInformation.CatoolVersion}\n\t" + + $"CaToolRunningPath\t --> {caToolInformation.CatoolRunningLocation}\n\t" + $"JFrogUrl:\t\t {appSettings.JFrogApi}\n\t" + $"Release:\t\t {appSettings.Release}\n\t" + $"LogFolderPath:\t\t {Path.GetFullPath(FolderPath)}\n", null); @@ -79,6 +82,31 @@ static async Task Main(string[] args) Logger.Logger.Log(null, Level.Notice, $"End of Artifactory Uploader execution : {DateTime.Now}\n", null); + // publish logs and bom file to pipeline artifact + PublishFilesToArtifact(); + + } + + public static void PublishFilesToArtifact() + { + try + { + + // Define Azure DevOps/VSTS artifact upload parameters + string containerFolder = "Container"; // Replace with your desired container folder + string artifactName = "catoolArtifactoryUploader"; // Replace with your artifact name + //string logFilePath = Path.GetFullPath(Log4Net.CatoolLogPath); + + // Output the artifact upload command + Console.WriteLine($"##vso[artifact.upload containerfolder={containerFolder};artifactname={artifactName}]{Log4Net.CatoolLogPath}"); + Console.WriteLine($"##vso[artifact.upload containerfolder={containerFolder};artifactname={artifactName}]{FileOperations.CatoolBomFilePath}"); + + + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } } private static CatoolInfo GetCatoolVersionFromProjectfile() diff --git a/src/LCT.Common/Constants/FileConstant.cs b/src/LCT.Common/Constants/FileConstant.cs index 78370f56..c3d80954 100644 --- a/src/LCT.Common/Constants/FileConstant.cs +++ b/src/LCT.Common/Constants/FileConstant.cs @@ -31,9 +31,9 @@ public static class FileConstant public const string PackageLockFileName = "package-lock.json"; public const string PackageConfigFileName = "packages.config"; public const string PackageLockJonFileName = "packages.lock.json"; - public const string LogFolder = "..\\Logs"; - public const string ComponentCreatorLog = "PacakgeCreator.log"; - public const string BomCreatorLog = "PacakgeIdentifier.log"; + public const string LogFolder = "Logs"; + public const string ComponentCreatorLog = "PackageCreator.log"; + public const string BomCreatorLog = "PackageIdentifier.log"; public const string FossologyUploaderLog = "FossologyUploader.log"; public const string ArtifactoryUploaderLog = "ArtifactoryUploader.log"; public const string XzFileExtension = ".tar.xz"; diff --git a/src/LCT.Common/FileOperations.cs b/src/LCT.Common/FileOperations.cs index a9305f79..4dfedbd7 100644 --- a/src/LCT.Common/FileOperations.cs +++ b/src/LCT.Common/FileOperations.cs @@ -23,6 +23,7 @@ namespace LCT.Common public class FileOperations : IFileOperations { static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + public static string CatoolBomFilePath { get; set; } public void ValidateFilePath(string filePath) { @@ -90,7 +91,7 @@ public string WriteContentToOutputBomFile(T dataToWrite, string folderPath, s string fileName = $"{projectName}_{fileNameWithExtension}"; - string filePath = Path.Combine(folderPath, fileName); + string filePath = CatoolBomFilePath = Path.Combine(folderPath, fileName); Logger.Debug($"filePath-{filePath}"); BackupTheGivenFile(folderPath, fileName); diff --git a/src/LCT.Common/Logging/Log4net.cs b/src/LCT.Common/Logging/Log4net.cs index 343b00f4..8e9f983c 100644 --- a/src/LCT.Common/Logging/Log4net.cs +++ b/src/LCT.Common/Logging/Log4net.cs @@ -14,6 +14,7 @@ using log4net.Core; using log4net.Appender; using System; +using LCT.Common.Constants; namespace LCT.Common { @@ -23,12 +24,16 @@ namespace LCT.Common public static class Log4Net { public static ILoggerRepository LoggerRepository { get; set; } + + public static string CatoolLogPath { get; set; } + public static string CatoolCurrentDirectory { get; set; } + public static void Init(string logFileName, string logFolder, bool verbose) { LoggerRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); XmlConfigurator.Configure(LoggerRepository, new FileInfo(GetDefaultLogConfigFile())); - - string logPath = Path.Combine(logFolder, logFileName); + string outPath = Directory.GetParent(Directory.GetCurrentDirectory()).FullName; + string logPath = CatoolLogPath = Path.Combine(CatoolCurrentDirectory, logFolder, logFileName); if (LoggerRepository is Hierarchy rootRepo) { diff --git a/src/LCT.PackageIdentifier/Program.cs b/src/LCT.PackageIdentifier/Program.cs index 34af2638..4e98e197 100644 --- a/src/LCT.PackageIdentifier/Program.cs +++ b/src/LCT.PackageIdentifier/Program.cs @@ -36,6 +36,7 @@ namespace LCT.PackageIdentifier public class Program { private static bool m_Verbose = false; + public static Stopwatch BomStopWatch { get; set; } private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -51,9 +52,10 @@ static async Task Main(string[] args) ISettingsManager settingsManager = new SettingsManager(); CommonAppSettings appSettings = settingsManager.ReadConfiguration(args, FileConstant.appSettingFileName); ProjectReleases projectReleases = new ProjectReleases(); + CatoolInfo caToolInformation = GetCatoolVersionFromProjectfile(); + Log4Net.CatoolCurrentDirectory = Directory.GetParent(caToolInformation.CatoolRunningLocation).FullName; string FolderPath = LogFolderInitialisation(appSettings); - CatoolInfo caToolInformation = GetCatoolVersionFromProjectfile(); settingsManager.CheckRequiredArgsToRun(appSettings, "Identifer"); Logger.Logger.Log(null, Level.Notice, $"\n====================<<<<< Package Identifier >>>>>====================", null); @@ -89,7 +91,7 @@ static async Task Main(string[] args) $"SW360ProjectName\t --> {appSettings.SW360ProjectName}\n\t" + $"SW360ProjectID\t\t --> {appSettings.SW360ProjectID}\n\t" + $"ProjectType\t\t --> {appSettings.ProjectType}\n\t" + - $"LogFolderPath\t\t --> {Path.GetFullPath(FolderPath)}\n\t" + + $"LogFolderPath\t\t --> {Log4Net.CatoolLogPath}\n\t" + $"InternalRepoList\t --> {listOfInternalRepoList}\n\t" + $"Include\t\t\t --> {listOfInlude}\n\t" + $"Exclude\t\t\t --> {listOfExclude}\n\t" + @@ -111,6 +113,32 @@ static async Task Main(string[] args) caToolInformation); } Logger.Logger.Log(null, Level.Notice, $"End of Package Identifier execution : {DateTime.Now}\n", null); + + // publish logs and bom file to pipeline artifact + PublishFilesToArtifact(); + + } + + public static void PublishFilesToArtifact() + { + try + { + + // Define Azure DevOps/VSTS artifact upload parameters + string containerFolder = "Container"; // Replace with your desired container folder + string artifactName = "catoolPackageIdentifier"; // Replace with your artifact name + //string logFilePath = Path.GetFullPath(Log4Net.CatoolLogPath); + + // Output the artifact upload command + Console.WriteLine($"##vso[artifact.upload containerfolder={containerFolder};artifactname={artifactName}]{Log4Net.CatoolLogPath}"); + Console.WriteLine($"##vso[artifact.upload containerfolder={containerFolder};artifactname={artifactName}]{FileOperations.CatoolBomFilePath}"); + + + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } } private static CatoolInfo GetCatoolVersionFromProjectfile() diff --git a/src/LCT.SW360PackageCreator/Program.cs b/src/LCT.SW360PackageCreator/Program.cs index 7210b7ee..349bb408 100644 --- a/src/LCT.SW360PackageCreator/Program.cs +++ b/src/LCT.SW360PackageCreator/Program.cs @@ -50,11 +50,14 @@ static async Task Main(string[] args) ISW360ApicommunicationFacade sW360ApicommunicationFacade; ISw360ProjectService sw360ProjectService= Getsw360ProjectServiceObject(appSettings, out sW360ApicommunicationFacade); ProjectReleases projectReleases = new ProjectReleases(); - + CatoolInfo caToolInformation = GetCatoolVersionFromProjectfile(); + + Log4Net.CatoolCurrentDirectory = Directory.GetParent(caToolInformation.CatoolRunningLocation).FullName; + + string FolderPath = InitiateLogger(appSettings); settingsManager.CheckRequiredArgsToRun(appSettings, "Creator"); await CreatorValidator.ValidateAppSettings(appSettings, sw360ProjectService, projectReleases); - CatoolInfo caToolInformation = GetCatoolVersionFromProjectfile(); Logger.Logger.Log(null, Level.Notice, $"\n====================<<<<< Package creator >>>>>====================", null); Logger.Logger.Log(null, Level.Notice, $"\nStart of Package creator execution : {DateTime.Now}", null); @@ -80,6 +83,31 @@ static async Task Main(string[] args) await InitiatePackageCreatorProcess(appSettings, sw360ProjectService, sW360ApicommunicationFacade); Logger.Logger.Log(null, Level.Notice, $"End of Package Creator execution: {DateTime.Now}\n", null); + // publish logs and bom file to pipeline artifact + PublishFilesToArtifact(); + + } + + public static void PublishFilesToArtifact() + { + try + { + + // Define Azure DevOps/VSTS artifact upload parameters + string containerFolder = "Container"; // Replace with your desired container folder + string artifactName = "catoolPacakgeCreator"; // Replace with your artifact name + //string logFilePath = Path.GetFullPath(Log4Net.CatoolLogPath); + + // Output the artifact upload command + Console.WriteLine($"##vso[artifact.upload containerfolder={containerFolder};artifactname={artifactName}]{Log4Net.CatoolLogPath}"); + Console.WriteLine($"##vso[artifact.upload containerfolder={containerFolder};artifactname={artifactName}]{FileOperations.CatoolBomFilePath}"); + + + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } } private static CatoolInfo GetCatoolVersionFromProjectfile()