Skip to content

Commit

Permalink
Merge pull request #26 from EAVFW/tst/docs-assembly-xml
Browse files Browse the repository at this point in the history
feat: Utilize path globbing to find assemblies
  • Loading branch information
thygesteffensen authored Nov 29, 2023
2 parents 49f4e80 + f77d677 commit 5aea56c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 71 deletions.
45 changes: 16 additions & 29 deletions src/EAVFW.Extensions.Docs.Extractor/DocumentLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, AssemblyInfo> BuildAssemblyDictionary(IEnumerable<string> binDirectories)
{
var dictionary = new Dictionary<string, AssemblyInfo>();

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;
}

/// <inheritdoc />
public IEnumerable<PluginDocumentation> ExtractPluginDocumentation(PluginInfo pluginInfo)
{
Expand Down Expand Up @@ -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<string, AssemblyInfo>();
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;
Expand Down
32 changes: 21 additions & 11 deletions src/EAVFW.Extensions.Docs.Extractor/Plugin/PluginInfo.cs
Original file line number Diff line number Diff line change
@@ -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")

Check warning on line 26 in src/EAVFW.Extensions.Docs.Extractor/Plugin/PluginInfo.cs

View workflow job for this annotation

GitHub Actions / Releasing

Dereference of a possibly null reference.

Check warning on line 26 in src/EAVFW.Extensions.Docs.Extractor/Plugin/PluginInfo.cs

View workflow job for this annotation

GitHub Actions / Building

Dereference of a possibly null reference.
: 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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,18 @@ 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")]
public DirectoryInfo OutputOption { get; set; }

[Alias("-t")]
[Alias("--target")]
[Description("Target?")]
[Description("What kind of documentation source should be extracted")]
public Targets Target { get; set; }

public enum Targets
Expand All @@ -76,12 +66,6 @@ private async Task<int> 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");
Expand Down Expand Up @@ -110,9 +94,7 @@ private async Task<int> GenerateWizardSource()
var entityDefinitions = _documentLogic.ExtractWizardDocumentation(
ManifestPathOption,
new PluginInfo(ProbePathOption,
AssemblyPathOption,
ConfigurationOption,
FrameworkOption));
AssemblyPathOption));

var basePath = new DirectoryInfo(CalculateFullPath("wizards"));

Expand All @@ -137,8 +119,7 @@ private async Task<int> GenerateWizardSource()
private async Task<int> GeneratePluginSource()
{
var plugins = _documentLogic
.ExtractPluginDocumentation(new PluginInfo(ProbePathOption, AssemblyPathOption, ConfigurationOption,
FrameworkOption))
.ExtractPluginDocumentation(new PluginInfo(ProbePathOption, AssemblyPathOption))
.ToArray();

var jsonString = JsonSerializer.Serialize(plugins, new JsonSerializerOptions
Expand Down Expand Up @@ -172,12 +153,6 @@ private bool IsMissingOptions(out List<string> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 5aea56c

Please sign in to comment.