private void createDynamicExtension(){
try{
Bundle bundle = plugin.getBundle();
InputStream inputStream = bundle.getEntry("extention.xml").openStream();
String bundleIdStr = ""+bundle.getBundleId();//Get bundle ID as a String
IContributor contributor = new RegistryContributor(bundleIdStr, bundle.getSymbolicName(),
null, null);
ExtensionRegistry extensionRegistry = (ExtensionRegistry) Platform.getExtensionRegistry();
Field declaredField = ExtensionRegistry.class.getDeclaredField("masterToken");
declaredField.setAccessible(true);
Object masterToken = declaredField.get(extensionRegistry);
boolean addContribution = extensionRegistry.addContribution(inputStream, contributor, false, bundle.getSymbolicName(), null, masterToken);
System.out.println(addContribution);
}catch(Exception ex){
ex.printStackTrace();
}
}
Here I have provided the extension content inside the "
extention.xml" file.