Uninstall a eclipse Plugin Programmatically before startup of eclipse -
i have rcp based product. , want uninstall eclipse plugins on start of rcp on checking license file , depending on license type.
i have achieved through subclass of workbenchadvisor , overriding prestartup() method.
below workbenchadvisor class.
public class applicationworkbenchadvisor extends workbenchadvisor { boolean islicenseavailable = true; /** * {@inheritdoc} */ @override public void prestartup() { licensemanager.getinstance(); } private static final string perspective_id = "com.example.perspective"; //$non-nls-1$ @override public workbenchwindowadvisor createworkbenchwindowadvisor(final iworkbenchwindowconfigurer configurer) { return new applicationworkbenchwindowadvisor(configurer); } @override public string getinitialwindowperspectiveid() { return perspective_id; }
}
then below snippet uninstalls plugins in licensemanager class depending on licensetype.
bundle plugin = platform.getbundle("com.example.test"); bundle bundle = plugin.getbundlecontext().getbundle(0); frameworkwiring adapt = bundle.adapt(frameworkwiring.class); try { if (plugin != null) { extensionregistry registry = (extensionregistry) platform.getextensionregistry(); field privatestringfield = extensionregistry.class.getdeclaredfield("mastertoken"); //$non-nls-1$ privatestringfield.setaccessible(true); object mastertoken = privatestringfield.get(registry); icontributor contributor = contributorfactoryosgi.createcontributor(plugin); iextension[] points = registry.getextensions(contributor); (iextension point : points) { point.getextensionpointuniqueidentifier(); platform.getextensionregistry().removeextension(point, mastertoken); } adapt.refreshbundles(adapt.getremovalpendingbundles()); plugin.uninstall(); thread.sleep(5000); } } catch (bundleexception | securityexception | illegalargumentexception e) { e.printstacktrace(); } catch (nosuchfieldexception | illegalaccessexception w) { w.printstacktrace(); } catch (interruptedexception e) { e.printstacktrace(); } super.prestartup();
now plugins getting uninstalled , menu contributions disappearing not of them. if have menu "test" , under 2 commands "c1 , c2". c1 , c2 disappears not menu "test".
and i'm getting below exception each time click on menu. , pop menus going toss. none of popup menus under navigator coming. there same exception.
org.eclipse.e4.core.di.injectionexception: org.eclipse.core.runtime.invalidregistryobjectexception: invalid registry object @ org.eclipse.e4.core.internal.di.methodrequestor.execute(methodrequestor.java:68) @ org.eclipse.e4.core.internal.di.injectorimpl.invokeusingclass(injectorimpl.java:252) @ org.eclipse.e4.core.internal.di.injectorimpl.invoke(injectorimpl.java:234) @ org.eclipse.e4.core.contexts.contextinjectionfactory.invoke(contextinjectionfactory.java:132) @ org.eclipse.e4.core.commands.internal.handlerservicehandler.setenabled(handlerservicehandler.java:80) @ org.eclipse.core.commands.command.setenabled(command.java:875)
Comments
Post a Comment