Skip to content

Commit ca6c1fc

Browse files
authored
Add more modules with Scala 3 support (#1591)
Add 7 more projects with Scala 3 support: - canvas - control - metrics - msgpack - json - rx - ulid
1 parent ea7fc56 commit ca6c1fc

File tree

10 files changed

+65
-27
lines changed

10 files changed

+65
-27
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ jobs:
5454
with:
5555
java-version: adopt@1.11
5656
- name: Scala 3.x test
57-
run: DOTTY=true ./sbt dottyTest/run
57+
# Only use a limited number of tests until AirSpec and DI can support Scala 3
58+
run: DOTTY=true ./sbt "projectDotty/compile; dottyTest/run"
5859
test_js:
5960
name: Scala.js / Scala 2.12
6061
runs-on: ubuntu-latest

airframe-codec/.jvm/src/main/scala/wvlet/airframe/codec/JavaStandardCodec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object JavaStandardCodec {
5656
override def unpack(u: Unpacker, v: MessageContext): Unit = {
5757
val name = u.unpackString
5858
enumTable.get(CName.toCanonicalName(name)) match {
59-
case Some(enum) => v.setObject(enum)
59+
case Some(javaEnum) => v.setObject(javaEnum)
6060
case _ =>
6161
v.setIncompatibleFormatException(this, s"${name} is not a value of ${enumType}")
6262
}

airframe-control/.jvm/src/main/scala/wvlet/airframe/control/Shell.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ object Shell extends LogSupport {
159159
*/
160160
def exec(cmdLine: String): Int = {
161161
val pb = prepareProcessBuilder(cmdLine, inheritIO = true)
162-
val exitCode = Process(pb).!(ProcessLogger { out: String => info(out) })
162+
val exitCode = Process(pb).!(ProcessLogger { (out: String) => info(out) })
163163
debug(s"exec command $cmdLine with exitCode:$exitCode")
164164
exitCode
165165
}
@@ -173,7 +173,7 @@ object Shell extends LogSupport {
173173

174174
def execRemote(hostname: String, cmdLine: String): Int = {
175175
val pb = prepareProcessBuilderFromSeq(Seq("ssh", hostname, quote(cmdLine)), inheritIO = true)
176-
val exitCode = Process(pb).!(ProcessLogger { out: String => info(out) })
176+
val exitCode = Process(pb).!(ProcessLogger { (out: String) => info(out) })
177177
debug(s"exec command $cmdLine with exitCode:$exitCode")
178178
exitCode
179179
}

airframe-control/src/main/scala/wvlet/airframe/control/CircuitBreaker.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ object CircuitBreaker extends LogSupport {
6565
default.withHealthCheckPolicy(HealthCheckPolicy.alwaysHealthy)
6666
}
6767

68-
private[control] def throwOpenException: CircuitBreakerContext => Unit = { ctx: CircuitBreakerContext =>
68+
private[control] def throwOpenException: CircuitBreakerContext => Unit = { (ctx: CircuitBreakerContext) =>
6969
throw CircuitBreakerOpenException(ctx)
7070
}
7171

72-
private[control] def reportStateChange = { ctx: CircuitBreakerContext =>
72+
private[control] def reportStateChange = { (ctx: CircuitBreakerContext) =>
7373
info(s"CircuitBreaker(name:${ctx.name}) is changed to ${ctx.state}")
7474
}
7575
}
@@ -284,15 +284,18 @@ case class CircuitBreaker(
284284
recoveryPolicy.recordSuccess
285285
val isDead = healthCheckPolicy.isMarkedDead
286286
currentState.get() match {
287-
case HALF_OPEN if (recoveryPolicy.canRecover) =>
287+
case HALF_OPEN if (recoveryPolicy.canRecover) => {
288288
// Probe request succeeds, so move to CLOSED state
289289
healthCheckPolicy.recovered
290290
close
291-
case CLOSED if isDead =>
291+
}
292+
case CLOSED if isDead => {
292293
open
293-
case OPEN if !isDead =>
294+
}
295+
case OPEN if !isDead => {
294296
// Service is not marked dead, so try proving at HALF_OPEN state
295297
halfOpen
298+
}
296299
case _ =>
297300
}
298301
}

airframe-control/src/main/scala/wvlet/airframe/control/ResultClass.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ object ResultClass {
4343
def retryableFailure(e: Throwable): Failed = Retry.retryableFailure(e)
4444
def nonRetryableFailure(e: Throwable): Failed = Retry.nonRetryableFailure(e)
4545

46-
def ALWAYS_SUCCEED: Any => ResultClass = { x: Any => Succeeded }
46+
def ALWAYS_SUCCEED: Any => ResultClass = { (x: Any) => Succeeded }
4747

48-
def ALWAYS_RETRY: Throwable => ResultClass.Failed = { e: Throwable => retryableFailure(e) }
48+
def ALWAYS_RETRY: Throwable => ResultClass.Failed = { (e: Throwable) => retryableFailure(e) }
4949
}

airframe-control/src/main/scala/wvlet/airframe/control/Retry.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ object Retry extends LogSupport {
9696

9797
case object NOT_STARTED extends Exception("Code is not executed")
9898

99-
private def REPORT_RETRY_COUNT: RetryContext => Unit = { ctx: RetryContext =>
99+
private def REPORT_RETRY_COUNT: RetryContext => Unit = { (ctx: RetryContext) =>
100100
warn(
101101
f"[${ctx.retryCount}/${ctx.maxRetry}] Execution failed: ${ctx.lastError.getMessage}. Retrying in ${ctx.nextWaitMillis / 1000.0}%.2f sec."
102102
)
103103
}
104104

105-
private def RETHROW_ALL: Throwable => ResultClass.Failed = { e: Throwable => throw e }
105+
private def RETHROW_ALL: Throwable => ResultClass.Failed = { (e: Throwable) => throw e }
106106

107107
private[control] val noExtraWait = ExtraWait()
108108

@@ -236,7 +236,7 @@ object Retry extends LogSupport {
236236
* Clear the default beforeRetry action
237237
*/
238238
def noRetryLogging: RetryContext = {
239-
this.copy(beforeRetryAction = { x: RetryContext => })
239+
this.copy(beforeRetryAction = { (x: RetryContext) => })
240240
}
241241

242242
/**
@@ -246,7 +246,7 @@ object Retry extends LogSupport {
246246
* @return
247247
*/
248248
def retryOn(errorClassifier: PartialFunction[Throwable, ResultClass.Failed]): RetryContext = {
249-
this.copy(errorClassifier = { e: Throwable => errorClassifier.applyOrElse(e, RETHROW_ALL) })
249+
this.copy(errorClassifier = { (e: Throwable) => errorClassifier.applyOrElse(e, RETHROW_ALL) })
250250
}
251251

252252
def run[A](body: => A): A = {
@@ -261,7 +261,10 @@ object Retry extends LogSupport {
261261
var result: Option[A] = None
262262
var retryContext: RetryContext = init(context)
263263

264-
do {
264+
var isFirst: Boolean = true
265+
266+
while (isFirst || (result.isEmpty && retryContext.canContinue)) {
267+
isFirst = false
265268
val ret = Try(body)
266269
val resultClass = ret match {
267270
case Success(x) =>
@@ -286,7 +289,7 @@ object Retry extends LogSupport {
286289
// Non-retryable error. Exit the loop by throwing the exception
287290
throw cause
288291
}
289-
} while (result.isEmpty && retryContext.canContinue)
292+
}
290293

291294
result match {
292295
case Some(a) =>

airframe-rx/src/main/scala/wvlet/airframe/rx/RxOption.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ trait RxOption[+A] extends Rx[Option[A]] {
4646
def transform[B](f: Option[A] => B): RxStream[B] = {
4747
MapOp(
4848
in,
49-
{ x: Option[A] =>
49+
{ (x: Option[A]) =>
5050
f(x)
5151
}
5252
)
@@ -60,7 +60,7 @@ trait RxOption[+A] extends Rx[Option[A]] {
6060
RxOptionOp[B](
6161
FlatMapOp(
6262
in,
63-
{ x: Option[A] =>
63+
{ (x: Option[A]) =>
6464
f(x)
6565
}
6666
)
@@ -71,7 +71,7 @@ trait RxOption[+A] extends Rx[Option[A]] {
7171
RxOptionOp[B](
7272
MapOp(
7373
in,
74-
{ x: Option[A] =>
74+
{ (x: Option[A]) =>
7575
f(x)
7676
}
7777
)

airframe-rx/src/main/scala/wvlet/airframe/rx/RxRunner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class RxRunner(
101101
val c2 = run(fm.input) {
102102
case OnNext(x) =>
103103
var toContinue: RxResult = RxResult.Continue
104-
Try(fm.f(x)) match {
104+
Try(fm.f.asInstanceOf[Function[Any, Rx[_]]](x)) match {
105105
case Success(rxb) =>
106106
// This code is necessary to properly cancel the effect if this operator is evaluated before
107107
c1.cancel

airframe-rx/src/main/scala/wvlet/airframe/rx/RxVar.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RxVar[A](private var currentValue: A) extends RxStream[A] with RxVarOps[A]
3131
override def get: A = currentValue
3232

3333
override def foreach[U](f: A => U): Cancelable = {
34-
val s = { ev: RxEvent =>
34+
val s = { (ev: RxEvent) =>
3535
ev match {
3636
case OnNext(v) =>
3737
f(v.asInstanceOf[A])
@@ -84,12 +84,12 @@ trait RxVarOps[A] {
8484
def foreach[U](f: A => U): Cancelable
8585
def :=(newValue: A): Unit = set(newValue)
8686
def set(newValue: A): Unit =
87-
update { x: A =>
87+
update { (x: A) =>
8888
newValue
8989
}
9090
def forceSet(newValue: A): Unit =
9191
update(
92-
{ x: A =>
92+
{ (x: A) =>
9393
newValue
9494
},
9595
force = true

build.sbt

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ val withDotty = SCALA_3_0 :: targetScalaVersions
1111
val AIRSPEC_VERSION = "21.4.0"
1212
val SCALACHECK_VERSION = "1.15.3"
1313
val MSGPACK_VERSION = "0.8.22"
14-
val SCALA_PARSER_COMBINATOR_VERSION = "1.1.2"
14+
val SCALA_PARSER_COMBINATOR_VERSION = "1.2.0-RC2"
1515
val SQLITE_JDBC_VERSION = "3.34.0"
1616
val SLF4J_VERSION = "1.7.30"
1717
val JS_JAVA_LOGGING_VERSION = "1.0.0"
@@ -246,7 +246,30 @@ lazy val projectDotty =
246246
noPublish,
247247
crossScalaVersions := Seq(SCALA_3_0)
248248
)
249-
.aggregate(logJVM, surfaceJVM)
249+
.aggregate(
250+
logJVM,
251+
surfaceJVM,
252+
canvas,
253+
controlJVM,
254+
// codec uses Scala reflection
255+
//codecJVM,
256+
//fluentd,
257+
//httpJVM,
258+
//// Finagle isn't supporting Scala 3
259+
//httpFinagle,
260+
//grpc,
261+
//jdbc,
262+
//jmx,
263+
//launcher,
264+
metricsJVM,
265+
msgpackJVM,
266+
jsonJVM,
267+
rxJVM,
268+
// rx-html uses Scala Macros
269+
//rxHtmlJVM,
270+
//sql,
271+
ulidJVM
272+
)
250273

251274
lazy val docs =
252275
project
@@ -468,6 +491,9 @@ lazy val ulid =
468491
name := "airframe-ulid",
469492
description := "ULID: Universally Unique Lexicographically Sortable Identifier"
470493
)
494+
.jsSettings(
495+
jsBuildSettings
496+
)
471497
.dependsOn(log % Test)
472498

473499
lazy val ulidJVM = ulid.jvm
@@ -883,7 +909,12 @@ lazy val rxHtml =
883909
.settings(
884910
name := "airframe-rx-html",
885911
description := "Reactive HTML elements for Scala and Scala.js",
886-
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
912+
libraryDependencies ++= {
913+
if (DOTTY)
914+
Seq.empty
915+
else
916+
Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided)
917+
}
887918
)
888919
.jsSettings(
889920
jsBuildSettings,

0 commit comments

Comments
 (0)