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

Added support for Scala 3.0.2 #28

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import mill.scalalib.publish._
import $ivy.`de.tototec::de.tobiasroeser.mill.osgi::0.3.2`
import de.tobiasroeser.mill.osgi._

val scalaVersions = Seq("2.13.2", "2.12.11", "2.11.12", "2.10.7")
val dominoVersion = "1.1.5"
val scalaVersions = Seq("3.0.2", "2.13.2", "2.12.11", "2.11.12", "2.10.7")
val dominoVersion = "1.1.6-SNAPSHOT"

object Deps {
val osgiCore = ivy"org.osgi:org.osgi.core:4.3.0"
Expand Down Expand Up @@ -38,7 +38,7 @@ class DominoModule(override val crossScalaVersion: String)
override def artifactName = "domino"

def scalaReflectIvyDeps = T{
if(mill.scalalib.api.Util.isDotty(crossScalaVersion))
if(mill.scalalib.api.Util.isDottyOrScala3(crossScalaVersion))
Agg.empty[Dep]
else
Agg(
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/domino/EmptyBundleActivator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import org.osgi.framework.{ BundleContext, BundleActivator }
* @see [[http://www.artima.com/scalazine/articles/stackable_trait_pattern.html Stackable Trait Pattern]]
*/
trait EmptyBundleActivator extends BundleActivator {
def start(context: BundleContext) {
def start(context: BundleContext): Unit = {
}

def stop(context: BundleContext) {
def stop(context: BundleContext): Unit = {
}
}
6 changes: 3 additions & 3 deletions src/main/scala/domino/OsgiContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ trait OsgiContext extends DynamicCapsuleContext with EmptyBundleActivator {
* @group Basics
* @param f Handler
*/
def whenBundleActive(f: => Unit) {
def whenBundleActive(f: => Unit): Unit = {
log.debug(s"Registering whenBundleActive for bundle in ${getClass()}")
if (bundleActiveHandler.isDefined) {
log.warn(s"Overriding already present whenBundleActive for bundle in ${getClass()}. The previous whenBundleActive will be ignored")
}
bundleActiveHandler = Some(f _)
}

abstract override def start(context: BundleContext) {
abstract override def start(context: BundleContext): Unit = {
// Integrate into the stacked traits
super.start(context)

Expand Down Expand Up @@ -85,7 +85,7 @@ trait OsgiContext extends DynamicCapsuleContext with EmptyBundleActivator {
}
}

abstract override def stop(context: BundleContext) {
abstract override def stop(context: BundleContext): Unit = {
// Stop and release all the capsules in the scope
try {
bundleActiveCapsuleScope.foreach { mc =>
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/domino/bundle_watching/BundleWatcherCapsule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ class BundleWatcherCapsule(f: BundleWatcherEvent => Unit, bundleContext: BundleC
*/
def tracker = _tracker

def start() {
def start(): Unit = {
log.debug(s"Bundle ${DominoUtil.dumpBundle(bundleContext)}: Start tracking bundle lifecycle events")

import org.osgi.framework.Bundle._

// Create a bundle tracker which tracks all bundle state transitions
_tracker = new BundleTracker[Bundle](bundleContext, ACTIVE + INSTALLED + RESOLVED + STARTING + STOPPING + UNINSTALLED, null) {
override def addingBundle(bundle: Bundle, event: BundleEvent) = {
override def addingBundle(bundle: Bundle, event: BundleEvent): Bundle = {
val watcherEvent = BundleWatcherEvent.AddingBundle(bundle, BundleWatcherContext(_tracker))
f(watcherEvent)
bundle
}

override def modifiedBundle(bundle: Bundle, event: BundleEvent, obj: Bundle) {
override def modifiedBundle(bundle: Bundle, event: BundleEvent, obj: Bundle): Unit = {
val watcherEvent = BundleWatcherEvent.ModifiedBundle(bundle, BundleWatcherContext(_tracker))
f(watcherEvent)
}

override def removedBundle(bundle: Bundle, event: BundleEvent, obj: Bundle) {
override def removedBundle(bundle: Bundle, event: BundleEvent, obj: Bundle): Unit = {
val watcherEvent = BundleWatcherEvent.RemovedBundle(bundle, BundleWatcherContext(_tracker))
f(watcherEvent)
}
Expand All @@ -53,7 +53,7 @@ class BundleWatcherCapsule(f: BundleWatcherEvent => Unit, bundleContext: BundleC
_tracker.open()
}

def stop() {
def stop(): Unit = {
log.debug(s"Bundle ${DominoUtil.dumpBundle(bundleContext)}: Stop tracking bundle lifecycle events")
// Stop tracking
_tracker.close()
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/domino/capsule/Capsule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ trait Capsule {
/**
* Starts the capsule. After that, the capsule is active.
*/
def start()
def start(): Unit

/**
* Stops the capsule. After that, the capsule is inactive.
*/
def stop()
def stop(): Unit
}
2 changes: 1 addition & 1 deletion src/main/scala/domino/capsule/CapsuleContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait CapsuleContext {
*
* @param capsule capsule
*/
def addCapsule(capsule: Capsule)
def addCapsule(capsule: Capsule): Unit

/**
* Creates a new capsule scope on top of the active one and executes the given function in it. So the function
Expand Down
16 changes: 6 additions & 10 deletions src/main/scala/domino/capsule/CapsuleConvenience.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ trait CapsuleConvenience {
*
* @param f start logic
*/
def onStart(f: => Unit) {
def onStart(f: => Unit): Unit = {
// Create a capsule which just contains start logic
val capsule = new Capsule {
def start() {
f
}
def stop() {}
def start(): Unit = f
def stop(): Unit = {}
}

// Add the capsule to the current scope
Expand All @@ -30,13 +28,11 @@ trait CapsuleConvenience {
*
* @param f stop logic
*/
def onStop(f: => Unit) {
def onStop(f: => Unit): Unit = {
// Create a capsule which just contains stop logic
val capsule = new Capsule {
def start() {}
def stop() {
f
}
def start(): Unit = {}
def stop(): Unit = f
}

// Add the capsule to the current scope
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/domino/capsule/CapsuleScope.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ trait CapsuleScope {
/**
* Stops all capsules in this scope.
*/
def stop()
def stop(): Unit
}
2 changes: 1 addition & 1 deletion src/main/scala/domino/capsule/DefaultCapsuleScope.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package domino.capsule
* @param capsules capsules in the scope
*/
class DefaultCapsuleScope(capsules: Traversable[Capsule]) extends CapsuleScope {
def stop() {
def stop(): Unit = {
capsules.foreach { _.stop() }
}
}
2 changes: 1 addition & 1 deletion src/main/scala/domino/capsule/DynamicCapsuleContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait DynamicCapsuleContext extends CapsuleContext {
*/
private val dynamicCapsuleSet = new DynamicVariable[Option[mutable.Set[Capsule]]](None)

def addCapsule(capsule: Capsule) {
def addCapsule(capsule: Capsule): Unit = {
// Start the capsule immediately
capsule.start()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ConfigurationWatcherCapsule(
*/
private[this] var oldOptConf: Option[Map[String, Any]] = None

override def start() {
override def start(): Unit = {
// Service properties
val propertiesMap = Map(Constants.SERVICE_PID -> servicePid)

Expand All @@ -69,7 +69,7 @@ class ConfigurationWatcherCapsule(
_reg = tmp.asInstanceOf[ServiceRegistration[ManagedService]]
}

override def stop() {
override def stop(): Unit = {
// Stop capsules in the newly created capsule scope
newCapsuleScope foreach { _.stop() }

Expand All @@ -78,7 +78,7 @@ class ConfigurationWatcherCapsule(
_reg = null
}

override def updated(conf: Dictionary[String, _]) {
override def updated(conf: Dictionary[String, _]): Unit = {
// We query the config admin directly because the user can make sure then that the config value is already set.
// See http://www.mail-archive.com/[email protected]/msg06764.html
val safeOptConf = Option(conf).map(d => DominoUtil.convertToMap(d)).orElse(getConfigDirectly)
Expand All @@ -90,7 +90,7 @@ class ConfigurationWatcherCapsule(
/**
* Executes the handler only if the configuration has changed compared to the one which was used last.
*/
private[this] def executeBlockWithConfIfChanged(optConf: Option[Map[String, Any]]) {
private[this] def executeBlockWithConfIfChanged(optConf: Option[Map[String, Any]]): Unit = {
if (oldOptConf != optConf) {
executeBlockWithConf(optConf)
}
Expand All @@ -99,7 +99,7 @@ class ConfigurationWatcherCapsule(
/**
* Executes the handler with the given configuration and saves it for future comparison.
*/
private[this] def executeBlockWithConf(optConf: Option[Map[String, Any]]) {
private[this] def executeBlockWithConf(optConf: Option[Map[String, Any]]): Unit = {
// Stop capsules in previous scope
newCapsuleScope foreach { _.stop() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FactoryConfigurationWatcherCapsule(
*/
private[this] var oldOptConfs = Map[String, Option[Map[String, Any]]]()

override def start() {
override def start(): Unit = {
// Service properties
val propertiesMap = Map(Constants.SERVICE_PID -> servicePid)

Expand All @@ -71,7 +71,7 @@ class FactoryConfigurationWatcherCapsule(
_reg = tmp.asInstanceOf[ServiceRegistration[ManagedServiceFactory]]
}

override def stop() {
override def stop(): Unit = {
// Stop capsules in all newly created capsule scopes
newCapsuleScopes.keys foreach { stopAndRemoveCapsuleScope }

Expand All @@ -80,17 +80,17 @@ class FactoryConfigurationWatcherCapsule(
_reg = null
}

override def getName() = name
override def getName(): String = name

override def updated(pid: String, conf: Dictionary[String, _]) {
override def updated(pid: String, conf: Dictionary[String, _]): Unit = {
// Execute handler only if configuration has changed
executeBlockWithConfIfChanged(pid, Option(conf).map(d => DominoUtil.convertToMap(d)))
}

/**
* Executes the handler only if the configuration has changed compared to the one which was used last.
*/
private[this] def executeBlockWithConfIfChanged(pid: String, optConf: Option[Map[String, Any]]) {
private[this] def executeBlockWithConfIfChanged(pid: String, optConf: Option[Map[String, Any]]): Unit = {
if (oldOptConfs.get(pid) != Some(optConf)) {
executeBlockWithConf(pid, optConf)
}
Expand All @@ -99,7 +99,7 @@ class FactoryConfigurationWatcherCapsule(
/**
* Executes the correct handler with the given configuration and saves the configuration for future comparison.
*/
private[this] def executeBlockWithConf(pid: String, optConf: Option[Map[String, Any]]) {
private[this] def executeBlockWithConf(pid: String, optConf: Option[Map[String, Any]]): Unit = {
// If factory configuration was changed, we need to stop the capsules in the corresponding capsule scope first
if (newCapsuleScopes.contains(pid)) {
// Existing service is reconfigured. So we have to stop the capsule corresponding to the PID first.
Expand Down Expand Up @@ -137,22 +137,22 @@ class FactoryConfigurationWatcherCapsule(
}
}

def deleted(pid: String) {
def deleted(pid: String): Unit = {
stopAndRemoveCapsuleScope(pid)
}

/**
* Adds a capsule scope for the given PID.
*/
private[this] def addCapsuleScope(pid: String, capsuleScope: CapsuleScope, optConf: Option[Map[String, Any]]) {
private[this] def addCapsuleScope(pid: String, capsuleScope: CapsuleScope, optConf: Option[Map[String, Any]]): Unit = {
newCapsuleScopes += (pid -> capsuleScope)
oldOptConfs += (pid -> optConf)
}

/**
* Stops the capsule scope for the given PID.
*/
private[this] def stopAndRemoveCapsuleScope(pid: String) {
private[this] def stopAndRemoveCapsuleScope(pid: String): Unit = {
val capsuleScope = newCapsuleScopes(pid)
capsuleScope.stop()
newCapsuleScopes -= pid
Expand Down
22 changes: 11 additions & 11 deletions src/main/scala/domino/logging/OsgiLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,47 @@ import domino.scala_logging.Logger
class OsgiLogger(logService: LogService) extends Logger {
import LogService._

def debug(message: => AnyRef) {
def debug(message: => AnyRef): Unit = {
log(LOG_DEBUG, message, null)
}

def debug(message: => AnyRef, exception: => Throwable) {
def debug(message: => AnyRef, exception: => Throwable): Unit = {
log(LOG_DEBUG, message, exception)
}

def info(message: => AnyRef) {
def info(message: => AnyRef): Unit = {
log(LOG_INFO, message, null)
}

def info(message: => AnyRef, exception: => Throwable) {
def info(message: => AnyRef, exception: => Throwable): Unit = {
log(LOG_INFO, message, exception)
}

def warn(message: => AnyRef) {
def warn(message: => AnyRef): Unit = {
log(LOG_WARNING, message, null)
}

def warn(message: => AnyRef, exception: => Throwable) {
def warn(message: => AnyRef, exception: => Throwable): Unit = {
log(LOG_WARNING, message, exception)
}

def error(message: => AnyRef) {
def error(message: => AnyRef): Unit = {
log(LOG_ERROR, message, null)
}

def error(message: => AnyRef, exception: => Throwable) {
def error(message: => AnyRef, exception: => Throwable): Unit = {
log(LOG_ERROR, message, exception)
}

def trace(message: => AnyRef) {
def trace(message: => AnyRef): Unit = {
log(LOG_DEBUG, message, null)
}

def trace(message: => AnyRef, exception: => Throwable) {
def trace(message: => AnyRef, exception: => Throwable): Unit = {
log(LOG_DEBUG, message, exception)
}

protected def log(level: Int, message: => AnyRef, exception: => Throwable) {
protected def log(level: Int, message: => AnyRef, exception: => Throwable): Unit = {
logService.log(level, message.toString, exception)
}
}
Loading