From f77d677619bfbdf383875fbd89e42b37b8ca5f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thyge=20Sk=C3=B8dt=20Steffensen?= <31892312+thygesteffensen@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:26:39 +0100 Subject: [PATCH] feat: Utilize path globbing to find assemblies Instead of using framework and configuration path globbing is used. Here the old use case for probing bin folders is still possible, but it is also possible to use a single folder with all assemblies, such as publish generates --- .../DocumentLogic.cs | 45 +++++++------------ .../Plugin/PluginInfo.cs | 32 ++++++++----- .../DocumentationSourceExtractorCommand.cs | 35 +++------------ .../Properties/launchSettings.json | 3 +- 4 files changed, 44 insertions(+), 71 deletions(-) diff --git a/src/EAVFW.Extensions.Docs.Extractor/DocumentLogic.cs b/src/EAVFW.Extensions.Docs.Extractor/DocumentLogic.cs index b189836..289e801 100644 --- a/src/EAVFW.Extensions.Docs.Extractor/DocumentLogic.cs +++ b/src/EAVFW.Extensions.Docs.Extractor/DocumentLogic.cs @@ -7,35 +7,13 @@ using System.Text.Json; using EAVFramework.Plugins; using EAVFW.Extensions.Manifest.SDK; +using Microsoft.Extensions.FileSystemGlobbing; using WorkflowEngine.Core; namespace EAVFW.Extensions.Docs.Extractor { public class DocumentLogic : IDocumentLogic { - private static Dictionary BuildAssemblyDictionary(IEnumerable binDirectories) - { - var dictionary = new Dictionary(); - - foreach (var directory in binDirectories) - { - var dlls = Directory.GetFiles(directory, "*.dll"); - foreach (var dll in dlls) - { - var assemblyName = AssemblyName.GetAssemblyName(dll); - - dictionary.TryAdd(assemblyName.Name!, new AssemblyInfo - { - Name = assemblyName.Name!, - Version = assemblyName.Version!.ToString(), - Path = dll - }); - } - } - - return dictionary; - } - /// public IEnumerable ExtractPluginDocumentation(PluginInfo pluginInfo) { @@ -64,14 +42,23 @@ from implementingType in implementingTypes private static Assembly LoadAssembly(PluginInfo pluginInfo) { - var subDirectories = pluginInfo.RootPath.EnumerateDirectories("*", SearchOption.AllDirectories); + var matcher = new Matcher(); + matcher.AddInclude(pluginInfo.Search); - var directoriesWithBin = - from d in subDirectories - where d.FullName.EndsWith($"bin/{pluginInfo.Configuration}/{pluginInfo.Framework}") - select d.FullName; + var dictionary = new Dictionary(); + foreach (var file in matcher.GetResultsInFullPath(pluginInfo.RootPath.FullName)) + { + var assemblyName = AssemblyName.GetAssemblyName(file); + + dictionary.TryAdd(assemblyName.Name!, new AssemblyInfo + { + Name = assemblyName.Name!, + Version = assemblyName.Version!.ToString(), + Path = file + }); + } - CustomAssemblyResolver.Dictionary = BuildAssemblyDictionary(directoriesWithBin.AsQueryable()); + CustomAssemblyResolver.Dictionary = dictionary; var currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += CustomAssemblyResolver.CustomAssemblyResolverEventHandler; diff --git a/src/EAVFW.Extensions.Docs.Extractor/Plugin/PluginInfo.cs b/src/EAVFW.Extensions.Docs.Extractor/Plugin/PluginInfo.cs index 344c615..a4d694e 100644 --- a/src/EAVFW.Extensions.Docs.Extractor/Plugin/PluginInfo.cs +++ b/src/EAVFW.Extensions.Docs.Extractor/Plugin/PluginInfo.cs @@ -1,28 +1,38 @@ using System; using System.IO; +using System.Linq; namespace EAVFW.Extensions.Docs.Extractor { public struct PluginInfo { - public PluginInfo(DirectoryInfo rootPath, FileInfo assemblyPath, string configuration, string framework) + public PluginInfo(DirectoryInfo rootPath, FileInfo assemblyPath) { - RootPath = !rootPath.Exists - ? throw new ArgumentException($"Directory {nameof(rootPath)} does not exists") - : rootPath; + var basePath = rootPath.Parent; + var search = rootPath.Name; + + if (rootPath.FullName.Contains("**")) + { + basePath = new DirectoryInfo(rootPath.FullName.Split("**").First()); + search = rootPath.FullName[basePath.FullName.Length..]; + } + else if (!rootPath.FullName.Contains('*')) + { + throw new ArgumentException("Probing path mu"); + } + + Search = search; + RootPath = !(basePath?.Exists ?? false) + ? throw new ArgumentException($"Directory {basePath.FullName} does not exists") + : basePath; + AssemblyPath = !assemblyPath.Exists ? throw new ArgumentException($"File {nameof(assemblyPath)} does not exists") : assemblyPath; - - Configuration = string.IsNullOrWhiteSpace(configuration) - ? throw new ArgumentNullException(configuration) - : configuration; - Framework = string.IsNullOrWhiteSpace(framework) ? throw new ArgumentNullException(framework) : framework; } public DirectoryInfo RootPath { get; } + public string Search { get; } public FileInfo AssemblyPath { get; } - public string Configuration { get; } - public string Framework { get; } } } diff --git a/src/EAVFW.Extensions.Manifest.ManifestEnricherTool/Commands/Documentation/DocumentationSourceExtractorCommand.cs b/src/EAVFW.Extensions.Manifest.ManifestEnricherTool/Commands/Documentation/DocumentationSourceExtractorCommand.cs index 3f7d10b..3769c3a 100644 --- a/src/EAVFW.Extensions.Manifest.ManifestEnricherTool/Commands/Documentation/DocumentationSourceExtractorCommand.cs +++ b/src/EAVFW.Extensions.Manifest.ManifestEnricherTool/Commands/Documentation/DocumentationSourceExtractorCommand.cs @@ -32,20 +32,10 @@ public class DocumentationSourceExtractorCommand : Command public FileInfo ManifestPathOption { get; set; } [Alias("-p")] - [Alias("--probing-path")] - [Description("Path to probe for dependent assemblies")] + [Alias("--probing-pattern")] + [Description("Path pattern used to probe for assemblies, supporting glob patterns")] public DirectoryInfo ProbePathOption { get; set; } - [Alias("-c")] - [Alias("--configuration")] - [Description("Configuration for the built assembly")] - public string ConfigurationOption { get; set; } - - [Alias("-f")] - [Alias("--framework")] - [Description("Framework confugraiton for the built assembly")] - public string FrameworkOption { get; set; } - [Alias("-o")] [Alias("--output")] [Description("Output directory for genreated documentation source files")] @@ -53,7 +43,7 @@ public class DocumentationSourceExtractorCommand : Command [Alias("-t")] [Alias("--target")] - [Description("Target?")] + [Description("What kind of documentation source should be extracted")] public Targets Target { get; set; } public enum Targets @@ -76,12 +66,6 @@ private async Task Run(ParseResult parseResult, IConsole console) return 126; } - if (!ProbePathOption.Exists) - { - Console.WriteLine("Probing path does not exists"); - return 1; - } - if (!AssemblyPathOption.Exists) { Console.WriteLine("Assembly does not exists"); @@ -110,9 +94,7 @@ private async Task GenerateWizardSource() var entityDefinitions = _documentLogic.ExtractWizardDocumentation( ManifestPathOption, new PluginInfo(ProbePathOption, - AssemblyPathOption, - ConfigurationOption, - FrameworkOption)); + AssemblyPathOption)); var basePath = new DirectoryInfo(CalculateFullPath("wizards")); @@ -137,8 +119,7 @@ private async Task GenerateWizardSource() private async Task GeneratePluginSource() { var plugins = _documentLogic - .ExtractPluginDocumentation(new PluginInfo(ProbePathOption, AssemblyPathOption, ConfigurationOption, - FrameworkOption)) + .ExtractPluginDocumentation(new PluginInfo(ProbePathOption, AssemblyPathOption)) .ToArray(); var jsonString = JsonSerializer.Serialize(plugins, new JsonSerializerOptions @@ -172,12 +153,6 @@ private bool IsMissingOptions(out List missing) if (ProbePathOption == null) missing.Add(nameof(ProbePathOption)); - if (string.IsNullOrWhiteSpace(ConfigurationOption)) - missing.Add(nameof(ConfigurationOption)); - - if (string.IsNullOrWhiteSpace(FrameworkOption)) - missing.Add(nameof(FrameworkOption)); - return false; } } diff --git a/src/EAVFW.Extensions.Manifest.ManifestEnricherTool/Properties/launchSettings.json b/src/EAVFW.Extensions.Manifest.ManifestEnricherTool/Properties/launchSettings.json index f04303c..99ec44f 100644 --- a/src/EAVFW.Extensions.Manifest.ManifestEnricherTool/Properties/launchSettings.json +++ b/src/EAVFW.Extensions.Manifest.ManifestEnricherTool/Properties/launchSettings.json @@ -5,7 +5,8 @@ "workingDirectory": "/Users/thyge/dev/playground", // "workingDirectory": "/Users/thyge/dev/hafnia/LetterofIndemnity/src/Hafnia.Models", // "commandLineArgs": "docs extract -c Release -t wizards -f net6.0 -a \"/Users/thyge/dev/hafnia/LetterofIndemnity/src/Hafnia.BusinessLogic/bin/Release/net6.0/Hafnia.BusinessLogic.dll\" -p \"/Users/thyge/dev/hafnia/LetterofIndemnity\" -gm /Users/thyge/dev/hafnia/LetterofIndemnity/src/Hafnia.Models/obj/manifest.g.json" - "commandLineArgs": "docs extract -c Release -t plugins -f net6.0 -a \"/Users/thyge/dev/hafnia/LetterofIndemnity/src/Hafnia.BusinessLogic/bin/Release/net6.0/Hafnia.BusinessLogic.dll\" -p \"/Users/thyge/dev/hafnia/LetterofIndemnity\" -gm /Users/thyge/dev/hafnia/LetterofIndemnity/src/Hafnia.Models/obj/manifest.g.json" +// "commandLineArgs": "docs extract -t plugins -a \"/Users/thyge/dev/hafnia/LetterofIndemnity/src/Hafnia.BusinessLogic/bin/Release/net6.0/Hafnia.BusinessLogic.dll\" -p \"/Users/thyge/dev/hafnia/LetterofIndemnity/**/bin/Release/net6.0/*.dll\" -gm /Users/thyge/dev/hafnia/LetterofIndemnity/src/Hafnia.Models/obj/manifest.g.json" + "commandLineArgs": "docs extract -t plugins -a \"/Users/thyge/dev/hafnia/LetterofIndemnity/src/Hafnia.BusinessLogic/bin/Release/net6.0/Hafnia.BusinessLogic.dll\" -p \"/Users/thyge/dev/hafnia/LetterofIndemnity/obj/publish/*.dll\" -gm /Users/thyge/dev/hafnia/LetterofIndemnity/src/Hafnia.Models/obj/manifest.g.json" // "commandLineArgs": "docs generate -c manifest.loi.json -p /Users/thyge/dev/playground/plugins.json -w /Users/thyge/dev/playground/wizards -o \"/Users/thyge/Documents/Obsidian Vault/Delegate Lava-Stone/Delegate/documentation.md\" -gm /Users/thyge/dev/hafnia/LetterofIndemnity/src/Hafnia.Models/obj/manifest.g.json" // "commandLineArgs": "binary --unzip 0x1F8B08000000000000139C51414EC33010FC8BAFD4C8719C36C9AD824BA50252E90D71D8D8EBC852EA147B73A8A2FE1D3B05CE153E8DAC99D99DD999812637FAC8DA993D0504C2FDDBEE19080EF83561A4178C117ADC2EAC4C72FE3C5106C3E8C28DC35A06CA182937C0D142C795EE2A5EA2042E6AD369B0AAAA9A82AD5840EDCE0E3DA5791FACA884EAACB45CDB3572D5E8861B5B36BFA235405DB3CFEB8A45029A9284BD4F5AA34193ACBAD15CEE1F6CC10D680E0831A7F0D3305C932F05D7F71896F0C71BCE90DC0993B514B2E485E0853C8A4DAB8A56C9C7B2484B370F42B442FC2D31B394C8D1E51516DD1E89308CD67983279FFE7FAA8CB702C66076E6FECD4DBA451EF1AFEAF2FB060000FFFF" // "commandLineArgs": "binary --unzip 0x1F8B08000000000000139C51414EC33010FC8BAFD4C8719C36C9AD824BA50252E90D71D8D8EBC852EA147B73A8A2FE1D3B05CE153E8DAC99D99DD999812637FAC8DA993D0504C2FDDBEE19080EF83561A4178C117ADC2EAC4C72FE3C5106C3E8C28DC35A06CA182937C0D142C795EE2A5EA2042E6AD369B0AAAA9A82AD5840EDCE0E3DA5791FACA884EAACB45CDB3572D5E8861B5B36BFA235405DB3CFEB8A45029A9284BD4F5AA34193ACBAD15CEE1F6CC10D680E0831A7F0D3305C932F05D7F71896F0C71BCE90DC0993B514B2E485E0853C8A4DAB8A56C9C7B2484B370F42B442FC2D31B394C8D1E51516DD1E89308CD67983279FFE7FAA8CB702C66076E6FECD4DBA451EF1AFEAF2FB060000FFFF"