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

Fixed Invalid CEN extra data field on recent JVM #81

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/main/scala/com/typesafe/sbt/osgi/Osgi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ private object Osgi {
failOnUndecidedPackage: Boolean,
sourceDirectories: Seq[File],
packageOptions: scala.Seq[sbt.PackageOption],
streams: TaskStreams): File = {
streams: TaskStreams,
useJVMJar: Boolean): File = {
val builder = new Builder

if (failOnUndecidedPackage) {
Expand Down Expand Up @@ -75,7 +76,23 @@ private object Osgi {
val log = streams.log
builder.getWarnings.asScala.foreach(s => log.warn(s"bnd: $s"))
builder.getErrors.asScala.foreach(s => log.error(s"bnd: $s"))
jar.write(tmpArtifactPath)

if (!useJVMJar) jar.write(tmpArtifactPath)
else {
val tmpArtifactDirectoryPath = file(artifactPath.absolutePath + "_tmpdir")
IO.delete(tmpArtifactDirectoryPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it also deletes all the content?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, I didn't write this code. @romainreuillon Might be able to explain more here.

tmpArtifactDirectoryPath.mkdirs()

val manifest = jar.getManifest
jar.writeFolder(tmpArtifactDirectoryPath)

def content =
sbt.Path.contentOf(tmpArtifactDirectoryPath).filterNot { case (_, p) => p == "META-INF/MANIFEST.MF" }

IO.jar(content, tmpArtifactPath, manifest)
IO.delete(tmpArtifactDirectoryPath)
}

IO.move(tmpArtifactPath, artifactPath)
artifactPath
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/com/typesafe/sbt/osgi/OsgiKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ object OsgiKeys {
SettingKey[Boolean](prefix("FailOnUndecidedPackage"), "Fail the build if a package is neither exported or private." +
"Without this setting such classes might be just transparently removed from the resulting artifact!")

val packageWithJVMJar: SettingKey[Boolean] =
SettingKey[Boolean](prefix("PackageWithJVMJar"), "Use the JVM jar tools to craft the bundle instead of the one from BND." +
"Without this setting the produced bundle are detected as corrupted by recent JVMs")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just swith to the jar tool?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the jar tool that comes with JVM, and we cant use BND because it creates corrupted jar's (thats why this feature was implemented in the first place)

private def prefix(key: String) = "osgi" + key

}
6 changes: 4 additions & 2 deletions src/main/scala/com/typesafe/sbt/osgi/SbtOsgi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ object SbtOsgi extends AutoPlugin {
failOnUndecidedPackage.value,
(sourceDirectories in Compile).value,
(packageOptions in (Compile, packageBin)).value,
streams.value),
streams.value,
packageWithJVMJar.value),
manifestHeaders := OsgiManifestHeaders(
bundleActivator.value,
description.value,
Expand Down Expand Up @@ -84,6 +85,7 @@ object SbtOsgi extends AutoPlugin {
requireCapability := Osgi.requireCapabilityTask(),
additionalHeaders := Map.empty,
embeddedJars := Nil,
explodedJars := Nil)
explodedJars := Nil,
packageWithJVMJar := false)
}
}