From a3b1e78f7f859a5e1fd32b04b8acd024a2df3b7c Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Mon, 12 Feb 2024 08:16:21 +0100 Subject: [PATCH 01/15] VCI-772: Update projects to net8 --- .../VirtoCommerce.Build.Tests.csproj | 4 ++-- src/VirtoCommerce.Build/VirtoCommerce.Build.csproj | 2 +- .../src/VirtoCloud.Client/VirtoCloud.Client.csproj | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/VirtoCommerce.Build.Tests/VirtoCommerce.Build.Tests.csproj b/src/VirtoCommerce.Build.Tests/VirtoCommerce.Build.Tests.csproj index 52cf136..ad74b8f 100644 --- a/src/VirtoCommerce.Build.Tests/VirtoCommerce.Build.Tests.csproj +++ b/src/VirtoCommerce.Build.Tests/VirtoCommerce.Build.Tests.csproj @@ -1,7 +1,7 @@ - + - net6.0 + net8.0 enable enable diff --git a/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj b/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj index 9f5435c..3ec1e93 100644 --- a/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj +++ b/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj @@ -2,7 +2,7 @@ VirtoCommerce.GlobalTool Exe - net6.0 + net8.0 LatestMajor false diff --git a/src/Virtocloud.Client/src/VirtoCloud.Client/VirtoCloud.Client.csproj b/src/Virtocloud.Client/src/VirtoCloud.Client/VirtoCloud.Client.csproj index af1160c..3a09e73 100644 --- a/src/Virtocloud.Client/src/VirtoCloud.Client/VirtoCloud.Client.csproj +++ b/src/Virtocloud.Client/src/VirtoCloud.Client/VirtoCloud.Client.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 VirtoCloud.Client 1.0.0.0 VirtoCloud.Client From 7bdbb147349f1eda1ac25ea06e4924180e228379 Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Mon, 12 Feb 2024 12:31:57 +0100 Subject: [PATCH 02/15] VCI-785: Update nuke and virto dependencies and fix obsoletes --- src/VirtoCommerce.Build/Build.cs | 49 +++++++++---------- .../PlatformTools/Build.InitPlatform.cs | 3 +- .../PlatformTools/Build.PackageManager.cs | 30 ++++++------ .../VirtoCommerce.Build.csproj | 14 +++--- 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/VirtoCommerce.Build/Build.cs b/src/VirtoCommerce.Build/Build.cs index a28d650..d6e28cc 100644 --- a/src/VirtoCommerce.Build/Build.cs +++ b/src/VirtoCommerce.Build/Build.cs @@ -69,7 +69,7 @@ public static Solution Solution var solutions = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln", SearchOption.TopDirectoryOnly); if (solutions.Any()) { - return ProjectModelTasks.ParseSolution(solutions[0]); + return SolutionModelTasks.ParseSolution(solutions[0]); } Log.Warning("No solution files found in the current directory"); @@ -271,7 +271,7 @@ public static Solution Solution .DependsOn(Compile) .Executes(() => { - var testProjects = Solution.GetProjects("*.Test|*.Tests|*.Testing"); + var testProjects = Solution.GetAllProjects("*.Test|*.Tests|*.Testing"); var outPath = RootDirectory / ".tmp"; foreach (var testProjectPath in testProjects.Select(p=> p.Path).ToArray()) @@ -294,7 +294,7 @@ public static Solution Solution if (coberturaReports.Count > 0) { - var reportGenerator = ToolResolver.GetPackageTool("dotnet-reportgenerator-globaltool", + var reportGenerator = ToolResolver.GetNuGetTool("dotnet-reportgenerator-globaltool", "ReportGenerator.dll", "4.8.8", "netcoreapp3.0"); reportGenerator.Invoke( $"-reports:{outPath / "**/coverage.cobertura.xml"} -targetdir:{outPath} -reporttypes:SonarQube"); @@ -532,7 +532,7 @@ private static void WebPackBuildMethod(Project webProject) var modulesJsonFilePath = ModulesLocalDirectory / ModulesJsonName; var externalManifests = - JsonConvert.DeserializeObject>(TextTasks.ReadAllText(modulesJsonFilePath)); + JsonConvert.DeserializeObject>(modulesJsonFilePath.ReadAllText()); var externalManifest = externalManifests?.Find(x => x.Id == manifest.Id); if (externalManifest != null) @@ -582,8 +582,7 @@ private static void WebPackBuildMethod(Project webProject) externalManifests?.Add(ExternalModuleManifest.FromManifest(manifest)); } - TextTasks.WriteAllText(modulesJsonFilePath, - JsonConvert.SerializeObject(externalManifests, Formatting.Indented)); + modulesJsonFilePath.WriteAllText(JsonConvert.SerializeObject(externalManifests, Formatting.Indented)); }); public Target PublishManifestGit => _ => _ @@ -603,7 +602,7 @@ private static void WebPackBuildMethod(Project webProject) .Requires(() => !IsModule) .Executes(async () => { - var swashbuckle = ToolResolver.GetPackageTool("Swashbuckle.AspNetCore.Cli", "dotnet-swagger.dll", + var swashbuckle = ToolResolver.GetNuGetTool("Swashbuckle.AspNetCore.Cli", "dotnet-swagger.dll", framework: "netcoreapp3.0"); var projectPublishPath = ArtifactsDirectory / "publish" / $"{WebProject.Name}.dll"; var swaggerJsonPath = ArtifactsDirectory / "swagger.json"; @@ -715,14 +714,14 @@ private static void WebPackBuildMethod(Project webProject) if (OperatingSystem.IsLinux()) { const string sonarScript = "sonar-scanner"; - var sonarScannerShPath = ToolPathResolver.GetPackageExecutable("dotnet-sonarscanner", + var sonarScannerShPath = NuGetToolPathResolver.GetPackageExecutable("dotnet-sonarscanner", sonarScript, framework: framework) .Replace("netcoreapp2.0", "net5.0") .Replace("netcoreapp3.0", "net5.0"); var sonarScannerShRightPath = Directory.GetParent(sonarScannerShPath)?.Parent?.FullName ?? string.Empty; var tmpFile = TemporaryDirectory / sonarScript; FileSystemTasks.MoveFile(sonarScannerShPath, tmpFile); - FileSystemTasks.DeleteDirectory(sonarScannerShRightPath); + ((AbsolutePath)sonarScannerShRightPath).DeleteDirectory(); var sonarScriptDestinationPath = Path.Combine(sonarScannerShRightPath, sonarScript); FileSystemTasks.MoveFile(tmpFile, sonarScriptDestinationPath); Log.Information($"{sonarScript} path: {sonarScriptDestinationPath}"); @@ -748,7 +747,7 @@ private static void WebPackBuildMethod(Project webProject) foreach (var moduleDirectory in Directory.GetDirectories(ModulesFolderPath)) { var isGitRepository = - FileSystemTasks.FindParentDirectory(moduleDirectory, x => x.GetDirectories(".git").Any()) != + ((AbsolutePath)moduleDirectory).FindParentOrSelf(x => x.GetDirectories(".git").Any()) != null; if (isGitRepository) @@ -831,7 +830,7 @@ private static void ClearTempOnExit() { if (ClearTempBeforeExit) { - FileSystemTasks.DeleteDirectory(TemporaryDirectory); + TemporaryDirectory.DeleteDirectory(); } } @@ -893,11 +892,11 @@ private static void RegisterMSBuildLocator() } } - private static void ConvertDotNukeFile(string path) + private static void ConvertDotNukeFile(AbsolutePath path) { var directory = Path.GetDirectoryName(path); var solutionPath = File.ReadLines(path).FirstOrDefault(); - FileSystemTasks.DeleteFile(path); + path.DeleteFile(); CreateDotNuke(directory, solutionPath); } @@ -905,9 +904,9 @@ private static void CreateDotNuke(string path, string solutionPath = "") { var dotnukeDir = Path.Join(path, ".nuke"); var paramsFilePath = Path.Join(dotnukeDir, "parameters.json"); - FileSystemTasks.EnsureExistingDirectory(dotnukeDir); + ((AbsolutePath)dotnukeDir).CreateDirectory(); var parameters = new NukeParameters { Solution = solutionPath }; - SerializationTasks.JsonSerializeToFile(parameters, paramsFilePath); + JsonExtensions.WriteJson(paramsFilePath, parameters); } public static void CustomDotnetLogger(OutputType type, string text) @@ -925,9 +924,9 @@ public static void ChangeProjectVersion(string versionPrefix = null, string vers //theme if (IsTheme) { - var jObject = SerializationTasks.JsonDeserializeFromFile(PackageJsonPath); + var jObject = JsonExtensions.ReadJson(PackageJsonPath); jObject["version"] = versionPrefix; - SerializationTasks.JsonSerializeToFile(jObject, Path.GetFullPath(PackageJsonPath)); + JsonExtensions.WriteJson(Path.GetFullPath(PackageJsonPath), jObject); return; } @@ -1172,7 +1171,7 @@ private void CompressExecuteMethod() if (ModuleIgnoreFile.FileExists()) { - ignoredFiles = ignoredFiles.Concat(TextTasks.ReadAllLines(ModuleIgnoreFile)).ToArray(); + ignoredFiles = ignoredFiles.Concat(ModuleIgnoreFile.ReadAllLines()).ToArray(); } ignoredFiles = ignoredFiles.Select(x => x.Trim()).Distinct().ToArray(); @@ -1180,7 +1179,7 @@ private void CompressExecuteMethod() var keepFiles = Array.Empty(); if (ModuleKeepFile.FileExists()) { - keepFiles = TextTasks.ReadAllLines(ModuleKeepFile).ToArray(); + keepFiles = ModuleKeepFile.ReadAllLines().ToArray(); } ArtifactPacker.CompressModule(options => options.WithSourceDirectory(ModuleOutputDirectory) @@ -1207,28 +1206,28 @@ private static void CleanSolution(string[] searchPattern, AbsolutePath[] ignoreP SourceDirectory .GlobDirectories(searchPattern) .Where(directory => !ignorePaths.Any(p => p.Contains(directory))) - .ForEach(FileSystemTasks.DeleteDirectory); + .ForEach(p => p.DeleteDirectory()); } else { - SourceDirectory.GlobDirectories(searchPattern).ForEach(FileSystemTasks.DeleteDirectory); + SourceDirectory.GlobDirectories(searchPattern).ForEach(p => p.DeleteDirectory()); } if (TestsDirectory.DirectoryExists()) { - TestsDirectory.GlobDirectories(searchPattern).ForEach(FileSystemTasks.DeleteDirectory); + TestsDirectory.GlobDirectories(searchPattern).ForEach(p => p.DeleteDirectory()); } if (SamplesDirectory.DirectoryExists()) { - SamplesDirectory.GlobDirectories(searchPattern).ForEach(FileSystemTasks.DeleteDirectory); + SamplesDirectory.GlobDirectories(searchPattern).ForEach(p => p.DeleteDirectory()); } } else { - RootDirectory.GlobDirectories(searchPattern).ForEach(FileSystemTasks.DeleteDirectory); + RootDirectory.GlobDirectories(searchPattern).ForEach(p => p.DeleteDirectory()); } - FileSystemTasks.EnsureCleanDirectory(ArtifactsDirectory); + ArtifactsDirectory.CreateOrCleanDirectory(); } } diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.InitPlatform.cs b/src/VirtoCommerce.Build/PlatformTools/Build.InitPlatform.cs index 52a6ece..fe282a4 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.InitPlatform.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.InitPlatform.cs @@ -1,4 +1,5 @@ using Nuke.Common; +using Nuke.Common.IO; using PlatformTools; using VirtoCommerce.Platform.Core.Common; @@ -10,7 +11,7 @@ internal partial class Build public static string DiscoveryPath { get; set; } [Parameter("Probing path")] - public static string ProbingPath { get; set; } = RootDirectory / "app_data" / "modules"; + public static AbsolutePath ProbingPath { get; set; } = RootDirectory / "app_data" / "modules"; [Parameter("appsettings.json path")] public static string AppsettingsPath { get; set; } = RootDirectory / "appsettings.json"; diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs index 2cb3481..f7ce134 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Nuke.Common; using Nuke.Common.IO; +using Nuke.Common.Utilities; using Nuke.Common.Utilities.Collections; using PlatformTools; using PlatformTools.Azure; @@ -56,7 +57,7 @@ internal partial class Build [Parameter("Url to Bundles file")] public static string BundlesUrl { get; set; } = "https://raw.githubusercontent.com/VirtoCommerce/vc-modules/master/bundles/stable.json"; - [Parameter("Backup file path")] public static string BackupFile { get; set; } = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + [Parameter("Backup file path")] public static AbsolutePath BackupFile { get; set; } = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); public Target Init => _ => _ .Executes(async () => @@ -82,7 +83,7 @@ internal partial class Build { UpdateModules(Module, externalModuleCatalog, modules); } - else if (!PlatformParameter && !modules.Any() && !FileSystemTasks.FileExists((AbsolutePath)Path.GetFullPath(PackageManifestPath))) + else if (!PlatformParameter && !modules.Any() && !File.Exists(Path.GetFullPath(PackageManifestPath))) { AddCommerceModules(externalModuleCatalog, modules); } @@ -160,7 +161,7 @@ private static IEnumerable ParseModuleParameter(string[] moduleStrin if (parts.Length > 1) { moduleId = parts[0]; - moduleVersion = parts.Last(); + moduleVersion = parts[parts.Count() - 1]; } else if (moduleStrings.Length == 1 && !string.IsNullOrEmpty(VersionToInstall)) { @@ -201,8 +202,7 @@ private static bool PlatformVersionChanged() modulesDirs = Directory.EnumerateDirectories(discoveryPath).ToList(); } var symlinks = modulesDirs.Where(m => new DirectoryInfo(m).LinkTarget != null).ToList(); - CompressionTasks.CompressTarGZip(RootDirectory, BackupFile, filter: f => !f.FullName.StartsWith(RootDirectory / ".nuke") && !symlinks.Any(s => f.FullName.StartsWith(s))); - + CompressionExtensions.TarGZipTo(RootDirectory, BackupFile, filter: f => !f.ToFileInfo().FullName.StartsWith(RootDirectory / ".nuke") && !symlinks.Any(s => f.ToFileInfo().FullName.StartsWith(s))); }); public Target Rollback => _ => _ @@ -210,7 +210,7 @@ private static bool PlatformVersionChanged() .After(Backup, Install, Update, InstallPlatform, InstallModules) .OnlyWhenDynamic(() => FailedTargets.Any() && SucceededTargets.Contains(Backup)) .AssuredAfterFailure() - .Executes(() => CompressionTasks.UncompressTarGZip(BackupFile, RootDirectory)); + .Executes(() => CompressionExtensions.UnTarGZipTo(BackupFile, RootDirectory)); public Target RemoveBackup => _ => _ .After(Backup, Rollback) @@ -218,14 +218,14 @@ private static bool PlatformVersionChanged() .AssuredAfterFailure() .Unlisted() .DependsOn(Backup) - .Executes(() => FileSystemTasks.DeleteFile(BackupFile)); + .Executes(() => BackupFile.DeleteFile()); public Target InstallPlatform => _ => _ .OnlyWhenDynamic(() => PlatformVersionChanged() && !IsModulesInstallation()) .Executes(async () => { var packageManifest = PackageManager.FromFile(PackageManifestPath); - var mixedManifest = SerializationTasks.JsonDeserializeFromFile(PackageManifestPath); + var mixedManifest = JsonExtensions.ReadJson(PackageManifestPath); var platformAssetUrlFromManifest = mixedManifest.PlatformAssetUrl; var platformAssetUrl = string.IsNullOrWhiteSpace(PlatformAssetUrl) ? platformAssetUrlFromManifest @@ -263,8 +263,8 @@ private static async Task InstallPlatformAsync(string platformVersion, string pl FileSystemTasks.MoveFile(AppsettingsPath, tempFile, FileExistsPolicy.Overwrite); } - CompressionTasks.Uncompress(platformZip, RootDirectory); - FileSystemTasks.DeleteFile(platformZip); + platformZip.UncompressTo(RootDirectory); + platformZip.DeleteFile(); // return appsettings.json back if (!string.IsNullOrEmpty(tempFile)) @@ -399,7 +399,7 @@ private static bool IsPlatformInstallationNeeded(string version) } var absoluteDiscoveryPath = (AbsolutePath)Path.GetFullPath(discoveryPath); var zipFiles = absoluteDiscoveryPath.GlobFiles("*/*.zip"); - zipFiles.ForEach(f => FileSystemTasks.DeleteFile(f)); + zipFiles.ForEach(f => f.DeleteFile()); localModuleCatalog.Reload(); }); @@ -466,8 +466,8 @@ private static ManifestModuleInfo LoadModuleInfo(ModuleItem module, ManifestModu var packageManifest = PackageManager.FromFile(PackageManifestPath); var localModulesCatalog = LocalModuleCatalog.GetCatalog(discoveryPath, ProbingPath); var githubModules = PackageManager.GetGithubModules(packageManifest); - FileSystemTasks.DeleteDirectory(ProbingPath); - Module.ForEach(m => FileSystemTasks.DeleteDirectory(Path.Combine(discoveryPath, m))); + ProbingPath.DeleteDirectory(); + Module.ForEach(m => AbsolutePath.Create(Path.Combine(discoveryPath, m)).DeleteDirectory()); githubModules.RemoveAll(m => Module.Contains(m.Id)); PackageManager.ToFile(packageManifest, PackageManifestPath); if (PlatformVersion.CurrentVersion == null) @@ -625,7 +625,7 @@ private static async Task OpenOrCreateManifest(string packageManif private static async Task DownloadBundleManifest(string bundleName, string outFile) { var rawBundlesFile = await HttpTasks.HttpDownloadStringAsync(BundlesUrl); - var bundlesDictionary = SerializationTasks.JsonDeserialize>(rawBundlesFile); + var bundlesDictionary = JsonExtensions.GetJson>(rawBundlesFile); KeyValuePair bundle; if (string.IsNullOrEmpty(bundleName)) { @@ -643,7 +643,7 @@ private static async Task DownloadBundleManifest(string bundleName, string outFi private static ManifestBase CreateManifestFromEnvironment(AbsolutePath platformPath, AbsolutePath discoveryPath) { var platformWebDllPath = platformPath / "VirtoCommerce.Platform.Web.dll"; - if (!FileSystemTasks.FileExists(platformWebDllPath)) + if (!File.Exists(platformWebDllPath)) { Assert.Fail($"{platformWebDllPath} can't be found!"); } diff --git a/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj b/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj index 3ec1e93..9dbaadc 100644 --- a/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj +++ b/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj @@ -33,14 +33,14 @@ - + - + all - + @@ -51,10 +51,10 @@ all - - - - + + + + From c29118792ef76fa7cce2d37d32e012484f376ca5 Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Mon, 12 Feb 2024 12:32:19 +0100 Subject: [PATCH 03/15] VCI-772: Increase version to 3.800 --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index b0d1497..03a922c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -6,7 +6,7 @@ Copyright © VirtoCommerce 2011-2022 - 3.21.0 + 3.800.0 $(VersionSuffix)-$(BuildNumber) From 04554017af8adda8cb5e923afef90685a05ad07e Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Tue, 13 Feb 2024 08:23:41 +0100 Subject: [PATCH 04/15] VCI-785: Update dependencies --- src/VirtoCommerce.Build/Build.cs | 6 +++--- .../PlatformTools/Azure/AzureCliToolSettings.cs | 2 +- .../PlatformTools/Build.MatchVerisons.cs | 2 +- src/VirtoCommerce.Build/VirtoCommerce.Build.csproj | 6 +++--- .../src/VirtoCloud.Client/Client/ApiClient.cs | 3 --- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/VirtoCommerce.Build/Build.cs b/src/VirtoCommerce.Build/Build.cs index d6e28cc..d63d466 100644 --- a/src/VirtoCommerce.Build/Build.cs +++ b/src/VirtoCommerce.Build/Build.cs @@ -45,9 +45,9 @@ internal partial class Build : NukeBuild /// - JetBrains Rider https://nuke.build/rider /// - Microsoft VisualStudio https://nuke.build/visualstudio /// - Microsoft VSCode https://nuke.build/vscode - private static readonly string[] _moduleContentFolders = { "dist", "Localizations", "Scripts", "Content" }; + private static readonly string[] _moduleContentFolders = ["dist", "Localizations", "Scripts", "Content"]; - private static readonly string[] _sonarLongLiveBranches = { "master", "develop", "dev", "main" }; + private static readonly string[] _sonarLongLiveBranches = ["master", "develop", "dev", "main"]; private static readonly HttpClient _httpClient = new(); private static int? _exitCode; @@ -67,7 +67,7 @@ public static Solution Solution get { var solutions = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln", SearchOption.TopDirectoryOnly); - if (solutions.Any()) + if (solutions.Length > 0) { return SolutionModelTasks.ParseSolution(solutions[0]); } diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureCliToolSettings.cs b/src/VirtoCommerce.Build/PlatformTools/Azure/AzureCliToolSettings.cs index aea4567..579bc69 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureCliToolSettings.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Azure/AzureCliToolSettings.cs @@ -6,6 +6,6 @@ namespace PlatformTools.Azure [Serializable] internal class AzureCliToolSettings : ToolSettings { - public override Action ProcessCustomLogger => ProcessTasks.DefaultLogger; + public override Action ProcessLogger => ProcessTasks.DefaultLogger; } } diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs b/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs index 238fb18..5f6b2e6 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs @@ -19,7 +19,7 @@ internal partial class Build .Executes(() => { var allPackages = new List(); - var allProjects = Solution.GetProjects("*"); + var allProjects = Solution.GetAllProjects("*"); foreach (var project in allProjects) { diff --git a/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj b/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj index 9dbaadc..f28a73e 100644 --- a/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj +++ b/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj @@ -30,8 +30,8 @@ - - + + @@ -41,7 +41,7 @@ all - + diff --git a/src/Virtocloud.Client/src/VirtoCloud.Client/Client/ApiClient.cs b/src/Virtocloud.Client/src/VirtoCloud.Client/Client/ApiClient.cs index 720a56e..4de2e49 100644 --- a/src/Virtocloud.Client/src/VirtoCloud.Client/Client/ApiClient.cs +++ b/src/Virtocloud.Client/src/VirtoCloud.Client/Client/ApiClient.cs @@ -7,7 +7,6 @@ * Generated by: https://github.com/openapitools/openapi-generator.git */ - using System; using System.Collections; using System.Collections.Generic; @@ -386,8 +385,6 @@ private HttpRequestMessage NewRequest( } } - - // TODO provide an alternative that allows cookies per request instead of per API client if (options.Cookies != null && options.Cookies.Count > 0) { From 52297afa9d97ae9eb3ecbfe93993f725d1203939 Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Tue, 20 Feb 2024 09:29:13 +0100 Subject: [PATCH 05/15] VCI-772: Fix for unit tests --- .../PackageManagerTests.cs | 6 ++++-- src/VirtoCommerce.Build/Cloud/Build.SaaS.cs | 8 +++---- .../Cloud/Client/VirtoCloudClient.cs | 5 +++-- .../Extensions/PathExtension.cs | 18 ++++++++++++++++ .../Github/GithubPrivateModulesInstaller.cs | 5 ++--- .../GitlabJobArtifactsModuleInstaller.cs | 5 ++--- .../PlatformTools/PackageManager.cs | 3 ++- .../Utils/ArtifactPacker.cs | 21 +++++++++++-------- 8 files changed, 47 insertions(+), 24 deletions(-) create mode 100644 src/VirtoCommerce.Build/Extensions/PathExtension.cs diff --git a/src/VirtoCommerce.Build.Tests/PackageManagerTests.cs b/src/VirtoCommerce.Build.Tests/PackageManagerTests.cs index 44ae008..5a39b91 100644 --- a/src/VirtoCommerce.Build.Tests/PackageManagerTests.cs +++ b/src/VirtoCommerce.Build.Tests/PackageManagerTests.cs @@ -1,3 +1,5 @@ +using Extensions; +using Nuke.Common.IO; using PlatformTools; using VirtoCommerce.Build.PlatformTools; @@ -76,7 +78,7 @@ public void ToFile_SavesManifestToFile() var path = "./test-vc-package.json"; // Act - PackageManager.ToFile(manifest, path); + PackageManager.ToFile(manifest, path.ToAbsolutePath()); // Assert Assert.True(File.Exists(path)); @@ -91,7 +93,7 @@ public void FromFile_LoadsManifestFromFile() // Arrange var manifest = PackageManager.CreatePackageManifest("1.0.0"); var path = "./test-vc-package.json"; - PackageManager.ToFile(manifest, path); + PackageManager.ToFile(manifest, path.ToAbsolutePath()); // Act var loadedManifest = PackageManager.FromFile(path); diff --git a/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs b/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs index 3b9fb6e..ac241df 100644 --- a/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs +++ b/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs @@ -134,7 +134,7 @@ private async Task PrepareDockerContextMethod() var modulesPath = platformDirectory / "modules"; var dockerfilePath = dockerBuildContext / "Dockerfile"; - FileSystemTasks.EnsureCleanDirectory(dockerBuildContext); + dockerBuildContext.CreateOrCleanDirectory(); await HttpTasks.HttpDownloadFileAsync(DockerfileUrl, dockerfilePath); @@ -186,7 +186,7 @@ private static void CopyModules(AbsolutePath modulesPath, AbsolutePath modulesSo var solutions = Directory.EnumerateFiles(solutionDir, "*.sln"); Assert.True(solutions.Count() == 1, $"Solutions found: {solutions.Count()}"); var solutionPath = solutions.FirstOrDefault(); - var solution = ProjectModelTasks.ParseSolution(solutionPath); + var solution = SolutionModelTasks.ParseSolution(solutionPath); var webProject = solution.AllProjects.First(p => p.Name.EndsWith(".Web")); WebPackBuildMethod(webProject); @@ -262,7 +262,6 @@ private static void CopyPlatformDirectory(AbsolutePath platformDirectory, Absolu Log.Information("Start listening to {0}", listenerPrefix); listener.Start(); - Log.Information("Openning browser window"); var authUrl = $"{CloudUrl}/externalsignin?authenticationType={CloudAuthProvider}&returnUrl=/api/saas/token/{port}"; Process.Start(new ProcessStartInfo(authUrl) { UseShellExecute = true }); @@ -293,7 +292,8 @@ private async Task GetCloudTokenAsync() private void SaveCloudToken(string token) { - FileSystemTasks.EnsureExistingDirectory(Path.GetDirectoryName(CloudTokenFile)); + AbsolutePath cloudTokenDir = Path.GetDirectoryName(CloudTokenFile); + cloudTokenDir.CreateDirectory(); File.WriteAllText(CloudTokenFile, token); } diff --git a/src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs b/src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs index 36169c9..8e0c093 100644 --- a/src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs +++ b/src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs @@ -6,6 +6,7 @@ using Cloud.Models; using Nuke.Common; using Nuke.Common.IO; +using Nuke.Common.Utilities; namespace Cloud.Client; @@ -42,7 +43,7 @@ public async Task UpdateEnvironmentAsync(string manifest, string appProj public async Task UpdateEnvironmentAsync(CloudEnvironment environment) { - var jsonString = SerializationTasks.JsonSerialize(environment); + var jsonString = JsonExtensions.ToJson(environment); var content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await _client.PutAsync(new Uri("api/saas/environments", UriKind.Relative), content); if (!response.IsSuccessStatusCode) @@ -65,7 +66,7 @@ public async Task GetEnvironment(string environmentName, strin } var responseContent = await response.Content.ReadAsStringAsync(); - var env = SerializationTasks.JsonDeserialize(responseContent); + var env = JsonExtensions.GetJson(responseContent); return env; } } diff --git a/src/VirtoCommerce.Build/Extensions/PathExtension.cs b/src/VirtoCommerce.Build/Extensions/PathExtension.cs new file mode 100644 index 0000000..c76e49c --- /dev/null +++ b/src/VirtoCommerce.Build/Extensions/PathExtension.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Nuke.Common.IO; +using System.IO; + +namespace Extensions +{ + public static class PathExtension + { + public static AbsolutePath ToAbsolutePath(this string path) + { + return AbsolutePath.Create(Path.GetFullPath(path)); + } + } +} diff --git a/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs index 0a62f7f..103f9bb 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs @@ -30,10 +30,9 @@ protected override async Task InnerInstall(ModuleSource source, IProgress optionsBuilderAction) @@ -40,13 +40,16 @@ public static void CompressModule(Action option } } - bool FilesFilter(FileInfo x) => - (!SkipFileByList(x.Name, options.IgnoreList) && - !SkipFileByRegex(x.Name, ignoreModuleFilesRegex)) || KeepFileByList(x.Name, options.KeepList) || - KeepFileByRegex(x.Name, includeModuleFilesRegex); + bool FilesFilter(AbsolutePath path) + { + var fileInfo = path.ToFileInfo(); + return (!SkipFileByList(fileInfo.Name, options.IgnoreList) && + !SkipFileByRegex(fileInfo.Name, ignoreModuleFilesRegex)) || KeepFileByList(fileInfo.Name, options.KeepList) || + KeepFileByRegex(fileInfo.Name, includeModuleFilesRegex); + } - FileSystemTasks.DeleteFile(options.OutputZipPath); - CompressionTasks.CompressZip(options.SourceDirectory, options.OutputZipPath, FilesFilter); + ((AbsolutePath)options.OutputZipPath).DeleteFile(); + ((AbsolutePath)options.SourceDirectory).ZipTo(options.OutputZipPath, FilesFilter); } From 5737314433c1963f7df265b4de9c56faf93b98a5 Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Wed, 21 Feb 2024 11:26:14 +0100 Subject: [PATCH 06/15] VCI-772: Add the extension to convert relative path in string to AbsolutePath --- src/VirtoCommerce.Build/Build.cs | 7 ++++--- .../Cloud/Models/HelmParameter.cs | 4 ++-- src/VirtoCommerce.Build/Extensions/PathExtension.cs | 2 ++ .../Azure/AzureUniversalPackagesModuleInstaller.cs | 5 +++-- .../PlatformTools/Build.ConnStringValidator.cs | 10 +++++----- .../PlatformTools/Build.InitPlatform.cs | 2 +- .../PlatformTools/Build.PackageManager.cs | 7 ++++--- .../PlatformTools/PackageManager.cs | 13 +++++++------ src/VirtoCommerce.Build/Utils/ArtifactPacker.cs | 5 +++-- 9 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/VirtoCommerce.Build/Build.cs b/src/VirtoCommerce.Build/Build.cs index d63d466..aa2e12a 100644 --- a/src/VirtoCommerce.Build/Build.cs +++ b/src/VirtoCommerce.Build/Build.cs @@ -9,6 +9,7 @@ using System.Text.Json; using System.Threading.Tasks; using System.Xml; +using Extensions; using Microsoft.Build.Locator; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -721,7 +722,7 @@ private static void WebPackBuildMethod(Project webProject) var sonarScannerShRightPath = Directory.GetParent(sonarScannerShPath)?.Parent?.FullName ?? string.Empty; var tmpFile = TemporaryDirectory / sonarScript; FileSystemTasks.MoveFile(sonarScannerShPath, tmpFile); - ((AbsolutePath)sonarScannerShRightPath).DeleteDirectory(); + sonarScannerShRightPath.ToAbsolutePath().DeleteDirectory(); var sonarScriptDestinationPath = Path.Combine(sonarScannerShRightPath, sonarScript); FileSystemTasks.MoveFile(tmpFile, sonarScriptDestinationPath); Log.Information($"{sonarScript} path: {sonarScriptDestinationPath}"); @@ -747,7 +748,7 @@ private static void WebPackBuildMethod(Project webProject) foreach (var moduleDirectory in Directory.GetDirectories(ModulesFolderPath)) { var isGitRepository = - ((AbsolutePath)moduleDirectory).FindParentOrSelf(x => x.GetDirectories(".git").Any()) != + moduleDirectory.ToAbsolutePath().FindParentOrSelf(x => x.GetDirectories(".git").Any()) != null; if (isGitRepository) @@ -904,7 +905,7 @@ private static void CreateDotNuke(string path, string solutionPath = "") { var dotnukeDir = Path.Join(path, ".nuke"); var paramsFilePath = Path.Join(dotnukeDir, "parameters.json"); - ((AbsolutePath)dotnukeDir).CreateDirectory(); + dotnukeDir.ToAbsolutePath().CreateDirectory(); var parameters = new NukeParameters { Solution = solutionPath }; JsonExtensions.WriteJson(paramsFilePath, parameters); } diff --git a/src/VirtoCommerce.Build/Cloud/Models/HelmParameter.cs b/src/VirtoCommerce.Build/Cloud/Models/HelmParameter.cs index 0b655ed..8a869c3 100644 --- a/src/VirtoCommerce.Build/Cloud/Models/HelmParameter.cs +++ b/src/VirtoCommerce.Build/Cloud/Models/HelmParameter.cs @@ -2,7 +2,7 @@ using System.ComponentModel; using System.Globalization; using Newtonsoft.Json; -using Nuke.Common.IO; +using Nuke.Common.Utilities; namespace Cloud.Models { @@ -17,7 +17,7 @@ public HelmParameter(bool? forceString = default, string name = default, string public override string ToString() { var parameter = new V1alpha1HelmParameter(null, Name, Value); - return SerializationTasks.JsonSerialize(parameter); + return parameter.ToJson(); } public class HelmJsonConverter : JsonConverter diff --git a/src/VirtoCommerce.Build/Extensions/PathExtension.cs b/src/VirtoCommerce.Build/Extensions/PathExtension.cs index c76e49c..44a59bf 100644 --- a/src/VirtoCommerce.Build/Extensions/PathExtension.cs +++ b/src/VirtoCommerce.Build/Extensions/PathExtension.cs @@ -12,6 +12,8 @@ public static class PathExtension { public static AbsolutePath ToAbsolutePath(this string path) { + if(path == null) return null; + return AbsolutePath.Create(Path.GetFullPath(path)); } } diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs index 8f185c2..44fd341 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs @@ -3,6 +3,7 @@ using System.IO.Compression; using System.Linq; using System.Threading.Tasks; +using Extensions; using Nuke.Common.IO; using Nuke.Common.Tooling; using VirtoCommerce.Build.PlatformTools; @@ -27,9 +28,9 @@ protected override Task InnerInstall(ModuleSource source, IProgress _ => _ .Executes(() => diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs index f7ce134..2d9dd4f 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Extensions; using Nuke.Common; using Nuke.Common.IO; using Nuke.Common.Utilities; @@ -272,7 +273,7 @@ private static async Task InstallPlatformAsync(string platformVersion, string pl var bakFileName = new StringBuilder("appsettings.") .Append(DateTime.Now.ToString("MMddyyHHmmss")) .Append(".bak"); - var destinationSettingsPath = !Force ? AppsettingsPath : Path.Join(Path.GetDirectoryName(AppsettingsPath), bakFileName.ToString()); + AbsolutePath destinationSettingsPath = !Force ? AppsettingsPath : Path.Join(Path.GetDirectoryName(AppsettingsPath), bakFileName.ToString()); FileSystemTasks.MoveFile(tempFile, destinationSettingsPath, FileExistsPolicy.Overwrite); if (Force) @@ -397,7 +398,7 @@ private static bool IsPlatformInstallationNeeded(string version) await installer.Install(moduleSource, progress); } - var absoluteDiscoveryPath = (AbsolutePath)Path.GetFullPath(discoveryPath); + AbsolutePath absoluteDiscoveryPath = Path.GetFullPath(discoveryPath); var zipFiles = absoluteDiscoveryPath.GlobFiles("*/*.zip"); zipFiles.ForEach(f => f.DeleteFile()); localModuleCatalog.Reload(); @@ -606,7 +607,7 @@ private static async Task OpenOrCreateManifest(string packageManif else if (!File.Exists(packageManifestPath) && File.Exists(platformWebDllPath)) { var discoveryAbsolutePath = Path.GetFullPath(GetDiscoveryPath()); - return CreateManifestFromEnvironment(RootDirectory, (AbsolutePath)discoveryAbsolutePath); + return CreateManifestFromEnvironment(RootDirectory, discoveryAbsolutePath.ToAbsolutePath()); } else if (!File.Exists(packageManifestPath)) { diff --git a/src/VirtoCommerce.Build/PlatformTools/PackageManager.cs b/src/VirtoCommerce.Build/PlatformTools/PackageManager.cs index 7cbf00c..7365892 100644 --- a/src/VirtoCommerce.Build/PlatformTools/PackageManager.cs +++ b/src/VirtoCommerce.Build/PlatformTools/PackageManager.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using Nuke.Common.IO; +using Extensions; using Nuke.Common.Utilities; using VirtoCommerce.Build.PlatformTools; @@ -9,7 +9,7 @@ namespace PlatformTools { public static class PackageManager { - private static readonly string _defaultModuleManifest = "https://raw.githubusercontent.com/VirtoCommerce/vc-modules/master/modules_v3.json"; + private const string _defaultModuleManifest = "https://raw.githubusercontent.com/VirtoCommerce/vc-modules/master/modules_v3.json"; public static ManifestBase CreatePackageManifest(string platformVersion, string platformAssetUrl) { @@ -46,20 +46,21 @@ public static MixedPackageManifest UpdatePlatform(MixedPackageManifest manifest, public static void ToFile(ManifestBase manifest, string path = "./vc-package.json") { - ((AbsolutePath)path).WriteJson(manifest); + path.ToAbsolutePath().WriteJson(manifest); } public static ManifestBase FromFile(string path = "./vc-package.json") { - var baseManifest = SerializationTasks.JsonDeserializeFromFile(path); + var absolutePath = path.ToAbsolutePath(); + var baseManifest = absolutePath.ReadJson(); ManifestBase result; if (string.IsNullOrEmpty(baseManifest.ManifestVersion) || new Version(baseManifest.ManifestVersion) < new Version("2.0")) { - result = SerializationTasks.JsonDeserializeFromFile(path); + result = absolutePath.ReadJson(); } else { - result = SerializationTasks.JsonDeserializeFromFile(path); + result = absolutePath.ReadJson(); } return result; diff --git a/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs b/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs index b152590..ba3c32a 100644 --- a/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs +++ b/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; +using Extensions; using Nuke.Common.IO; namespace Utils @@ -48,8 +49,8 @@ bool FilesFilter(AbsolutePath path) KeepFileByRegex(fileInfo.Name, includeModuleFilesRegex); } - ((AbsolutePath)options.OutputZipPath).DeleteFile(); - ((AbsolutePath)options.SourceDirectory).ZipTo(options.OutputZipPath, FilesFilter); + options.OutputZipPath.ToAbsolutePath().DeleteFile(); + options.SourceDirectory.ToAbsolutePath().ZipTo(options.OutputZipPath, FilesFilter); } From 4eb6b4808f9f7f8a09d5fc55239f0966fde534d1 Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Wed, 21 Feb 2024 15:37:27 +0100 Subject: [PATCH 07/15] VCI-772: Fix for shell tests --- src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs index 2d9dd4f..37584bf 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs @@ -73,7 +73,7 @@ internal partial class Build .DependsOn(Backup) .Executes(async () => { - var packageManifest = await OpenOrCreateManifest(PackageManifestPath, Edge); + var packageManifest = await OpenOrCreateManifest(PackageManifestPath.ToAbsolutePath(), Edge); var githubModuleSources = PackageManager.GetGithubModuleManifests(packageManifest); var modules = PackageManager.GetGithubModules(packageManifest); @@ -226,7 +226,7 @@ private static bool PlatformVersionChanged() .Executes(async () => { var packageManifest = PackageManager.FromFile(PackageManifestPath); - var mixedManifest = JsonExtensions.ReadJson(PackageManifestPath); + var mixedManifest = PackageManifestPath.ToAbsolutePath().ReadJson(); var platformAssetUrlFromManifest = mixedManifest.PlatformAssetUrl; var platformAssetUrl = string.IsNullOrWhiteSpace(PlatformAssetUrl) ? platformAssetUrlFromManifest From a5a50f785b2d392555cf675cbe40cba500ef5641 Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Wed, 21 Feb 2024 15:57:40 +0100 Subject: [PATCH 08/15] VCI-772: Fix codesmells --- src/VirtoCommerce.Build/Build.cs | 6 +++--- src/VirtoCommerce.Build/Cloud/Build.SaaS.cs | 2 +- src/VirtoCommerce.Build/Extensions/PathExtension.cs | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/VirtoCommerce.Build/Build.cs b/src/VirtoCommerce.Build/Build.cs index aa2e12a..2923ae2 100644 --- a/src/VirtoCommerce.Build/Build.cs +++ b/src/VirtoCommerce.Build/Build.cs @@ -841,7 +841,7 @@ private static void CreateNukeDirectory() var nukeFiles = Directory.GetFiles(currentDirectory, ".nuke"); - if (!nukeFiles.Any() && !Directory.Exists(Path.Join(currentDirectory, ".nuke"))) + if (nukeFiles.Length == 0 && !Directory.Exists(Path.Join(currentDirectory, ".nuke"))) { Console.WriteLine("No .nuke file found!"); var solutions = Directory.GetFiles(currentDirectory, "*.sln"); @@ -857,7 +857,7 @@ private static void CreateNukeDirectory() CreateDotNuke(currentDirectory); } } - else if (nukeFiles.Any()) + else if (nukeFiles.Length > 0) { var nukeFile = nukeFiles[0]; ConvertDotNukeFile(nukeFile); @@ -1202,7 +1202,7 @@ private static void CleanSolution(string[] searchPattern, AbsolutePath[] ignoreP { if (SourceDirectory.DirectoryExists()) { - if (ignorePaths?.Any() == true) + if (ignorePaths?.Length > 0) { SourceDirectory .GlobDirectories(searchPattern) diff --git a/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs b/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs index a04fac2..93d0e1e 100644 --- a/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs +++ b/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs @@ -378,7 +378,7 @@ private void SaveCloudToken(string token) public Target CloudUp => _ => _ .DependsOn(CloudInit, CloudDeploy); - private static ISaaSDeploymentApi CreateVirtocloudClient(string url, string token) + private static SaaSDeploymentApi CreateVirtocloudClient(string url, string token) { var config = new VirtoCloud.Client.Client.Configuration(); config.BasePath = url; diff --git a/src/VirtoCommerce.Build/Extensions/PathExtension.cs b/src/VirtoCommerce.Build/Extensions/PathExtension.cs index 44a59bf..e93d309 100644 --- a/src/VirtoCommerce.Build/Extensions/PathExtension.cs +++ b/src/VirtoCommerce.Build/Extensions/PathExtension.cs @@ -12,7 +12,10 @@ public static class PathExtension { public static AbsolutePath ToAbsolutePath(this string path) { - if(path == null) return null; + if(path == null) + { + return null; + } return AbsolutePath.Create(Path.GetFullPath(path)); } From a41421f53b3e4f813d04d2d3cc0a5ab1b5456ad7 Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Thu, 22 Feb 2024 11:19:45 +0100 Subject: [PATCH 09/15] VCI-772: Fix codesmells --- src/VirtoCommerce.Build/Build.cs | 5 +++-- .../PlatformTools/Build.MatchVerisons.cs | 13 +++++++------ .../PlatformTools/Build.PackageManager.cs | 6 +++--- src/VirtoCommerce.Build/Utils/ArtifactPacker.cs | 7 +++++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/VirtoCommerce.Build/Build.cs b/src/VirtoCommerce.Build/Build.cs index 2923ae2..9c37bfe 100644 --- a/src/VirtoCommerce.Build/Build.cs +++ b/src/VirtoCommerce.Build/Build.cs @@ -234,12 +234,13 @@ public static Solution Solution protected static bool IsModule => ModuleManifestFile.FileExists(); + private static readonly string[] cleanSearchPattern = new[] { "**/bin", "**/obj" }; + public Target Clean => _ => _ .Before(Restore) .Executes(() => { - var searchPattern = new[] { "**/bin", "**/obj" }; - CleanSolution(searchPattern); + CleanSolution(cleanSearchPattern); }); public Target Restore => _ => _ diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs b/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs index 5f6b2e6..1692ea8 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs @@ -13,7 +13,8 @@ namespace VirtoCommerce.Build { internal partial class Build { - private Regex _moduleNameRegEx = new Regex(@"(VirtoCommerce.+)Module", RegexOptions.Compiled); + [GeneratedRegex(@"(VirtoCommerce.+)Module", RegexOptions.Compiled)] + private static partial Regex ModuleNameRegEx(); public Target MatchVersions => _ => _ .Executes(() => @@ -38,7 +39,7 @@ internal partial class Build var missedDependenciesErrors = ValidateForMissedDependencies(allPackages); errors.AddRange(missedDependenciesErrors); - if (errors.Any()) + if (errors.Count != 0) { Assert.Fail(errors.Join(Environment.NewLine)); } @@ -54,7 +55,7 @@ private IEnumerable GetProjectPackages(Project project) // find all VirtoCommerce references return msBuildProject.Items .Where(x => x.ItemType == "PackageReference" - && (x.EvaluatedInclude.StartsWith("VirtoCommerce.Platform.") || _moduleNameRegEx.IsMatch(x.EvaluatedInclude))) + && (x.EvaluatedInclude.StartsWith("VirtoCommerce.Platform.") || ModuleNameRegEx().IsMatch(x.EvaluatedInclude))) .Select(x => { var versionMetadata = x.Metadata.FirstOrDefault(x => x.Name == "Version"); @@ -90,7 +91,7 @@ private IEnumerable ValdatePlatformVersion(IEnumerable pack /// /// Check dependencies for module packages versions mismatch /// - private IEnumerable ValidateModuleDependenciesVersions(IEnumerable packages) + private List ValidateModuleDependenciesVersions(IEnumerable packages) { var result = new List(); @@ -117,7 +118,7 @@ private IEnumerable ValidateModuleDependenciesVersions(IEnumerable /// Check project packages for missed dependency in manifest /// - private IEnumerable ValidateForMissedDependencies(IEnumerable packages) + private List ValidateForMissedDependencies(IEnumerable packages) { var result = new List(); @@ -139,7 +140,7 @@ private IEnumerable ValidateForMissedDependencies(IEnumerable x.Value == dependencyName); } } diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs index 37584bf..eb318e4 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs @@ -84,7 +84,7 @@ internal partial class Build { UpdateModules(Module, externalModuleCatalog, modules); } - else if (!PlatformParameter && !modules.Any() && !File.Exists(Path.GetFullPath(PackageManifestPath))) + else if (!PlatformParameter && modules.IsEmpty() && !File.Exists(Path.GetFullPath(PackageManifestPath))) { AddCommerceModules(externalModuleCatalog, modules); } @@ -162,7 +162,7 @@ private static IEnumerable ParseModuleParameter(string[] moduleStrin if (parts.Length > 1) { moduleId = parts[0]; - moduleVersion = parts[parts.Count() - 1]; + moduleVersion = parts[parts.Length - 1]; } else if (moduleStrings.Length == 1 && !string.IsNullOrEmpty(VersionToInstall)) { @@ -209,7 +209,7 @@ private static bool PlatformVersionChanged() public Target Rollback => _ => _ .DependsOn(Backup) .After(Backup, Install, Update, InstallPlatform, InstallModules) - .OnlyWhenDynamic(() => FailedTargets.Any() && SucceededTargets.Contains(Backup)) + .OnlyWhenDynamic(() => FailedTargets.Count > 0 && SucceededTargets.Contains(Backup)) .AssuredAfterFailure() .Executes(() => CompressionExtensions.UnTarGZipTo(BackupFile, RootDirectory)); diff --git a/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs b/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs index ba3c32a..8066db4 100644 --- a/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs +++ b/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs @@ -8,7 +8,7 @@ namespace Utils { - public static class ArtifactPacker + public static partial class ArtifactPacker { public static void CompressPlatform(AbsolutePath sourceDirectory, AbsolutePath outputZipPath) { @@ -26,7 +26,7 @@ public static void CompressModule(Action option FileExistsPolicy.Overwrite); //Exclude all ignored files and *module files not related to compressed module - var ignoreModuleFilesRegex = new Regex(@".+Module\..*", RegexOptions.IgnoreCase); + var ignoreModuleFilesRegex = IgnoreModuleFilesRegex(); var includeModuleFilesRegex = new Regex(@$".*{options.ModuleId}(Module)?\..*", RegexOptions.IgnoreCase); @@ -73,5 +73,8 @@ public static bool KeepFileByRegex(string name, Regex keepRegex) { return keepRegex.IsMatch(name); } + + [GeneratedRegex(@".+Module\..*", RegexOptions.IgnoreCase)] + private static partial Regex IgnoreModuleFilesRegex(); } } From b753f5f8cfa41341110c28f8aa0603eee27f9c16 Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Thu, 22 Feb 2024 11:28:49 +0100 Subject: [PATCH 10/15] VCI-772: Improve maintainability --- .../PlatformTools/Build.MatchVerisons.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs b/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs index 1692ea8..d156c50 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs @@ -5,6 +5,7 @@ using Nuke.Common; using Nuke.Common.ProjectModel; using Nuke.Common.Utilities; +using Nuke.Common.Utilities.Collections; using PlatformTools; using VirtoCommerce.Platform.Core.Common; using VirtoCommerce.Platform.Core.Modularity; @@ -39,7 +40,7 @@ internal partial class Build var missedDependenciesErrors = ValidateForMissedDependencies(allPackages); errors.AddRange(missedDependenciesErrors); - if (errors.Count != 0) + if (!errors.IsEmpty()) { Assert.Fail(errors.Join(Environment.NewLine)); } @@ -48,7 +49,7 @@ internal partial class Build /// /// Get list of VirtoCommerce packages (platform and module) /// - private IEnumerable GetProjectPackages(Project project) + private static IEnumerable GetProjectPackages(Project project) { var msBuildProject = project.GetMSBuildProject(); @@ -127,18 +128,18 @@ private List ValidateForMissedDependencies(IEnumerable pack return result; } - foreach (var packageGroup in packages.Where(x => !x.IsPlatformPackage).GroupBy(x => x.Name)) + foreach (var packageGroupKey in packages.Where(x => !x.IsPlatformPackage).GroupBy(x => x.Name).Select(packageGroup => packageGroup.Key)) { - if (!ModuleManifest.Dependencies.Any(dependency => HasNameMatch(packageGroup.Key, dependency.Id))) + if (!ModuleManifest.Dependencies.Any(dependency => HasNameMatch(packageGroupKey, dependency.Id))) { - result.Add($"Dependency in module.manifest is missing. Package name: {packageGroup.Key}"); + result.Add($"Dependency in module.manifest is missing. Package name: {packageGroupKey}"); } } return result; } - private bool HasNameMatch(string packageName, string dependencyName) + private static bool HasNameMatch(string packageName, string dependencyName) { var match = ModuleNameRegEx().Match(packageName); return match.Groups.Values.Any(x => x.Value == dependencyName); From e52b12d1c653897ce55ade7fb83c6a4155ad6f82 Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Thu, 22 Feb 2024 12:27:32 +0100 Subject: [PATCH 11/15] VCI-772: Minor fixes --- .../PlatformTools/Build.MatchVerisons.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs b/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs index d156c50..f87d270 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs @@ -5,7 +5,6 @@ using Nuke.Common; using Nuke.Common.ProjectModel; using Nuke.Common.Utilities; -using Nuke.Common.Utilities.Collections; using PlatformTools; using VirtoCommerce.Platform.Core.Common; using VirtoCommerce.Platform.Core.Modularity; @@ -40,7 +39,7 @@ internal partial class Build var missedDependenciesErrors = ValidateForMissedDependencies(allPackages); errors.AddRange(missedDependenciesErrors); - if (!errors.IsEmpty()) + if (errors.Count > 0) { Assert.Fail(errors.Join(Environment.NewLine)); } @@ -81,12 +80,13 @@ private static IEnumerable GetProjectPackages(Project project) /// /// Check match between manifest platform version and platform packages /// - private IEnumerable ValdatePlatformVersion(IEnumerable packages) + private List ValdatePlatformVersion(IEnumerable packages) { return packages .Where(package => package.IsPlatformPackage && SemanticVersion.Parse(package.Version) != SemanticVersion.Parse(ModuleManifest.PlatformVersion)) .Select(x => - $"Mismatched platform dependency version found. Platform version: {ModuleManifest.PlatformVersion}, Platform package name: {x.Name}, platform package version: {x.Version}, project name: {x.ProjectName}"); + $"Mismatched platform dependency version found. Platform version: {ModuleManifest.PlatformVersion}, Platform package name: {x.Name}, platform package version: {x.Version}, project name: {x.ProjectName}") + .ToList(); } /// From a7141c215873c6196a82249f67d69e50d1dc4572 Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Thu, 22 Feb 2024 12:47:39 +0100 Subject: [PATCH 12/15] VCI-772: Fix codesmells --- .../PlatformTools/Build.MatchVerisons.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs b/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs index f87d270..87c665e 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs @@ -80,7 +80,7 @@ private static IEnumerable GetProjectPackages(Project project) /// /// Check match between manifest platform version and platform packages /// - private List ValdatePlatformVersion(IEnumerable packages) + private static List ValdatePlatformVersion(IEnumerable packages) { return packages .Where(package => package.IsPlatformPackage && SemanticVersion.Parse(package.Version) != SemanticVersion.Parse(ModuleManifest.PlatformVersion)) @@ -92,7 +92,7 @@ private List ValdatePlatformVersion(IEnumerable packages) /// /// Check dependencies for module packages versions mismatch /// - private List ValidateModuleDependenciesVersions(IEnumerable packages) + private static List ValidateModuleDependenciesVersions(IEnumerable packages) { var result = new List(); @@ -119,7 +119,7 @@ private List ValidateModuleDependenciesVersions(IEnumerable /// /// Check project packages for missed dependency in manifest /// - private List ValidateForMissedDependencies(IEnumerable packages) + private static List ValidateForMissedDependencies(IEnumerable packages) { var result = new List(); From f2983af98c4ec6a29f8b51d39eafa3c69fab2fd6 Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Fri, 1 Mar 2024 07:57:51 +0100 Subject: [PATCH 13/15] VCI-821: Add check for symlinks in installmodules target --- .../PackageManagerTests.cs | 2 +- .../Azure/AzureBlobModuleItem.cs | 11 -- .../PlatformTools/Build.InitPlatform.cs | 1 + .../PlatformTools/Build.PackageManager.cs | 16 +- .../LocalModuleCatalogExtensions.cs | 23 +++ .../PlatformTools/GithubReleases.cs | 2 +- .../PlatformTools/MixedPackageManifest.cs | 1 + .../{ => Modules}/Azure/AzureBlob.cs | 4 +- .../Azure/AzureBlobModuleInstaller.cs | 6 +- .../Modules/Azure/AzureBlobModuleItem.cs | 13 ++ .../Azure/AzureCliToolSettings.cs | 2 +- .../{ => Modules}/Azure/AzureDevClient.cs | 80 +++++----- .../{ => Modules}/Azure/AzureModuleItem.cs | 30 ++-- .../Azure/AzurePipelineArtifacts.cs | 28 ++-- .../Azure/AzurePipelineArtifactsClient.cs | 84 +++++----- .../AzurePipelineArtifactsModuleInstaller.cs | 102 ++++++------- .../Azure/AzureUniversalPackages.cs | 28 ++-- .../AzureUniversalPackagesModuleInstaller.cs | 130 ++++++++-------- .../{ => Modules}/ExtModuleCatalog.cs | 2 +- .../Github/GithubPrivateModuleItem.cs | 4 +- .../Github/GithubPrivateModulesInstaller.cs | 6 +- .../Github/GithubPrivateRepos.cs | 4 +- .../{ => Modules}/Gitlab/GitLabClient.cs | 4 +- .../Gitlab/GitlabJobArtifacts.cs | 4 +- .../GitlabJobArtifactsModuleInstaller.cs | 6 +- .../Gitlab/GitlabJobArtifactsModuleItem.cs | 6 +- .../{ => Modules}/LocalCatalog.cs | 6 +- .../{ => Modules}/LocalModuleCatalog.cs | 2 +- .../ModuleInstallationException.cs | 2 +- .../{ => Modules}/ModuleInstallerFacade.cs | 2 +- .../PlatformTools/{ => Modules}/ModuleItem.cs | 2 +- .../{ => Modules}/ModuleSource.cs | 22 +-- .../{ => Modules}/ModuleSourceConverter.cs | 143 +++++++++--------- .../{ => Modules}/ModulesInstallerBase.cs | 2 +- .../PlatformTools/PackageManager.cs | 1 + .../PlatformTools/PackageManifest.cs | 1 + 36 files changed, 411 insertions(+), 371 deletions(-) delete mode 100644 src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlobModuleItem.cs create mode 100644 src/VirtoCommerce.Build/PlatformTools/Extensions/LocalModuleCatalogExtensions.cs rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Azure/AzureBlob.cs (81%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Azure/AzureBlobModuleInstaller.cs (94%) create mode 100644 src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureBlobModuleItem.cs rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Azure/AzureCliToolSettings.cs (85%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Azure/AzureDevClient.cs (95%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Azure/AzureModuleItem.cs (81%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Azure/AzurePipelineArtifacts.cs (80%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Azure/AzurePipelineArtifactsClient.cs (94%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Azure/AzurePipelineArtifactsModuleInstaller.cs (90%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Azure/AzureUniversalPackages.cs (81%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Azure/AzureUniversalPackagesModuleInstaller.cs (95%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/ExtModuleCatalog.cs (98%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Github/GithubPrivateModuleItem.cs (78%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Github/GithubPrivateModulesInstaller.cs (95%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Github/GithubPrivateRepos.cs (79%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Gitlab/GitLabClient.cs (97%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Gitlab/GitlabJobArtifacts.cs (78%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Gitlab/GitlabJobArtifactsModuleInstaller.cs (90%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Gitlab/GitlabJobArtifactsModuleItem.cs (59%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/LocalCatalog.cs (97%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/LocalModuleCatalog.cs (98%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/ModuleInstallationException.cs (92%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/ModuleInstallerFacade.cs (97%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/ModuleItem.cs (88%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/ModuleSource.cs (76%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/ModuleSourceConverter.cs (90%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/ModulesInstallerBase.cs (96%) diff --git a/src/VirtoCommerce.Build.Tests/PackageManagerTests.cs b/src/VirtoCommerce.Build.Tests/PackageManagerTests.cs index 5a39b91..85b3638 100644 --- a/src/VirtoCommerce.Build.Tests/PackageManagerTests.cs +++ b/src/VirtoCommerce.Build.Tests/PackageManagerTests.cs @@ -1,6 +1,6 @@ using Extensions; -using Nuke.Common.IO; using PlatformTools; +using PlatformTools.Modules; using VirtoCommerce.Build.PlatformTools; namespace VirtoCommerce.Build.Tests diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlobModuleItem.cs b/src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlobModuleItem.cs deleted file mode 100644 index 72a387d..0000000 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlobModuleItem.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace PlatformTools.Azure -{ - internal class AzureBlobModuleItem: ModuleItem - { - public AzureBlobModuleItem(string id, string version): base(id, version) - { - - } - public string BlobName { get; set; } - } -} diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.InitPlatform.cs b/src/VirtoCommerce.Build/PlatformTools/Build.InitPlatform.cs index 6a87638..ee75203 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.InitPlatform.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.InitPlatform.cs @@ -1,6 +1,7 @@ using Nuke.Common; using Nuke.Common.IO; using PlatformTools; +using PlatformTools.Modules; using VirtoCommerce.Platform.Core.Common; namespace VirtoCommerce.Build diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs index eb318e4..5ba4ac7 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs @@ -11,9 +11,11 @@ using Nuke.Common.Utilities; using Nuke.Common.Utilities.Collections; using PlatformTools; -using PlatformTools.Azure; -using PlatformTools.Github; -using PlatformTools.Gitlab; +using PlatformTools.Extensions; +using PlatformTools.Modules; +using PlatformTools.Modules.Azure; +using PlatformTools.Modules.Github; +using PlatformTools.Modules.Gitlab; using Serilog; using VirtoCommerce.Build.PlatformTools; using VirtoCommerce.Platform.Core.Common; @@ -312,6 +314,7 @@ private static bool IsPlatformInstallationNeeded(string version) return result; } + public Target InstallModules => _ => _ .After(InstallPlatform) .OnlyWhenDynamic(() => !PlatformParameter) @@ -322,6 +325,7 @@ private static bool IsPlatformInstallationNeeded(string version) { SkipDependencySolving = true; } + var packageManifest = PackageManager.FromFile(PackageManifestPath); var moduleSources = PackageManager.GetModuleSources(packageManifest).Where(s => s is not GithubReleases).ToList(); var githubReleases = PackageManager.GetGithubModulesSource(packageManifest); @@ -343,7 +347,7 @@ private static bool IsPlatformInstallationNeeded(string version) return; } - if (alreadyInstalledModules.Any(installedModule => installedModule.ModuleName == module.Id && installedModule.Version.ToString() == module.Version)) + if (alreadyInstalledModules.Exists(installedModule => installedModule.ModuleName == module.Id && installedModule.Version.ToString() == module.Version) || localModuleCatalog.IsModuleFromSourceCode(module.Id)) { continue; } @@ -485,7 +489,7 @@ private static ManifestModuleInfo LoadModuleInfo(ModuleItem module, ManifestModu .Executes(async () => { SkipDependencySolving = true; - var manifest = PackageManager.FromFile(PackageManifestPath); + var manifest = await OpenOrCreateManifest(PackageManifestPath, Edge); if (Edge) { @@ -638,7 +642,7 @@ private static async Task DownloadBundleManifest(string bundleName, string outFi } var manifestUrl = bundle.Value; - await HttpTasks.HttpDownloadFileAsync(manifestUrl, outFile); + await HttpTasks.HttpDownloadFileAsync(manifestUrl, outFile.ToAbsolutePath()); } private static ManifestBase CreateManifestFromEnvironment(AbsolutePath platformPath, AbsolutePath discoveryPath) diff --git a/src/VirtoCommerce.Build/PlatformTools/Extensions/LocalModuleCatalogExtensions.cs b/src/VirtoCommerce.Build/PlatformTools/Extensions/LocalModuleCatalogExtensions.cs new file mode 100644 index 0000000..4ce7a2a --- /dev/null +++ b/src/VirtoCommerce.Build/PlatformTools/Extensions/LocalModuleCatalogExtensions.cs @@ -0,0 +1,23 @@ +using System.IO; +using System.Linq; +using PlatformTools.Modules; +using VirtoCommerce.Platform.Core.Modularity; + +namespace PlatformTools.Extensions +{ + public static class LocalModuleCatalogExtensions + { + public static bool IsModuleFromSourceCode(this ILocalModuleCatalog moduleCatalog, string moduleId) + { + var moduleInfo = moduleCatalog.Modules.OfType().FirstOrDefault(m => m.ModuleName == moduleId); + if(moduleInfo == null) + { + return false; + } + + var fileInfo = new FileInfo(moduleInfo.FullPhysicalPath); + + return fileInfo.LinkTarget != null; + } + } +} diff --git a/src/VirtoCommerce.Build/PlatformTools/GithubReleases.cs b/src/VirtoCommerce.Build/PlatformTools/GithubReleases.cs index 65a5dea..88544e7 100644 --- a/src/VirtoCommerce.Build/PlatformTools/GithubReleases.cs +++ b/src/VirtoCommerce.Build/PlatformTools/GithubReleases.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using PlatformTools; +using PlatformTools.Modules; namespace VirtoCommerce.Build.PlatformTools { diff --git a/src/VirtoCommerce.Build/PlatformTools/MixedPackageManifest.cs b/src/VirtoCommerce.Build/PlatformTools/MixedPackageManifest.cs index 056e843..edbe1c0 100644 --- a/src/VirtoCommerce.Build/PlatformTools/MixedPackageManifest.cs +++ b/src/VirtoCommerce.Build/PlatformTools/MixedPackageManifest.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using PlatformTools.Modules; namespace VirtoCommerce.Build.PlatformTools { diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlob.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureBlob.cs similarity index 81% rename from src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlob.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureBlob.cs index 4ab2e4a..97e81f0 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlob.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureBlob.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; -using VirtoCommerce.Build.PlatformTools; +using PlatformTools.Modules; -namespace PlatformTools.Azure +namespace PlatformTools.Modules.Azure { internal class AzureBlob : ModuleSource { diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlobModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureBlobModuleInstaller.cs similarity index 94% rename from src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlobModuleInstaller.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureBlobModuleInstaller.cs index c6e4875..e0b1c7e 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlobModuleInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureBlobModuleInstaller.cs @@ -3,11 +3,11 @@ using System.IO.Compression; using System.Linq; using System.Threading.Tasks; -using VirtoCommerce.Build.PlatformTools; +using PlatformTools.Modules; using VirtoCommerce.Platform.Core.Modularity; using AzureBlobs = Azure.Storage.Blobs; -namespace PlatformTools.Azure +namespace PlatformTools.Modules.Azure { internal class AzureBlobModuleInstaller : ModulesInstallerBase { @@ -31,7 +31,7 @@ protected override Task InnerInstall(ModuleSource source, IProgress GetArtifactUrl(Guid project, string branch, string definitionName) - { - var client = await _connection.GetClientAsync(); - var build = await client.GetLatestBuildAsync(project, definitionName, branch); - var artifacts = await client.GetArtifactsAsync(project, build.Id); - Assert.NotEmpty(artifacts, - $"No builds found for the project id: {project.ToString()}{Environment.NewLine}branch: {branch}{Environment.NewLine}definition: {definitionName}"); - var result = artifacts.FirstOrDefault()?.Resource.DownloadUrl; - - return new Uri(result ?? string.Empty); - } - - public async Task GetArtifactStream(Guid project, string branch, string definitionName) - { - var client = await _connection.GetClientAsync(); - var build = await client.GetLatestBuildAsync(project, definitionName, branch); - var result = await client.GetArtifactContentZipAsync(project, build.Id, "backend"); - return result; - } -} +using System; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.TeamFoundation.Build.WebApi; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; +using Nuke.Common; + +namespace PlatformTools.Modules.Azure; + +public class AzureDevClient +{ + private readonly VssConnection _connection; + + public AzureDevClient(string orgName, string token) + { + _connection = new VssConnection(new Uri(orgName), new VssBasicCredential(string.Empty, token)); + } + + public async Task GetArtifactUrl(Guid project, string branch, string definitionName) + { + var client = await _connection.GetClientAsync(); + var build = await client.GetLatestBuildAsync(project, definitionName, branch); + var artifacts = await client.GetArtifactsAsync(project, build.Id); + Assert.NotEmpty(artifacts, + $"No builds found for the project id: {project.ToString()}{Environment.NewLine}branch: {branch}{Environment.NewLine}definition: {definitionName}"); + var result = artifacts.FirstOrDefault()?.Resource.DownloadUrl; + + return new Uri(result ?? string.Empty); + } + + public async Task GetArtifactStream(Guid project, string branch, string definitionName) + { + var client = await _connection.GetClientAsync(); + var build = await client.GetLatestBuildAsync(project, definitionName, branch); + var result = await client.GetArtifactContentZipAsync(project, build.Id, "backend"); + return result; + } +} diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureModuleItem.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureModuleItem.cs similarity index 81% rename from src/VirtoCommerce.Build/PlatformTools/Azure/AzureModuleItem.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureModuleItem.cs index f5e9e4e..30b73d7 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureModuleItem.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureModuleItem.cs @@ -1,14 +1,16 @@ -namespace PlatformTools.Azure -{ - internal class AzureModuleItem : ModuleItem - { - public AzureModuleItem(string id, string version) : base(id, version) - { - } - - public string BuildId { get; set; } - public string Branch { get; set; } - public string Definition { get; set; } - } -} - +using PlatformTools.Modules; + +namespace PlatformTools.Modules.Azure +{ + internal class AzureModuleItem : ModuleItem + { + public AzureModuleItem(string id, string version) : base(id, version) + { + } + + public string BuildId { get; set; } + public string Branch { get; set; } + public string Definition { get; set; } + } +} + diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifacts.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifacts.cs similarity index 80% rename from src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifacts.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifacts.cs index 110a749..43b96a3 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifacts.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifacts.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; -using VirtoCommerce.Build.PlatformTools; - -namespace PlatformTools.Azure -{ - internal class AzurePipelineArtifacts : ModuleSource - { - public string Organization { get; set; } - public string Project { get; set; } - public List Modules { get; set; } - public override string Name { get; set; } = nameof(AzurePipelineArtifacts); - } -} - +using System.Collections.Generic; +using PlatformTools.Modules; + +namespace PlatformTools.Modules.Azure +{ + internal class AzurePipelineArtifacts : ModuleSource + { + public string Organization { get; set; } + public string Project { get; set; } + public List Modules { get; set; } + public override string Name { get; set; } = nameof(AzurePipelineArtifacts); + } +} + diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsClient.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsClient.cs similarity index 94% rename from src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsClient.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsClient.cs index 6c3a10f..118793f 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsClient.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsClient.cs @@ -1,42 +1,42 @@ -using System; -using System.IO; -using System.Net.Http; -using System.Text; -using Microsoft.Extensions.Options; -using VirtoCommerce.Platform.Core.Modularity; -using VirtoCommerce.Platform.Modules.External; - -namespace PlatformTools.Azure -{ - public class AzurePipelineArtifactsClient : IExternalModulesClient - { - private readonly ExternalModuleCatalogOptions _options; - - public AzurePipelineArtifactsClient(IOptions options) - { - _options = options.Value; - } - - public Stream OpenRead(Uri address) - { - var client = new HttpClient(); - var request = new HttpRequestMessage(HttpMethod.Get, address); - HttpResponseMessage response; - try - { - if (!string.IsNullOrEmpty(_options.AuthorizationToken)) - { - var tokenEncoded = Convert.ToBase64String(Encoding.UTF8.GetBytes($":{_options.AuthorizationToken}")); - request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic " + tokenEncoded); - } - response = client.Send(request); - return response.Content.ReadAsStream(); - } - finally - { - client?.Dispose(); - } - } - } -} - +using System; +using System.IO; +using System.Net.Http; +using System.Text; +using Microsoft.Extensions.Options; +using VirtoCommerce.Platform.Core.Modularity; +using VirtoCommerce.Platform.Modules.External; + +namespace PlatformTools.Modules.Azure +{ + public class AzurePipelineArtifactsClient : IExternalModulesClient + { + private readonly ExternalModuleCatalogOptions _options; + + public AzurePipelineArtifactsClient(IOptions options) + { + _options = options.Value; + } + + public Stream OpenRead(Uri address) + { + var client = new HttpClient(); + var request = new HttpRequestMessage(HttpMethod.Get, address); + HttpResponseMessage response; + try + { + if (!string.IsNullOrEmpty(_options.AuthorizationToken)) + { + var tokenEncoded = Convert.ToBase64String(Encoding.UTF8.GetBytes($":{_options.AuthorizationToken}")); + request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic " + tokenEncoded); + } + response = client.Send(request); + return response.Content.ReadAsStream(); + } + finally + { + client?.Dispose(); + } + } + } +} + diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsModuleInstaller.cs similarity index 90% rename from src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsModuleInstaller.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsModuleInstaller.cs index 189a130..cf7d513 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsModuleInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsModuleInstaller.cs @@ -1,51 +1,51 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.IO.Compression; -using System.Threading.Tasks; -using VirtoCommerce.Build.PlatformTools; -using VirtoCommerce.Platform.Core.Modularity; - -namespace PlatformTools.Azure -{ - internal class AzurePipelineArtifactsModuleInstaller : ModulesInstallerBase - { - private readonly string _token; - private readonly string _discoveryPath; - - public AzurePipelineArtifactsModuleInstaller(string token, string discoveryPath) - { - this._token = token; - this._discoveryPath = discoveryPath; - } - - protected override async Task InnerInstall(ModuleSource source, IProgress progress) - { - var artifacts = (AzurePipelineArtifacts)source; - var azureClient = new AzureDevClient(artifacts.Organization, _token); - var clientOptions = ExtModuleCatalog.GetOptions(_token, new List() { "https://virtocommerce.com" }); - var downloadClient = new AzurePipelineArtifactsClient(clientOptions); - foreach (var module in artifacts.Modules) - { - progress.ReportInfo($"Installing {module.Id}"); - var moduleDestination = Path.Join(_discoveryPath, module.Id); - Directory.CreateDirectory(moduleDestination); - var zipName = $"{module.Id}.zip"; - var zipDestination = Path.Join(moduleDestination, zipName); - var artifactUrl = await azureClient.GetArtifactUrl(Guid.Parse(artifacts.Project), module.Branch, module.Definition); - progress.ReportInfo($"Downloading {artifactUrl}"); - using (var stream = downloadClient.OpenRead(artifactUrl)) - { - using (var output = File.OpenWrite(zipDestination)) - { - await stream.CopyToAsync(output); - } - } - progress.ReportInfo($"Extracting {zipName}"); - ZipFile.ExtractToDirectory(zipDestination, moduleDestination); - progress.ReportInfo($"Successfully installed {module.Id}"); - } - } - } -} - +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Threading.Tasks; +using PlatformTools.Modules; +using VirtoCommerce.Platform.Core.Modularity; + +namespace PlatformTools.Modules.Azure +{ + internal class AzurePipelineArtifactsModuleInstaller : ModulesInstallerBase + { + private readonly string _token; + private readonly string _discoveryPath; + + public AzurePipelineArtifactsModuleInstaller(string token, string discoveryPath) + { + _token = token; + _discoveryPath = discoveryPath; + } + + protected override async Task InnerInstall(ModuleSource source, IProgress progress) + { + var artifacts = (AzurePipelineArtifacts)source; + var azureClient = new AzureDevClient(artifacts.Organization, _token); + var clientOptions = ExtModuleCatalog.GetOptions(_token, new List() { "https://virtocommerce.com" }); + var downloadClient = new AzurePipelineArtifactsClient(clientOptions); + foreach (var module in artifacts.Modules) + { + progress.ReportInfo($"Installing {module.Id}"); + var moduleDestination = Path.Join(_discoveryPath, module.Id); + Directory.CreateDirectory(moduleDestination); + var zipName = $"{module.Id}.zip"; + var zipDestination = Path.Join(moduleDestination, zipName); + var artifactUrl = await azureClient.GetArtifactUrl(Guid.Parse(artifacts.Project), module.Branch, module.Definition); + progress.ReportInfo($"Downloading {artifactUrl}"); + using (var stream = downloadClient.OpenRead(artifactUrl)) + { + using (var output = File.OpenWrite(zipDestination)) + { + await stream.CopyToAsync(output); + } + } + progress.ReportInfo($"Extracting {zipName}"); + ZipFile.ExtractToDirectory(zipDestination, moduleDestination); + progress.ReportInfo($"Successfully installed {module.Id}"); + } + } + } +} + diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackages.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureUniversalPackages.cs similarity index 81% rename from src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackages.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureUniversalPackages.cs index 34611af..66fc6f4 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackages.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureUniversalPackages.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; -using VirtoCommerce.Build.PlatformTools; - -namespace PlatformTools.Azure -{ - internal class AzureUniversalPackages : ModuleSource - { - public override string Name { get; set; } = nameof(AzureUniversalPackages); - public string Organization { get; set; } - public string Project { get; set; } - public string Feed { get; set; } - public List Modules { get; set; } - } -} +using System.Collections.Generic; +using PlatformTools.Modules; + +namespace PlatformTools.Modules.Azure +{ + internal class AzureUniversalPackages : ModuleSource + { + public override string Name { get; set; } = nameof(AzureUniversalPackages); + public string Organization { get; set; } + public string Project { get; set; } + public string Feed { get; set; } + public List Modules { get; set; } + } +} diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureUniversalPackagesModuleInstaller.cs similarity index 95% rename from src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureUniversalPackagesModuleInstaller.cs index 44fd341..3cc508f 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzureUniversalPackagesModuleInstaller.cs @@ -1,65 +1,65 @@ -using System; -using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Threading.Tasks; -using Extensions; -using Nuke.Common.IO; -using Nuke.Common.Tooling; -using VirtoCommerce.Build.PlatformTools; -using VirtoCommerce.Platform.Core.Modularity; - -namespace PlatformTools.Azure -{ - internal class AzureUniversalPackagesModuleInstaller : ModulesInstallerBase - { - readonly string token; - readonly string discoveryPath; - - public AzureUniversalPackagesModuleInstaller(string token, string discoveryPath) - { - this.token = token; - this.discoveryPath = discoveryPath; - } - - protected override Task InnerInstall(ModuleSource source, IProgress progress) - { - var artifacts = (AzureUniversalPackages)source; - foreach (var module in artifacts.Modules) - { - progress.ReportInfo($"Installing {module.Id}"); - var moduleDestination = Path.Join(discoveryPath, module.Id).ToAbsolutePath(); - Directory.CreateDirectory(moduleDestination); - moduleDestination.CreateOrCleanDirectory(); - var azPath = ToolPathResolver.GetPathExecutable("az"); - var azToolSettings = new AzureCliToolSettings() - .AddProcessEnvironmentVariable("AZURE_DEVOPS_EXT_PAT", token) - .SetProcessToolPath(azPath) - .SetProcessArgumentConfigurator(c => c - .Add("artifacts universal download") - .Add("--organization \"{0}\"", artifacts.Organization) - .Add("--project \"{0}\"", artifacts.Project) - .Add("--feed {0}", artifacts.Feed) - .Add("--name {0}", module.Id) - .Add("--path \"{0}\"", moduleDestination) - .Add("--scope {0}", "project") - .Add("--version {0}", module.Version) - ); - ProcessTasks.StartProcess(azToolSettings).AssertZeroExitCode(); - - var zipPath = Directory.GetFiles(moduleDestination).FirstOrDefault(p => p.EndsWith(".zip")); - if (zipPath == null) - { - progress.ReportError($"Can't download {module.Id} - {module.Version}"); - } - - progress.ReportInfo($"Extracting {zipPath}"); - ZipFile.ExtractToDirectory(zipPath, moduleDestination); - progress.ReportInfo($"Successfully installed {module.Id}"); - } - - return Task.CompletedTask; - } - } -} - +using System; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Threading.Tasks; +using Extensions; +using Nuke.Common.IO; +using Nuke.Common.Tooling; +using PlatformTools.Modules; +using VirtoCommerce.Platform.Core.Modularity; + +namespace PlatformTools.Modules.Azure +{ + internal class AzureUniversalPackagesModuleInstaller : ModulesInstallerBase + { + readonly string token; + readonly string discoveryPath; + + public AzureUniversalPackagesModuleInstaller(string token, string discoveryPath) + { + this.token = token; + this.discoveryPath = discoveryPath; + } + + protected override Task InnerInstall(ModuleSource source, IProgress progress) + { + var artifacts = (AzureUniversalPackages)source; + foreach (var module in artifacts.Modules) + { + progress.ReportInfo($"Installing {module.Id}"); + var moduleDestination = Path.Join(discoveryPath, module.Id).ToAbsolutePath(); + Directory.CreateDirectory(moduleDestination); + moduleDestination.CreateOrCleanDirectory(); + var azPath = ToolPathResolver.GetPathExecutable("az"); + var azToolSettings = new AzureCliToolSettings() + .AddProcessEnvironmentVariable("AZURE_DEVOPS_EXT_PAT", token) + .SetProcessToolPath(azPath) + .SetProcessArgumentConfigurator(c => c + .Add("artifacts universal download") + .Add("--organization \"{0}\"", artifacts.Organization) + .Add("--project \"{0}\"", artifacts.Project) + .Add("--feed {0}", artifacts.Feed) + .Add("--name {0}", module.Id) + .Add("--path \"{0}\"", moduleDestination) + .Add("--scope {0}", "project") + .Add("--version {0}", module.Version) + ); + ProcessTasks.StartProcess(azToolSettings).AssertZeroExitCode(); + + var zipPath = Directory.GetFiles(moduleDestination).FirstOrDefault(p => p.EndsWith(".zip")); + if (zipPath == null) + { + progress.ReportError($"Can't download {module.Id} - {module.Version}"); + } + + progress.ReportInfo($"Extracting {zipPath}"); + ZipFile.ExtractToDirectory(zipPath, moduleDestination); + progress.ReportInfo($"Successfully installed {module.Id}"); + } + + return Task.CompletedTask; + } + } +} + diff --git a/src/VirtoCommerce.Build/PlatformTools/ExtModuleCatalog.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/ExtModuleCatalog.cs similarity index 98% rename from src/VirtoCommerce.Build/PlatformTools/ExtModuleCatalog.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/ExtModuleCatalog.cs index cdc2e0b..14de565 100644 --- a/src/VirtoCommerce.Build/PlatformTools/ExtModuleCatalog.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/ExtModuleCatalog.cs @@ -9,7 +9,7 @@ using VirtoCommerce.Platform.Modules; using VirtoCommerce.Platform.Modules.External; -namespace PlatformTools +namespace PlatformTools.Modules { internal static class ExtModuleCatalog { diff --git a/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModuleItem.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModuleItem.cs similarity index 78% rename from src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModuleItem.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModuleItem.cs index 3100664..2a29b0d 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModuleItem.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModuleItem.cs @@ -1,4 +1,6 @@ -namespace PlatformTools.Github +using PlatformTools.Modules; + +namespace PlatformTools.Modules.Github { internal class GithubPrivateModuleItem : ModuleItem { diff --git a/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModulesInstaller.cs similarity index 95% rename from src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModulesInstaller.cs index 103f9bb..ca8a2fc 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModulesInstaller.cs @@ -6,10 +6,10 @@ using System.Threading.Tasks; using Nuke.Common.IO; using Octokit; -using VirtoCommerce.Build.PlatformTools; +using PlatformTools.Modules; using VirtoCommerce.Platform.Core.Modularity; -namespace PlatformTools.Github +namespace PlatformTools.Modules.Github { internal class GithubPrivateModulesInstaller : ModulesInstallerBase { @@ -27,7 +27,7 @@ public GithubPrivateModulesInstaller(string token, string discoveryPath) protected override async Task InnerInstall(ModuleSource source, IProgress progress) { - var githubPrivateRepos = (GithubPrivateRepos) source; + var githubPrivateRepos = (GithubPrivateRepos)source; foreach (var module in githubPrivateRepos.Modules) { var moduleDestination = AbsolutePath.Create(Path.Join(_discoveryPath, module.Id)); diff --git a/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateRepos.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateRepos.cs similarity index 79% rename from src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateRepos.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateRepos.cs index b4fee67..bd8ceff 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateRepos.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateRepos.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; -using VirtoCommerce.Build.PlatformTools; +using PlatformTools.Modules; -namespace PlatformTools.Github +namespace PlatformTools.Modules.Github { internal class GithubPrivateRepos : ModuleSource { diff --git a/src/VirtoCommerce.Build/PlatformTools/Gitlab/GitLabClient.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitLabClient.cs similarity index 97% rename from src/VirtoCommerce.Build/PlatformTools/Gitlab/GitLabClient.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitLabClient.cs index d200dfd..6e9ed7e 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Gitlab/GitLabClient.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitLabClient.cs @@ -7,7 +7,7 @@ using Newtonsoft.Json.Linq; using Nuke.Common; -namespace PlatformTools.Gitlab; +namespace PlatformTools.Modules.Gitlab; public class GitLabClient { @@ -28,7 +28,7 @@ public async Task DownloadArtifact(string projectId, string jobId, strin var jobResponse = await _client.GetAsync(jobUrl); var jobJson = await jobResponse.Content.ReadAsStringAsync(); var jobData = JObject.Parse(jobJson); - + // Get artifact file name and URL var artifactFileName = (string)jobData["artifacts_file"]?["filename"]; diff --git a/src/VirtoCommerce.Build/PlatformTools/Gitlab/GitlabJobArtifacts.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitlabJobArtifacts.cs similarity index 78% rename from src/VirtoCommerce.Build/PlatformTools/Gitlab/GitlabJobArtifacts.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitlabJobArtifacts.cs index 4e7c204..417bb82 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Gitlab/GitlabJobArtifacts.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitlabJobArtifacts.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; -using VirtoCommerce.Build.PlatformTools; +using PlatformTools.Modules; -namespace PlatformTools.Gitlab; +namespace PlatformTools.Modules.Gitlab; internal class GitlabJobArtifacts : ModuleSource { diff --git a/src/VirtoCommerce.Build/PlatformTools/Gitlab/GitlabJobArtifactsModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitlabJobArtifactsModuleInstaller.cs similarity index 90% rename from src/VirtoCommerce.Build/PlatformTools/Gitlab/GitlabJobArtifactsModuleInstaller.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitlabJobArtifactsModuleInstaller.cs index ea2cba7..0efaab7 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Gitlab/GitlabJobArtifactsModuleInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitlabJobArtifactsModuleInstaller.cs @@ -3,10 +3,10 @@ using System.IO.Compression; using System.Threading.Tasks; using Nuke.Common.IO; -using VirtoCommerce.Build.PlatformTools; +using PlatformTools.Modules; using VirtoCommerce.Platform.Core.Modularity; -namespace PlatformTools.Gitlab; +namespace PlatformTools.Modules.Gitlab; internal class GitlabJobArtifactsModuleInstaller : ModulesInstallerBase { @@ -21,7 +21,7 @@ public GitlabJobArtifactsModuleInstaller(string server, string token, string dis protected override async Task InnerInstall(ModuleSource source, IProgress progress) { - var gitlabJobArtifacts = (GitlabJobArtifacts) source; + var gitlabJobArtifacts = (GitlabJobArtifacts)source; foreach (var module in gitlabJobArtifacts.Modules) { var moduleDestination = AbsolutePath.Create(Path.Join(_discoveryPath, module.Id)); diff --git a/src/VirtoCommerce.Build/PlatformTools/Gitlab/GitlabJobArtifactsModuleItem.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitlabJobArtifactsModuleItem.cs similarity index 59% rename from src/VirtoCommerce.Build/PlatformTools/Gitlab/GitlabJobArtifactsModuleItem.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitlabJobArtifactsModuleItem.cs index ef0336b..68c0eb7 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Gitlab/GitlabJobArtifactsModuleItem.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Gitlab/GitlabJobArtifactsModuleItem.cs @@ -1,6 +1,8 @@ -namespace PlatformTools.Gitlab; +using PlatformTools.Modules; -internal class GitlabJobArtifactsModuleItem: ModuleItem +namespace PlatformTools.Modules.Gitlab; + +internal class GitlabJobArtifactsModuleItem : ModuleItem { public GitlabJobArtifactsModuleItem(string id, string version) : base(id, version) { diff --git a/src/VirtoCommerce.Build/PlatformTools/LocalCatalog.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/LocalCatalog.cs similarity index 97% rename from src/VirtoCommerce.Build/PlatformTools/LocalCatalog.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/LocalCatalog.cs index 78c9b7e..182962c 100644 --- a/src/VirtoCommerce.Build/PlatformTools/LocalCatalog.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/LocalCatalog.cs @@ -11,7 +11,7 @@ using VirtoCommerce.Platform.DistributedLock; using VirtoCommerce.Platform.Modules; -namespace PlatformTools +namespace PlatformTools.Modules { public class LocalCatalog : LocalStorageModuleCatalog { @@ -19,7 +19,7 @@ public class LocalCatalog : LocalStorageModuleCatalog private readonly ILogger _logger; private readonly IInternalDistributedLockService _distributedLockProvider; private readonly string _discoveryPath; - public LocalCatalog(IOptions options, IInternalDistributedLockService distributedLockProvider, ILogger logger): + public LocalCatalog(IOptions options, IInternalDistributedLockService distributedLockProvider, ILogger logger) : base(options, distributedLockProvider, logger) { _options = options.Value; @@ -201,7 +201,7 @@ private void CopyFile(string sourceFilePath, string targetFilePath) targetVersion = new Version(targetFileVersionInfo.FileMajorPart, targetFileVersionInfo.FileMinorPart, targetFileVersionInfo.FileBuildPart, targetFileVersionInfo.FilePrivatePart); } - var versionsAreSameButLaterDate = (sourceVersion == targetVersion && targetFileInfo.Exists && sourceFileInfo.Exists && targetFileInfo.LastWriteTimeUtc < sourceFileInfo.LastWriteTimeUtc); + var versionsAreSameButLaterDate = sourceVersion == targetVersion && targetFileInfo.Exists && sourceFileInfo.Exists && targetFileInfo.LastWriteTimeUtc < sourceFileInfo.LastWriteTimeUtc; if (!targetFileInfo.Exists || sourceVersion > targetVersion || versionsAreSameButLaterDate) { var targetDirectoryPath = Path.GetDirectoryName(targetFilePath); diff --git a/src/VirtoCommerce.Build/PlatformTools/LocalModuleCatalog.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/LocalModuleCatalog.cs similarity index 98% rename from src/VirtoCommerce.Build/PlatformTools/LocalModuleCatalog.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/LocalModuleCatalog.cs index e445365..77a662a 100644 --- a/src/VirtoCommerce.Build/PlatformTools/LocalModuleCatalog.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/LocalModuleCatalog.cs @@ -4,7 +4,7 @@ using VirtoCommerce.Platform.DistributedLock; using VirtoCommerce.Platform.Modules; -namespace PlatformTools +namespace PlatformTools.Modules { internal static class LocalModuleCatalog { diff --git a/src/VirtoCommerce.Build/PlatformTools/ModuleInstallationException.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleInstallationException.cs similarity index 92% rename from src/VirtoCommerce.Build/PlatformTools/ModuleInstallationException.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/ModuleInstallationException.cs index 83aa0bf..982ab0c 100644 --- a/src/VirtoCommerce.Build/PlatformTools/ModuleInstallationException.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleInstallationException.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.Serialization; -namespace VirtoCommerce.Build.PlatformTools +namespace PlatformTools.Modules { [Serializable] public class ModuleInstallationException : Exception diff --git a/src/VirtoCommerce.Build/PlatformTools/ModuleInstallerFacade.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleInstallerFacade.cs similarity index 97% rename from src/VirtoCommerce.Build/PlatformTools/ModuleInstallerFacade.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/ModuleInstallerFacade.cs index 5b66c46..66c46be 100644 --- a/src/VirtoCommerce.Build/PlatformTools/ModuleInstallerFacade.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleInstallerFacade.cs @@ -6,7 +6,7 @@ using VirtoCommerce.Platform.Modules; using VirtoCommerce.Platform.Modules.External; -namespace PlatformTools +namespace PlatformTools.Modules { internal static class ModuleInstallerFacade { diff --git a/src/VirtoCommerce.Build/PlatformTools/ModuleItem.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleItem.cs similarity index 88% rename from src/VirtoCommerce.Build/PlatformTools/ModuleItem.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/ModuleItem.cs index e9f4ef6..49cfe91 100644 --- a/src/VirtoCommerce.Build/PlatformTools/ModuleItem.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleItem.cs @@ -1,4 +1,4 @@ -namespace PlatformTools +namespace PlatformTools.Modules { public class ModuleItem { diff --git a/src/VirtoCommerce.Build/PlatformTools/ModuleSource.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleSource.cs similarity index 76% rename from src/VirtoCommerce.Build/PlatformTools/ModuleSource.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/ModuleSource.cs index 6f89fbc..ac6ec87 100644 --- a/src/VirtoCommerce.Build/PlatformTools/ModuleSource.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleSource.cs @@ -1,11 +1,11 @@ -using Newtonsoft.Json; - -namespace VirtoCommerce.Build.PlatformTools -{ - [JsonConverter(typeof(ModuleSourceConverter))] - public abstract class ModuleSource - { - public abstract string Name { get; set; } - } -} - +using Newtonsoft.Json; + +namespace PlatformTools.Modules +{ + [JsonConverter(typeof(ModuleSourceConverter))] + public abstract class ModuleSource + { + public abstract string Name { get; set; } + } +} + diff --git a/src/VirtoCommerce.Build/PlatformTools/ModuleSourceConverter.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleSourceConverter.cs similarity index 90% rename from src/VirtoCommerce.Build/PlatformTools/ModuleSourceConverter.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/ModuleSourceConverter.cs index 2ef5d2d..68af9f4 100644 --- a/src/VirtoCommerce.Build/PlatformTools/ModuleSourceConverter.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/ModuleSourceConverter.cs @@ -1,71 +1,72 @@ -using System; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; -using PlatformTools.Azure; -using PlatformTools.Github; -using PlatformTools.Gitlab; - -namespace VirtoCommerce.Build.PlatformTools -{ - public class ModuleSourceConverter : JsonConverter - { - private static JsonSerializerSettings SpecifiedSubclassConversion = new JsonSerializerSettings() { ContractResolver = new ModuleSourceSpecifiedConcreteClassConverter() }; - - public override bool CanConvert(Type objectType) - { - return (objectType == typeof(ModuleSource)); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - JObject jo = JObject.Load(reader); - var sourceName = jo[nameof(ModuleSource.Name)].Value(); - switch (sourceName) - { - case nameof(GithubReleases): - return JsonConvert.DeserializeObject(jo.ToString(), SpecifiedSubclassConversion); - - case nameof(AzurePipelineArtifacts): - return JsonConvert.DeserializeObject(jo.ToString(), SpecifiedSubclassConversion); - - case nameof(AzureUniversalPackages): - return JsonConvert.DeserializeObject(jo.ToString(), SpecifiedSubclassConversion); - - case nameof(GithubPrivateRepos): - return JsonConvert.DeserializeObject(jo.ToString(), SpecifiedSubclassConversion); - case nameof(AzureBlob): - return JsonConvert.DeserializeObject(jo.ToString(), SpecifiedSubclassConversion); - case nameof(GitlabJobArtifacts): - return JsonConvert.DeserializeObject(jo.ToString(), - SpecifiedSubclassConversion); - default: - throw new TypeLoadException($"Unknown module source: {sourceName}"); - } - throw new NotImplementedException(); - } - - public override bool CanWrite - { - get { return false; } - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotImplementedException(); // won't be called because CanWrite returns false - } - } - - public class ModuleSourceSpecifiedConcreteClassConverter : DefaultContractResolver - { - protected override JsonConverter ResolveContractConverter(Type objectType) - { - if (typeof(ModuleSource).IsAssignableFrom(objectType) && !objectType.IsAbstract) - { - return null; // pretend TableSortRuleConvert is not specified (thus avoiding a stack overflow) - } - - return base.ResolveContractConverter(objectType); - } - } -} +using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; +using PlatformTools.Modules.Azure; +using PlatformTools.Modules.Github; +using PlatformTools.Modules.Gitlab; +using VirtoCommerce.Build.PlatformTools; + +namespace PlatformTools.Modules +{ + public class ModuleSourceConverter : JsonConverter + { + private static JsonSerializerSettings SpecifiedSubclassConversion = new JsonSerializerSettings() { ContractResolver = new ModuleSourceSpecifiedConcreteClassConverter() }; + + public override bool CanConvert(Type objectType) + { + return objectType == typeof(ModuleSource); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var jo = JObject.Load(reader); + var sourceName = jo[nameof(ModuleSource.Name)].Value(); + switch (sourceName) + { + case nameof(GithubReleases): + return JsonConvert.DeserializeObject(jo.ToString(), SpecifiedSubclassConversion); + + case nameof(AzurePipelineArtifacts): + return JsonConvert.DeserializeObject(jo.ToString(), SpecifiedSubclassConversion); + + case nameof(AzureUniversalPackages): + return JsonConvert.DeserializeObject(jo.ToString(), SpecifiedSubclassConversion); + + case nameof(GithubPrivateRepos): + return JsonConvert.DeserializeObject(jo.ToString(), SpecifiedSubclassConversion); + case nameof(AzureBlob): + return JsonConvert.DeserializeObject(jo.ToString(), SpecifiedSubclassConversion); + case nameof(GitlabJobArtifacts): + return JsonConvert.DeserializeObject(jo.ToString(), + SpecifiedSubclassConversion); + default: + throw new TypeLoadException($"Unknown module source: {sourceName}"); + } + throw new NotImplementedException(); + } + + public override bool CanWrite + { + get { return false; } + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + throw new NotImplementedException(); // won't be called because CanWrite returns false + } + } + + public class ModuleSourceSpecifiedConcreteClassConverter : DefaultContractResolver + { + protected override JsonConverter ResolveContractConverter(Type objectType) + { + if (typeof(ModuleSource).IsAssignableFrom(objectType) && !objectType.IsAbstract) + { + return null; // pretend TableSortRuleConvert is not specified (thus avoiding a stack overflow) + } + + return base.ResolveContractConverter(objectType); + } + } +} diff --git a/src/VirtoCommerce.Build/PlatformTools/ModulesInstallerBase.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/ModulesInstallerBase.cs similarity index 96% rename from src/VirtoCommerce.Build/PlatformTools/ModulesInstallerBase.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/ModulesInstallerBase.cs index aadeddd..d024ad2 100644 --- a/src/VirtoCommerce.Build/PlatformTools/ModulesInstallerBase.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/ModulesInstallerBase.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using VirtoCommerce.Platform.Core.Modularity; -namespace VirtoCommerce.Build.PlatformTools +namespace PlatformTools.Modules { public abstract class ModulesInstallerBase { diff --git a/src/VirtoCommerce.Build/PlatformTools/PackageManager.cs b/src/VirtoCommerce.Build/PlatformTools/PackageManager.cs index 7365892..5066001 100644 --- a/src/VirtoCommerce.Build/PlatformTools/PackageManager.cs +++ b/src/VirtoCommerce.Build/PlatformTools/PackageManager.cs @@ -3,6 +3,7 @@ using System.Linq; using Extensions; using Nuke.Common.Utilities; +using PlatformTools.Modules; using VirtoCommerce.Build.PlatformTools; namespace PlatformTools diff --git a/src/VirtoCommerce.Build/PlatformTools/PackageManifest.cs b/src/VirtoCommerce.Build/PlatformTools/PackageManifest.cs index f00093f..492c2ca 100644 --- a/src/VirtoCommerce.Build/PlatformTools/PackageManifest.cs +++ b/src/VirtoCommerce.Build/PlatformTools/PackageManifest.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using PlatformTools.Modules; using VirtoCommerce.Build.PlatformTools; namespace PlatformTools From 6051c871dce813730fb840fcae34b66f3ae03970 Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Tue, 5 Mar 2024 08:42:51 +0100 Subject: [PATCH 14/15] VCI-821: Add check for symlinks --- .../PlatformTools/Build.PackageManager.cs | 20 +++++++++++++++---- .../LocalModuleCatalogExtensions.cs | 2 +- .../PlatformTools/Modules/ExtModuleCatalog.cs | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs index 5ba4ac7..8271c69 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs @@ -205,7 +205,7 @@ private static bool PlatformVersionChanged() modulesDirs = Directory.EnumerateDirectories(discoveryPath).ToList(); } var symlinks = modulesDirs.Where(m => new DirectoryInfo(m).LinkTarget != null).ToList(); - CompressionExtensions.TarGZipTo(RootDirectory, BackupFile, filter: f => !f.ToFileInfo().FullName.StartsWith(RootDirectory / ".nuke") && !symlinks.Any(s => f.ToFileInfo().FullName.StartsWith(s))); + CompressionExtensions.TarGZipTo(RootDirectory, BackupFile, filter: f => !f.ToFileInfo().FullName.StartsWith(RootDirectory / ".nuke") && !symlinks.Exists(s => f.ToFileInfo().FullName.StartsWith(s))); }); public Target Rollback => _ => _ @@ -347,7 +347,7 @@ private static bool IsPlatformInstallationNeeded(string version) return; } - if (alreadyInstalledModules.Exists(installedModule => installedModule.ModuleName == module.Id && installedModule.Version.ToString() == module.Version) || localModuleCatalog.IsModuleFromSourceCode(module.Id)) + if (alreadyInstalledModules.Exists(installedModule => installedModule.ModuleName == module.Id && installedModule.Version.ToString() == module.Version) || localModuleCatalog.IsModuleSymlinked(module.Id)) { continue; } @@ -656,13 +656,25 @@ private static ManifestBase CreateManifestFromEnvironment(AbsolutePath platformP var platformVersion = platformWebDllFileInfo.ProductVersion; var packageManifest = PackageManager.CreatePackageManifest(platformVersion); var githubModules = PackageManager.GetGithubModules(packageManifest); - + var githubModulesSource = PackageManager.GetGithubModulesSource(packageManifest); + var localModuleCatalog = (LocalCatalog)LocalModuleCatalog.GetCatalog(GetDiscoveryPath(), ProbingPath); + var externalModuleCatalog = ExtModuleCatalog.GetCatalog(GitHubToken, localModuleCatalog, githubModulesSource.ModuleSources).GetAwaiter().GetResult(); + var modulesInCatalog = externalModuleCatalog.Modules.Where(m => !m.Ref.StartsWith("file://")).Select(m => m.ModuleName).ToList(); var manifests = discoveryPath.GlobFiles("*/module.manifest"); manifests.ForEach(m => { var manifest = ManifestReader.Read(m); - githubModules.Add(new ModuleItem(manifest.Id, manifest.Version)); + if (!modulesInCatalog.Contains(manifest.Id)) + { + Log.Warning("There is no module {0}:{1} in external catalog. You should add it in manifest manually.", manifest.Id, manifest.Version); + + } + else + { + githubModules.Add(new ModuleItem(manifest.Id, manifest.Version)); + } }); + return packageManifest; } } diff --git a/src/VirtoCommerce.Build/PlatformTools/Extensions/LocalModuleCatalogExtensions.cs b/src/VirtoCommerce.Build/PlatformTools/Extensions/LocalModuleCatalogExtensions.cs index 4ce7a2a..6dfaf69 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Extensions/LocalModuleCatalogExtensions.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Extensions/LocalModuleCatalogExtensions.cs @@ -7,7 +7,7 @@ namespace PlatformTools.Extensions { public static class LocalModuleCatalogExtensions { - public static bool IsModuleFromSourceCode(this ILocalModuleCatalog moduleCatalog, string moduleId) + public static bool IsModuleSymlinked(this ILocalModuleCatalog moduleCatalog, string moduleId) { var moduleInfo = moduleCatalog.Modules.OfType().FirstOrDefault(m => m.ModuleName == moduleId); if(moduleInfo == null) diff --git a/src/VirtoCommerce.Build/PlatformTools/Modules/ExtModuleCatalog.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/ExtModuleCatalog.cs index 14de565..7016f75 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Modules/ExtModuleCatalog.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/ExtModuleCatalog.cs @@ -44,7 +44,7 @@ public static IOptions GetOptions(string authToken { var options = new ExternalModuleCatalogOptions { - ModulesManifestUrl = new Uri(manifestUrls.First()), + ModulesManifestUrl = new Uri(manifestUrls[0]), AuthorizationToken = authToken, IncludePrerelease = false, AutoInstallModuleBundles = Array.Empty(), From eae403e27aff6d502123267122e7b9a7523f2377 Mon Sep 17 00:00:00 2001 From: Alexander Morogov Date: Thu, 7 Mar 2024 08:32:17 +0100 Subject: [PATCH 15/15] VCI-821: Fix codesmells --- .../PlatformTools/Build.PackageManager.cs | 6 +++--- .../Modules/Azure/AzurePipelineArtifactsClient.cs | 2 +- .../Modules/Github/GithubPrivateModulesInstaller.cs | 6 ++++-- .../PlatformTools/Modules/LocalCatalog.cs | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs index 6eca2c9..c1c55a6 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs @@ -610,7 +610,7 @@ private static async Task OpenOrCreateManifest(string packageManif else if (!File.Exists(packageManifestPath) && File.Exists(platformWebDllPath)) { var discoveryAbsolutePath = Path.GetFullPath(GetDiscoveryPath()); - return CreateManifestFromEnvironment(RootDirectory, discoveryAbsolutePath.ToAbsolutePath()); + return await CreateManifestFromEnvironment(RootDirectory, discoveryAbsolutePath.ToAbsolutePath()); } else if (!File.Exists(packageManifestPath)) { @@ -644,7 +644,7 @@ private static async Task DownloadBundleManifest(string bundleName, string outFi await HttpTasks.HttpDownloadFileAsync(manifestUrl, outFile.ToAbsolutePath()); } - private static ManifestBase CreateManifestFromEnvironment(AbsolutePath platformPath, AbsolutePath discoveryPath) + private async static Task CreateManifestFromEnvironment(AbsolutePath platformPath, AbsolutePath discoveryPath) { var platformWebDllPath = platformPath / "VirtoCommerce.Platform.Web.dll"; if (!File.Exists(platformWebDllPath)) @@ -657,7 +657,7 @@ private static ManifestBase CreateManifestFromEnvironment(AbsolutePath platformP var githubModules = PackageManager.GetGithubModules(packageManifest); var githubModulesSource = PackageManager.GetGithubModulesSource(packageManifest); var localModuleCatalog = (LocalCatalog)LocalModuleCatalog.GetCatalog(GetDiscoveryPath(), ProbingPath); - var externalModuleCatalog = ExtModuleCatalog.GetCatalog(GitHubToken, localModuleCatalog, githubModulesSource.ModuleSources).GetAwaiter().GetResult(); + var externalModuleCatalog = await ExtModuleCatalog.GetCatalog(GitHubToken, localModuleCatalog, githubModulesSource.ModuleSources); var modulesInCatalog = externalModuleCatalog.Modules.Where(m => !m.Ref.StartsWith("file://")).Select(m => m.ModuleName).ToList(); var manifests = discoveryPath.GlobFiles("*/module.manifest"); manifests.ForEach(m => diff --git a/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsClient.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsClient.cs index 118793f..f0eb2e1 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsClient.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsClient.cs @@ -34,7 +34,7 @@ public Stream OpenRead(Uri address) } finally { - client?.Dispose(); + client.Dispose(); } } } diff --git a/src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModulesInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModulesInstaller.cs index ca8a2fc..a322fa8 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModulesInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModulesInstaller.cs @@ -41,12 +41,14 @@ protected override async Task InnerInstall(ModuleSource source, IProgress { diff --git a/src/VirtoCommerce.Build/PlatformTools/Modules/LocalCatalog.cs b/src/VirtoCommerce.Build/PlatformTools/Modules/LocalCatalog.cs index 182962c..a85c5b9 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Modules/LocalCatalog.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Modules/LocalCatalog.cs @@ -136,7 +136,7 @@ private static string GetFileAbsoluteUri(string rootPath, string relativePath) return builder.Uri.ToString(); } - private IDictionary GetModuleManifests() + private Dictionary GetModuleManifests() { var result = new Dictionary();