A plugin can no longer listen for its own PluginUninstallingEvent since Atlassian Plugins 5

Prior to Jira 8 (and Atlassian Plugins 5), you were able to listen for the PluginUninstallingEvent of your plugin from within your plugin, giving you the opportunity to perform some cleanup before uninstalling. For example, a plugin installed from an Obr could also uninstall its accompanying plugins.

Following the Jira 8 upgrade (which I assume may be due to upgrading to Atlassian Plugins 5 too), the plugin is disabled and therefore completely unwired, before the PluginUninstallingEvent is published, making it impossible for a plugin to know when it is about to be uninstalled.

Is this intentional or an untested side-effect of changes in the platform?

It seem we are also unable to submit bugs to the plugin project in the Atlassian Ecosystem Jira too, so instead i’m posting here, in the hope that someone from the Atlassian plugins team can help.

2 Likes

You’ll probably want to use @PreDestroy or DisposableBean. See the docs for more information:

https://developer.atlassian.com/server/jira/platform/plugins2-add-ons/#component-destruction

I’ve submitted this as a bug, with an example for context, which I’ll repost here for clarity…

@Named
public class Cleanup {

    @ComponentImport
    private final EventPublisher eventPublisher;

    @ComponentImport
    private final PluginRetrievalService pluginRetrievalService;

    @Inject
    public Cleanup(EventPublisher eventPublisher,
                   PluginRetrievalService pluginRetrievalService) {
        this.eventPublisher = eventPublisher;
        this.pluginRetrievalService = pluginRetrievalService;
    }

    @PostConstruct
    public void register() {
        eventPublisher.register(this);
    }

    @PreDestroy
    public void unregister() {
        eventPublisher.unregister(this);
    }

    @EventListener
    public void onPluginUninstallingEvent(PluginUninstallingEvent event) {
        final Plugin obr = pluginRetrievalService.getPlugin();

        if (event.getPlugin().equals(obr)) {
            // DO SOME CLEANUP HERE
        }
    }
}

The cleanup is something that should be done only on the deliberate uninstallation of the plugin, not just when it disables, and esp not when it upgrades.

And this worked perfectly fine pre Jira 8.

1 Like

I see. Once you find a solution I guess these people would be interested as well.

1 Like

Hi Everyone,

A product issue is created for this. Please see progress in https://ecosystem.atlassian.net/browse/AMPS-1503

Cheers,
Anne