Add Bundle-Version to all wrapped bundles
By default a bundle that is created thanks to the wrap protocol has 0 as version which is not convenient, the goal of this task is to add the bundle version to all wrapped bundles in the features file.
The version needs to start with an integer:
https://github.com/osgi/osgi/blob/6eee417af367c749a6f84a11239d94cc63f6bdcb/org.osgi.framework/src/org/osgi/framework/Version.java#L126
There are bundles in which the major version starts with a string:
<bundle dependency='true'>wrap:mvn:com.google.apis/google-api-services-drive/${google-api-services-drive-version}</bundle>
<google-api-services-drive-version>v3-rev20240123-2.0.0</google-api-services-drive-version>
Test in which I've purposefully modified camel-gson:
karaf@root()> feature:info camel-gson
Feature camel-gson 4.5.0.SNAPSHOT
Feature has no configuration
Feature has no configuration files
Feature depends on:
camel-core [4.5,4.6)
Feature contains followed bundles:
mvn:com.google.code.gson/gson/2.10.1
wrap:mvn:com.google.apis/google-api-services-drive/v3-rev20240123-2.0.0$Bundle-Version=v3-rev20240123-2.0.0
mvn:org.apache.camel.karaf/camel-gson/4.5.0-SNAPSHOT
Feature has no conditionals.
karaf@root()> feature:install camel-gson
org.osgi.framework.BundleException: Could not create bundle object.
at org.apache.felix.framework.Felix.installBundle(Felix.java:3339)
at org.apache.felix.framework.BundleContextImpl.installBundle(BundleContextImpl.java:147)
at org.eclipse.equinox.internal.region.BundleIdBasedRegion.installBundle0(BundleIdBasedRegion.java:120)
at org.eclipse.equinox.internal.region.BundleIdBasedRegion.installBundleAtLocation(BundleIdBasedRegion.java:100)
at org.apache.karaf.features.internal.service.BundleInstallSupportImpl.installBundle(BundleInstallSupportImpl.java:135)
at org.apache.karaf.features.internal.service.FeaturesServiceImpl.installBundle(FeaturesServiceImpl.java:1145)
at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:906)
at org.apache.karaf.features.internal.service.FeaturesServiceImpl.doProvision(FeaturesServiceImpl.java:1069)
at org.apache.karaf.features.internal.service.FeaturesServiceImpl.lambda$doProvisionInThread$13(FeaturesServiceImpl.java:1004)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalArgumentException: invalid version "v3-rev20240123-2.0.0": non-numeric "v3-rev20240123-2"
at org.osgi.framework.Version.parseInt(Version.java:169)
at org.osgi.framework.Version.<init>(Version.java:126)
at org.osgi.framework.Version.valueOf(Version.java:255)
at org.osgi.framework.Version.parseVersion(Version.java:226)
at org.apache.felix.framework.util.manifestparser.ManifestParser.<init>(ManifestParser.java:129)
at org.apache.felix.framework.BundleRevisionImpl.<init>(BundleRevisionImpl.java:117)
at org.apache.felix.framework.BundleImpl.createRevision(BundleImpl.java:1290)
at org.apache.felix.framework.BundleImpl.<init>(BundleImpl.java:114)
at org.apache.felix.framework.Felix.installBundle(Felix.java:3287)
... 12 more
Caused by: java.lang.NumberFormatException: For input string: "v3-rev20240123-2"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Integer.parseInt(Integer.java:668)
at java.base/java.lang.Integer.parseInt(Integer.java:786)
at org.osgi.framework.Version.parseInt(Version.java:167)
... 20 more
How should we proceed in these situations?
I see 2 options
-
Don't specify the version.
-
Rely on https://github.com/apache/felix-dev/blob/org.apache.felix.main-7.0.5/utils/src/main/java/org/apache/felix/utils/version/VersionCleaner.java to obtain the version in a valid format. For instance
org.apache.felix.utils.version.VersionCleaner.clean("v3-rev20240123-2.0.0")returns0.0.0.v3-rev20240123-2_0_0. Downside: We stop relying on version placeholders to specify the Bundle-Version.A workaround for the maintenance issue could be to use a Maven plugin to modify the features file. While working on this issue I've come up with https://github.com/stataru8/feature-utils.