How to have plugin disable itself

How does a plugin disable itself. I figure it would do the usual things in the @PreDestroy method and then send a PluginDisabledEvent so Jira (the UPM) knows. But, I don’t see any examples of this.

I’m not sure if it is possible for a plugin to disable itself - what is the underlying problem you’re trying to solve that would necessitate this?

In theory it is possible - but I think you’ll get a lot of funkiness happening (like @HeyJoe mentioned).

You’d have to make use of https://docs.atlassian.com/atlassian-plugins-api/4.0.0-m009/atlassian-plugins-api/apidocs/com/atlassian/plugin/PluginController.html (or PluginManager) and just have it uninstall the plugin. That said - there will be thread, pointers, caches etc that will probably freak out since your thread is executing code that shouldn’t be existing at some point.

Just like @HeyJoe - I am curious what the underlying issue is…

Hi all,

Actually, the plugin is initiating its own “shutdown” by calling the usual methods during a disable or untinstall from the UPM, e.g., @PreDestroy methods, etc… I do this when detecting certain critical errors that need to be resolved before it can run properly instead of filling-up the logs with errors.

So, I can shutdown the plugin internally, but the UPM doesn’t know about it and it still shows the plugin as enabled, which is misleading to the users. I figured all I need to do is just send a PluginDisabledEvent so the UPM could know about it, but that’s just a guess and I couldn’t find any examples of that even in the base Jira source.

Hi Daniel,

Thanks for the reference to PluginController; seems right but I don’t understand why you would say that the plugin code would still be running. Shouldn’t it call the @PreDestroy methods of the plugin as usual?

That depends on how good each of the module creators have been… (this is not a common use case).

What do you mean by module creators? You mean the developers?

Yeah. Each module descriptor has its own way of handling things. For example the cache manager def doesn’t handle things disappearing on it.

Ok, so I guess the verdict is that although PluginController and PluginManager are interesting, they aren’t stable solutions. Thanks Daniel.