Skip to content

Commit

Permalink
Merge pull request #115 from mdedetrich/add-test-for-packageWithJvmJar
Browse files Browse the repository at this point in the history
Fix packageWithJVMJar := true not working on Windows
  • Loading branch information
mdedetrich authored Jan 22, 2024
2 parents ec8428e + 02341db commit b4dd37f
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/scala/com/typesafe/sbt/osgi/Osgi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ private object Osgi {
import _root_.java.nio.file._
import _root_.scala.collection.JavaConverters._
val path = tmpArtifactDirectoryPath.toPath
Files.walk(path).iterator.asScala.map(f => f.toFile -> path.relativize(f).toString).filterNot { case (_, p) => p == "META-INF/MANIFEST.MF" }.toTraversable
Files.walk(path).iterator.asScala.map(f => f.toFile -> path.relativize(f))
.collect { case (f, p) if p != (file("META-INF") / "MANIFEST.MF").toPath => (f, p.toString) }
.toTraversable
}

IO.jar(content, tmpArtifactPath, manifest)
Expand Down
73 changes: 73 additions & 0 deletions src/sbt-test/sbt-osgi/test-08-packageWithJVMJar/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
lazy val test08 = (project in file ("")).enablePlugins(SbtOsgi)

organization := "com.typesafe.sbt"

name := "sbt-osgi-test"

version := "1.2.3"

libraryDependencies += "org.osgi" % "org.osgi.core" % "4.3.0" % "provided"

osgiSettings

OsgiKeys.packageWithJVMJar := true

TaskKey[Unit]("verifyBundleActivator") := {
val activator = OsgiKeys.bundleActivator.value
if (activator.isDefined)
sys.error("Expected bundle-activator to be None, but was %s!" format activator)
}

TaskKey[Unit]("verifyBundleSymbolicName") := {
val name = OsgiKeys.bundleSymbolicName.value
if (name != "com.typesafe.sbt.osgi.test")
sys.error("Expected bundle-symbolic-name to be %s, but was %s!".format("com.typesafe.sbt.osgi.test", name))
}

TaskKey[Unit]("verifyBundleRequiredExecutionEnvironment") := {
val re = OsgiKeys.bundleRequiredExecutionEnvironment.value
if (re.nonEmpty)
sys.error("Expected bundleRequiredExecutionEnvironment to be Nil, but was %s!" format re)
}

TaskKey[Unit]("verifyBundleVerion") := {
val version = OsgiKeys.bundleVersion.value
if (version != "1.2.3")
sys.error("Expected bundle-version to be %s, but was %s!".format("1.2.3", version))
}

TaskKey[Unit]("verifyDynamicImportPackage") := {
val pkg = OsgiKeys.dynamicImportPackage.value
if (!pkg.isEmpty)
sys.error("Expected dynamic-import-package to be empty, but was %s!" format pkg)
}

TaskKey[Unit]("verifyExportPackage") := {
val pkg = OsgiKeys.exportPackage.value
if (!pkg.isEmpty)
sys.error("Expected export-package to be empty, but was %s!" format pkg)
}

TaskKey[Unit]("verifyImportPackage") := {
val pkg = OsgiKeys.importPackage.value
if (pkg != Seq("*"))
sys.error("Expected import-package to be %s, but was %s!".format(Seq("*"), pkg))
}

TaskKey[Unit]("verifyFragmentHost") := {
val host = OsgiKeys.fragmentHost.value
if (host != None)
sys.error("Expected fragment-host to be None, but was %s!" format host)
}

TaskKey[Unit]("verifyPrivatePackage") := {
val pkg = OsgiKeys.privatePackage.value
if (pkg != Seq("com.typesafe.sbt.osgi.test.*"))
sys.error("Expected private-package to be %s, but was %s!".format(Seq("com.typesafe.sbt.osgi.test.*"), pkg))
}

TaskKey[Unit]("verifyRequireBundle") := {
val bundle = OsgiKeys.requireBundle.value
if (!bundle.isEmpty)
sys.error("Expected require-bundle to be empty, but was %s!" format bundle)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-osgi" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
15 changes: 15 additions & 0 deletions src/sbt-test/sbt-osgi/test-08-packageWithJVMJar/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Default settings
> verifyBundleActivator
> verifyBundleSymbolicName
> verifyBundleVerion
> verifyBundleRequiredExecutionEnvironment
> verifyDynamicImportPackage
> verifyExportPackage
> verifyImportPackage
> verifyFragmentHost
> verifyPrivatePackage
> verifyRequireBundle

# Existence of JAR file
> osgiBundle
$ exists target/scala-2.12/sbt-osgi-test_2.12-1.2.3.jar

0 comments on commit b4dd37f

Please sign in to comment.