The Gecko.io Documentation Project

We just started a documentation project on Gecko.io Gitlab.

It started with a FAQ / Nive to know collection of information about OSGi, bndtools, Eclipse we want to share.

This is what we have till now:

Plain OSGi

I want to use a LDAP style target filter as service property. How do I have to escape this filter string, that the org.osgi.framework.FrameworkUtil can create a valid Filter instance?

If you have a target filter like this (foo=bar). In case you define that target filter as service property you get something like myprop=(foo=bar). A corresponding LDAP like filter string would look like (myprop=(foo=bar))

Creating an org.osgi.framework.Filter out of this using the org.osgi.framework.FrameworkUtil#createFilter method will cause an org.osgi.framework.InvalidSyntaxException

If you create a filter like this:

Filter f = FrameworkUtil.createFilter("(myprop=(foo=bar))");

Apache Felix answers with an exception like this:

org.osgi.framework.InvalidSyntaxException: Invalid value: (foo=bar)): (myprop=(foo=bar))

The correct escape is an reverse solidus '\' . So a valid string would be:

Filter f = FrameworkUtil.createFilter("(myprop=\\(foo=bar\\))");

You find the syntax definition in the OSGi Core Specification in section 3.2.7:

https://osgi.org/specification/osgi.core/7.0.0/framework.module.html#framework.module.filtersyntax

bnd / bndtools

I want to bringt my gradle workspace to a new bnd version. How can I do that?

Usually you can use the workspace template of the IDE version of bnd. Its no problem to create / update a workspace with a newer one. If you have own workspace templates, you should update this. No matter if for the template or a single project,you have to do this.

Use the template on the GitHub page: https://github.com/bndtools/workspace. Note, that you have selected the right branch!

To upgrade from bnd 4.1.0 with gradle 4.x to bnd 4.3.1 with gradle 5.x we touched the following files:

gradle.properties
This file contains the bnd version you want to use, in our case 4.3.1

.gradle-wrapper/gradle-wrapper.properties
This file contains the URL to the gradle packages. The distributions are usually available here:

https://services.gradle.org/distributions/

settings.gradle
The build setup for bnd and the corresponding plugins.

You can take a look at the build.gradle for changes.

If you update the gradle version, stop the gradle daemon calling ./gradlew --stop, before using the newer version.

I use bndtools for the Eclipse Plugin development. The E4 tools do not recognize my classes or files in bnd projects. E4 says that these projects are no OSGi projects.

This is because E4 tools look into the projects and expect a META-INF/MANIFEST.MF. In bnd, this file is usually generated and therefore only contained in the final artifact in the projects generated folder.

An easy workaround is to place an empty META-INF/MANIFEST.MF file in the project with at least a valid Bundle-SymbolicName declaration. This manifest will not be bundled in the jar by bnd, as long as you dont include it in the -includeresource instruction

You can create a bnd project template for such projects, where the manifest is automatically created. Just take a look at the bndtools GitHub repository. There is the code for their default templates:

https://github.com/bndtools/project-templates/tree/master/org.bndtools.templates.osgi