Skip to content

Commit

Permalink
feat: ProbePattern or list of assemblies replace configuration and do…
Browse files Browse the repository at this point in the history
…tnet version to find assemblies
  • Loading branch information
thygesteffensen committed Nov 29, 2023
1 parent f77d677 commit eb98cbb
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 82 deletions.
18 changes: 7 additions & 11 deletions src/EAVFW.Extensions.Docs.Extractor/DocumentLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
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
{
/// <inheritdoc />
public IEnumerable<PluginDocumentation> ExtractPluginDocumentation(PluginInfo pluginInfo)
public IEnumerable<PluginDocumentation> ExtractPluginDocumentation(FileInfo assemblyInfo, string[] assemblies)
{
var assembly = LoadAssembly(pluginInfo);
var assembly = LoadAssembly(assemblyInfo, assemblies);

var implementingTypes = assembly.GetTypes()
.Where(t => typeof(IPlugin).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract);
Expand All @@ -40,13 +39,10 @@ from implementingType in implementingTypes
return plugins;
}

private static Assembly LoadAssembly(PluginInfo pluginInfo)
private static Assembly LoadAssembly(FileInfo assemblyInfo, string [] assemblies)
{
var matcher = new Matcher();
matcher.AddInclude(pluginInfo.Search);

var dictionary = new Dictionary<string, AssemblyInfo>();
foreach (var file in matcher.GetResultsInFullPath(pluginInfo.RootPath.FullName))
foreach (var file in assemblies)
{
var assemblyName = AssemblyName.GetAssemblyName(file);

Expand All @@ -63,15 +59,15 @@ private static Assembly LoadAssembly(PluginInfo pluginInfo)
var currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += CustomAssemblyResolver.CustomAssemblyResolverEventHandler;

var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(pluginInfo.AssemblyPath.FullName);
var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyInfo.FullName);
return assembly;
}

/// <inheritdoc/>
public Dictionary<string, EntityDefinition> ExtractWizardDocumentation(FileInfo manifestFile,
PluginInfo pluginInfo)
FileInfo assemblyInfo, string[] assemblies)
{
var assembly = LoadAssembly(pluginInfo);
var assembly = LoadAssembly(assemblyInfo, assemblies);

// Preloading types to easily query for documentation
var workflows = assembly.GetTypes()
Expand Down
4 changes: 2 additions & 2 deletions src/EAVFW.Extensions.Docs.Extractor/IDocumentLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IDocumentLogic
/// Remember to enable GenerateDocumentationFile for the project.
/// <param name="pluginInfo"></param>
/// </summary>
IEnumerable<PluginDocumentation> ExtractPluginDocumentation(PluginInfo pluginInfo);
IEnumerable<PluginDocumentation> ExtractPluginDocumentation(FileInfo assemblyInfo, string[] assemblies);

/// <summary>
/// Extract Wizards from the given Manifest and generate documentation based on manifest metadata and workflow
Expand All @@ -22,6 +22,6 @@ public interface IDocumentLogic
/// <param name="manifestFile"></param>
/// <param name="pluginInfo"></param>
/// <returns></returns>
Dictionary<string, EntityDefinition> ExtractWizardDocumentation(FileInfo manifestFile, PluginInfo pluginInfo);
Dictionary<string, EntityDefinition> ExtractWizardDocumentation(FileInfo manifestFile, FileInfo assemblyInfo, string[] assemblies);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
using System.Text.Json;
using System.Threading.Tasks;
using EAVFW.Extensions.Docs.Extractor;
using Microsoft.Extensions.FileSystemGlobbing;

namespace EAVFW.Extensions.Manifest.ManifestEnricherTool.Commands.Documentation
{
/*
* There are many parameters to the command and generating source for both plugin and wizard requires the tool to be
* executed twice. Alternatively, the "configuration" could be done using a configuration, which would provide all
* necessary parameters. Both it would be more rigid and could not easily be changed in a pipeline or other.
* necessary parameters. Both it would be more rigid and could not easily be changed in a pipeline or other.
*/

public class DocumentationSourceExtractorCommand : Command
{
private readonly IDocumentLogic _documentLogic;
Expand All @@ -34,7 +35,7 @@ public class DocumentationSourceExtractorCommand : Command
[Alias("-p")]
[Alias("--probing-pattern")]
[Description("Path pattern used to probe for assemblies, supporting glob patterns")]
public DirectoryInfo ProbePathOption { get; set; }
public IEnumerable<string> ProbePathOption { get; set; }

[Alias("-o")]
[Alias("--output")]
Expand All @@ -46,13 +47,19 @@ public class DocumentationSourceExtractorCommand : Command
[Description("What kind of documentation source should be extracted")]
public Targets Target { get; set; }

[Alias("-d")]
[Alias("--debug")]
[Description("Enable debug output")]
public bool Debug { get; set; } = false;

public enum Targets
{
Plugins,
Wizards
}

public DocumentationSourceExtractorCommand(IDocumentLogic documentLogic) : base("extract", "Extract documentation source")
public DocumentationSourceExtractorCommand(IDocumentLogic documentLogic) : base("extract",
"Extract documentation source")
{
_documentLogic = documentLogic ?? throw new ArgumentNullException(nameof(documentLogic));
Handler = COmmandExtensions.Create(this, Array.Empty<Command>(), Run);
Expand All @@ -72,6 +79,37 @@ private async Task<int> Run(ParseResult parseResult, IConsole console)
return 1;
}

if (ProbePathOption.Count() == 1 && ProbePathOption.First().Contains('*'))
{
DebugMsg("No assemblies in list, probing...");

var probePath = new DirectoryInfo(ProbePathOption.First());

var matcher = new Matcher();
var basePath = probePath.Parent;

if (probePath.FullName.Contains("**"))
{
basePath = new DirectoryInfo(probePath.FullName.Split("**").First());
matcher.AddInclude(probePath.FullName[basePath.FullName.Length..]);
}
else if (probePath.Name.Contains("."))
{
matcher.AddInclude(probePath.Name);
}

ProbePathOption = matcher.GetResultsInFullPath(basePath.FullName).ToList();

}

DebugMsg($"Found {ProbePathOption.Count()} assemblies");

if (!ProbePathOption.Any())
{
Console.WriteLine("Did not find any assemblies");
return 1;
}

switch (Target)
{
case Targets.Plugins:
Expand All @@ -92,15 +130,13 @@ private async Task<int> GenerateWizardSource()
}

var entityDefinitions = _documentLogic.ExtractWizardDocumentation(
ManifestPathOption,
new PluginInfo(ProbePathOption,
AssemblyPathOption));
ManifestPathOption, AssemblyPathOption, ProbePathOption.ToArray());

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

if(!basePath.Exists)
if (!basePath.Exists)
basePath.Create();

foreach (var (key, value) in entityDefinitions)
{
var fileName = Path.Combine(basePath.FullName, $"{key}.json");
Expand All @@ -119,9 +155,9 @@ private async Task<int> GenerateWizardSource()
private async Task<int> GeneratePluginSource()
{
var plugins = _documentLogic
.ExtractPluginDocumentation(new PluginInfo(ProbePathOption, AssemblyPathOption))
.ExtractPluginDocumentation(AssemblyPathOption, ProbePathOption.ToArray())
.ToArray();

var jsonString = JsonSerializer.Serialize(plugins, new JsonSerializerOptions
{
WriteIndented = true
Expand Down Expand Up @@ -155,5 +191,11 @@ private bool IsMissingOptions(out List<string> missing)

return false;
}

private void DebugMsg(string msg)
{
if (Debug)
Console.WriteLine(msg);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<PackAsTool>true</PackAsTool>
<ToolCommandName>eavfw-manifest</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Title>ManifestEnricherTool</Title>
<Authors>Poul Kjeldager</Authors>
<Description>A tool to enrich and transform manifest.json to manifest.g.json</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/EAVFW/EAVFW.Extensions.Manifest.ManifestEnricherTool</RepositoryUrl>


</PropertyGroup>
<ItemGroup>
<None Include="..\..\README.md" Link="README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DotNETDevOps.JsonFunctions" Version="3.0.26" />

<PackageReference Include="LibGit2Sharp" Version="0.27.2" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="8.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.2" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Semver" Version="2.2.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='netcoreapp3.1'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite">
<Version>3.1.31</Version>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite">
<Version>6.0.11</Version>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite">
<Version>7.0.13</Version>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<PackAsTool>true</PackAsTool>
<ToolCommandName>eavfw-manifest</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Title>ManifestEnricherTool</Title>
<Authors>Poul Kjeldager</Authors>
<Description>A tool to enrich and transform manifest.json to manifest.g.json</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/EAVFW/EAVFW.Extensions.Manifest.ManifestEnricherTool</RepositoryUrl>


<ItemGroup Condition="$(UseEAVFromNuget) == 'false'">
<ProjectReference Include="$(LocalEAVFrameworkPath)\src\EAVFramework.csproj" />
<ProjectReference Include="$(LocalExternalpath)/EAVFW.Extensions.CommandLine/src/EAVFW.Extensions.CommandLine/EAVFW.Extensions.CommandLine.csproj" />
</ItemGroup>

<ItemGroup Condition="$(UseEAVFromNuget) != 'false'">
<PackageReference Include="EAVFramework" Version="4.2.0" />
<PackageReference Include="EAVFW.Extensions.CommandLine" Version="1.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EAVFW.Extensions.Docs.Extractor\EAVFW.Extensions.Docs.Extractor.csproj" />
<ProjectReference Include="..\EAVFW.Extensions.Docs.Generator\EAVFW.Extensions.Docs.Generator.csproj" />
</ItemGroup>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\README.md" Link="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="DotNETDevOps.JsonFunctions" Version="3.0.26"/>

<PackageReference Include="LibGit2Sharp" Version="0.27.2"/>
<PackageReference Include="Microsoft.Extensions.Primitives" Version="8.0.0"/>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.2"/>
<PackageReference Include="Microsoft.Extensions.Primitives" Version="7.0.0"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
<PackageReference Include="Semver" Version="2.2.0"/>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='netcoreapp3.1'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite">
<Version>3.1.31</Version>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite">
<Version>6.0.11</Version>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite">
<Version>7.0.13</Version>
</PackageReference>
</ItemGroup>


<ItemGroup Condition="$(UseEAVFromNuget) == 'false'">
<ProjectReference Include="$(LocalEAVFrameworkPath)\src\EAVFramework.csproj"/>
<ProjectReference Include="$(LocalExternalpath)/EAVFW.Extensions.CommandLine/src/EAVFW.Extensions.CommandLine/EAVFW.Extensions.CommandLine.csproj"/>
</ItemGroup>

<ItemGroup Condition="$(UseEAVFromNuget) != 'false'">
<PackageReference Include="EAVFramework" Version="4.2.0"/>
<PackageReference Include="EAVFW.Extensions.CommandLine" Version="1.4.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EAVFW.Extensions.Docs.Extractor\EAVFW.Extensions.Docs.Extractor.csproj"/>
<ProjectReference Include="..\EAVFW.Extensions.Docs.Generator\EAVFW.Extensions.Docs.Generator.csproj"/>
</ItemGroup>
</Project>

0 comments on commit eb98cbb

Please sign in to comment.