Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make jars to osgi compaible bundles #81

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stbischof
Copy link

This is the first step to make your core jar file to a bundle that is usable in an osgi framework.
Are you open for such an PR? If yes, tell me an i will complete this.

Using bnd to generate osgi compatible bundles and auto-generate jpms and services files using annotations.

  • OSGi Bundle Manifest

    • @org.osgi.annotation.bundle.Export
    • @aQute.bnd.annotation.licenses.MIT
    • @ServiceConsumer (may be replaces by later usind osgi services)
    • Bundle-NativeCode:
  • META-INF/services

  • module-info (optional) bnd doc jpms
    --jpms: instruction

    • @org.osgi.annotation.bundle.Header(name = "Automatic-Module-Name",value = "diozero.core")
    • @aQute.bnd.annotation.jpms.ExportTo()
    • @org.osgi.annotation.bundle.Export

Manifest

BEFORE:

Manifest-Version: 1.0
Created-By: Maven Jar Plugin 3.2.0
Build-Jdk-Spec: 16
Class-Path: tinylog-api-2.3.2.jar tinylog-impl-2.3.2.jar
Implementation-Title: diozero - Core
Implementation-Version: 1.3.2
Implementation-Vendor: diozero
Automatic-Module-Name: diozero.core

AFTER:

Manifest-Version: 1.0
Created-By: 16.0.1 (Oracle Corporation)
Build-Jdk-Spec: 16
Class-Path: tinylog-api-2.3.2.jar tinylog-impl-2.3.2.jar
Bnd-LastModified: 1633031009565
Bundle-Description: Java Device I/O library that is portable across Sing
 le Board Computers (including Raspberry Pi, BeagleBone Black, Odroid C2
 , CHIP, ASUS TinkerBoard, Allwinner H3 / H5 / H6)
Bundle-Developers: mattjlewis;email="deviceiozero@gmail.com";name="Matth
 ew Lewis"
Bundle-DocURL: https://www.diozero.com/diozero/diozero-core/
Bundle-License: "MIT License";link="https://opensource.org/licenses/MIT"
Bundle-ManifestVersion: 2
Bundle-Name: diozero - Core
Bundle-NativeCode: lib/linux-aarch64/libdiozero-system-utils.so; osname=
 Linux; processor=aarch64,lib/linux-armv7/libdiozero-system-utils.so; os
 name=Linux; processor=ARM,lib/linux-armv6/libdiozero-system-utils.so; o
 sname=Linux; processor=armv6,lib/linux-armv7/libdiozero-system-utils.so
 ; osname=Linux; processor=armv7,lib/linux-x86_64/libdiozero-system-util
 s.so; osname=Linux; processor=x86_64,lib/macosx-x86_64/libdiozero-syste
 m-utils.so; osname=MacOSX; processor=x86_64
Bundle-SCM: url="https://github.com/mattjlewis/diozero/diozero/diozero-c
 ore",connection="scm:git:https://github.com/mattjlewis/diozero.git/dioz
 ero/diozero-core",developer-connection="scm:git:https://github.com/matt
 jlewis/diozero.git/diozero/diozero-core",tag=HEAD
Bundle-SymbolicName: com.diozero.diozero-core
Bundle-Vendor: diozero
Bundle-Version: 1.3.2
Import-Package: org.tinylog;version="[2.3,3)"
Private-Package: boarddefs,com.diozero.animation,com.diozero.animation.e
 asing,com.diozero.api,com.diozero.api.function,com.diozero.api.sandpit,
 com.diozero.devices,com.diozero.devices.mcp23xxx,com.diozero.devices.mo
 tor,com.diozero.devices.oled,com.diozero.devices.sandpit,com.diozero.in
 ternal,com.diozero.internal.board,com.diozero.internal.board.allwinner,
 com.diozero.internal.board.beaglebone,com.diozero.internal.board.chip,c
 om.diozero.internal.board.odroid,com.diozero.internal.board.raspberrypi
 ,com.diozero.internal.board.tinkerboard,com.diozero.internal.provider.b
 uiltin,com.diozero.internal.provider.builtin.gpio,com.diozero.internal.
 provider.builtin.i2c,com.diozero.internal.provider.builtin.serial,com.d
 iozero.internal.provider.builtin.spi,com.diozero.internal.spi,com.dioze
 ro.sbc,com.diozero.util,lib.linux-aarch64,lib.linux-armv6,lib.linux-arm
 v7,lib.linux-x86_64,lib.macosx-x86_64
Provide-Capability: osgi.service;objectClass:List<String>="com.diozero.i
 nternal.spi.BoardInfoProvider";effective:=active,osgi.serviceloader;osg
 i.serviceloader="com.diozero.internal.spi.BoardInfoProvider";register:=
 "com.diozero.internal.board.allwinner.AllwinnerH5BoardInfoProvider",osg
 i.serviceloader;osgi.serviceloader="com.diozero.internal.spi.BoardInfoP
 rovider";register:="com.diozero.internal.board.allwinner.AllwinnerH6Boa
 rdInfoProvider",osgi.serviceloader;osgi.serviceloader="com.diozero.inte
 rnal.spi.BoardInfoProvider";register:="com.diozero.internal.board.allwi
 nner.AllwinnerSun8iBoardInfoProvider",osgi.serviceloader;osgi.servicelo
 ader="com.diozero.internal.spi.BoardInfoProvider";register:="com.diozer
 o.internal.board.beaglebone.BeagleBoneBoardInfoProvider",osgi.servicelo
 ader;osgi.serviceloader="com.diozero.internal.spi.BoardInfoProvider";re
 gister:="com.diozero.internal.board.chip.ChipBoardInfoProvider",osgi.se
 rviceloader;osgi.serviceloader="com.diozero.internal.spi.BoardInfoProvi
 der";register:="com.diozero.internal.board.odroid.OdroidBoardInfoProvid
 er",osgi.serviceloader;osgi.serviceloader="com.diozero.internal.spi.Boa
 rdInfoProvider";register:="com.diozero.internal.board.raspberrypi.Raspb
 erryPiBoardInfoProvider",osgi.serviceloader;osgi.serviceloader="com.dio
 zero.internal.spi.BoardInfoProvider";register:="com.diozero.internal.bo
 ard.tinkerboard.TinkerBoardBoardInfoProvider"
Require-Capability: osgi.extender;filter:="(&(osgi.extender=osgi.service
 loader.processor)(version>=1.0.0)(!(version>=2.0.0)))";resolution:=opti
 onal,osgi.extender;filter:="(&(osgi.extender=osgi.serviceloader.registr
 ar)(version>=1.0.0)(!(version>=2.0.0)))",osgi.serviceloader;filter:="(o
 sgi.serviceloader=com.diozero.internal.spi.BoardInfoProvider)";osgi.ser
 viceloader="com.diozero.internal.spi.BoardInfoProvider";resolution:=opt
 ional,osgi.serviceloader;filter:="(osgi.serviceloader=com.diozero.inter
 nal.spi.NativeDeviceFactoryInterface)";osgi.serviceloader="com.diozero.
 internal.spi.NativeDeviceFactoryInterface";resolution:=optional,osgi.ee
 ;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Tool: Bnd-5.3.0.202102221516

Optional generated module-info.class

//  (version 9 : 53.0, no super bit)
 module com.diozero.diozero-core  {
  // Version: 1.3.2

  requires java.base;
  requires java.desktop;
  requires tinylog-api;

  uses com.diozero.internal.spi.BoardInfoProvider
  uses com.diozero.internal.spi.NativeDeviceFactoryInterface

  provides com.diozero.internal.spi.BoardInfoProvider with com.diozero.internal.board.allwinner.AllwinnerH5BoardInfoProvider, com.diozero.internal.board.allwinner.AllwinnerH6BoardInfoProvider, com.diozero.internal.board.allwinner.AllwinnerSun8iBoardInfoProvider, com.diozero.internal.board.beaglebone.BeagleBoneBoardInfoProvider, com.diozero.internal.board.chip.ChipBoardInfoProvider, com.diozero.internal.board.odroid.OdroidBoardInfoProvider, com.diozero.internal.board.raspberrypi.RaspberryPiBoardInfoProvider, com.diozero.internal.board.tinkerboard.TinkerBoardBoardInfoProvider;
  
  Module packages:
    boarddefs
    com.diozero.animation
    com.diozero.animation.easing
    com.diozero.api
    com.diozero.api.function
    com.diozero.api.sandpit
    com.diozero.devices
    com.diozero.devices.mcp23xxx
    com.diozero.devices.motor
    com.diozero.devices.oled
    com.diozero.devices.sandpit
    com.diozero.internal
    com.diozero.internal.board
    com.diozero.internal.board.allwinner
    com.diozero.internal.board.beaglebone
    com.diozero.internal.board.chip
    com.diozero.internal.board.odroid
    com.diozero.internal.board.raspberrypi
    com.diozero.internal.board.tinkerboard
    com.diozero.internal.provider.builtin
    com.diozero.internal.provider.builtin.gpio
    com.diozero.internal.provider.builtin.i2c
    com.diozero.internal.provider.builtin.serial
    com.diozero.internal.provider.builtin.spi
    com.diozero.internal.spi
    com.diozero.sbc
    com.diozero.util

}

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
@mattjlewis
Copy link
Owner

Thanks for this. Very happy to change the MANIFEST.MF file, however, I don't want to add any additional dependencies. From a quick look at this, it would appear this would be relying on OSGi for service loading rather than the standard JDK ServiceLoader? I rely on ServiceLoader to resolve the device factory as well as the detected board.

@stbischof
Copy link
Author

stbischof commented Oct 2, 2021

I let you service loader ability as it is.
I just removed s/META-INF/services/com.diozero.internal.spi.BoardInfoProvider because it is now generated

I just used annotations to allow that workl in osgi. This adds just requirements and capabilities to the manifest. Also other Things i like to add does not add additional dependencies.

The annotations only exist are processed at buildtime.

Have a look on the import package Header in the manifest. Just you dependencie exist.

I

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants