Skip to content
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

Make JSON imports optional in OSGi environments #3971

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rombert
Copy link

@rombert rombert commented Sep 27, 2024

When deploying in OSGi containers the Jedis bundle has two hard requirements on having the GSON and JSON bundles around. Since these depenendencies are optional we mark the imports as such in the OSGi manifest.

If these packages are not exported the bundle will be installed and will be unable to make use of the JSON functionality. When they are present they will be used.

Additionally, allow newer version of the org.json bundle to be used without requiring a new release of Jedis.

Fixes #3956 .

When deploying in OSGi containers the Jedis bundle has two hard requirements on having
the GSON and JSON bundles around. Since these depenendencies are optional we mark
the imports as such in the OSGi manifest.

If these packages are not exported the bundle will be installed and will be unable to
make use of the JSON functionality. When they are present they will be used.

Additionally, allow newer version of the org.json bundle to be used without requiring
a new release of Jedis.
@rombert rombert force-pushed the feature/optional-json-imports-osgi branch from 81d4678 to e4d5aa4 Compare September 27, 2024 12:50
Copy link
Collaborator

@sazzad16 sazzad16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rombert Thank you for the PR. We're checking about this change. It may take some time. In the mean time, I have a question:

-->
<Import-Package>
com.google.gson;resolution:=optional,
org.json;resolution:=optional;version="20240303.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indicates a fixed version. Does this mean whenever we update the version of org.json, we'd have to change here as well?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that this is an open range - ["20240303.0", Infinity). I'll dig up some references to it and post some screenshots of it working with different versions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://docs.osgi.org/specification/osgi.core/7.0.0/framework.module.html#i3189032

If a version range is specified as a single version, it must be interpreted as the range [version,∞).

So this means just a minimal version. Right now org.json does not have a version newer that 20240303, but I will update the bundle locally to accept older versions for org.json so I can post a test with exact match and one with a newer version.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a more explicit test. I modified the Jedis bundle locally to reference a lower import range

diff --git a/pom.xml b/pom.xml
index f929411d..415273d4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -300,7 +300,7 @@
 						-->
 						<Import-Package>
 							com.google.gson;resolution:=optional,
-							org.json;resolution:=optional;version="20240303.0",
+							org.json;resolution:=optional;version="20220303.0",
 							*
 						</Import-Package>
 					</instructions>

I then deployed it in my OSGi app and kept the same (new) 20240303 org.json bundle. In the screenshot you can see that the import is resolved at runtime with the new 20240303.0 version, even though the Import-Package declaration references 20220303.0 .

Effectively all versions newer than 20240303.0 are supported. If you want me I can lower the import range if you think that older versions can be used. Otherwise I'm happy to leave this as it is.

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @rombert for your investigation. It'll be helpful for us.

@tishun
Copy link

tishun commented Oct 10, 2024

I was wondering: if we are able to use the Jedis driver without these two - shouldn't we mark them as optional in the Maven dependency tree too. If we do then the maven-bundle-plugin would pick this up and generate the same result in the MANIFEST.MF, if I am not mistaken.

@rombert
Copy link
Author

rombert commented Oct 10, 2024

I was wondering: if we are able to use the Jedis driver without these two - shouldn't we mark them as optional in the Maven dependency tree too. If we do then the maven-bundle-plugin would pick this up and generate the same result in the MANIFEST.MF, if I am not mistaken.

Yes, if the Maven dependencies are marked as optional the maven-bundle-plugin should also make the imports optional. The version pinning for the org.json import, if deemed acceptable, still needs to stay.

@sazzad16
Copy link
Collaborator

I was wondering: if we are able to use the Jedis driver without these two - shouldn't we mark them as optional in the Maven dependency tree too. If we do then the maven-bundle-plugin would pick this up and generate the same result in the MANIFEST.MF, if I am not mistaken.

Yes, but this is a breaking change and has been considered as unfavorable #3278

@sazzad16 sazzad16 added the dependencies Pull request that updates a dependency label Oct 10, 2024
@tishun
Copy link

tishun commented Oct 11, 2024

I was wondering: if we are able to use the Jedis driver without these two - shouldn't we mark them as optional in the Maven dependency tree too. If we do then the maven-bundle-plugin would pick this up and generate the same result in the MANIFEST.MF, if I am not mistaken.

Yes, but this is a breaking change and has been considered as unfavorable #3278

Apologies, was not aware of #3278, makes sense.

In this case, for OSGi specifically, this seems a reasonable improvement. AFAIK most (all?) OSGi containers depend on the user to deploy the artefacts (e.g. by using a WAR file or a nested JAR file or some other way) and the MANIFEST.MF only serves to mandate what should be loaded, so we should not have the same issues as the ones described in #3278

@rombert
Copy link
Author

rombert commented Oct 11, 2024

OSGi containers depend on the user to deploy the artefacts (e.g. by using a WAR file or a nested JAR file or some other way) and the MANIFEST.MF only serves to mandate what should be loaded

Yes, that is correct. In the current form of Jedis the two JSON bundles must be deployed, even if they are not used by the application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull request that updates a dependency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refine OSGi metadata for JSON dependencies
3 participants