-
-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
auto register capabilities for META-INF/services #6309
auto register capabilities for META-INF/services #6309
Conversation
I think this is an ok idea and the code is quite suitable for this. However, I think the decision can better be done in MetaInfServiceParser. The MetaInfService code is gathering the information of the services directory. It is generally not a good idea then to mix in strategy. I.e. you can now no longer detect if the service implementation was marked or not on the higher level. You never know when you need that. You could also not leverage the project setup to treat it special. Plus it is would be a gratuitous API change. In MetaInfServiceParser we do policy. We have access to the project and workspace properties so we can make decisions on the actual project setup, unlike MetaInfService who is a worker bee. Here we can detect that a given service implementation is not annotated and treat it special. We might add an instruction like |
Thanks for the feedback @pkriens , I will move the code higher up to MetaInfParse.
Wondering what should be possible values and what should be the default? What about:
As I have no experience with this topic just out of curiosity: What would be the effect if "auto" would be the default on libraries out there in the wild? Update: I moved the code to MetaInfServiceParser and added |
@royteeuwen could you test this PR with your bundle? |
…ct Provide-Capability headers: bndtools/bnd#6309
I tried it on my branch (see referenced commit) but it doesnt produce the headers yet. Anything I can do to debug? |
Hmm...
When I do this bnd then it seems If I do it with one specific jar it works: IF it works with a specific jar file then we need to find out the correct syntax for -includeresource to do this with *.jar |
it would be nice, because as you can see in my referenced branch, I'm wrapping like 20 jars in the same time using pluginManagement, making sure there is always only one dependency (namely the wrappable non-osgi jar), which avoids me from hardcoding the thing. If there is another syntax to achieve the same, I'm completely fine with it of course! |
Have you built my branch locally too? |
Of course :)
First time I have checked out the repo, so there is definitely not another SNAPSHOT in my .m2 ;p |
@chrisrueger I do think its still not using the correct bnd, I'm debugging locally by using |
Just guessing: Maybe you also need to reference the latest bndlib 7.1.0-SNAPSHOT in the
Or maybe try removing the |
On that one: This avoids that |
Yes I got the same issue: Oh you are right. it seems I tested with So you get the Provide-Capability headers now? |
@chrisrueger well it seems that the Yep, I get the I'm adding some extra maven properties and doing it like this:
|
I'll test the actual bundle tomorrow, but seeing as it uses already existing functionality, I guess it should work out ;). Thanks a lot so far! |
Yeah, and thanks for your feedback.
Ok good point. as a code comment would be fine for me, I can work it in. |
5e54421
to
ba16fdb
Compare
11172b9
to
c050112
Compare
@chrisrueger everything seems to work on my side :) i already validated it in a real life OSGi env that uses the opentelemetry jars. What would be required to make this into a release? Very nice work :) By the way, another nice feature that would also be nice and currently isn't done yet is that it also detects when a ServiceLoader.load is used in a jar and also create the |
@royteeuwen great news: I had a little discussion with @pkriens about why bnd.annotations needs to be a dependency on the classpath to use the textual ServiceProvider annotation in services files or via So he was so kind to work on a fix. b206734 Long story short: The following dependency is NOT required in your pom.xml anymore:
I will update the docs again later and then I think this PR is ready to merge. |
fa93a4a
to
b6a6c78
Compare
it leverages the recent addition of PR bndtools#5912 that allowed to add annotations in comments of files in META-INF/services. But in this PR we basically pretent and add a aQute.bnd.annotation.spi.ServiceProvider annotation artificially. this causes bnd to generate Provide-Capability manifest headers for the services Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
e.g. onmouseover in bnd.bnd editor shows help text. Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
Yeah sorry. I was a bit too fast. It was the change to make 'auto' the default. |
OK 👍 , let me know when I should retest I see for example that the Require-Capability in my wrapped bundle changed from
to
(notice the Java version) |
@royteeuwen I reverted for now. so 'annotation' is the default again and you need to have I will investigate the failing tests with 'auto' default in the next days |
9c9942c
to
c248e9c
Compare
@chrisrueger I see you already pushed some commits in the meantime and all builds are green except the rebuild jdk17, is that still something you have to look at or should I already retest? |
Yeah the rebuild is on my list. Haven't managed to reproduce that locally. If it's not too much hazzle you could retest. But i could also ping you when i know more about the rebuild. |
hmm. Maybe making this the default is breaking too much. Hate to do this to you but I guess when you contacted me last night I had a glass of wine and felt more bravado than today. Wdyt, shall we make the default no automatic annotations? Sorry for the work :-( |
- 'auto' as the new default makes things much easier for library authors since no additional configuration is required Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
This makes 'auto' the default again and fixes the previously failing tests. The problem was that the "@Serviceprovider" from our own classpath added Java-17 (or whatever was the Java version on the machine you are compiling) to the list of ees which had an impact on how osgi.ee was calculated... this broke all the tests. the fix was in Analyzer to ignore all classes added via addClasspathDefault() for calculation of the ees variable. Signed-off-by: Christoph Rueger <chrisrueger@gmail.com> fix failing gradle tests filter out invalid fqn names e.g. key=value e.g. fixes [ERROR] [org.gradle.api.Task] error : analyzer processing annotation key=value but the associated class is not found in the JAR because key=value is not a valid serviceImplementation name Signed-off-by: Christoph Rueger <chrisrueger@gmail.com> add resolution: optional to try to fix test auto-registered annotations are added with "resolution: optional" directive, in order to fix tests which failed due to Unresolved requirements: osgi.extender; (&(osgi.extender=osgi.serviceloader.registrar)(version>=1.0.0)(!(version>=2.0.0))) which was added by the auto-registed annotations Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
e351378
to
cfbef6f
Compare
@pkriens I managed to fix the tests and build (https://github.com/bndtools/bnd/actions/runs/11235758156). The last and maybe important change was to make the new auto-registered annotation
Could you please review this commit above and then let's decide if we change the default or not? @royteeuwen could you retest too? do you see a problem with the |
Not at all, seems even logical. Using the service loaders should be pluggable, if you don't need them you should be able to disable it :) I'll see if I can get a test done tomorrow! |
addClasspathDefault() adds the annotation class to lookAsideClasses instead of classspace and adjust findClass() which now also looks into this new map. That way we don't not put stuff in classspace which should not be there Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
we rely on the error in Analyzer.findClass() if someone puts garbage in services files Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
@royteeuwen had a review with @pkriens |
Just sidenote for me how to build locally like build is done via Github Actions (at least that is what I figured)
|
we decided to make '-metainf-services: annotation the default. so '-metainf-services: auto' has to explicity be enabled in bnd file. This decision was due to the fact that it is a brand new feature, and the impact on projects in the wild are hard to predict, since it changes metadata in MANIFEST.MF. So it is unclear at the moment if this would be considered a breaking change. So to be safe, we do not do 'auto' by default but 'annotation'. that means that textual annotations in META-INF/services files are automatically processed, because they were put there on purpose. this commit also adjusts and adds some testcases based on that behavior. Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
fixes the little annoyance that some code blocks appeared cutoff on the right side Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
@royteeuwen I think I'm done and would appreaciate your test. There is still the option to make it the default in a future version of bnd if experience shows this options works.
can be enough. Note: @pkriens I (think) I implemented everything we talked about today. Regarding avoiding mixed-services we talked about:
1e130b2#diff-c50541e76ba2146c1d0ee544d6a8df58d45e1a7aaf8f3e1628143d08016e9bb0R58 This might not be the most elegant implementation of splitting, but all I could come up with today. I am open for suggestions. |
Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
used by BndScanner Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
LGTM, let's merge |
@chrisrueger just tested it and works as expected, nice! Thanks a lot! Any idea on when a new release would happen for the bnd plugin? I see the last release was already a year ago, so I'm not sure how often it happens? |
We had talked about a release before the OCX conference but that is not happening. We should have a release in the next few months. |
@pkriens @chrisrueger ok sad to hear, I also got a talk at adaptTo conference next week where I wanted to use the wrapped jars in the demo: https://adapt.to/2024/schedule/observability-in-aemaacs-with-opentelemetry Guess I'll have to try and find a way to release them with the snapshot version of |
I am trying to find some funding for this work. Since I have no more customers in this area, there is a lack of customer pressure and financial incentive. |
In this PR
this is an idea based on #6304 by @royteeuwen
it leverages the recent addition of PR #5912 that allowed to add annotations in comments of files in
META-INF/services
.See https://github.com/bndtools/bnd/blob/master/docs/_chapters/230-manifest-annotations.md#meta-infservices-annotations
In this PR we basically add a
aQute.bnd.annotation.spi.ServiceProvider
annotation automatically if a service doesn't specify one. this causes bnd to generateProvide-Capability
manifest headers for files inMETA-INF/services
which was the requirement in the #6304example
bnd.bnd
file and a groovy-3.0.22.jar in a thelib
foldercreated the following manifest headers
Note:
-metainf-services: auto
is a new instruction needed to activate this new behavior (see comment below)make sure
biz.aQute.bnd.annotation
is on the buildpath which contains the 'aQute.bnd.annotation.spi.ServiceProvider' annotation.Let's use this as a base for discussion if it makes sense at all, or needs configurability etc.