capint
2/16/2016 - 11:03 AM

Eclipse >> Extension >> Extension registry

Eclipse >> Extension >> Extension registry

private Object getExtRegistryMasterToken() {

  Field[] fs = _registry.getClass().getDeclaredFields();
  Field fTgt = null;
  for (Field f : fs) {
    if (f.getName().equals("masterToken")) { //$NON-NLS-1$
      fTgt = f;
      break;
    }
  }
  fTgt.setAccessible(true);

  Object mtoken = null;

  try {
    mtoken = fTgt.get(_registry);
  } catch (IllegalArgumentException e) {
    // Do nothing
  } catch (IllegalAccessException e) {
    // Do nothing
  }

  return mtoken;
_registry = Platform.getExtensionRegistry();
//*** Get all contributing extensions to the EXT_POINT extension point
IExtension[] extensions = _registry.getExtensionPoint(EXT_POINT).getExtensions();
for (IExtension extension : extensions) {
  //*** Master token allows all operations; user token only allows non-persisted registry elements to be modified
  Object _token = getExtRegistryMasterToken();
  //*** Remove the extension from registry
  _registry.removeExtension(extension, _token);
  
  //*** Stream open on the plugin.xml file
  ByteArrayInputStream is = generateXMLDescStream();
  IContributor contributor = extension.getContributor();
  //*** Add new contribution
  _registry.addContribution(is, contributor, true, null, null, _token);
}