0

I am using maven-scr-plugin to generate component and metatype descriptions. I am migrating from org.apache.felix.scr annotations to org.osgi.service.component annotations.

Carsten Ziegeler has written an excellent blog on how to do this migration here. However, that does not explain on how to have the metatype descriptions directly generated from the component annotations. Instead, I would have to make a separate configuration @interface for every component, and rewrite all component activators (at least, to make use of the added value of those extra @interface classes).

I can still use the maven-scr-plugin to process the osgi annotations by adding a dependency on org.apache.felix.scr.ds-annotations. However, maven-scr-plugin only outputs metatype information if that is explicitly switched on. With the felix annotations, a dedicated parameter metatype=true in the @Component annotation is available to enable metatype generation. However, such a parameter is not available in the OSGi version of the @Component annotation.

Is there a way to either force maven-scr-plugin to generate the metatype descriptions, or can I make maven-bundle-plugin (or bndtools) to generate the metatype data based on the osgi @Component annotation, instead of having to define a dedicated configuration class for every component?

Igor P
  • 85
  • 1
  • 5

2 Answers2

1

Metatype is generated when you use the @Designate annotation. (At least in the bnd implementation.)

 @Designate( ocd=Config.class, factory=true )
 @Component
 public class SomeComponent {
    @ObjectClassDefinition
    @interface Config {
       int port();
    }
    @Activate
    void activate( Config config) { }
 }
Peter Kriens
  • 15,196
  • 1
  • 37
  • 55
  • Yes, I understood, and this works without problems. However, to do this properly, I would also have to change all activators, as demonstrated in your example (I know it can be done without, but that leaves a lot of unused boilerplate code in my classes). Can I see your answer as a confirmation that bnd does not support the approach I am looking for? Then I can exclude that solution path, only leaving the maven-scr-plugin as a possible solution. – Igor P Nov 23 '16 at 15:39
0

As far as I know you need a separate configuration @interface for each component. It is also not possible to generate the meta type from the @Component annotations as they do not describe configurations.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • The @Component annotation has the `property` parameter, where all basic info for the configuration parameters is defined (name, default value, object type). Of course, additional information like limiting ranges and explenatory descriptions cannot be added, but I do not need those in my case – Igor P Nov 23 '16 at 14:44
  • I don't think the properties on @Component are taken into account when creating the meta type but I might be wrong. Maybe Peter can answer that. – Christian Schneider Nov 23 '16 at 15:36
  • They are not. Metatype xml is generated from ObjectClassDefinition annotated types. It is not generated from property elements of Component annotations. – BJ Hargrave Nov 23 '16 at 16:30