Search code examples
eclipseeclipse-plugin

Reload target platform in eclipse dynamically from plugin


I'm writing a plugin to eclipse, in which I need to reload active target platform, at a given time. - just as the Preferences -> Plug-In Development -> Target Platform -> Reload.button, but of course dynamically from my plugin.

I would imagine something like this would be the way, but i can't find the entrance/MagicProvider:

MagicProvider.getTargetPlatforms().getActive().reload();

Hope some of you know the trick :)


Solution

  • Tried Max's approach, but it didn't seem to work. After searching the eclipse source I found out, that the ITargetDefinition is just a working copy, and must be saved. So the code will be:

    org.eclipse.pde.internal.core.target.provisional.ITargetPlatformService service = org.eclipse.pde.internal.core.PDECore.getDefault().acquireService(ITargetPlatformService.class.getName());
    org.eclipse.pde.internal.core.target.provisional.ITargetDefinition target = service.getWorkspaceTargetHandle().getTargetDefinition();
    target.resolve(IProgressMonitor);
    org.eclipse.pde.internal.core.target.provisional.LoadTargetDefinitionJob.load(target);
    

    But credits to Max for the guideline. :)

    If anyone else needs some info, I recommend taking a look at

    org.eclipse.pde.internal.ui.preferences.TargetPlatformPreferencePage near line 771 - 812 and method handleReload() and org.eclipse.pde.internal.ui.editor.targetdefinition.TargetEditor near line line 231