protected void installEP(final ExtensionPointName<ServiceDescriptor> pointName, final ComponentManager componentManager) { myExtensionPointName = pointName; final ExtensionPoint<ServiceDescriptor> extensionPoint = Extensions.getArea(null).getExtensionPoint(pointName); assert extensionPoint != null; final MutablePicoContainer picoContainer = (MutablePicoContainer)componentManager.getPicoContainer(); myExtensionPointListener = new ExtensionPointListener<ServiceDescriptor>() { public void extensionAdded(@NotNull final ServiceDescriptor descriptor, final PluginDescriptor pluginDescriptor) { if (descriptor.overrides) { ComponentAdapter oldAdapter = picoContainer.unregisterComponent(descriptor.getInterface());// Allow to re-define service implementations in plugins. if (oldAdapter == null) { throw new RuntimeException("Service: " + descriptor.getInterface() + " doesn't override anything"); } } picoContainer.registerComponent(new MyComponentAdapter(descriptor, pluginDescriptor, (ComponentManagerEx)componentManager)); } public void extensionRemoved(@NotNull final ServiceDescriptor extension, final PluginDescriptor pluginDescriptor) { picoContainer.unregisterComponent(extension.getInterface()); } }; extensionPoint.addExtensionPointListener(myExtensionPointListener); }
protected void installEP(@NotNull ExtensionPointName<ServiceDescriptor> pointName, @NotNull final ComponentManager componentManager) { LOG.assertTrue(myExtensionPointName == null, "Already called installEP with " + myExtensionPointName); myExtensionPointName = pointName; final ExtensionPoint<ServiceDescriptor> extensionPoint = Extensions.getArea(null).getExtensionPoint(pointName); final MutablePicoContainer picoContainer = (MutablePicoContainer)componentManager.getPicoContainer(); myExtensionPointListener = new ExtensionPointListener<ServiceDescriptor>() { @Override public void extensionAdded(@NotNull final ServiceDescriptor descriptor, final PluginDescriptor pluginDescriptor) { if (descriptor.overrides) { // Allow to re-define service implementations in plugins. ComponentAdapter oldAdapter = picoContainer.unregisterComponent(descriptor.getInterface()); if (oldAdapter == null) { throw new RuntimeException("Service: " + descriptor.getInterface() + " doesn't override anything"); } } if (!ComponentManagerImpl.isComponentSuitableForOs(descriptor.os)) { return; } // empty serviceImplementation means we want to unregister service if (!StringUtil.isEmpty(descriptor.getImplementation())) { picoContainer.registerComponent(new MyComponentAdapter(descriptor, pluginDescriptor, (ComponentManagerEx)componentManager)); } } @Override public void extensionRemoved(@NotNull final ServiceDescriptor extension, final PluginDescriptor pluginDescriptor) { picoContainer.unregisterComponent(extension.getInterface()); } }; extensionPoint.addExtensionPointListener(myExtensionPointListener); }
public List<ServiceDescriptor> getAllDescriptors() { ServiceDescriptor[] extensions = Extensions.getExtensions(myExtensionPointName); return Arrays.asList(extensions); }
@Override public void disposeComponent() { final ExtensionPoint<ServiceDescriptor> extensionPoint = Extensions.getArea(null).getExtensionPoint(myExtensionPointName); extensionPoint.removeExtensionPointListener(myExtensionPointListener); }
public MyComponentAdapter(final ServiceDescriptor descriptor, final PluginDescriptor pluginDescriptor, ComponentManagerEx componentManager) { myDescriptor = descriptor; myPluginDescriptor = pluginDescriptor; myComponentManager = componentManager; myDelegate = null; }