bndtools / bnd

Bnd/Bndtools. Tooling to build OSGi bundles including Eclipse, Maven, and Gradle plugins.
https://bndtools.org
Other
526 stars 304 forks source link

bnd-maven-plugin: Explicit Service-Component instruction is merged with value generated from `DSAnnotations` plugin #6108

Closed kwin closed 2 months ago

kwin commented 2 months ago

It seems that under certain circumstances the explicit value of Service-Component being set in the bnd file gets merged with the values being retrieved by the DSAnnotations plugin (https://github.com/bndtools/bnd/blob/79dad59d406f627e2f0eb612909ef78fc904570f/biz.aQute.bndlib/src/aQute/bnd/component/DSAnnotations.java#L143C4-L143C18).

This does not really work if I put something like this in my bnd file

Service-Component: OSGI-INF/*.xml

(for example to also detect service components from attached bundle fragments). This should obviously not be merged with other values (as it already covers them and otherwise leads to duplicate registration of components).

I would expect the Service-Component to behave similarly as Import-Package i.e. disregard the automatically calculated value except if * is explicitly being used (https://bnd.bndtools.org/releases/4.0.0/heads/import_package.html).

There seem to be edge cases where it does work as expected (i.e. the explicit value takes precedence and overwrites the implicit values).

kwin commented 2 months ago

You find an example where it is merged in https://github.com/Adobe-Consulting-Services/acs-aem-commons/tree/master/bundle while for https://github.com/Adobe-Consulting-Services/acs-aem-commons/tree/master/bundle-cloud it isn't (although both modules contain Declarative services and share most of the bnd configuration from https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/e2c2bfaf5107e768f87cc6d145dccb0a31cd6a62/pom.xml#L255

kwin commented 2 months ago

Looks to me like a bug within https://github.com/bndtools/bnd/blob/79dad59d406f627e2f0eb612909ef78fc904570f/biz.aQute.bndlib/src/aQute/bnd/component/DSAnnotations.java#L258.

pkriens commented 2 months ago

I looked at the code and it did exactly what should be done imho: it should remove any path that the annotations like to add but overlaps with a wildcard defined in the bnd file.

Notice that this is quite different from the Import-Package case. With the I-P case, all wildcarding is done by bnd while in the Service-Component case the wildcarding happens in runtime (and thus can take fragments into account).

Can you make a small github repo (or bnd test case) with an example where this occurs in a way you don't agree with?

kwin commented 2 months ago

Sorry for the noise, turned out that this bnd plugin is to blame here: https://github.com/apache/felix-dev/blob/81edc6e48db29feae5d0deb0af23719f50ddcb2b/tools/org.apache.felix.scr.bnd/src/main/java/org/apache/felix/scrplugin/bnd/SCRDescriptorBndPlugin.java#L212. The DSAnnotations plugin behaves as expected.

pkriens commented 2 months ago

I assume you used 'apache felix' instead of 'bnd' :-)

Thanks for letting us know.

kwin commented 2 months ago

I used a Felix Bnd plugin together with bnd-maven-plugin ;-). FTR: Apache Felix SCR will be more lenient with duplicate Service-Component entries in the future: https://issues.apache.org/jira/browse/FELIX-6699