The best option is to: * fix the system bundle capabilities * use a dependency feature as you did
To fix the system bundle capabilities, depending on the framework used, you can do something along the following: org.osgi.framework.system.capabilities=\ ...\ ${${framework}-capabilities} felix-capabilities= equinox-capabilities=\ osgi.service;effective:=active;objectClass=javax.xml.parsers. SAXParserFactory I haven't tested the above, but hopefully you'll get the idea. It's similar to what's done for the ${jre-${java.specification.version}}... 2017-02-06 9:16 GMT+01:00 Markus Rathgeb <maggu2...@gmail.com>: > Hi Guillaume, > thank you for your reply. > > In this special case it is about an implementation for > "javax.xml.parsers.SAXParserFactory" and a service for that. > The bundle "org.eclipse.equinox.registry" (I need to use to satisfy > third party dependencies) is using a tracker to find an implementation > and prints errors to stdout if there is no one. > To prevent that messages on every Karaf start I would like to have > such a service in the Karaf instance. > > The Equinox OSGi framework provides that service itself. Without any > provide capability in its manifest. > The Apache Felix OSGi framework doesn't provide such a service. > > So, what are the options: > > add it to "org.osgi.framework.system.capabilities" > IMHO this will be not correct, because the service is present if > Equinox is used and not present if Felix is used. > > Use "conditionals" in a feature to install another bundle that > provides a "javax.xml.parsers.SAXParserFactory" service if Felix is > used (and so the conditional will skip the installation if Equinox is > used). > If my reading has been correct, conditionals could be used for > installed features and not for the special OSGi framework > implementation. > > I can install another bundle / feature that provides that service > implementation for both frameworks. > This is okay, but if it is not necessary... > > So, is there a simple method to leave it up to the user to switch > between "karaf.framework" Felix or Equinox and handle that in some > way, so another implementation is installed only if not Equinox is > choosen? > > Best regards, > Markus > > 2017-02-06 8:45 GMT+01:00 Guillaume Nodet <gno...@apache.org>: > > You can modify the etc/config.properties file, in particular the > > org.osgi.framework.system.capabilities > > configuration. If some service are provided by default by the framework > and > > are missing, > > you may want to raise a JIRA issue and provide a patch / pull request. > > > > 2017-02-05 12:05 GMT+01:00 Markus Rathgeb <maggu2...@gmail.com>: > >> > >> Ah, okay, I assume it is caused by the missing > >> Provide-Capability of the Equinox bundle that it provides that service. > >> Could this information be added by some configuration file without > >> modify the Equinox bundle itself? > >> > >> 2017-02-05 11:49 GMT+01:00 Markus Rathgeb <maggu2...@gmail.com>: > >> > Hello, > >> > > >> > I thought I understand how the dependency flag is working for features > >> > and bundles, but at least it seems to be different. > >> > Perhaps someone could explain me the following scenario: > >> > > >> > Feature file: > >> > === > >> > <?xml version="1.0" encoding="UTF-8"?> > >> > <features name="saxparserfactory" > >> > xmlns="http://karaf.apache.org/xmlns/features/v1.4.0"> > >> > > >> > <feature name="saxparserfactory" version="1.0-SNAPSHOT"> > >> > > >> > <requirement>osgi.service;filter:="(objectClass=javax. > xml.parsers.SAXParserFactory)";effective:=active</requirement> > >> > <feature dependency="true">jboss-xerces</feature> > >> > </feature> > >> > > >> > <feature name="jboss-xerces" description="JBoss Xerces" > >> > version="1.0-SNAPSHOT"> > >> > <details>OSGi service for > >> > 'javax.xml.parsers.SAXParserFactory'</details> > >> > > >> > <!-- Maven repository: > >> > https://repository.jboss.org/nexus/content/repositories/releases/ --> > >> > <!-- <bundle > >> > > >> > start-level="30">mvn:org.jboss.osgi.xerces/jbosgi- > xerces/3.1.0.Final</bundle> > >> > --> > >> > <bundle > >> > start-level="30">https://repository.jboss.org/nexus/ > content/repositories/releases/org/jboss/osgi/xerces/jbosgi- > xerces/3.1.0.Final/jbosgi-xerces-3.1.0.Final.jar</bundle> > >> > > >> > <capability>osgi.service;objectClass=javax.xml.parsers. > SAXParserFactory</capability> > >> > > >> > <bundle dependency="true" > >> > start-level="30">mvn:org.osgi/org.osgi.util.xml/1.0.1</bundle> > >> > <bundle dependency="true" > >> > start-level="8">mvn:org.ops4j.pax.logging/pax-logging-api/1. > 9.1</bundle> > >> > </feature> > >> > > >> > </features> > >> > === > >> > > >> > I would expect if I install the feature "saxparserfactory" the feature > >> > jboss-xerces is installed only if the requirements are not already > >> > fulfilled. > >> > The only requirement the feature drops in should be to ensure that > >> > there is a SAXParserFactory service available. > >> > Should this be possible? > >> > > >> > > >> > Test > >> > === > >> > > >> > I used the current Karaf 4.1.0 form the second voting round. > >> > > >> > Start a clean instance: > >> > $ bin/karaf clean > >> > > >> > As expected Apache Felix is the used OSGi framework > >> > > >> > karaf@root()> bundle:list -t 0 -s 0 | grep Active > >> > 0 │ Active │ 0 │ 5.6.1 │ org.apache.felix.framework > >> > > >> > I added the feature repository file. > >> > > >> > karaf@root()> feature:repo-add > >> > file:///home/maggu2810/tmp/saxparserfactory-feature.xml > >> > Adding feature url > >> > file:///home/maggu2810/tmp/saxparserfactory-feature.xml > >> > > >> > After that let's look if there is already a SAXParserFactory present: > >> > > >> > karaf@root()> service:list javax.xml.parsers.SAXParserFactory > >> > > >> > No output, so as expected, no service found. > >> > > >> > Check what will be done if the feature is installed: > >> > > >> > karaf@root()> feature:install -t -v saxparserfactory > >> > Adding features: saxparserfactory/[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT] > >> > Changes to perform: > >> > Region: root > >> > Bundles to install: > >> > > >> > https://repository.jboss.org/nexus/content/repositories/ > releases/org/jboss/osgi/xerces/jbosgi-xerces/3.1.0. > Final/jbosgi-xerces-3.1.0.Final.jar > >> > mvn:org.osgi/org.osgi.util.xml/1.0.1 > >> > > >> > This is as I expect what should be done. > >> > > >> > Let's exit the Karaf container. > >> > > >> > karaf@root()> shutdown -f > >> > > >> > > >> > > >> > After that I used the Equinox framework > >> > > >> > $ echo 'karaf.framework=equinox' >> etc/custom.properties > >> > > >> > and started again a clean isntance. > >> > > >> > $ bin/karaf clean > >> > > >> > Ensure the feature repository is available: > >> > > >> > karaf@root()> feature:repo-add > >> > file:///home/maggu2810/tmp/saxparserfactory-feature.xml > >> > Adding feature url > >> > file:///home/maggu2810/tmp/saxparserfactory-feature.xml > >> > > >> > The Equinox OSGi framework bundle already provides a SAXParserFactory > >> > service. > >> > > >> > karaf@root()> service:list javax.xml.parsers.SAXParserFactory > >> > [javax.xml.parsers.SAXParserFactory] > >> > ------------------------------------ > >> > service.pid = > >> > 0.org.eclipse.osgi.internal.framework.XMLParsingServiceFactory > >> > service.vendor = Eclipse.org - Equinox > >> > service.id = 20 > >> > service.bundleid = 0 > >> > service.scope = bundle > >> > Provided by : > >> > OSGi System Bundle (0) > >> > > >> > Now I would expect that the installation of the saxparserfactory > >> > feature will not trigger an installation of the jboss-xerces feature, > >> > because all requirements should be already satisfied. > >> > But it looks like: > >> > > >> > karaf@root()> feature:install -t -v saxparserfactory > >> > Adding features: saxparserfactory/[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT] > >> > Changes to perform: > >> > Region: root > >> > Bundles to install: > >> > > >> > https://repository.jboss.org/nexus/content/repositories/ > releases/org/jboss/osgi/xerces/jbosgi-xerces/3.1.0. > Final/jbosgi-xerces-3.1.0.Final.jar > >> > mvn:org.osgi/org.osgi.util.xml/1.0.1 > >> > > >> > What am I doing wrong? > >> > > >> > Best regards, > >> > Markus Rathgeb > > > > > > > > > > -- > > ------------------------ > > Guillaume Nodet > > > -- ------------------------ Guillaume Nodet