From da200a5e0a3f709444408dbf921ddc01496b6e6a Mon Sep 17 00:00:00 2001 From: Alexandr Morogov <42555001+krankenbro@users.noreply.github.com> Date: Thu, 7 Mar 2024 08:59:44 +0100 Subject: [PATCH] VCI-821: Check if module in symlink on update (#121) --- .../PackageManagerTests.cs | 2 +- .../Azure/AzureBlobModuleItem.cs | 11 -- .../PlatformTools/Build.InitPlatform.cs | 1 + .../PlatformTools/Build.PackageManager.cs | 37 +++-- .../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 | 4 +- .../Github/GithubPrivateModuleItem.cs | 4 +- .../Github/GithubPrivateModulesInstaller.cs | 12 +- .../Github/GithubPrivateRepos.cs | 4 +- .../{ => Modules}/Gitlab/GitLabClient.cs | 4 +- .../Gitlab/GitlabJobArtifacts.cs | 4 +- .../GitlabJobArtifactsModuleInstaller.cs | 6 +- .../Gitlab/GitlabJobArtifactsModuleItem.cs | 6 +- .../{ => Modules}/LocalCatalog.cs | 8 +- .../{ => 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, 433 insertions(+), 380 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 (92%) 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 (95%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Github/GithubPrivateModuleItem.cs (78%) rename src/VirtoCommerce.Build/PlatformTools/{ => Modules}/Github/GithubPrivateModulesInstaller.cs (91%) 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 (96%) 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..c1c55a6 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; @@ -203,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 => _ => _ @@ -322,6 +324,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 +346,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.IsModuleSymlinked(module.Id)) { continue; } @@ -485,7 +488,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) { @@ -607,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)) { @@ -638,10 +641,10 @@ 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) + private async static Task CreateManifestFromEnvironment(AbsolutePath platformPath, AbsolutePath discoveryPath) { var platformWebDllPath = platformPath / "VirtoCommerce.Platform.Web.dll"; if (!File.Exists(platformWebDllPath)) @@ -652,13 +655,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 = 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 => { 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 new file mode 100644 index 0000000..6dfaf69 --- /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 IsModuleSymlinked(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 92% rename from src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsClient.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Azure/AzurePipelineArtifactsClient.cs index 6c3a10f..f0eb2e1 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 95% rename from src/VirtoCommerce.Build/PlatformTools/ExtModuleCatalog.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/ExtModuleCatalog.cs index cdc2e0b..7016f75 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 { @@ -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(), 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 91% rename from src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/Github/GithubPrivateModulesInstaller.cs index 103f9bb..a322fa8 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)); @@ -41,12 +41,14 @@ protected override async Task InnerInstall(ModuleSource source, IProgress { 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 96% rename from src/VirtoCommerce.Build/PlatformTools/LocalCatalog.cs rename to src/VirtoCommerce.Build/PlatformTools/Modules/LocalCatalog.cs index 78c9b7e..a85c5b9 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; @@ -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(); @@ -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