Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Tasty Recipes for OSGi Bundles

1,667 views

Published on

Introduction to the Eclipse Bundle Recipe project and how to generate OSGi bundles for any library in Maven Central or in a Maven repository behind corporate walls.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Tasty Recipes for OSGi Bundles

  1. 1. Tasty Recipes for OSGi Bundles Gunnar Wagenknecht (@guw)
  2. 2. – Someone asking for help! „I’m trying to use this library from Maven. It doesn’t work in OSGi. How can I make it work?“
  3. 3. The
 Eclipse Bundle Recipe
 Project
  4. 4. – https://projects.eclipse.org/projects/rt.ebr „The EBR project provides a library of templates and tools that can be used to create bundles for open source projects.“
  5. 5. How it works
  6. 6. Prerequisites git clone ... git://git.eclipse.org/gitroot/
 ebr/org.eclipse.ebr.recipes.git
  7. 7. Create a Recipe mvn ebr:create-recipe 
 -DgroupId=javax.servlet 
 -DartifactId=javax.servlet-api
 -Dversion=3.1.0 
 -DbundleSymbolicName=javax.servlet
  8. 8. osgi.bnd Define what packages to export and import and how Make use of rules/macros to simplify your life
  9. 9. osgi.bnd package-version=${version;===;${Bundle-Version}} Export-Package: 
 !about.html,!about_files, 
 *.internal*; 
 x-internal:=true;version="${package-version}", 
 *.impl*; 
 x-internal:=true;version="${package-version}", 
 *;version="${package-version}" Import-Package: 
 *;resolution:=optional
  10. 10. Build the Bundle mvn clean package
  11. 11. Result • OSGi Bundle • Ready for localization • License information • Eclipse Source Bundle • Eclipse p2 meta data • Eclipse about files
  12. 12. Tips &Tricks
  13. 13. Regular Dependencies package-version=${version;===;${Bundle-Version}} 
 javax-ws-version=2.3 Export-Package: 
 ... Import-Package: 
 javax.ws.*; 
 version="${range;[==,+);${javax-ws-version}}", 
 *;resolution:=optional becomes: [2.3,3)
  14. 14. Internal Dependencies package-version=${version;===;${Bundle-Version}} Export-Package: 
 ... Import-Package: 
 my.library.*.internal.*; 
 version="${range;[===,==+);${package-version}}", 
 my.library.*.spi.*; 
 version="${range;[===,=+);${package-version}}", 
 *;resolution:=optional becomes: [1.1.3,1.2) becomes: [1.1.3,1.1.4)
  15. 15. Re-use jersey-common-exports= 
 !about.html,!about_files, 
 *.internal*;... Export-Package: ${jersey-common-exports} jersey-common-imports= 
 javax.ws.*;version="[2.0,3)", 
 javax.servlet.*;version="[2.6,4)", 
 ...
 *;resolution:=optional Import-Package: ${jersey-common-imports}
  16. 16. Include & Override -include: ~../jersey-common/osgi.bnd Import-Package: 
 sun.misc.*;resolution:=optional 
 ${jersey-common-imports}
  17. 17. Partial Bundles <project xmlns="http://maven.apache.org/POM/4.0.0" ...> <properties> <!-- only include the org.slf4j.impl package --> <recipe.includes>org/slf4j/impl/*.*</recipe.includes> </properties> </project>
  18. 18. Partial Bundles <project xmlns="http://maven.apache.org/POM/4.0.0" ...> <properties> <!-- exclude the org.slf4j.impl package --> <recipe.excludes>org/slf4j/impl/*.*</recipe.excludes> </properties> </project>
  19. 19. SpecialVersions <project xmlns="http://maven.apache.org/POM/4.0.0" ...> <dependencies> <dependency> <groupId>org.glassfish.hk2</groupId> <artifactId>hk2-api</artifactId> <version>2.4.0-b07</version> </dependency> </dependencies> <properties> <!-- the HK2 version suffix --> <hk2.version.suffix>b07</hk2.version.suffix> <!-- add special qualifier for HK2 --> <recipe.qualifier.format> '${hk2.version.suffix}-v’yyyyMMdd-HHmm </recipe.qualifier.format> </properties> </project> osgi.bnd: package-version=${version;===;${Bundle-Version}}.${hk2.version.suffix}
  20. 20. EBR 
 Specialities
  21. 21. Bundle Symbolic Name • Always add “.ebr”! • Helps identifying source of bundle easier.
  22. 22. MY_EBR_BUNDLES_GROUP • The Maven group identifier of recipies is just a placeholder. • The EBR project will not publish recipies to a Maven repository. • But you can!
  23. 23. No Downloads • EBR produces only recipies! • There are no bundles to download. • This is due to legal reasons.
  24. 24. EBR 
 On Premise
  25. 25. Prerequisites git clone replace group id build recipies build p2 repository
  26. 26. Contribute to EBR • Clone the Git repository • Create recipies • Push a Gerrit Review or submit a pull request
  27. 27. ebr-dev@eclipse.org Get support for creating & contributing recipes!

×