From 6f20a16d6771741aaa4e577df9dc1de4c48b37eb Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Fri, 2 Aug 2019 16:51:09 -0700 Subject: [PATCH] #475: Use Scala 2.13 compatible collection syntaxes (#572) * Use Scala 2.13 compatibile collection syntaxes * Enable existential types for Scala 2.11 --- .../canvas/OffHeapMemoryAllocator.scala | 2 +- .../wvlet/airframe/codec/JDBCCodec.scala | 7 +- .../airframe/codec/CollectionCodecTest.scala | 2 +- .../wvlet/airframe/codec/JDBCCodecTest.scala | 3 +- .../airframe/codec/PrimitiveCodecTest.scala | 2 +- .../airframe/codec/CollectionCodec.scala | 2 +- .../airframe/config/PropertiesConfig.scala | 2 +- .../wvlet/airframe/config/YamlReader.scala | 2 +- .../scala/wvlet/airframe/config/package.scala | 2 +- .../wvlet/airframe/control/Parallel.scala | 118 +++++++++--------- .../scala/wvlet/airframe/control/Shell.scala | 4 +- .../wvlet/airframe/control/ParallelTest.scala | 4 +- .../airframe/fluentd/FluentdLogger.scala | 2 +- .../wvlet/airframe/fluentd/MetricLogger.scala | 2 +- .../airframe/http/HttpClientException.scala | 1 + .../scala/wvlet/airframe/jmx/JMXMBean.scala | 2 +- .../scala/wvlet/airframe/jmx/JMXUtil.scala | 2 +- .../wvlet/airframe/launcher/Launcher.scala | 2 +- .../airframe/launcher/LauncherTest.scala | 2 +- .../src/main/scala/wvlet/log/Logger.scala | 2 +- .../main/scala/wvlet/log/io/StopWatch.scala | 2 +- .../wvlet/airframe/metrics/TimeWindow.scala | 2 +- .../airframe/msgpack/impl/PackerImpl.scala | 2 +- .../airframe/msgpack/impl/UnpackerImpl.scala | 2 +- .../airframe/msgpack/spi/RoundTripTest.scala | 4 +- .../airframe/msgpack/spi/ValueTest.scala | 1 + .../airframe/sql/parser/SQLInterpreter.scala | 2 +- .../wvlet/airframe/surface/package.scala | 2 +- .../surface/reflect/ObjectBuilder.scala | 2 +- .../reflect/ReflectSurfaceFactory.scala | 2 +- .../surface/reflect/TypeConverter.scala | 2 +- .../airframe/surface/reflect/PathTest.scala | 2 +- .../scala/wvlet/airframe/surface/Zero.scala | 2 +- .../wvlet/airframe/AirframeSession.scala | 2 +- .../main/scala/wvlet/airframe/package.scala | 2 +- .../wvlet/airframe/tracing/DIStats.scala | 2 +- build.sbt | 12 +- 37 files changed, 108 insertions(+), 102 deletions(-) diff --git a/airframe-canvas/src/main/scala/wvlet/airframe/canvas/OffHeapMemoryAllocator.scala b/airframe-canvas/src/main/scala/wvlet/airframe/canvas/OffHeapMemoryAllocator.scala index db4a5d15f9..f5ff542d12 100644 --- a/airframe-canvas/src/main/scala/wvlet/airframe/canvas/OffHeapMemoryAllocator.scala +++ b/airframe-canvas/src/main/scala/wvlet/airframe/canvas/OffHeapMemoryAllocator.scala @@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicLong import wvlet.log.LogSupport -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ private[canvas] case class MemoryRefHolder(ref: MemoryReference, size: Long) diff --git a/airframe-codec/.jvm/src/main/scala/wvlet/airframe/codec/JDBCCodec.scala b/airframe-codec/.jvm/src/main/scala/wvlet/airframe/codec/JDBCCodec.scala index af087b6bdf..ed53bbfb60 100644 --- a/airframe-codec/.jvm/src/main/scala/wvlet/airframe/codec/JDBCCodec.scala +++ b/airframe-codec/.jvm/src/main/scala/wvlet/airframe/codec/JDBCCodec.scala @@ -17,6 +17,7 @@ import java.sql.{ResultSet, Time, Timestamp, Types} import wvlet.airframe.codec.PrimitiveCodec._ import wvlet.airframe.msgpack.spi.{MessagePack, Packer, Unpacker, ValueType} import wvlet.log.LogSupport +import scala.collection.compat._ /** * @@ -45,7 +46,7 @@ object JDBCCodec extends LogSupport { /** * Encode the all ResultSet rows as JSON object values */ - def toJsonSeq: TraversableOnce[String] = { + def toJsonSeq: IterableOnce[String] = { mapMsgPackMapRows { msgpack => JSONCodec.toJson(msgpack) } @@ -93,14 +94,14 @@ object JDBCCodec extends LogSupport { /** * Create an interator for reading ResultSet as a sequence of MsgPack Map values */ - def mapMsgPackMapRows[U](f: Array[Byte] => U): TraversableOnce[U] = { + def mapMsgPackMapRows[U](f: Array[Byte] => U): IterableOnce[U] = { new RStoMsgPackIterator[U](f, packer = packRowAsMap(_)) } /** * Create an interator for reading ResultSet as a sequence of MsgPack array values */ - def mapMsgPackArrayRows[U](f: Array[Byte] => U): TraversableOnce[U] = { + def mapMsgPackArrayRows[U](f: Array[Byte] => U): IterableOnce[U] = { new RStoMsgPackIterator[U](f, packer = packRowAsArray(_)) } diff --git a/airframe-codec/.jvm/src/test/scala/wvlet/airframe/codec/CollectionCodecTest.scala b/airframe-codec/.jvm/src/test/scala/wvlet/airframe/codec/CollectionCodecTest.scala index 38c2a96f6e..b8654f007b 100644 --- a/airframe-codec/.jvm/src/test/scala/wvlet/airframe/codec/CollectionCodecTest.scala +++ b/airframe-codec/.jvm/src/test/scala/wvlet/airframe/codec/CollectionCodecTest.scala @@ -16,7 +16,7 @@ package wvlet.airframe.codec import wvlet.airframe.msgpack.spi.MessagePack import wvlet.airframe.surface.Surface -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ /** * diff --git a/airframe-codec/.jvm/src/test/scala/wvlet/airframe/codec/JDBCCodecTest.scala b/airframe-codec/.jvm/src/test/scala/wvlet/airframe/codec/JDBCCodecTest.scala index 76c6e5780c..7e7299fdd2 100644 --- a/airframe-codec/.jvm/src/test/scala/wvlet/airframe/codec/JDBCCodecTest.scala +++ b/airframe-codec/.jvm/src/test/scala/wvlet/airframe/codec/JDBCCodecTest.scala @@ -20,6 +20,7 @@ import wvlet.airframe.AirframeSpec import wvlet.airframe.codec.JDBCCodec._ import wvlet.airframe.msgpack.spi.MessagePack import wvlet.log.io.IOUtil.withResource +import scala.collection.compat._ /** * @@ -183,7 +184,7 @@ class JDBCCodecTest extends AirframeSpec { |(select * from (values (1, 'leo'), (2, 'yui'))) |select * from a order by id asc |""".stripMargin) { rs => - val jsonSeq = JDBCCodec(rs).toJsonSeq.toIndexedSeq + val jsonSeq = JDBCCodec(rs).toJsonSeq.iterator.toIndexedSeq jsonSeq(0) shouldBe """{"id":1,"name":"leo"}""" jsonSeq(1) shouldBe """{"id":2,"name":"yui"}""" } diff --git a/airframe-codec/.jvm/src/test/scala/wvlet/airframe/codec/PrimitiveCodecTest.scala b/airframe-codec/.jvm/src/test/scala/wvlet/airframe/codec/PrimitiveCodecTest.scala index 86347ba833..eb0813fccd 100644 --- a/airframe-codec/.jvm/src/test/scala/wvlet/airframe/codec/PrimitiveCodecTest.scala +++ b/airframe-codec/.jvm/src/test/scala/wvlet/airframe/codec/PrimitiveCodecTest.scala @@ -29,7 +29,7 @@ import wvlet.airframe.surface.{ArraySurface, GenericSurface, Surface} * */ class PrimitiveCodecTest extends CodecSpec with ScalaCheckDrivenPropertyChecks { - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ def roundTripTest[T](surface: Surface, dataType: DataType)(implicit impArb: Arbitrary[T]): Unit = { forAll { (v: T) => diff --git a/airframe-codec/src/main/scala/wvlet/airframe/codec/CollectionCodec.scala b/airframe-codec/src/main/scala/wvlet/airframe/codec/CollectionCodec.scala index 34dfffaaea..ddd4c32d63 100644 --- a/airframe-codec/src/main/scala/wvlet/airframe/codec/CollectionCodec.scala +++ b/airframe-codec/src/main/scala/wvlet/airframe/codec/CollectionCodec.scala @@ -19,7 +19,7 @@ import wvlet.airframe.json.JSONParseException import wvlet.airframe.msgpack.spi.{MessagePack, Packer, Unpacker, ValueType} import wvlet.airframe.surface.{Surface, Zero} -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.collection.mutable object CollectionCodec { diff --git a/airframe-config/src/main/scala/wvlet/airframe/config/PropertiesConfig.scala b/airframe-config/src/main/scala/wvlet/airframe/config/PropertiesConfig.scala index 7b7ecbddd0..2e69b66b4c 100644 --- a/airframe-config/src/main/scala/wvlet/airframe/config/PropertiesConfig.scala +++ b/airframe-config/src/main/scala/wvlet/airframe/config/PropertiesConfig.scala @@ -86,7 +86,7 @@ object PropertiesConfig extends LogSupport { def overrideWithProperties(config: Config, props: Properties, onUnusedProperties: Properties => Unit): Config = { val overrides: Seq[ConfigProperty] = { - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ val b = Seq.newBuilder[ConfigProperty] for ((k, v) <- props.asScala) yield { val key = configKeyOf(k) diff --git a/airframe-config/src/main/scala/wvlet/airframe/config/YamlReader.scala b/airframe-config/src/main/scala/wvlet/airframe/config/YamlReader.scala index 6c34c4b0b8..ff301d9346 100644 --- a/airframe-config/src/main/scala/wvlet/airframe/config/YamlReader.scala +++ b/airframe-config/src/main/scala/wvlet/airframe/config/YamlReader.scala @@ -25,7 +25,7 @@ import wvlet.log.io.IOUtil._ import wvlet.airframe.surface.Surface import wvlet.airframe.surface.reflect.ReflectTypeUtil -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.collection.immutable.ListMap import scala.reflect.runtime.{universe => ru} diff --git a/airframe-config/src/main/scala/wvlet/airframe/config/package.scala b/airframe-config/src/main/scala/wvlet/airframe/config/package.scala index 4ba669e926..1409b4ba03 100644 --- a/airframe-config/src/main/scala/wvlet/airframe/config/package.scala +++ b/airframe-config/src/main/scala/wvlet/airframe/config/package.scala @@ -115,7 +115,7 @@ package object config { def overrideConfigParamsWithProperties( props: Properties, onUnusedProperties: Properties => Unit = REPORT_UNUSED_PROPERTIES): Design = { - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ val m = for (key <- props.propertyNames().asScala) yield { key.toString -> props.get(key).asInstanceOf[Any] } diff --git a/airframe-control/src/main/scala/wvlet/airframe/control/Parallel.scala b/airframe-control/src/main/scala/wvlet/airframe/control/Parallel.scala index ec99578c74..3cc9f7ac46 100644 --- a/airframe-control/src/main/scala/wvlet/airframe/control/Parallel.scala +++ b/airframe-control/src/main/scala/wvlet/airframe/control/Parallel.scala @@ -57,9 +57,9 @@ object Parallel extends LogSupport { /** * Process all elements of the source by the given function then wait for the completion. * - * @param source Source collection + * @param source Source collection * @param parallelism Parallelism, the default value is a number of available processors - * @param f Function which processes each element of the source collection + * @param f Function which processes each element of the source collection * @return Collection of the results */ def run[T, R: ClassTag](source: Seq[T], parallelism: Int = Runtime.getRuntime.availableProcessors())( @@ -81,7 +81,7 @@ object Parallel extends LogSupport { try { // Process all elements of source - val it = source.zipWithIndex.toIterator + val it = source.zipWithIndex.iterator while (it.hasNext) { val worker = requestQueue.take() worker.message.set(it.next()) @@ -114,9 +114,9 @@ object Parallel extends LogSupport { * Process all elements of the source by the given function then don't wait completion. * The result is an iterator which is likely a stream which elements are pushed continuously. * - * @param source the source iterator + * @param source the source iterator * @param parallelism Parallelism, the default value is a number of available processors - * @param f Function which processes each element of the source collection + * @param f Function which processes each element of the source collection * @return Iterator of the results */ def iterate[T, R](source: Iterator[T], @@ -174,60 +174,60 @@ object Parallel extends LogSupport { new ResultIterator[R](resultQueue) } -// /** -// * Run the given function with each element of the source periodically and repeatedly. -// * Execution can be stopped by the returned Stoppable object. -// * -// * @param source Source collection -// * @param interval Interval of execution of an element -// * @param f Function which process each element of the source collection -// * @return Object to stop execution -// */ -// def repeat[T](source: Seq[T], interval: Duration, ticker: Ticker = Ticker.systemTicker)(f: T => Unit): Stoppable = { -// val requestQueue = new LinkedBlockingQueue[IndexedWorker[T, Unit]](source.size) -// val resultArray = new Array[Unit](source.size) -// val executor = Executors.newFixedThreadPool(source.size) -// val cancelable = new Stoppable(executor) -// -// Range(0, source.size).foreach { _ => -// val repeatedFunction = (arg: T) => { -// while (!cancelable.isStopped) { -// // Use nanotime to make it independent from the system clock time -// val startNano = ticker.read -// f(arg) -// val durationNanos = ticker.read - startNano -// val wait = math.max(0, interval.toMillis - TimeUnit.NANOSECONDS.toMillis(durationNanos)) -// try { -// Thread.sleep(wait) -// } catch { -// case _: InterruptedException => () -// } -// } -// } -// -// val worker = new IndexedWorker[T, Unit](requestQueue, resultArray, repeatedFunction) -// requestQueue.put(worker) -// } -// -// source.zipWithIndex.foreach { -// case (e, i) => -// val worker = requestQueue.take() -// worker.message.set(e, i) -// executor.execute(worker) -// } -// -// cancelable -// } -// -// class Stoppable(executor: ExecutorService) { -// private val cancelled = new AtomicBoolean(false) -// def isStopped: Boolean = cancelled.get() -// -// def stop: Unit = { -// executor.shutdownNow() -// cancelled.set(true) -// } -// } + // /** + // * Run the given function with each element of the source periodically and repeatedly. + // * Execution can be stopped by the returned Stoppable object. + // * + // * @param source Source collection + // * @param interval Interval of execution of an element + // * @param f Function which process each element of the source collection + // * @return Object to stop execution + // */ + // def repeat[T](source: Seq[T], interval: Duration, ticker: Ticker = Ticker.systemTicker)(f: T => Unit): Stoppable = { + // val requestQueue = new LinkedBlockingQueue[IndexedWorker[T, Unit]](source.size) + // val resultArray = new Array[Unit](source.size) + // val executor = Executors.newFixedThreadPool(source.size) + // val cancelable = new Stoppable(executor) + // + // Range(0, source.size).foreach { _ => + // val repeatedFunction = (arg: T) => { + // while (!cancelable.isStopped) { + // // Use nanotime to make it independent from the system clock time + // val startNano = ticker.read + // f(arg) + // val durationNanos = ticker.read - startNano + // val wait = math.max(0, interval.toMillis - TimeUnit.NANOSECONDS.toMillis(durationNanos)) + // try { + // Thread.sleep(wait) + // } catch { + // case _: InterruptedException => () + // } + // } + // } + // + // val worker = new IndexedWorker[T, Unit](requestQueue, resultArray, repeatedFunction) + // requestQueue.put(worker) + // } + // + // source.zipWithIndex.foreach { + // case (e, i) => + // val worker = requestQueue.take() + // worker.message.set(e, i) + // executor.execute(worker) + // } + // + // cancelable + // } + // + // class Stoppable(executor: ExecutorService) { + // private val cancelled = new AtomicBoolean(false) + // def isStopped: Boolean = cancelled.get() + // + // def stop: Unit = { + // executor.shutdownNow() + // cancelled.set(true) + // } + // } private[control] class Worker[T, R](executionId: String, workerId: String, diff --git a/airframe-control/src/main/scala/wvlet/airframe/control/Shell.scala b/airframe-control/src/main/scala/wvlet/airframe/control/Shell.scala index 4a247fcc86..a6fb8f4e2a 100644 --- a/airframe-control/src/main/scala/wvlet/airframe/control/Shell.scala +++ b/airframe-control/src/main/scala/wvlet/airframe/control/Shell.scala @@ -20,7 +20,7 @@ import wvlet.log.LogSupport import scala.collection.mutable.WeakHashMap import scala.sys.process.{Process, ProcessLogger} -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ /** * Launch UNIX (or cygwin) commands from Scala @@ -190,7 +190,7 @@ object Shell extends LogSupport { def prepareProcessBuilder(cmdLine: String, inheritIO: Boolean): ProcessBuilder = { trace(s"cmdLine: $cmdLine") val tokens = Array(Shell.getCommand("sh"), "-c", if (OS.isWindows) quote(cmdLine) else cmdLine) - prepareProcessBuilderFromSeq(tokens, inheritIO) + prepareProcessBuilderFromSeq(tokens.toIndexedSeq, inheritIO) } def prepareProcessBuilderFromSeq(tokens: Seq[String], inheritIO: Boolean): ProcessBuilder = { diff --git a/airframe-control/src/test/scala/wvlet/airframe/control/ParallelTest.scala b/airframe-control/src/test/scala/wvlet/airframe/control/ParallelTest.scala index 0cb3fb3f00..4c6de27657 100644 --- a/airframe-control/src/test/scala/wvlet/airframe/control/ParallelTest.scala +++ b/airframe-control/src/test/scala/wvlet/airframe/control/ParallelTest.scala @@ -55,7 +55,7 @@ class ParallelTest extends AirframeSpec { val source = Seq(1, 2, 3) val startTime = Array(Long.MaxValue, Long.MaxValue, Long.MaxValue) - val result = Parallel.iterate(source.toIterator, parallelism = 3) { i => + val result = Parallel.iterate(source.iterator, parallelism = 3) { i => startTime(i - 1) = System.currentTimeMillis() i * 2 } @@ -103,7 +103,7 @@ class ParallelTest extends AirframeSpec { val exception = new RuntimeException("failure") val result = Parallel - .iterate(source.toIterator, parallelism = 3) { i => + .iterate(source.iterator, parallelism = 3) { i => Try { if (i == 2) { throw exception diff --git a/airframe-fluentd/src/main/scala/wvlet/airframe/fluentd/FluentdLogger.scala b/airframe-fluentd/src/main/scala/wvlet/airframe/fluentd/FluentdLogger.scala index 83d6855889..5bd4af090a 100644 --- a/airframe-fluentd/src/main/scala/wvlet/airframe/fluentd/FluentdLogger.scala +++ b/airframe-fluentd/src/main/scala/wvlet/airframe/fluentd/FluentdLogger.scala @@ -57,7 +57,7 @@ class FluentdLogger(val tagPrefix: Option[String] = None, useExtendedEventTime: } private def toJavaMap(event: Map[String, Any]): java.util.Map[String, AnyRef] = { - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ (for ((k, v) <- event) yield { k -> v.asInstanceOf[AnyRef] }).asJava diff --git a/airframe-fluentd/src/main/scala/wvlet/airframe/fluentd/MetricLogger.scala b/airframe-fluentd/src/main/scala/wvlet/airframe/fluentd/MetricLogger.scala index 6e064ab14f..857122aa07 100644 --- a/airframe-fluentd/src/main/scala/wvlet/airframe/fluentd/MetricLogger.scala +++ b/airframe-fluentd/src/main/scala/wvlet/airframe/fluentd/MetricLogger.scala @@ -59,7 +59,7 @@ class MetricLoggerFactory(fluentdClient: MetricLogger, def getLoggerWithTagPrefix(tagPrefix: String): MetricLogger = fluentdClient.withTagPrefix(tagPrefix) - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ import scala.reflect.runtime.{universe => ru} private val loggerCache = new ConcurrentHashMap[Surface, TypedMetricLogger[_]]().asScala diff --git a/airframe-http/src/main/scala/wvlet/airframe/http/HttpClientException.scala b/airframe-http/src/main/scala/wvlet/airframe/http/HttpClientException.scala index fac84658e1..3c95f0f5ea 100644 --- a/airframe-http/src/main/scala/wvlet/airframe/http/HttpClientException.scala +++ b/airframe-http/src/main/scala/wvlet/airframe/http/HttpClientException.scala @@ -22,6 +22,7 @@ import wvlet.airframe.control.ResultClass import wvlet.airframe.control.ResultClass.{Failed, Succeeded, nonRetryableFailure, retryableFailure} import wvlet.airframe.control.Retry.RetryContext import wvlet.log.LogSupport +import scala.language.existentials /** * diff --git a/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXMBean.scala b/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXMBean.scala index 1a1b435883..f93b9321fa 100644 --- a/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXMBean.scala +++ b/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXMBean.scala @@ -49,7 +49,7 @@ case class JMXMBean(obj: AnyRef, mBeanInfo: MBeanInfo, attributes: Seq[MBeanPara override def setAttributes(attributes: AttributeList): AttributeList = { val l = new AttributeList(attributes.size()) - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ for (a <- attributes.asList().asScala) { l.add(setAttribute(a)) } diff --git a/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXUtil.scala b/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXUtil.scala index 032a73869b..1faaf804d4 100644 --- a/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXUtil.scala +++ b/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXUtil.scala @@ -68,7 +68,7 @@ object JMXUtil extends LogSupport { p.setProperty("com.sun.management.jmxremote.authenticate", "false") p.setProperty("com.sun.management.jmxremote.ssl", "false") - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ if (isAtLeastJava9) { // TODO Java9 support // Try { diff --git a/airframe-launcher/src/main/scala/wvlet/airframe/launcher/Launcher.scala b/airframe-launcher/src/main/scala/wvlet/airframe/launcher/Launcher.scala index 04d07cee52..685502427c 100755 --- a/airframe-launcher/src/main/scala/wvlet/airframe/launcher/Launcher.scala +++ b/airframe-launcher/src/main/scala/wvlet/airframe/launcher/Launcher.scala @@ -351,7 +351,7 @@ class CommandLauncher(private[launcher] val launcherInfo: LauncherInfo, val subCommandName = result.unusedArgument.head findSubCommand(subCommandName) match { case Some(subCommand) => - subCommand.execute(launcherConfig, nextStack, result.unusedArgument.tail, showHelpMessage) + subCommand.execute(launcherConfig, nextStack, result.unusedArgument.tail.toIndexedSeq, showHelpMessage) case None => throw new IllegalArgumentException(s"Unknown sub command: ${subCommandName}") } diff --git a/airframe-launcher/src/test/scala/wvlet/airframe/launcher/LauncherTest.scala b/airframe-launcher/src/test/scala/wvlet/airframe/launcher/LauncherTest.scala index 88a05c9231..0500699269 100755 --- a/airframe-launcher/src/test/scala/wvlet/airframe/launcher/LauncherTest.scala +++ b/airframe-launcher/src/test/scala/wvlet/airframe/launcher/LauncherTest.scala @@ -232,7 +232,7 @@ class LauncherTest extends AirframeSpec { f.arg should be(None) val f2 = Launcher.execute[OptArg]("hello") - f2.arg should be('defined) + f2.arg shouldBe defined f2.arg.get should be("hello") } diff --git a/airframe-log/shared/src/main/scala/wvlet/log/Logger.scala b/airframe-log/shared/src/main/scala/wvlet/log/Logger.scala index 34db09c25c..5f5f9b0497 100644 --- a/airframe-log/shared/src/main/scala/wvlet/log/Logger.scala +++ b/airframe-log/shared/src/main/scala/wvlet/log/Logger.scala @@ -175,7 +175,7 @@ object Logger { // Set a custom LogManager to show log messages even in shutdown hooks System.setProperty("java.util.logging.manager", "wvlet.log.AirframeLogManager") - import collection.JavaConverters._ + import scala.jdk.CollectionConverters._ private lazy val loggerCache = new ConcurrentHashMap[String, Logger].asScala diff --git a/airframe-log/shared/src/main/scala/wvlet/log/io/StopWatch.scala b/airframe-log/shared/src/main/scala/wvlet/log/io/StopWatch.scala index 9c31dfe7ba..b92122fcb5 100644 --- a/airframe-log/shared/src/main/scala/wvlet/log/io/StopWatch.scala +++ b/airframe-log/shared/src/main/scala/wvlet/log/io/StopWatch.scala @@ -90,7 +90,7 @@ import scala.collection.mutable.LinkedHashMap * @author leo */ trait Timer extends Serializable { - import collection.JavaConverters._ + import scala.jdk.CollectionConverters._ @transient private[this] val holder = new ThreadLocal[util.ArrayDeque[TimeReport]] { override def initialValue() = new util.ArrayDeque[TimeReport]() diff --git a/airframe-metrics/jvm/src/main/scala/wvlet/airframe/metrics/TimeWindow.scala b/airframe-metrics/jvm/src/main/scala/wvlet/airframe/metrics/TimeWindow.scala index d6f1f5d2e7..0e8f3431c6 100644 --- a/airframe-metrics/jvm/src/main/scala/wvlet/airframe/metrics/TimeWindow.scala +++ b/airframe-metrics/jvm/src/main/scala/wvlet/airframe/metrics/TimeWindow.scala @@ -112,7 +112,7 @@ case class TimeWindow(start: ZonedDateTime, end: ZonedDateTime) { object TimeWindow { def withTimeZone(zoneName: String): TimeWindowBuilder = { - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ // Add commonly used daylight saving times val idMap = ZoneId.SHORT_IDS.asScala ++ Map("PDT" -> "-07:00", "EDT" -> "-04:00", "CDT" -> "-05:00", "MDT" -> "-06:00") diff --git a/airframe-msgpack/.jvm/src/main/scala/wvlet/airframe/msgpack/impl/PackerImpl.scala b/airframe-msgpack/.jvm/src/main/scala/wvlet/airframe/msgpack/impl/PackerImpl.scala index 5e12aadea5..c56ede5b23 100644 --- a/airframe-msgpack/.jvm/src/main/scala/wvlet/airframe/msgpack/impl/PackerImpl.scala +++ b/airframe-msgpack/.jvm/src/main/scala/wvlet/airframe/msgpack/impl/PackerImpl.scala @@ -154,7 +154,7 @@ object PackerImpl { v8.ValueFactory.newExtension(-1, extBytes) } case ArrayValue(elems) => - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ val values = elems.map(x => toMsgPackV8Value(x)).toList.asJava v8.ValueFactory.newArray(values) case MapValue(entries) => diff --git a/airframe-msgpack/.jvm/src/main/scala/wvlet/airframe/msgpack/impl/UnpackerImpl.scala b/airframe-msgpack/.jvm/src/main/scala/wvlet/airframe/msgpack/impl/UnpackerImpl.scala index f064ec3b3b..5aa318e792 100644 --- a/airframe-msgpack/.jvm/src/main/scala/wvlet/airframe/msgpack/impl/UnpackerImpl.scala +++ b/airframe-msgpack/.jvm/src/main/scala/wvlet/airframe/msgpack/impl/UnpackerImpl.scala @@ -193,7 +193,7 @@ object UnpackerImpl { import org.msgpack.{value => v8} import wvlet.airframe.msgpack.spi.Value._ - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ def fromMsgPackV8Value(v: v8.Value): Value = { v match { diff --git a/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/RoundTripTest.scala b/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/RoundTripTest.scala index 5f67719f02..c6b3d993a4 100644 --- a/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/RoundTripTest.scala +++ b/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/RoundTripTest.scala @@ -186,12 +186,12 @@ class RoundTripTest extends AirframeSpec with ScalaCheckPropertyChecks { rawRoundtrip(null) { (cursor, v) => OffsetPacker.packNil(cursor) } { cursor => - OffsetUnpacker.unpackNil(_); null + OffsetUnpacker.unpackNil(cursor); null } rawRoundtrip(null) { (cursor, v) => OffsetPacker.packNil(cursor) } { cursor => - OffsetUnpacker.tryUnpackNil(_); null + OffsetUnpacker.tryUnpackNil(cursor); null } } diff --git a/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/ValueTest.scala b/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/ValueTest.scala index 15fcd13bc5..82a4e99eba 100644 --- a/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/ValueTest.scala +++ b/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/ValueTest.scala @@ -163,6 +163,7 @@ class ValueTest extends AirframeSpec with ScalaCheckPropertyChecks { def sanitize(s: String): Seq[String] = { s.replaceAll("""[\{\}\[\]\"]""", "") .split("[,:]") + .toIndexedSeq .sorted } sanitize(a) shouldBe sanitize(b) diff --git a/airframe-sql/src/main/scala/wvlet/airframe/sql/parser/SQLInterpreter.scala b/airframe-sql/src/main/scala/wvlet/airframe/sql/parser/SQLInterpreter.scala index f99280f36d..5f3929c8f8 100644 --- a/airframe-sql/src/main/scala/wvlet/airframe/sql/parser/SQLInterpreter.scala +++ b/airframe-sql/src/main/scala/wvlet/airframe/sql/parser/SQLInterpreter.scala @@ -32,7 +32,7 @@ object SQLInterpreter { class SQLInterpreter extends SqlBaseBaseVisitor[Any] with LogSupport { import SQLInterpreter._ - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ private val parserRules = SqlBaseParser.ruleNames.toList.asJava private var parameterPosition: Int = 0 diff --git a/airframe-surface/js/src/main/scala/wvlet/airframe/surface/package.scala b/airframe-surface/js/src/main/scala/wvlet/airframe/surface/package.scala index e39e9f185e..dbb31d8dae 100644 --- a/airframe-surface/js/src/main/scala/wvlet/airframe/surface/package.scala +++ b/airframe-surface/js/src/main/scala/wvlet/airframe/surface/package.scala @@ -15,7 +15,7 @@ package wvlet.airframe import java.util.concurrent.ConcurrentHashMap -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.collection.mutable /** diff --git a/airframe-surface/jvm/src/main/scala/wvlet/airframe/surface/reflect/ObjectBuilder.scala b/airframe-surface/jvm/src/main/scala/wvlet/airframe/surface/reflect/ObjectBuilder.scala index 3f9b63ff07..a2fd5e6944 100644 --- a/airframe-surface/jvm/src/main/scala/wvlet/airframe/surface/reflect/ObjectBuilder.scala +++ b/airframe-surface/jvm/src/main/scala/wvlet/airframe/surface/reflect/ObjectBuilder.scala @@ -18,7 +18,7 @@ import wvlet.airframe.surface._ import wvlet.airframe.surface.reflect.ReflectTypeUtil._ import wvlet.log.LogSupport -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.collection.mutable import scala.collection.mutable.ArrayBuffer import scala.language.existentials diff --git a/airframe-surface/jvm/src/main/scala/wvlet/airframe/surface/reflect/ReflectSurfaceFactory.scala b/airframe-surface/jvm/src/main/scala/wvlet/airframe/surface/reflect/ReflectSurfaceFactory.scala index f6bab84427..609082c32d 100644 --- a/airframe-surface/jvm/src/main/scala/wvlet/airframe/surface/reflect/ReflectSurfaceFactory.scala +++ b/airframe-surface/jvm/src/main/scala/wvlet/airframe/surface/reflect/ReflectSurfaceFactory.scala @@ -19,7 +19,7 @@ import java.util.concurrent.ConcurrentHashMap import wvlet.log.LogSupport import wvlet.airframe.surface._ -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.reflect.runtime.{universe => ru} /** diff --git a/airframe-surface/jvm/src/main/scala/wvlet/airframe/surface/reflect/TypeConverter.scala b/airframe-surface/jvm/src/main/scala/wvlet/airframe/surface/reflect/TypeConverter.scala index 5e61aa795e..8b6d1abf58 100644 --- a/airframe-surface/jvm/src/main/scala/wvlet/airframe/surface/reflect/TypeConverter.scala +++ b/airframe-surface/jvm/src/main/scala/wvlet/airframe/surface/reflect/TypeConverter.scala @@ -22,7 +22,7 @@ import wvlet.airframe.surface.{Primitive, Surface, Zero} import scala.collection.mutable import scala.reflect.ClassTag -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ /** * diff --git a/airframe-surface/jvm/src/test/scala/wvlet/airframe/surface/reflect/PathTest.scala b/airframe-surface/jvm/src/test/scala/wvlet/airframe/surface/reflect/PathTest.scala index d068374186..890393868c 100644 --- a/airframe-surface/jvm/src/test/scala/wvlet/airframe/surface/reflect/PathTest.scala +++ b/airframe-surface/jvm/src/test/scala/wvlet/airframe/surface/reflect/PathTest.scala @@ -36,7 +36,7 @@ class PathTest extends SurfaceSpec { p.isAbsolute should be(true) p.fullPath should be("/abs/path") val pp = p.parent - pp should be('defined) + pp shouldBe defined pp map { _.fullPath should be("/abs") } val p2 = Path("/abs/path") diff --git a/airframe-surface/shared/src/main/scala/wvlet/airframe/surface/Zero.scala b/airframe-surface/shared/src/main/scala/wvlet/airframe/surface/Zero.scala index 23c87077d2..8fee62eadd 100644 --- a/airframe-surface/shared/src/main/scala/wvlet/airframe/surface/Zero.scala +++ b/airframe-surface/shared/src/main/scala/wvlet/airframe/surface/Zero.scala @@ -25,7 +25,7 @@ import scala.reflect.ClassTag */ object Zero extends LogSupport { - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ private val preregisteredZeroInstance = new ConcurrentHashMap[Surface, Any]().asScala /** diff --git a/airframe/src/main/scala/wvlet/airframe/AirframeSession.scala b/airframe/src/main/scala/wvlet/airframe/AirframeSession.scala index 172e8cbac9..544615b2b9 100644 --- a/airframe/src/main/scala/wvlet/airframe/AirframeSession.scala +++ b/airframe/src/main/scala/wvlet/airframe/AirframeSession.scala @@ -21,7 +21,7 @@ import wvlet.airframe.surface.Surface import wvlet.airframe.tracing.{DIStats, DefaultTracer, Tracer} import wvlet.log.LogSupport -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.util.Try import scala.reflect.runtime.{universe => ru} diff --git a/airframe/src/main/scala/wvlet/airframe/package.scala b/airframe/src/main/scala/wvlet/airframe/package.scala index deb62fb9b3..a0b0f75a81 100644 --- a/airframe/src/main/scala/wvlet/airframe/package.scala +++ b/airframe/src/main/scala/wvlet/airframe/package.scala @@ -99,7 +99,7 @@ package object airframe extends LogSupport { // For internal use to hold caches of factories of trait with a session def registerTraitFactory[A]: Surface = macro registerTraitFactoryImpl[A] - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ val traitFactoryCache = new ConcurrentHashMap[Surface, Session => Any].asScala def getOrElseUpdateTraitFactoryCache(s: Surface, factory: Session => Any): Session => Any = { trace(s"Adding factory of ${s}") diff --git a/airframe/src/main/scala/wvlet/airframe/tracing/DIStats.scala b/airframe/src/main/scala/wvlet/airframe/tracing/DIStats.scala index 29f5160b2e..8e737a0fe6 100644 --- a/airframe/src/main/scala/wvlet/airframe/tracing/DIStats.scala +++ b/airframe/src/main/scala/wvlet/airframe/tracing/DIStats.scala @@ -20,7 +20,7 @@ import wvlet.airframe.surface.Surface import wvlet.airframe.{Design, Session} import wvlet.log.LogSupport -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ case class DIStatsReport( coverage: Double, diff --git a/build.sbt b/build.sbt index ad9d3a2e7e..d45c1cb05c 100644 --- a/build.sbt +++ b/build.sbt @@ -363,9 +363,10 @@ lazy val surface = name := "airframe-surface", description := "A library for extracting object structure surface", libraryDependencies ++= Seq( - "org.scala-lang" % "scala-reflect" % scalaVersion.value, - "org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided", - "org.scalatest" %%% "scalatest" % SCALATEST_VERSION % "test" + "org.scala-lang" % "scala-reflect" % scalaVersion.value, + "org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.1", + "org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided", + "org.scalatest" %%% "scalatest" % SCALATEST_VERSION % "test" ) ) .jvmSettings( @@ -451,8 +452,9 @@ lazy val log = name := "airframe-log", description := "Fancy logger for Scala", libraryDependencies ++= Seq( - "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided", - "org.scalatest" %%% "scalatest" % SCALATEST_VERSION % "test" + "org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.1", + "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided", + "org.scalatest" %%% "scalatest" % SCALATEST_VERSION % "test" ) ) .jvmSettings(