Does OSGI capabilities support versioning and how does it work? Say I have a module with the following declared:
Bundle-SymbolicName: my-module
Implementation-Version: 1.8.1-qualifier
Provide-Capability: org.foo.dependency;nameId="my-module",version="1.8.1-qualifier"
Would I then be able to add this require to get the module above?
Require-Capability: org.foo.dependency;filter:="&(nameId=my-module)(version>=1.8)"
Is there also a way to leverage Implementation-Version on the manifest if it's already specified in the provider module? I see references to osgi.wiring.bundle here. Would I be able to do this instead on the require:
Require-Capability: org.foo.dependency;filter:="(nameId=my.module)",osgi.wiring.bundle;filter:="(bundle-version>=1.8)"
Appreciate any pointers on the subject matter.
1.8.1-qualifier is not a valid OSGi version. 1.8.1.qualifier is a valid OSGi version.
&(nameId=my-module)(version>=1.8) is not a valid OSGi filter expression. You need to surround with parenthesis. (&(nameId=my-module)(version>=1.8))
You cannot use Implementation-Version, but you can use Bundle-Version.
Bundle-SymbolicName: my-module
Bundle-Version: 1.8.1.qualifier
Require-Capability: osgi.wiring.bundle;filter:="(&(osgi.wiring.bundle=my-module)(bundle-version>=1.8))"
See https://docs.osgi.org/specification/osgi.core/8.0.0/framework.namespaces.html#framework.namespaces.osgi.wiring.bundle.
Related
I am trying to get Log4J2 working via Pax Logging but online docs focus on Log4J (v1). My project is Java, Gradle with BND plugin for OSGi bundles aimed at the Equinox environment.
I am using Gradle 6.8.3
I have my build.gradle file for an OSGi bundle that aims to expose logging functionality to other bundles using:
implementation 'org.ops4j.pax.logging:pax-logging-api:2.1.0'
implementation 'org.ops4j.pax.logging:pax-logging-log4j2:2.1.0'
In my BND file, I include the following imports:
Import-Package: org.apache.logging.log4j;version="2.17.1";provider=paxlogging, org.apache.commons.logging;version="[1.1.1,2)";provider=paxlogging, org.apache.logging.log4j.core;version="2.17.1";provider=paxlogging
Since my project has file appenders defined, which don't form part of the Log4J2 API, but Log4J2 Core, I therefore export the following from the same bundle to enable Log4J2 Core classes to have visibility in other bundles that depend on the logging bundle:
Export-Package: com.mycompany.loggingbundle, org.apache.logging.log4j, org.apache.logging.log4j.message, org.apache.logging.log4j.util, org.apache.logging.log4j.core;version="2.17.1", org.apache.logging.log4j.core.appender;version="2.17.1", org.apache.logging.log4j.core.filter;version="2.17.1", org.apache.logging.log4j.core.impl;version="2.17.1", org.apache.logging.log4j.spi;version="2.17.1"
Everything compiles, builds and install fine.
At runtime, I have an issue:
org.osgi.framework.BundleException: Could not resolve module: com.mycompany.otherbundle [1306]
Unresolved requirement: Require-Bundle: com.mycompany.loggingbundle
-> Bundle-SymbolicName: com.mycompany.loggingbundle; bundle-version="<hidden>"; singleton:="true"
com.mycompany.loggingbundle [1311]
Unresolved requirement: Import-Package: org.apache.logging.log4j.core; provider="paxlogging"; version="2.17.1"
at org.eclipse.osgi.container.Module.start(Module.java:434)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1582)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1561)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1533)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1476)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Hopefully some OSGi expert knows what I've got wrong because the whole reason to use Pax Logging was to avoid the need to create Log4J2 fragments and have an easier configuration for a multi-bundled environment. Perhaps there is a systematic series of things to look at to resolve this?
Update
I opened up the pax-logging-log4j2 JAR file to review its manifest and can see it doesn't export anything from org.apache.logging.log4j.core so my re-exporting it from my bundle could never provide the core packages I was hoping.
This still leaves the problem of how to get access to things like a FileAppnder elsewhere in code, but it answers the question as to what is wrong with my approach.
I have a problem during an portlet deployment.
How to resolve?
Liferay (last version).
Eclipse + liferay plugin
2019-07-26 19:51:54.531 ERROR [fileinstall-D:/STUDIO JAVA/liferay-dxp-7.2.10-ga1/osgi/modules][LogService:93] Error while starting bundle: file:/D:/STUDIO%20JAVA/liferay-dxp-7.2.10-ga1/osgi/modules/com.prova.jar
org.osgi.framework.BundleException: Could not resolve module: com.prova [2197]_ Unresolved requirement: Require-Capability: osgi.ee; filter:="(osgi.ee=UNKNOWN)"_ [Sanitized]
at org.eclipse.osgi.container.Module.start(Module.java:444)
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1264)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1237)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:520)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316)
It seems you hit https://issues.liferay.com/browse/LPS-93643
Long story short, the tooling is using old version of Bnd that does not know how to handle Java 11 runtime.
What you can do as workaround is disable the generation of the osgi.ee requirement. To do so you need to place this instruction in your bnd.bnd file:
-noee: true
As a result, OSGi runtime will not check if the Java version your module expects is compatible with the one of the runtime. It should not cause any issues for as long as you make sure you both build and run with the same Java version.
I'm using a (Maven) dependency which itself depends on xml-apis. Unfortunately, the presence of this package now causes conflicts in our OSGi environment (see below in case it should be relevant).
Looking at the JAR content, I find classes which seem to be present in a current JRE anyways. So, my question: Is it safe to exclude this dependency?
In general: Is there any official documentation about classes which used to be stand alone dependencies and which have been integrated into the JRE now?
Here's the mentioned OSGi error when the created xml-apis bundle is present:
Bundle was not resolved because of a uses contraint violation.
org.osgi.service.resolver.ResolutionException: Uses constraint violation. Unable to resolve resource my.company.plugin [osgi.identity; osgi.identity="my.company.plugin"; type="osgi.bundle"; version:Version="2.0.0.201707131542"; singleton:="true"] because it is exposed to package 'javax.xml.transform' from resources org.eclipse.osgi [osgi.identity; type="osgi.bundle"; version:Version="3.11.1.v20160708-1632"; osgi.identity="org.eclipse.osgi"; singleton:="true"] and xml-apis [osgi.identity; type="osgi.bundle"; version:Version="1.4.1.bnd-vA0Q7A"; osgi.identity="xml-apis"] via two dependency chains.
You can define the xml-apis as an explicit dependency in the pom.xml of your project with the scope "provided". Then it will not be part of the runtime dependencies.
I am trying to get the org.apache.felix.http.jetty bundle working to provide a HTTP Service to my OSGi environment.
I also have the servlet-api bundle deployed, which exports the versioned packages, but does not provide the JavaServlet capability (as it probably should, based on the OSGi Alliance page on Reference Contracts).
Here's part of the MANIFEST of the servlet-api bundle
Export-Package: javax.servlet;uses:="javax.servlet.descriptor,javax.se
rvlet.annotation";version="3.1.0",javax.servlet.descriptor;version="3
.1.0",javax.servlet.annotation;uses:="javax.servlet";version="3.1.0",
javax.servlet.http;uses:="javax.servlet";version="3.1.0"
Implementation-Version: 3.1.0
Specification-Vendor: Oracle Corporation
Bundle-Name: Java Servlet API
Bundle-Vendor: GlassFish Community
Import-Package: javax.servlet;version="3.1.0",javax.servlet.annotation
;version="3.1.0",javax.servlet.descriptor;version="3.1.0",javax.servl
et.http;version="3.1.0"
The Provide-Capability header is not specified at all.
So, when I start the OSGi container, it complains with this error:
Unresolved requirements: [[org.apache.felix.http.jetty [28](R 28.0)]
osgi.contract; (&(osgi.contract=JavaServlet)(version=3.1))]
Anyone knows how this can be fixed?
You should be using org.apache.felix.http.servlet-api bundle from Felix itself.
I'm pretty new to osgi and bndtools, but in the past couple days have managed to get jar->bundle creation working using bnd ant task, plus wrapping of our 3rd party jars as bundles (for those not already defining an 'Export-Package' in the manifest file). I must comment that bndtools seems amazing for doing all the heavy lifting when it comes to exports and imports, so thank you to your hard work on this project!
i've got two issues that maybe you can shed some light on:
1
I'm trying to get the bundles to load in felix and am immediately running into resolution errors. In this basic scenario, we have our in-house bundle called omniquery_common, which uses several 3rd party jars, including gson. when i resolve i get this:
Unable to resolve <<INITIAL>> version=null:
missing requirement Require[osgi.identity]{}{filter=(osgi.identity=omniquery_common)} [caused by:
Unable to resolve omniquery_common version=1.0.0.0:
missing requirement Require[osgi.wiring.package]{}{filter=(&(osgi.wiring.package=com.google.gson)(version>=2.2.0)(!(version>=3.0.0)))}]
To me this says omniquery_common is importing com.google.gson (of a version at least 2.2 and less than 3.0). the gson bundle is exporting version 2.2.4, so this should satisfy its dependency, but is not.
can you help me understand how i am wiring this up wrong?
manifest for omniquery_common:
Manifest-Version: 1.0
Bnd-LastModified: 1442336803995
Bundle-ManifestVersion: 2
Bundle-Name: omniquery_common
Bundle-SymbolicName: omniquery_common
Bundle-Version: 1.0.0.0
Created-By: 1.8.0_40 (Oracle Corporation)
Export-Package: com.radian6.omni.common.osgi;version="1.0.0"
Import-Package: com.google.gson;version="[2.2,3)",com.radian6.omni.commo
n.util,org.apache.commons.io;version="[1.4,2)",org.apache.commons.lang;
version="[2.6,3)",org.junit
Private-Package: com.radian6.omni.common.core
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.7))"
Tool: Bnd-2.4.1.201501161923
manifest for gson:
Manifest-Version: 1.0
Export-Package: com.google.gson;version=2.2.4, com.google.gson.annotat
ions;version=2.2.4, com.google.gson.reflect;version=2.2.4, com.google
.gson.stream;version=2.2.4, com.google.gson.internal;version=2.2.4, c
om.google.gson.internal.bind;version=2.2.4
Bundle-ClassPath: .
Built-By: inder
Bundle-Name: Gson
Created-By: Apache Maven 3.0.4
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: Google Gson Project
Bundle-ContactAddress: http://code.google.com/p/google-gson/
Bundle-Version: 2.2.4
Build-Jdk: 1.7.0_21
Bundle-ManifestVersion: 2
Bundle-Description: Google Gson library
Bundle-SymbolicName: com.google.gson
Archiver-Version: Plexus Archiver
2
if i alter the order of the bundles in the 'run requirements' list, putting the gson bundle before omniquery_common, i then get
Unable to resolve <<INITIAL>> version=null:
missing requirement Require[osgi.identity]{}{filter=(osgi.identity=com.google.gson)}
which i find unintuitive - i would have thought the bundle order in that list would not matter...?
The order of the requirements in the -runrequirements list does matter, because if there is an error early in the list then we don't bother trying to resolve everything below it. That is: once we know that the resolution cannot succeed, we just exit and print the first error we encountered.
The second error message you copied (when you put the GSON requirement first) suggests that you simply don't have the GSON bundle in your repository. Or, it is not in a repository that is visible to the resolver. The filter (osgi.identity=com.google.gson) fails, which means there is no resource with the identity com.google.gson.
This would also explain the first error message from your own omniquery_common bundle. The resolver cannot find any bundle exporting the package com.google.gson, which would make perfect sense if the GSON bundle is not there.
So, look into the repositories you are resolving against and what their indexes contain. If GSON really does appear to be in there, then I will need further info on to figure out the problem.
Incidentally, once you have this working, you shouldn't need to list GSON explicitly at all in -runrequirements. That is the point of the resolver: we will find all your dependencies based on the packages you used.