Skip to content

Commit

Permalink
Discard the sbt-osgi plugin - it conflicts with module-info
Browse files Browse the repository at this point in the history
I cannot make it package also the `module-info.class`. So instead just
populate the right OSGI attributes in the manifest.
  • Loading branch information
luben committed Oct 29, 2023
1 parent 8ba2eda commit d375fdf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
55 changes: 38 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ThisBuild / versionScheme := Some("strict")

scalaVersion := "2.13.12"

enablePlugins(JniPlugin, SbtOsgi, ModuleInfoPlugin)
enablePlugins(JniPlugin, ModuleInfoPlugin)
moduleInfo := com.sandinh.javamodule.moduleinfo.JpmsModule(
"com.github.luben.zstd_jni", // moduleName
openModule = false,
Expand Down Expand Up @@ -163,8 +163,16 @@ description := "JNI bindings for Zstd native library that provides fast and high

Compile / packageBin / packageOptions ++= Seq(
Package.ManifestAttributes(new java.util.jar.Attributes.Name("Automatic-Module-Name") -> "com.github.luben.zstd_jni"),
Package.ManifestAttributes(new java.util.jar.Attributes.Name("Bnd-LastModified") -> s"${java.lang.System.currentTimeMillis()}"),
Package.ManifestAttributes(new java.util.jar.Attributes.Name("Bundle-Name") -> "zstd-jni"),
Package.ManifestAttributes(new java.util.jar.Attributes.Name("Bundle-SymbolicName") -> "com.github.luben.zstd-jni"),
Package.ManifestAttributes(new java.util.jar.Attributes.Name("Bundle-Description") -> description.value),
Package.ManifestAttributes(new java.util.jar.Attributes.Name("Bundle-Vendor") -> organization.value),
Package.ManifestAttributes(new java.util.jar.Attributes.Name("Bundle-License") -> "https://opensource.org/licenses/BSD-2-Clause;description=BSD 2-Clause License"),
Package.ManifestAttributes(new java.util.jar.Attributes.Name("Bundle-Version") -> version.value),

This comment has been minimized.

Copy link
@dalbani

dalbani Oct 31, 2023

FYI, taking the version as-is over in the manifest broke my build:

org.osgi.framework.BundleException: Unable to build resource for mvn:com.github.luben/zstd-jni/1.5.5-7: Unsupported 'Bundle-ManifestVersion' value: 1.5.5-7 -> [Help 1]

From https://docs.osgi.org/whitepaper/semantic-versioning/040-semantic-versions.html#semantic-versions, I guess the version should have been 1.5.5.7 (like it was before for the previous release).

This comment has been minimized.

Copy link
@luben

luben Oct 31, 2023

Author Owner

good catch. fix is coming

This comment has been minimized.

Copy link
@luben

luben Oct 31, 2023

Author Owner

published v1.5.5-8 with fixed OSGI bundle version

This comment has been minimized.

Copy link
@dalbani

dalbani Oct 31, 2023

Thanks for this very prompt reaction.
But, alas, whereas Bundle-Version is now fixed, there's still something wrong with Bundle-ManifestVersion.
As in:

Bundle-Version: 1.5.5.8
Bundle-ManifestVersion: 1.5.5-8

This comment has been minimized.

Copy link
@luben

luben Oct 31, 2023

Author Owner

published 1.5.5-9 with that fixed

This comment has been minimized.

Copy link
@dalbani

dalbani Nov 1, 2023

Oh, my bad, I put you on the wrong track w.r.t. Bundle-ManifestVersion 😬
The value shouldn't be a repetition of Bundle-Version, but rather follow that the spec says at https://docs.osgi.org/specification/osgi.core/8.0.0/framework.module.html#d0e2020.

This comment has been minimized.

Copy link
@luben

luben Nov 1, 2023

Author Owner

Ooo, I see. I was wandering why I didn't replace it the first time - it was using totally wrong version

This comment has been minimized.

Copy link
@luben

luben Nov 1, 2023

Author Owner

Releasing v1.5.5-10 with that fix

This comment has been minimized.

Copy link
@dalbani

dalbani Nov 1, 2023

Great! Thanks a lot for all your effort 👍

Package.ManifestAttributes(new java.util.jar.Attributes.Name("Bundle-ManifestVersion") -> version.value),
Package.ManifestAttributes(new java.util.jar.Attributes.Name("Bundle-NativeCode") ->
{s"""darwin/x86_64/libzstd-jni-${version.value}.dylib;osname=MacOS;osname=MacOSX;processor=x86_64,
s"""darwin/x86_64/libzstd-jni-${version.value}.dylib;osname=MacOS;osname=MacOSX;processor=x86_64,
|darwin/aarch64/libzstd-jni-${version.value}.dylib;osname=MacOS;osname=MacOSX;processor=aarch64,
|freebsd/amd64/libzstd-jni-${version.value}.so;osname=FreeBSD;processor=amd64,
|freebsd/i386/libzstd-jni-${version.value}.so;osname=FreeBSD;processor=i386,
Expand All @@ -180,9 +188,36 @@ Compile / packageBin / packageOptions ++= Seq(
|linux/s390x/libzstd-jni-${version.value}.so;osname=Linux;processor=s390x,
|win/amd64/libzstd-jni-${version.value}.dll;osname=Win32;processor=amd64,
|win/aarch64/libzstd-jni-${version.value}.dll;osname=Win32;processor=aarch64,
|win/x86/libzstd-jni-${version.value}.dll;osname=Win32;processor=x86""".stripMargin}),
|win/x86/libzstd-jni-${version.value}.dll;osname=Win32;processor=x86""".stripMargin.replace("\n", "")),
Package.ManifestAttributes(new java.util.jar.Attributes.Name("Export-Package") -> s"""com.github.luben.zstd;version="${version.value}",com.github.luben.zstd.util;version="${version.value}""""),
Package.ManifestAttributes(new java.util.jar.Attributes.Name("Import-Package") -> "org.osgi.framework;resolution:=optional"),
Package.ManifestAttributes(new java.util.jar.Attributes.Name("Private-Package") ->
"""darwin.aarch64,
|darwin.x86_64,
|freebsd.amd64,
|freebsd.i386,
|linux.aarch64,
|linux.amd64,
|linux.arm,
|linux.i386,
|linux.loongarch64,
|linux.mips64,
|linux.ppc64,
|linux.ppc64le,
|linux.riscv64,
|linux.s390x,
|win.aarch64,
|win.amd64,
|win.x86""".stripMargin.replace("\n","")),
Package.ManifestAttributes(new java.util.jar.Attributes.Name("Require-Capability") -> """osgi.ee;filter:="(&(osgi.ee=JavaSE)(version>=1.8))""""),
)

// publish the main jar as bundle
Compile / packageBin / artifact := {
val prev: Artifact = (Compile / packageBin / artifact).value
prev.withType("bundle")
}

pomExtra := (
<url>https://github.com/luben/zstd-jni</url>
<scm>
Expand All @@ -200,20 +235,6 @@ pomExtra := (
</developers>
)

// OSGI
OsgiKeys.bundleSymbolicName := "com.github.luben.zstd-jni"
OsgiKeys.exportPackage := Seq(s"com.github.luben.zstd", "com.github.luben.zstd.util")
OsgiKeys.importPackage := Seq("org.osgi.framework;resolution:=optional")
OsgiKeys.privatePackage := Seq(
"linux.amd64", "linux.i386", "linux.aarch64", "linux.arm", "linux.ppc64",
"linux.ppc64le", "linux.mips64", "linux.loongarch64", "linux.s390x", "darwin.x86_64",
"darwin.aarch64", "win.amd64", "win.x86", "win.aarch64", "freebsd.amd64", "freebsd.i386",
"linux.riscv64"
)
// Explicitly specify the version of JavaSE required
// (rather depend on figuring that out from the JDK it was built with)
OsgiKeys.requireCapability := "osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version>=1.8))\""

// Jacoco coverage setting
jacocoReportSettings := JacocoReportSettings(
"Jacoco Coverage Report",
Expand Down
1 change: 0 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
addSbtPlugin("io.github.joprice" % "sbt-jni" % "0.2.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.6")
addSbtPlugin("com.github.sbt" % "sbt-jacoco" % "3.4.0")
addSbtPlugin("com.sandinh" % "sbt-java-module-info" % "0.5.2")

0 comments on commit d375fdf

Please sign in to comment.