Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCI-822: Add local modules source #125

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/CLI-tools/package-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ This command downloads and installs the platform or modules into the relevant fo
"Id": "42920184"
}
]
},
{
"Name": "Local",
"Modules": [
{
"Path": "C:/projects/vc/vc-module-saas/artifacts/VirtoCommerce.SaaS_3.214.0.zip",
"Id": "OptionalForThisSource"
},
{
"Path": "C:\\projects\\vc\\vc-module-catalog\\artifacts\\VirtoCommerce.Catalog"
}
]
}
],
"ManifestVersion": "2.0",
Expand Down
5 changes: 3 additions & 2 deletions src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using PlatformTools.Modules.Azure;
using PlatformTools.Modules.Github;
using PlatformTools.Modules.Gitlab;
using PlatformTools.Modules.LocalModules;
using Serilog;
using VirtoCommerce.Build.PlatformTools;
using VirtoCommerce.Platform.Core.Common;
Expand Down Expand Up @@ -474,13 +475,14 @@ private static ManifestModuleInfo LoadModuleInfo(ModuleItem module, ManifestModu
return moduleInfo;
}

private static ModulesInstallerBase GetModuleInstaller(ModuleSource moduleSource) => moduleSource switch
private static ModuleInstallerBase GetModuleInstaller(ModuleSource moduleSource) => moduleSource switch
{
AzurePipelineArtifacts => new AzurePipelineArtifactsModuleInstaller(AzureToken, GetDiscoveryPath()),
AzureUniversalPackages => new AzureUniversalPackagesModuleInstaller(AzureToken, GetDiscoveryPath()),
GithubPrivateRepos => new GithubPrivateModulesInstaller(GitHubToken, GetDiscoveryPath()),
AzureBlob _ => new AzureBlobModuleInstaller(AzureToken, GetDiscoveryPath()),
GitlabJobArtifacts _ => new GitlabJobArtifactsModuleInstaller(GitLabServer, GitLabToken, GetDiscoveryPath()),
Local _ => new LocalModuleInstaller(GetDiscoveryPath()),
_ => throw new NotImplementedException("Unknown module source"),
};

Expand Down Expand Up @@ -687,7 +689,6 @@ private async static Task<ManifestBase> CreateManifestFromEnvironment(AbsolutePa
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace PlatformTools.Modules.Azure
{
internal class AzureBlobModuleInstaller : ModulesInstallerBase
internal class AzureBlobModuleInstaller : ModuleInstallerBase
{
private readonly string _token;
private readonly string _destination;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace PlatformTools.Modules.Azure
{
internal class AzurePipelineArtifactsModuleInstaller : ModulesInstallerBase
internal class AzurePipelineArtifactsModuleInstaller : ModuleInstallerBase
{
private readonly string _token;
private readonly string _discoveryPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace PlatformTools.Modules.Azure
{
internal class AzureUniversalPackagesModuleInstaller : ModulesInstallerBase
internal class AzureUniversalPackagesModuleInstaller : ModuleInstallerBase
{
readonly string token;
readonly string discoveryPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace PlatformTools.Modules.Github
{
internal class GithubPrivateModulesInstaller : ModulesInstallerBase
internal class GithubPrivateModulesInstaller : ModuleInstallerBase
{

private readonly string _token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace PlatformTools.Modules.Gitlab;

internal class GitlabJobArtifactsModuleInstaller : ModulesInstallerBase
internal class GitlabJobArtifactsModuleInstaller : ModuleInstallerBase
{
private readonly GitLabClient _client;
private readonly string _discoveryPath;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections.Generic;

namespace PlatformTools.Modules.LocalModules;
internal class Local : ModuleSource
{
public override string Name { get; set; } = nameof(Local);
public List<LocalModuleItem> Modules { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Extensions;
using Nuke.Common.IO;
using VirtoCommerce.Platform.Core.Modularity;

namespace PlatformTools.Modules.LocalModules
{
internal class LocalModuleInstaller : ModuleInstallerBase
{
readonly string _modulesDirectory;

public LocalModuleInstaller(string modulesDirectory)
{
_modulesDirectory = modulesDirectory;
}
protected override async Task InnerInstall(ModuleSource source, IProgress<ProgressMessage> progress)
{
var moduleSource = (Local)source;

foreach (var module in moduleSource.Modules)
{
var moduleSourceName = module.Id ?? Path.GetFileName(module.Path);
var moduleDestination = Path.Combine(_modulesDirectory, moduleSourceName);
var attributes = File.GetAttributes(module.Path);
if (attributes.HasFlag(FileAttributes.Directory))
{
progress.ReportInfo($"Copying the module from the directory {module.Path}");
await SetupModuleFromDirectory(module.Path, moduleDestination);
}
else
{
progress.ReportInfo($"Extracting an archive {moduleSourceName}");
await SetupModuleFromArchive(module.Path, moduleDestination);
}
progress.ReportInfo($"Successfully installed {moduleSourceName}");
}
}

private static Task SetupModuleFromArchive(string src, string moduleDestination)
{
var absolutePath = src.ToAbsolutePath();
absolutePath.UnZipTo(moduleDestination.ToAbsolutePath());
return Task.CompletedTask;
}

private static Task SetupModuleFromDirectory(string src, string moduleDestination)
{
var absolutePath = src.ToAbsolutePath();
FileSystemTasks.CopyDirectoryRecursively(absolutePath, moduleDestination.ToAbsolutePath(), DirectoryExistsPolicy.Merge, FileExistsPolicy.OverwriteIfNewer);
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace PlatformTools.Modules.LocalModules;

internal class LocalModuleItem : ModuleItem
{
public LocalModuleItem(string id, string version) : base(id, version)
{

}

public string Path { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PlatformTools.Modules
{
public abstract class ModulesInstallerBase
public abstract class ModuleInstallerBase
{
public virtual Task Install(ModuleSource source, IProgress<ProgressMessage> progress)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using PlatformTools.Modules.Azure;
using PlatformTools.Modules.Github;
using PlatformTools.Modules.Gitlab;
using PlatformTools.Modules.LocalModules;
using VirtoCommerce.Build.PlatformTools;

namespace PlatformTools.Modules
Expand Down Expand Up @@ -40,6 +41,8 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
case nameof(GitlabJobArtifacts):
return JsonConvert.DeserializeObject<GitlabJobArtifacts>(jo.ToString(),
SpecifiedSubclassConversion);
case nameof(Local):
return JsonConvert.DeserializeObject<Local>(jo.ToString(), SpecifiedSubclassConversion);
default:
throw new TypeLoadException($"Unknown module source: {sourceName}");
}
Expand Down
Loading