在启动Eclipse

时间:2016-11-10 10:15:56

标签: eclipse eclipse-plugin eclipse-rcp osgi-bundle

我有基于RCP的产品。我想在启动RCP时卸载一些eclipse插件,检查一些许可证文件并根据许可证类型。

我通过WorkbenchAdvisor的子类和重写方法实现了这一点。

以下是我的WorkbenchAdvisor课程。

public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {

  boolean isLicenseAvailable = true;

  /**
   * {@inheritDoc}
   */
  @Override
  public void preStartup() {
    LicenseManager.getInstance();
  }

  private static final String PERSPECTIVE_ID = "com.example.perspective"; //$NON-NLS-1$

  @Override
  public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(final IWorkbenchWindowConfigurer configurer) {
    return new ApplicationWorkbenchWindowAdvisor(configurer);
  }

  @Override
  public String getInitialWindowPerspectiveId() {
    return PERSPECTIVE_ID;
  }
}

然后,下面是根据许可证类型卸载LicenseManager类中的插件的代码段。

  Bundle plugin = Platform.getBundle("com.example.test");
Bundle bundle = plugin.getBundleContext().getBundle(0);
FrameworkWiring adapt = bundle.adapt(FrameworkWiring.class);
try {
  if (plugin != null) {
    ExtensionRegistry registry = (ExtensionRegistry) Platform.getExtensionRegistry();
    Field privateStringField = ExtensionRegistry.class.getDeclaredField("masterToken"); //$NON-NLS-1$
    privateStringField.setAccessible(true);
    Object masterToken = privateStringField.get(registry);

    IContributor contributor = ContributorFactoryOSGi.createContributor(plugin);
    IExtension[] points = registry.getExtensions(contributor);
    for (IExtension point : points) {
      point.getExtensionPointUniqueIdentifier();
      Platform.getExtensionRegistry().removeExtension(point, masterToken);
    }
    adapt.refreshBundles(adapt.getRemovalPendingBundles());
    plugin.uninstall();
    Thread.sleep(5000);
  }
}
catch (BundleException | SecurityException | IllegalArgumentException e) {
  e.printStackTrace();
}
catch (NoSuchFieldException | IllegalAccessException w) {
  w.printStackTrace();
}
catch (InterruptedException e) {
  e.printStackTrace();
}
super.preStartup();

现在插件正在卸载,菜单贡献正在消失,但不是全部。如果我有菜单"测试"在它下面有两个命令" c1和C2"。 c1和c2消失,但不是菜单"测试"。

每次点击该菜单时,我都会遇到异常。弹出菜单也可以折腾。导航器下的弹出菜单都没有出现。我也得到了同样的例外。

org.eclipse.e4.core.di.InjectionException: org.eclipse.core.runtime.InvalidRegistryObjectException: Invalid registry object
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:68)
    at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:252)
    at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:234)
    at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
    at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.setEnabled(HandlerServiceHandler.java:80)
    at org.eclipse.core.commands.Command.setEnabled(Command.java:875)


0 个答案:

没有答案