You can define an extension point and search / call fragment classes through extensions.
IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtensionPoint extensionPoint = registry .getExtensionPoint("myplugin.myextension"); IConfigurationElement points[] = extensionPoint .getConfigurationElements(); for (IConfigurationElement point : points) { if ("myextensionFactory".equals(point.getName())) { Object impl = point.createExecutableExtension("class"); if (impl instanceof IMyExtension) { ((IMyExtension) impl).foo(); } } } }
EDIT:
To use this approach, I need to convert my fragment projects to plugin projects. - bmatthews68
You do not need. For example, in my test code, I have the following files in the host plugin:
META-INF / MANIFEST.MF :
Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Myplugin Plug-in Bundle-SymbolicName: myplugin;singleton:=true Bundle-Version: 1.0.0 Bundle-Activator: myplugin.Activator Require-Bundle: org.eclipse.core.runtime Eclipse-LazyStart: true Export-Package: myplugin
plugin.xml
<?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.2"?> <plugin> <extension-point id="myextension" name="myextension" schema="schema/myextension.exsd" /> </plugin>
The snippet contains these files:
META-INF / MANIFEST.MF :
Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Myfragment Fragment Bundle-SymbolicName: myfragment;singleton:=true Bundle-Version: 1.0.0 Fragment-Host: myplugin;bundle-version="1.0.0"
fragment.xml
<?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.2"?> <fragment> <extension point="myplugin.myextension"> <myextensionFactory class="myfragment.MyExtension1"> </myextensionFactory> </extension> </fragment>
These projects were created using Eclipse 3.3.1.1.
Mcdowell
source share