Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support multiple ExportsPlugin declarations #45

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Added toplevel menu for manual bake avatar, even when MA is also installed (#35)
- Added support for multiple ExportsPlugin declarations (#40)

### Fixed
- Create ApplyOnPlayGlobalActivator correctly when creating and opening scenes (#31)
Expand Down
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.