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

Remove sbt 0.13.x support and syntax improvements #118

Merged
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
16 changes: 2 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ Plugin for [sbt](http://www.scala-sbt.org) to to create [OSGi](http://www.osgi.o
Installing sbt-osgi
-------------------

sbt-osgi is a plugin for sbt. In order to install sbt, please refer to the sbt documentation([0.13](https://www.scala-sbt.org/0.13/docs/Setup.html), [1.x](https://www.scala-sbt.org/1.x/docs/Setup.html)). Please make sure that you are using a suitable version of sbt:
sbt-osgi is a plugin for sbt. In order to install sbt, please refer to the sbt [1.x](https://www.scala-sbt.org/1.x/docs/Setup.html)). Please make sure that you are using a suitable version of sbt:

- sbt-osgi 0.5 → sbt 0.12
- sbt-osgi 0.7 → sbt 0.13
- sbt-osgi 0.9.{0-3} → sbt 0.13 / sbt 1.x
- sbt-osgi 0.9.{4-x} -> sbt 1.6.2+ (older versions of sbt may work but 1.6.2+ supports all JDK LTS versions)

As sbt-osgi is a plugin for sbt, it is installed like any other sbt plugin, that is by mere configuration: just add sbt-osgi to your global or local plugin definition. Global plugins are defined in `~/.sbt/<SBT_VERSION>/plugins/plugins.sbt` and local plugins are defined in `project/plugins.sbt` in your project.
Expand Down Expand Up @@ -42,19 +39,10 @@ Using sbt-osgi
#### Version 0.8.0 and above
As, since version `0.8.0`, sbt-osgi uses the sbt 0.13.5 *Autoplugin* feature, it can be enabled for individual projects like any other sbt Autoplugin. For more information on enabling and disabling plugins, refer to the [sbt plugins tutorial](http://www.scala-sbt.org/release/tutorial/Using-Plugins.html#Enabling+and+disabling+auto+plugins).

To enable sbt-osgi for a specific Project, use the project instance `enablePlugins(Plugins*)` method providing it with `SbtOsgi` as a parameter value. If using only '.sbt' definition files with only the implicitly declared root project with sbt 0.13.5 you will be required to obtain a reference to the project by explicitly declaring it in your build file. This may easily be done using the `project` macro, as shown in the example below. If using sbt 0.13.6 or greater, `enablePlugins(Plugins*)` is directly available in `.sbt` files.

Example `<PROJECT_ROOT>/build.sbt`:

```scala
// sbt 0.13.5
lazy val fooProject = (project in file(".")) // Obtain the root project reference
.enablePlugins(SbtOsgi) // Enables sbt-osgi for this project. This will automatically append
// the plugin's default settings to this project thus providing the
// `osgiBundle` task.

// sbt 0.13.6+
enablePlugins(SbtOsgi) // No need to obtain root project reference on single project builds for sbt 0.13.6+
enablePlugins(SbtOsgi)
```

Example `<PROJECT_ROOT>/project/Build.scala`:
Expand Down
11 changes: 0 additions & 11 deletions src/main/scala-sbt-0.13/com/typesafe/sbt/osgi/SbtCompat.scala

This file was deleted.

11 changes: 0 additions & 11 deletions src/main/scala-sbt-1.0/com/typesafe/sbt/osgi/SbtCompat.scala

This file was deleted.

30 changes: 14 additions & 16 deletions src/main/scala/com/typesafe/sbt/osgi/Osgi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@

package com.typesafe.sbt.osgi

import java.nio.file.{FileVisitOption, Files, Path}
import java.nio.file.{ FileVisitOption, Files, Path }
Copy link
Collaborator Author

@mdedetrich mdedetrich Jan 24, 2024

Choose a reason for hiding this comment

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

Imports were messed up in this PR, this fixes it back


import aQute.bnd.osgi.Builder
import aQute.bnd.osgi.Constants.*
import aQute.bnd.osgi.Constants._
import com.typesafe.sbt.osgi.OsgiKeys.CacheStrategy

import java.util.Properties
import java.util.function.Predicate
import java.util.stream.Collectors
import sbt.*
import sbt.Keys.*

import sbt._
import sbt.Keys._
import sbt.Package.ManifestAttributes

import scala.collection.JavaConverters.*
import scala.collection.JavaConverters._
import scala.language.implicitConversions

private object Osgi {
Expand Down Expand Up @@ -260,7 +261,8 @@ private object Osgi {
bundleActivator foreach (properties.put(BUNDLE_ACTIVATOR, _))
strToStrOpt(bundleDescription) foreach (properties.put(BUNDLE_DESCRIPTION, _))
bundleDocURL foreach (u => properties.put(BUNDLE_DOCURL, u.toString))
bundleLicense.headOption foreach (l => properties.put(BUNDLE_LICENSE, s"${l._2.toString};description=${l._1}"))
bundleLicense.headOption foreach {case (license, url) =>
properties.put(BUNDLE_LICENSE, s"${url.toString};description=$license")}
strToStrOpt(bundleName) foreach (properties.put(BUNDLE_NAME, _))
seqToStrOpt(bundleRequiredExecutionEnvironment)(id) foreach (properties.put(BUNDLE_REQUIREDEXECUTIONENVIRONMENT, _))
strToStrOpt(bundleVendor) foreach (properties.put(BUNDLE_VENDOR, _))
Expand Down Expand Up @@ -293,7 +295,7 @@ private object Osgi {
val organizationParts = parts(organization)
val nameParts = parts(name)
val partsWithoutOverlap = (organizationParts.lastOption, nameParts.headOption) match {
case (Some(last), Some(head)) if (last == head) => organizationParts ++ nameParts.tail
case (Some(last), Some(head)) if last == head => organizationParts ++ nameParts.tail
case _ => organizationParts ++ nameParts
}
partsWithoutOverlap mkString "."
Expand All @@ -304,13 +306,9 @@ private object Osgi {
def parts(s: String) = s split "[.-]" filterNot (_.isEmpty)

// ------------ Poor Man's Java 8 make-it-look-nice inter-op ----------------
implicit def asPredicate[T](f: (T) => Boolean): Predicate[T] =
new Predicate[T] {
override def test(t: T): Boolean = f(t)
}
implicit def asFunction[A, B](f: (A) => B): java.util.function.Function[A, B] =
new java.util.function.Function[A, B] {
override def apply(a: A): B = f(a)
}
implicit def asPredicate[T](f: T => Boolean): Predicate[T] =
(t: T) => f(t)
implicit def asFunction[A, B](f: A => B): java.util.function.Function[A, B] =
(a: A) => f(a)
// ------------ Poor Man's Java 8 make-it-look-nice inter-op ----------------
}
42 changes: 22 additions & 20 deletions src/main/scala/com/typesafe/sbt/osgi/OsgiKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,96 +18,96 @@ package com.typesafe.sbt.osgi

import sbt._

object OsgiKeys {
trait OsgiKeys {

val bundle: TaskKey[File] =
lazy val bundle: TaskKey[File] =
TaskKey[File](
prefix("Bundle"),
"Create an OSGi bundle.")

val manifestHeaders: TaskKey[OsgiManifestHeaders] =
lazy val manifestHeaders: TaskKey[OsgiManifestHeaders] =
TaskKey[OsgiManifestHeaders](
prefix("ManifestHeaders"),
"The aggregated manifest headers.")

val bundleActivator: SettingKey[Option[String]] =
lazy val bundleActivator: SettingKey[Option[String]] =
SettingKey[Option[String]](
prefix("BundleActivator"),
"Optional value for *Bundle-Activator* header.")

val bundleSymbolicName: SettingKey[String] =
lazy val bundleSymbolicName: SettingKey[String] =
SettingKey[String](
prefix("BundleSymbolicName"),
"Value for *Bundle-SymbolicName* header.")

val bundleVersion: SettingKey[String] =
lazy val bundleVersion: SettingKey[String] =
SettingKey[String](
prefix("BundleVersion"),
"Value for *Bundle-Version* header.")

val bundleRequiredExecutionEnvironment: SettingKey[Seq[String]] =
lazy val bundleRequiredExecutionEnvironment: SettingKey[Seq[String]] =
SettingKey[Seq[String]](
prefix("BundleRequiredExecutionEnvironment"),
"Value for *Bundle-RequiredExecutionEnvironment* header.")

val dynamicImportPackage: SettingKey[Seq[String]] =
lazy val dynamicImportPackage: SettingKey[Seq[String]] =
SettingKey[Seq[String]](
prefix("DynamicImportPackage"),
"Values for *Dynamic-ImportPackage* header.")

val exportPackage: SettingKey[Seq[String]] =
lazy val exportPackage: SettingKey[Seq[String]] =
SettingKey[Seq[String]](
prefix("ExportPackage"),
"Values for *Export-Package* header.")

val importPackage: SettingKey[Seq[String]] =
lazy val importPackage: SettingKey[Seq[String]] =
SettingKey[Seq[String]](
prefix("import-package"),
"Values for *Import-Package* header.")

val fragmentHost: SettingKey[Option[String]] =
lazy val fragmentHost: SettingKey[Option[String]] =
SettingKey[Option[String]](
prefix("FragmentHost"),
"Optional value for *Fragment-Host* header.")

val privatePackage: SettingKey[Seq[String]] =
lazy val privatePackage: SettingKey[Seq[String]] =
SettingKey[Seq[String]](
prefix("PrivatePackage"),
"Values for *Private-Package* header.")

val requireBundle: SettingKey[Seq[String]] =
lazy val requireBundle: SettingKey[Seq[String]] =
SettingKey[Seq[String]](
prefix("RequireBundle"),
"Values for *Require-Bundle* header.")

val additionalHeaders: SettingKey[Map[String, String]] =
lazy val additionalHeaders: SettingKey[Map[String, String]] =
SettingKey[Map[String, String]](
prefix("AdditionalHeaders"),
"Additional headers to pass to BND.")

val embeddedJars: TaskKey[Seq[File]] =
lazy val embeddedJars: TaskKey[Seq[File]] =
TaskKey[Seq[File]](
prefix("EmbeddedJars"),
"Jar files to be embedded inside the bundle.")

val explodedJars: TaskKey[Seq[File]] =
lazy val explodedJars: TaskKey[Seq[File]] =
TaskKey[Seq[File]](
prefix("ExplodedJars"),
"Jar files to be exploded into the bundle.")

val requireCapability: TaskKey[String] =
lazy val requireCapability: TaskKey[String] =
TaskKey[String](prefix("RequireCapability"), "Value for *Require-Capability* header. If not" +
"specified defaults to 'osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version=*PROJECT JAVA VERSION*))\"'.")

val failOnUndecidedPackage: SettingKey[Boolean] =
lazy val failOnUndecidedPackage: SettingKey[Boolean] =
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] =
lazy 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")

val cacheStrategy: SettingKey[Option[CacheStrategy]] =
lazy val cacheStrategy: SettingKey[Option[CacheStrategy]] =
SettingKey[Option[CacheStrategy]](prefix("CacheBundle"), "Do not build a new bundle if a bundle already exists and has been crafted from identical inputs")


Expand All @@ -121,3 +121,5 @@ object OsgiKeys {
object LastModified extends CacheStrategy
}
}

object OsgiKeys extends OsgiKeys
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.typesafe.sbt.osgi

import sbt.URL

case class OsgiManifestHeaders(
final case class OsgiManifestHeaders(
bundleActivator: Option[String],
bundleDescription: String,
bundleDocURL: Option[URL],
Expand Down
22 changes: 11 additions & 11 deletions src/main/scala/com/typesafe/sbt/osgi/SbtOsgi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import sbt.plugins.JvmPlugin

object SbtOsgi extends AutoPlugin {

override val trigger: PluginTrigger = noTrigger
override lazy val trigger: PluginTrigger = noTrigger

override val requires: Plugins = JvmPlugin
override lazy val requires: Plugins = JvmPlugin

override lazy val projectSettings: Seq[Def.Setting[_]] = defaultOsgiSettings

Expand All @@ -33,25 +33,25 @@ object SbtOsgi extends AutoPlugin {

val OsgiKeys = com.typesafe.sbt.osgi.OsgiKeys

def osgiSettings: Seq[Setting[_]] = Seq(
packagedArtifact in (Compile, packageBin) := Scoped.mkTuple2((artifact in (Compile, packageBin)).value, OsgiKeys.bundle.value),
SbtCompat.packageBinBundle)
lazy val osgiSettings: Seq[Setting[_]] = Seq(
Compile / packageBin / packagedArtifact := Scoped.mkTuple2((Compile / packageBin / artifact).value, OsgiKeys.bundle.value),
Compile / packageBin / artifact ~= (_.withType("bundle")) )
}

def defaultOsgiSettings: Seq[Setting[_]] = {
lazy val defaultOsgiSettings: Seq[Setting[_]] = {
import OsgiKeys._
Seq(
bundle := Osgi.bundleTask(
manifestHeaders.value,
additionalHeaders.value,
(dependencyClasspathAsJars in Compile).value.map(_.data) ++ (products in Compile).value,
(artifactPath in (Compile, packageBin)).value,
(resourceDirectories in Compile).value,
(Compile / dependencyClasspathAsJars).value.map(_.data) ++ (Compile / products).value,
(Compile / packageBin / artifactPath).value,
(Compile / resourceDirectories).value,
embeddedJars.value,
explodedJars.value,
failOnUndecidedPackage.value,
(sourceDirectories in Compile).value,
(packageOptions in (Compile, packageBin)).value,
(Compile / sourceDirectories).value,
(Compile / packageBin / packageOptions).value,
packageWithJVMJar.value,
cacheStrategy.value,
streams.value),
Expand Down
Loading