From b675aac81b6d4a78b744dbd744baab938d782fdc Mon Sep 17 00:00:00 2001 From: Ingo Bauersachs Date: Sun, 17 Oct 2021 15:57:48 +0200 Subject: [PATCH] Make Smack jars OSGi bundles Fixes SMACK-343 by using bnd instead of the deprecated Gradle plugin that was previously used and removed in commit d06f533bb975f41a5e86c990e1bb830b7e7dc923. --- build.gradle | 14 +++++++++++--- smack-core/build.gradle | 13 +++++++++++++ smack-xmlparser-stax/build.gradle | 15 +++++++++++++++ smack-xmlparser-xpp3/build.gradle | 15 +++++++++++++++ smack-xmlparser/build.gradle | 14 ++++++++++++++ 5 files changed, 68 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index d80fbb28c..3991e96ed 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ buildscript { dependencies { classpath 'org.kordamp.gradle:clirr-gradle-plugin:0.2.2' classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1" + classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:6.0.0" } } @@ -413,6 +414,7 @@ subprojects { apply plugin: 'signing' apply plugin: 'checkstyle' apply plugin: 'org.kordamp.gradle.clirr' + apply plugin: 'biz.aQute.bnd.builder' checkstyle { toolVersion = '8.27' @@ -575,9 +577,15 @@ project(':smack-omemo').clirr.enabled = false project(':smack-omemo-signal').clirr.enabled = false subprojects*.jar { - manifest { - from sharedManifest - } + manifest { + from sharedManifest + } + bundle { + bnd( + '-removeheaders': 'Tool, Bnd-*', + '-exportcontents': '*', + ) + } } configure(subprojects - gplLicensedProjects) { diff --git a/smack-core/build.gradle b/smack-core/build.gradle index b0cd79641..6b35345e8 100644 --- a/smack-core/build.gradle +++ b/smack-core/build.gradle @@ -1,3 +1,8 @@ +// Note that this is also declared in the main build.gradle for +// subprojects, but since evaluationDependsOnChildren is enabled we +// need to declare it here too to have bundle{bnd{...}} available +apply plugin: 'biz.aQute.bnd.builder' + description = """\ Smack core components.""" @@ -55,3 +60,11 @@ task createVersionResource(type: CreateFileTask) { } compileJava.dependsOn(createVersionResource) + +jar { + bundle { + bnd( + 'DynamicImport-Package': '*', + ) + } +} diff --git a/smack-xmlparser-stax/build.gradle b/smack-xmlparser-stax/build.gradle index d4e21ba8f..5012907c1 100644 --- a/smack-xmlparser-stax/build.gradle +++ b/smack-xmlparser-stax/build.gradle @@ -1,3 +1,8 @@ +// Note that this is also declared in the main build.gradle for +// subprojects, but since evaluationDependsOnChildren is enabled we +// need to declare it here too to have bundle{bnd{...}} available +apply plugin: 'biz.aQute.bnd.builder' + description = """\ Smack XML parser using Stax.""" @@ -5,3 +10,13 @@ dependencies { compile project(':smack-xmlparser') //testCompile project(path: ":smack-xmlparser", configuration: "testRuntime") } + +jar { + bundle { + bnd( + // see http://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.loader.html + 'Require-Capability': 'osgi.extender;filter:="(osgi.extender=osgi.serviceloader.registrar)"', + 'Provide-Capability': "osgi.serviceloader;osgi.serviceloader=org.jivesoftware.smack.xml.XmlPullParserFactory;register:=org.jivesoftware.smack.xml.stax.StaxXmlPullParserFactory", + ) + } +} diff --git a/smack-xmlparser-xpp3/build.gradle b/smack-xmlparser-xpp3/build.gradle index a0afd7c4a..f0a9f56c6 100644 --- a/smack-xmlparser-xpp3/build.gradle +++ b/smack-xmlparser-xpp3/build.gradle @@ -1,3 +1,8 @@ +// Note that this is also declared in the main build.gradle for +// subprojects, but since evaluationDependsOnChildren is enabled we +// need to declare it here too to have bundle{bnd{...}} available +apply plugin: 'biz.aQute.bnd.builder' + description = """\ Smack XML parser using XPP3.""" @@ -11,3 +16,13 @@ dependencies { api project(':smack-xmlparser') //testCompile project(path: ":smack-xmlparser", configuration: "testRuntime") } + +jar { + bundle { + bnd( + // see http://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.loader.html + 'Require-Capability': 'osgi.extender;filter:="(osgi.extender=osgi.serviceloader.registrar)"', + 'Provide-Capability': "osgi.serviceloader;osgi.serviceloader=org.jivesoftware.smack.xml.XmlPullParserFactory;register:=org.jivesoftware.smack.xml.xpp3.Xpp3XmlPullParserFactory", + ) + } +} diff --git a/smack-xmlparser/build.gradle b/smack-xmlparser/build.gradle index 46318a504..513a2b153 100644 --- a/smack-xmlparser/build.gradle +++ b/smack-xmlparser/build.gradle @@ -1,2 +1,16 @@ +// Note that this is also declared in the main build.gradle for +// subprojects, but since evaluationDependsOnChildren is enabled we +// need to declare it here too to have bundle{bnd{...}} available +apply plugin: 'biz.aQute.bnd.builder' + description = """\ Smack XML parser fundamentals""" + +jar { + bundle { + bnd( + // see http://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.loader.html + 'Require-Capability': 'osgi.extender;filter:="(osgi.extender=osgi.serviceloader.processor)"', + ) + } +}