Search code examples
osgircpe4

Eclipse e4 OSGI Service @Component Annotation


If a create the following OSGI-INF/service.xml and set it via Service-Component: OSGi-INF/service.xml in my MANIFEXT.MF

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="EvalManagerContextFunction">

   <implementation class="x.y.context.EvalManagerContextFunction"/>

   <property name="service.context.key" type="String" value="x.y.eval.EvalManager"/>

   <service>
      <provide interface="org.eclipse.e4.core.contexts.IContextFunction"/>
   </service>

</scr:component>

The EvalManager is created if it is requested the first time (ContextFunction Class compute is called)

Now if I try to do the same with annotations the compute Functions is not called.

@Component(name = "EvalManagerContextFunction", service = IContextFunction.class, property = "service.context.key=x.y.eval.EvalManager")
public class EvalManagerContextFunction extends ContextFunction {

    @Override
    public Object compute(IEclipseContext context, String contextKey) {

        EvalManager manager = ContextInjectionFactory.make(EvalManager.class, context);

        context.get(MApplication.class).getContext().set(EvalManager.class, ContextInjectionFactory.make(EvalManager.class, context));

        return manager;

    }

}

Solution

  • I can't see any references to the @Component annotation class anywhere in the Eclipse core source so it would appear it is not supported.

    There is a plug-in in the Eclipse Marketplace here which appears to add support for this (I have not tried this).

    Update: Support for this has been added to the Eclipse Neon Milestone 6 (4.6M6) build.