Skip to content

Commit

Permalink
feat: support multiple ExportsPlugin declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunderscore committed Oct 3, 2023
1 parent 08b8419 commit 73c8f9b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Editor/API/Attributes/ExportsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace nadena.dev.ndmf
/// }
/// </code>
/// </summary>
[AttributeUsage(AttributeTargets.Assembly)]
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class ExportsPlugin : Attribute
{
public Type PluginType { get; }
Expand Down
8 changes: 8 additions & 0 deletions UnitTests~/PluginResolverTests.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions UnitTests~/PluginResolverTests/SupportsMultipleDeclarations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Collections.Immutable;
using System.Linq;
using nadena.dev.ndmf;
using NUnit.Framework;
using UnitTests.ExportsPluginTest;

[assembly: ExportsPlugin(typeof(PluginA))]
[assembly: ExportsPlugin(typeof(PluginB))]

namespace UnitTests.ExportsPluginTest
{
internal class PluginA : Plugin<PluginA>
{
protected override void Configure()
{
InPhase(BuildPhase.Transforming).Run("test", _ctx => { });
}
}

internal class PluginB : Plugin<PluginB>
{
protected override void Configure()
{
InPhase(BuildPhase.Transforming).Run("test", _ctx => { });
}
}

public class SupportsMultipleDeclarations
{
[Test]
public void TestSupportsMultipleDeclarations()
{
var resolver = new PluginResolver();
var plugins =
resolver.Passes.SelectMany(kv => kv.Item2) // passes per phase
.Select(pass => pass.Plugin.GetType())
.ToImmutableHashSet();

Assert.IsTrue(plugins.Contains(typeof(PluginA)));
Assert.IsTrue(plugins.Contains(typeof(PluginB)));
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 73c8f9b

Please sign in to comment.