-
Notifications
You must be signed in to change notification settings - Fork 116
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
[osgi] Solutions for https://github.com/eclipse/microprofile/issues/33 #381
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,4 @@ jobs: | |
java-version: ${{matrix.java}} | ||
|
||
- name: build with maven | ||
run: mvn verify | ||
run: mvn -ntp verify |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
-exportcontents: \ | ||
org.eclipse.microprofile.* | ||
|
||
Import-Package: \ | ||
javax.enterprise.util;version="[1.1,3)", \ | ||
* | ||
|
||
Bundle-SymbolicName: org.eclipse.microprofile.config | ||
|
||
# For reproducible builds | ||
-noextraheaders: true | ||
-snapshot: SNAPSHOT | ||
|
||
# Apply OSGi Portable Java Contracts [1] with "active" effectiveness so that | ||
# they are not strict runtime requirements. This removes the need to import | ||
# packages with versions. | ||
-contract: *;effective:=active | ||
|
||
# Simulate the JavaCDI contract since the compile dependencies used do not | ||
# provide them. | ||
-define-contract: \ | ||
osgi.contract;\ | ||
osgi.contract=JavaCDI;\ | ||
version:List<Version>='2.0,1.1';\ | ||
uses:='\ | ||
javax.decorator,\ | ||
javax.enterprise.context,\ | ||
javax.enterprise.context.spi,\ | ||
javax.enterprise.event,\ | ||
javax.enterprise.inject,\ | ||
javax.enterprise.inject.spi,\ | ||
javax.enterprise.util' | ||
|
||
# [1] https://www.osgi.org/portable-java-contract-definitions/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,8 +42,8 @@ | |
* | ||
* @author <a href="mailto:[email protected]">Mark Struberg</a> | ||
* @author <a href="mailto:[email protected]">Emily Jiang</a> | ||
* | ||
* | ||
*/ | ||
@org.osgi.annotation.versioning.Version("1.0") | ||
@org.osgi.annotation.versioning.Version("1.0.1") | ||
package org.eclipse.microprofile.config.inject; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ | |
|
||
import org.eclipse.microprofile.config.Config; | ||
|
||
import aQute.bnd.annotation.spi.ServiceConsumer; | ||
|
||
/** | ||
* The service provider for implementations of the MicroProfile Configuration specification. | ||
* <p> | ||
|
@@ -36,6 +38,16 @@ | |
* @author <a href="mailto:[email protected]">Romain Manni-Bucau</a> | ||
* @author <a href="mailto:[email protected]">Emily Jiang</a> | ||
*/ | ||
|
||
/* | ||
* The @ServiceConsumer annotation adds support for Service Loader Mediator in | ||
* order to support wiring of Service Loader providers to consumers in OSGi. | ||
* However, the requirements generated are specified as effective:=active to | ||
* prevent this from being a strict requirement. As such the API is usable in | ||
* runtimes without a Service Loader Mediator implementation while allowing for | ||
* such to be enabled when using the resolver during assembly. | ||
*/ | ||
@ServiceConsumer(value = ConfigProviderResolver.class, effective = "active") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this is also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly! Since there has been resistance to the SLM solution, this makes the feature usable during assembly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whether this gets documented in the spec is up for debate. I think we could come up with standard language would simplify applying this to other MP specs if desired. It would largely be the same words for every spec except for the identity (which I'd suggest simply going with the bsn of the API for consistency and avoid confusion). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this work, given that, at the moment, the service loading isn't done using the thread context classloader? See line 110:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. For example, you can use a fragment to attach the META-INF/service resource and add any necessary Import-Package/DynamicImport-Package statement to this bundle. Apache Aries SPI Fly is another option. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeap! The SML spec never limited exactly how the loading was done and so within the past two years the Apache Aries SPI Fly implementation was enhanced to support the two argument load(Class, ClassLoader) method. The heuristic is to use the passed ClassLoader as fallback if no providers are found. So no code change here is required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
SLM :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, a thread context class loader does not help here as trying to use it would introduce timing issues similar to using setInstance. You would have to arrange to set the TCCL properly before being the first one to cause the ServiceLoader to load the impl class. To be fair, there are also timing issues with SPI Fly in that you have to ensure it is started (perhaps via start levels) before anyone causes the ServiceLoader call to be made. Using a fragment is probably the safest as it will be attached at resolve time which is by definition before any code in the host bundle can execute. |
||
public abstract class ConfigProviderResolver { | ||
/** | ||
* Construct a new instance. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very fishy. Why do you have to add
Requirement
twice? Why cannot it cope with both effective and resolution?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rotty3000 What is the goal here in attempting to generate 2 requirements in bundles using the
ConfigProperty
annotation? I am guessing your goals is to have a non-optional requirements at active time so provisioning resolutions will include a CDI extender bundle and to have an optional requirement at runtime so the bundle will resolve even when there is no bundle providing the CDI extender capability. Sort of a bridge to the future while still working with the past?If so, we need to have some comments here explaining why we are doing this. Since this confused @Emily-Jiang.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we will also need to add some words to the Config spec so that CDI extender bundles provide this capability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bjhargrave you are exactly correct!
BTW, in times past when I've discussed this with @pkriens and @tjwatson we've dubbed this combination of two requirements, one optional, one effective active as a weak requirement.
A weak requirement is used because IBM clearly does not want to strictly require Service Loader Mediator. This avoids that. Meanwhile, anyone who does want to use the resolver for assembly can simply enable
active
effectiveness.About the OSGi CDI extension name, if folks are in agreement we could document that in the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The case here is not about SLM. It is about the fact that there are some CDI extension implementations which do not provide the capability for resolve time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's the exact same reason. If someone doesn't want to use OSGi CDI and manually wire things up it will still work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this PR should put comments in the source code where we apply the weak requirements to document why there are 2 seemingly duplicate requirements and why we use
effective:=active
for non-runtime resolution scenarios.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds reasonable! I'll do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my original objection for this PR with the requirement for runtime to provide CDI capability. Otherwise the bundle does not resolve. I think with this weak requirement, it is reasonable change. Agreed with @bjhargrave to add comments to explain this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to agree on, and document in the spec, the name of the CDI extension for Config. @rotty3000 proposes
org.eclipse.microprofile.config
which seems fine to me. But others (spec readers and implementors) will need to know the agreed upon name.