Meld OSGi Bundles with Java Modules - Udo Hafermann (Software AG)1. © 2018 Software AG. All rights reserved.
Udo Hafermann
Todor Boev
MELD OSGI BUNDLES WITH
JAVA MODULES
OSGI RFP 190
2. 2 |
MOTIVATION
Example: My bundle requires AWT—what is the minimum Java module set?
© 2018 Software AG. All rights reserved. For internal use only
3. 3 |
OVERVIEW
This talk presents RFP 190: Resource Encoding of Java Modules
1. Application Domain and Problem Statement
2. Use Cases
3. Requirements
4. Proof of Concept
5. Open Ends
© 2018 Software AG. All rights reserved. For internal use only
4. 4 |
PROBLEM STATEMENT
• We want self-contained Java applications with minimal footprint
• For OSGi, we can resolve the set of required bundles
• But JRE can easily dominate the overall size
• With JPMS, we can strip down to the modules required
• How to determine which ones are required?
• R7 provides the flat list of all boot layer packages
• Removing modules from the boot layer is a trial and error process
• We need the modules as such to be visible to tools and runtime
© 2018 Software AG. All rights reserved. For internal use only
5. 5 |
USE CASES
• Build a compact Docker image
• Build a self-contained, no-installation tool
• Analyze JRE footprint, bundle by bundle
• Introspect JRE at runtime
• Create hybrid app of OSGi bundles and JPMS modules
© 2018 Software AG. All rights reserved. For internal use only
6. 6 |
GENERAL REQUIREMENTS
• Resolver can still be used to build consistent set of modules and bundles
– Should not require a new tool or component
• Bundles are not forced to explicitly reference modules
– Just as we don’t want bundles to explicitly reference bundles
• A bundle may function as a module
– OSGi framework as a special case
• Includes third-party modules
• Best-effort JPMS validation
– Rejects duplicate and (optionally) conflicting and cyclic modules
© 2018 Software AG. All rights reserved. For internal use only
7. 7 |
RESOLVING DEPENDENCIES
• Module identity and version
• Bundle package imports to module exports
• Modules to modules
• (Optional) Module services as resources
• (Optional) Requirements to module services
© 2018 Software AG. All rights reserved. For internal use only
8. 8 |
ENHANCING METADATA
• Add version range requirements for modules
• Use bundle annotations for additional JPMS module dependencies
• Replace org.osgi.framework.system.packages with module resource
representations
© 2018 Software AG. All rights reserved. For internal use only
9. 9 |
PROOF OF CONCEPT
• Modeling
– Module as special kind of bundle
– Require module as require-bundle
– Module exports as export-package
– Module provides as service-loader capability
– Module uses as service-loader requirement
• Extracts of actual metadata
• Run resolver on “awt” example
© 2018 Software AG. All rights reserved. For internal use only
10. 10 |
MODULE METADATA
© 2018 Software AG. All rights reserved. For internal use only
java.desktop
osgi.identity
osgi.identity=java.desktop
type=java-module
singleton=true
version=10.0.2
osgi.wiring.bundle
filter:=(&(osgi.wiring.bundle=java.base)(bundle-version=10.0.2)(java-module=true))
resolution:=mandatory
osgi.wiring.bundle
filter:=(&(osgi.wiring.bundle=java.prefs)(bundle-version=10.0.2)(java-module=true))
visibility:=reexport
resolution:=mandatory osgi.serviceloader
filter:=(&(osgi.serviceloader=javax.imageio.spi.ImageOutputStreamSpi)(version>=0.0.0))
resolution:=optional
cardinality:=multiple ...
...
osgi.wiring.package
osgi.wiring.package=java.awt.color
bundle-symbolic-name=java.desktop
bundle-version=10.0.2
version=0.0.0
osgi.wiring.package
osgi.wiring.package=javax.swing
bundle-symbolic-name=java.desktop
bundle-version=10.0.2
version=0.0.0
osgi.serviceloader
osgi.serviceloader=javax.sound.midi.spi.MidiDeviceProvider
version=0.0.0
...
...
Provides
Requires
osgi.wiring.bundle
osgi.wiring.bundle=java.desktop
java-module=true
bundle-version=10.0.2
11. 11 |
DEMO TEST
• org.example.awtclient 1.0.0
• osgi.wiring.package; filter:=(&(osgi.wiring.package=java.awt)(version>=0.0.0))
© 2018 Software AG. All rights reserved.
12. 12 |
THANK YOU
• Feedback welcome on https://github.com/osgi/design/blob/master/rfps/rfp-0190-
Resource%20encoding%20for%20Java%20Modules.odt
© 2018 Software AG. All rights reserved. For internal use only
13. 13 | © 2018 Software AG. All rights reserved.