Eclipse 3.8 to 4.6 Migration Platform.getPlugin()

2019-09-17 09:51发布

问题:

I have to migrate from Eclipse 3.8 to 4.6. My problem is that in 4.6 (or earlier) Platform.getPlugin() got deprecated and will always return null. Using the Bundles in place of plugins doesn't help me beacuse in that case we will have to break our public API. Do you know if there is a way from the bundle to get the plugin ?

/**
 * As the org.eclipse.core.runtime.compatibility plug-in has been removed in
 * Eclipse 4.6 this method is not supported anymore.
 *
 */
@Deprecated
public static Plugin getPlugin(String id) {
    return null;
}

回答1:

The question I have to ask is what were you using it for, and then point out that while Platform#getPlugin(String) is deprecated, Plugin itself is not. If your Bundle-Activator class extends Plugin, just have it save a reference to itself in its constructor, ala http://git.eclipse.org/c/sourceediting/webtools.sourceediting.git/tree/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/JSPCorePlugin.java#n54 . Then it's just a matter of accessing it when you need it.