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

Reply via email to