Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Dynamically loading plugin from another plugin
Dynamically loading plugin from another plugin [message #1761265] Tue, 09 May 2017 12:22 Go to next message
Arkadi Vinnik is currently offline Arkadi VinnikFriend
Messages: 2
Registered: May 2017
Junior Member
I need to load plugin from another plugin (loader). The plugin has menus defined in plugin.xml . When I load the plugin the first time it looks and works OK. When I load it the second time all UI items are present (from the loader and from the plugin) and UI is behaving in a strange way (some windows do not open, etc.). When I rename the plugin everything works fine again.
I need only loader UI to be present. I cannot figure out how to achieve it. It looks like something is cached, but I am not sure how to clear the cache automatically.

Any ideas?

Re: Dynamically loading plugin from another plugin [message #1761391 is a reply to message #1761265] Wed, 10 May 2017 13:30 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 788
Registered: January 2012
Senior Member

What version of the Eclipse Platform are you running?

A big hammer is run with `-clearPersistedState`: that causes the E4 level to ignore the saved UI layouts.

Brian.


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Dynamically loading plugin from another plugin [message #1761413 is a reply to message #1761391] Wed, 10 May 2017 17:24 Go to previous messageGo to next message
Arkadi Vinnik is currently offline Arkadi VinnikFriend
Messages: 2
Registered: May 2017
Junior Member
It needs to work on 3 last versions of Eclipse. I think I found a working solution:
in Activator of the loader (in stop and start callbacks) I unload the dynamically loaded plugin. Now all menus are gone and everything works fine.

This is unload code:
public static void UninstallPlugin()
{
Bundle plugin = Platform.getBundle("bb.aa.cc.dd");
if(plugin == null) return;
try {
Bundle bundle = plugin.getBundleContext().getBundle(0);
FrameworkWiring adapt = bundle.adapt(FrameworkWiring.class);

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);
for (IExtension point : points) {
point.getExtensionPointUniqueIdentifier();
Platform.getExtensionRegistry().removeExtension(point, masterToken);
}
adapt.refreshBundles(adapt.getRemovalPendingBundles());
plugin.uninstall();
Thread.sleep(5000);

//update menus
IWorkbenchWindow window = Workbench.getInstance().getActiveWorkbenchWindow();
MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
//menuManager.update();
menuManager.updateAll(true);

}
catch (Exception e) {
e.printStackTrace();
}
}
Re: Dynamically loading plugin from another plugin [message #1761828 is a reply to message #1761413] Thu, 11 May 2017 15:25 Go to previous message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 788
Registered: January 2012
Senior Member

You should be able to use the OSGi-level APIs to load and unload the bundles directly, and the Extension Registry will react automatically. But you will still need to refresh the window menu manager (and be aware that you may have multiple windows and will need to update them all). The support for cleaning up from dynamically added or removed extension contributions is uneven and though much improved in Neon.

Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Previous Topic:Suddenly getting "Missing artifact com.sun:tools:jar:0" in Maven project
Next Topic:Eclipse startup hung forever at "Loading org.eclipse.emf.edit"
Goto Forum:
  


Current Time: Fri Nov 16 01:27:17 GMT 2018

Powered by FUDForum. Page generated in 0.02097 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top