Hook for plugin uninstall process

Is there a possibility to do some task at Uninstall plugin stage ?

I mean something similar  to 'postStartupActivity' phase

Where is the hook if exists ?

Thank you
Regards

0
7 comments

Hi Bernard,

There is a `com.intellij.ide.plugins.PluginInstaller#addStateListener` though it is not a part of Open API therefore it is not guaranteed that this method would not be changed in the future.

0

Hi Ivan,

thank you for the answer,

I'll try it in ASAP

 

0

Hello,

Finally, I took time to test it.

It works, thanks you for the tip

Regards

 

PS: For anyone interested, here is the piece of code:

public class RegisterPluginInstallerStateListener implements StartupActivity {

@Override
public void runActivity(@NotNull Project project) {
com.intellij.ide.plugins.PluginInstaller.addStateListener(new PluginStateListener() {
@Override
public void install(@NotNull IdeaPluginDescriptor ideaPluginDescriptor) {
}

@Override
public void uninstall(@NotNull IdeaPluginDescriptor ideaPluginDescriptor) {
try {
String filename = "/tmp/zzz";
File file = new File(filename);
if (file.exists()) {
file.delete();
}
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
0

Is this still the recommended way to achieve this? I am trying to prompt users to provide some feedback if they uninstall the plugin and this is not working for me. My code looks like:

import com.intellij.ide.BrowserUtil;
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginInstaller;
import com.intellij.ide.plugins.PluginStateListener;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import org.jetbrains.annotations.NotNull;


public class PromptFeedbackAtUninstall implements StartupActivity {

@Override
public void runActivity(@NotNull Project project) {
PluginInstaller.addStateListener(new PluginStateListener() {
@Override
public void install(@NotNull IdeaPluginDescriptor descriptor) {
}

@Override
public void uninstall(@NotNull IdeaPluginDescriptor descriptor) {
BrowserUtil.browse("https://www.mywebsite.com/feedback");
}
});
}
}

 

Thanks.

0

How can I test this? I want to trigger this from an automated test, but couldn't find how to do that.

The closed I got was using:

PluginInstaller.prepareToUninstall(pluginDescriptor)

But it throws an exception because it initiates my plugin as a bundled one

pluginDescriptor.isBundled() == true

So.... How can I test an uninstall event?

0

How do you install your plugin in your test?

0

Using:

extends LightPlatformCodeInsightFixture4TestCase
0

Please sign in to leave a comment.