Can anyone help what would be perfect way to achieve this requirement:
We have number of OSGi services in our project and divided into 2 sets.
Based on a parameter passed during build, we need to enable one set of OSGi services and disable other set.
We have OSGi service1, service2, service3, service4.
If param == enableFirstSet ----> then enable service1 & service2
If param == enableSecondSet ----> then enable service3 & service4
I have tried below code in activate method to deactivate individual services based on param but the problem is their attached OCD(configuration) still available in OSGi configuration tab as those configurations attached at bundle level rather than component level.
One way to do what you want is to make it so an OSGi configuration needs to be available for the component to be enabled (this is called ConfigurationPolicy.REQUIRE on the OSGi Component). See here, for example:
Then using this, you can leverage runmodes like /apps/myapp/config.qaauthor, /apps/myapp/config.qapublish. Or you can enable them by removing the config of one component and enabling the config of the other.
Also, you might consider thinking about it differently. Instead of having different OSGi components / services active for different builds, maybe have a logical controller that checks a method on the service interface that returns boolean (true/false) to see if the service is "enabled".