Get ahead
VMware offers training and certification to turbo-charge your progress.
Learn moreAs Rob's post points out, over the last few months we've learned quite a bit about how people want to manage their own OSGi applications.
We found that some developers want to manage their own bundle manifests, but need a bit of help to automate the details such as specifying package versions across a range of imports. Other developers want to have manifests generated based on the content of their project and the dependencies specified in their build files. In addition, both kinds of developers need to work with existing libraries that do not have the necessary OSGi metadata that enable them to be used in an OSGi Service Platform.
Bundlor provides a solution to all of these cases and is the tool that we've been using internally for some time to manage the bundles published to the SpringSource Enterprise Bundle Repository. Bundlor automates the detection of dependencies and the creation of OSGi manifest directives for JARs after their creation. It takes as input a JAR and a template consisting of a superset of the standard OSGi manifest headers. It then analyses the source code and support files contained in the JAR, applies the template to the results, and generates a manifest.
Header | Description |
---|---|
Excluded-Exports | A comma-separated list of packages that must not be added to the manifest's Export-Package header. |
Excluded-Imports | By default, Bundlor will add imports for every package which it determines is referenced by the code or special files in the jar. This header allows a comma-separated list of packages for which imports will not be generated to be specified. |
Export-Template | By default, Bundlor versions all exported packages at the specified Bundle-Version. This header allows individual exported packages to be exported at different versions. E.g. Export-Template com.foo.*;version="1.5" will cause any Export-Package entries for com.foo or its subpackages to be versioned at 1.5. |
Ignored-Existing-Headers | For cases where the JAR for which a manifest is being generated already contains an OSGi-compliant manifest, this header can be used to list headers in the original manifest which Bundlor should ignore. |
Import-Template | This header is used to augment package imports that Bundlor generates via bytecode and special file analysis. Typically this will be to version the import and, in some cases, to mark them as optional. The header's value is in the form of a comma-separated list of package names and attributes. |
The following is an example Bundlor manifest template from the Spring Binding bundle showing the use of both wildcarding and explicit Import-Package statements.
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.springframework.binding
Bundle-Name: Spring Binding
Bundle-Vendor: SpringSource
Import-Package:
ognl;version="[2.6.9, 3.0.0)";resolution:=optional,
org.jboss.el;version="[2.0.0, 3.0.0)";resolution:=optional
Import-Template:
org.springframework.*;version="[2.5.4.A, 3.0.0)",
org.apache.commons.logging;version="[1.1.1, 2.0.0)",
javax.el;version="[2.1.0, 3.0.0)";resolution:=optional
Bundlor scans for the following types
Add the SpringSource Enterprise Bundle Repository to the pom.xml file.
<pluginRepositories>
<pluginRepository>
<id>com.springsource.repository.bundles.milestone</id>
<name>SpringSource Enterprise Bundle Repository</name>
<url>http://repository.springsource.com/maven/bundles/milestone</url>
</pluginRepository>
...
</pluginRepositories>
Add the bundlor plugin to the pom.xml file
<build>
<plugins>
<plugin>
<groupId>com.springsource.bundlor</groupId>
<artifactId>com.springsource.bundlor.maven</artifactId>
<version>1.0.0.M2</version>
<executions>
<execution>
<id>bundlor</id>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
Finally, build a bundle with the package command.
mvn install package
To run Bundlor from inside of ANT, you start by defining a bundlor namespace.
<project name="bundlor-sample-ant"
xmlns:bundlor="antlib:com.springsource.bundlor.ant">
Then you import the bundlor task into the build.
<target name="bundlor.init">
<taskdef resource="com/springsource/bundlor/ant/antlib.xml"
uri="antlib:com.springsource.bundlor.ant">
<classpath id="bundlor.classpath">
<fileset dir="${bundlor.home}/dist"/>
<fileset dir="${bundlor.home}/lib"/>
</classpath>
</taskdef>
</target>
Finally, use the bundlor task.
<bundlor:bundlor
bundlePath="${basedir}/org.springframework.integration.jar"
outputPath="${basedir}/target/org.springframework.integration.jar"
bundleVersion="1.0.2.BUILD-${timestamp}"
manifestTemplatePath="${basedir}/template.mf"/>
To run the Bundlor from the command line change directory to the $BUNDLOR_HOME/bin directory and run either bundlor.sh or bundlor.bat.
% ./bundlor.sh transform \ --bundle ./org.springframework.integration.jar \ --manifest ./template.mf \ --outputfile ./target/org.springframework.integration.jar Transformed bundle written to ./target/org.springframework.integration.jar %