Skip to content

Commit dcd3b33

Browse files
committed
Require that plugins are specified instead of autodiscovered.
1 parent 895823b commit dcd3b33

File tree

8 files changed

+37
-23
lines changed

8 files changed

+37
-23
lines changed

src/InEngine.Core.Test/appsettings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"InEngine": {
3+
"Plugins": [
4+
"InEngine.Commands"
5+
],
36
"Queue": {
7+
"UseCompression": false,
8+
"PrimaryQueueConsumers": 16,
9+
"SecondaryQueueConsumers": 4,
410
"QueueName": "InEngine:Queue",
511
"RedisHost": "localhost",
612
"RedisPort": 6379,

src/InEngine.Core/Commands/Options.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public class Options : IOptions
88
[VerbOption("echo", HelpText= "Echo some text to the console. Useful for end-to-end testing.")]
99
public Echo Echo { get; set; }
1010

11-
[VerbOption("process", HelpText = "Launch an arbitrary process.")]
12-
public RuntimeProcess Process { get; set; }
11+
[VerbOption("proc", HelpText = "Launch an arbitrary process.")]
12+
public SystemProcess SystemProcess { get; set; }
1313

1414
[HelpVerbOption]
1515
public string GetUsage(string verb)

src/InEngine.Core/Commands/RuntimeProcess.cs renamed to src/InEngine.Core/Commands/SystemProcess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace InEngine.Core.Commands
88
{
9-
public class RuntimeProcess : AbstractCommand
9+
public class SystemProcess : AbstractCommand
1010
{
1111
[Option('c', "command", Required = true, HelpText = "The name of the CLI program/command to run.")]
1212
public string Command { get; set; }

src/InEngine.Core/InEngineSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class InEngineSettings
99
{
1010
public static string BasePath { get; set; } = Directory.GetCurrentDirectory();
1111
public static string ConfigurationFile { get; set; } = "appsettings.json";
12-
public List<string> PluginDirectories { get; set; }
12+
public List<string> Plugins { get; set; } = new List<string>();
1313
public QueueSettings Queue { get; set; }
1414

1515
public static InEngineSettings Make()

src/InEngine.Core/Plugin.cs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,26 @@ public List<T> Make<T>() where T : class, IPluginType
4242
.ToList();
4343
}
4444

45-
public static List<Plugin> Discover<T>() where T : IPluginType
45+
public static List<Plugin> Load<T>() where T : IPluginType
4646
{
47-
var logger = LogManager.GetCurrentClassLogger();
48-
var discoveredAssemblies = InEngineSettings.Make().PluginDirectories.SelectMany(x => {
49-
if (!Directory.Exists(x)) {
50-
logger.Warn("Plugin directory does not exist: " + x);
51-
return new List<Assembly>();
52-
}
53-
return Directory.GetFiles(x, "*.dll").Select(y => Assembly.LoadFrom(y));
54-
});
5547
var pluginList = new List<Plugin>();
56-
foreach (var assembly in discoveredAssemblies)
48+
var logger = LogManager.GetCurrentClassLogger();
49+
50+
logger.Debug("Loading core plugin...");
51+
try
52+
{
53+
pluginList.Add(new Plugin(Assembly.GetExecutingAssembly()));
54+
}
55+
catch (Exception exception)
56+
{
57+
logger.Error(exception, "Error loading InEngine.Core plugin.");
58+
}
59+
60+
var assemblies = InEngineSettings
61+
.Make()
62+
.Plugins
63+
.Select(x => Assembly.LoadFrom($"{x}.dll"));
64+
foreach (var assembly in assemblies)
5765
{
5866
try
5967
{
@@ -62,9 +70,11 @@ public static List<Plugin> Discover<T>() where T : IPluginType
6270
}
6371
catch (Exception exception)
6472
{
65-
logger.Error(exception, "Error discovering plugins");
73+
logger.Error(exception, "Error loading plugins.");
6674
}
6775
}
76+
if (!pluginList.Any())
77+
throw new PluginNotFoundException("There are no plugins available.");
6878
return pluginList.OrderBy(x => x.Name).ToList();
6979
}
7080

src/InEngine/ArgumentInterpreter.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
using System;
22
using System.Linq;
33
using CommandLine;
4-
using CommandLine.Text;
54
using InEngine.Core;
65
using InEngine.Core.Exceptions;
76
using NLog;
87
using InEngine.Core.IO;
9-
using System.ServiceProcess;
10-
using System.IO;
118
using System.Collections.Generic;
129

1310
namespace InEngine
@@ -33,7 +30,7 @@ ___ _____ _ _ _ _____ _____
3330

3431
public void Interpret(string[] args)
3532
{
36-
var plugins = Plugin.Discover<IOptions>();
33+
var plugins = Plugin.Load<IOptions>();
3734
var parser = new Parser(with => {
3835
with.IgnoreUnknownArguments = true;
3936
with.MutuallyExclusive = true;
@@ -159,9 +156,9 @@ public void PrintPluginHelpTextAndExit(Plugin plugin, List<IOptions> pluginOptio
159156
.ToList()
160157
.ForEach(x => {
161158
var optionAttribute = (x as BaseOptionAttribute);
162-
Console.WriteLine($" {optionAttribute.LongName}\t{optionAttribute.HelpText}");
159+
Write.Text($" {optionAttribute.LongName}".PadRight(20));
160+
Write.Line(optionAttribute.HelpText);
163161
});
164-
165162
}
166163
ExitWithSuccess();
167164
}

src/InEngine/Jobs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class Jobs
1111
public static void Schedule(IScheduler scheduler)
1212
{
1313
var logger = LogManager.GetCurrentClassLogger();
14-
Plugin.Discover<IJobs>().ForEach(x => {
14+
Plugin.Load<IJobs>().ForEach(x => {
1515
logger.Info($"Registering jobs from plugin: {x.Name}");
1616
x.Make<IJobs>().ForEach(y => y.Schedule(scheduler));
1717
});

src/InEngine/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"InEngine": {
3-
"PluginDirectories": [ ".", "Plugins" ],
3+
"Plugins": [
4+
],
45
"Queue": {
56
"UseCompression": false,
67
"PrimaryQueueConsumers": 16,

0 commit comments

Comments
 (0)