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

(GH-17) Use dynamic loading of addins #127

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

AdmiringWorm
Copy link
Member

This pull requests starts the first steps of allowing addins to be loaded dynamically,
I am starting with the Generic Reporter addin as this is the one addin not compatible with .NET Core.

The dynamic loading is done entirely by using reflection after calling a temporary cake script to restore the addin as a tool, and then enumerating throug all of the declared types in the assembly to find the ones with want.

All of this is very much in progress, but would appreciate feedback of what is currently done.

Tested on Windows and Linux using both Cake .NET and Cake .NET Core

Copy link
Member

@pascalberger pascalberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What bothers me about this approach is, that it requires to basically redefine the whole API of every addin (once used for everything) using reflection. Which will be a significant effort (there are currently over 75 aliases and much more public classes). Therefore I don't see this as the approach which works for every case. Another possibility would be to write the code just as a string which is then executed at runtime.

I think in the end we need to find a good balance between which addins are added always (e.g. Cake Issues core addins), which are loaded dynamic but executed as string and aliases and API is not available to scripts using Cake.Issues.Recipe and which of the API is made available to users.

@@ -113,16 +115,31 @@ IssuesBuildTasks.CreateFullIssuesReportTask = Task("Create-FullIssuesReport")
IssuesParameters.OutputDirectory.CombineWithFilePath(reportFileName);
EnsureDirectoryExists(IssuesParameters.OutputDirectory);

IIssueReportFormat issueFormat = null;

if (!Context.Environment.Runtime.IsCoreClr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading of addins should mainly be triggered by parameters. Meaning that if any parameter is set which requires the reporting addin it should be loaded. In case of the reporting addin which is currently not compatible with .NET Core we can decide what to do in this case (IMHO it should be an error, since the user says he want's report and the script is not capable of creating one).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I didn't want to implement any changes to the options class for this PR, which is why I just added a check if we are running on .NET Core or not.

But I do agree that it should be triggered by parameters.

Cake.Issues.Recipe/Content/build.cake Outdated Show resolved Hide resolved
@AdmiringWorm
Copy link
Member Author

What bothers me about this approach is, that it requires to basically redefine the whole API of every addin (once used for everything) using reflection.

Only if you need to use everything, basically the intention is to just define what you need instead of the whole API.

Another possibility would be to write the code just as a string which is then executed at runtime.

Well, I could definitely try to re-implement a more generic approach with this in thought.

@AdmiringWorm
Copy link
Member Author

@pascalberger I changed the logic up a bit to allow for more loosely coupled reflection (like passing in string as a method name), instead of redefining the API (not yet complete, but it is a start I believe).

Hopefully this is a bit closer to what you had in mind.

@AdmiringWorm AdmiringWorm force-pushed the load-with-reflection branch 2 times, most recently from da0b54f to 7156d2f Compare July 21, 2020 13:26
@AdmiringWorm AdmiringWorm marked this pull request as ready for review July 24, 2020 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants