From 4e040e0b540985aa27e2d4e267f6e2ec8abaf863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dejan=20Miji=C4=87?= Date: Tue, 24 Mar 2020 18:47:33 +0100 Subject: [PATCH] Add support for Scala 2.11 (#176) --- .circleci/config.yml | 90 ++++++++++++++----- .../zio/nio/core/channels/Selector.scala | 8 +- .../zio/nio/core/channels/SelectorSpec.scala | 2 +- .../scala/zio/nio/channels/Selector.scala | 8 +- .../scala/zio/nio/channels/SelectorSpec.scala | 2 +- project/BuildHelper.scala | 75 +++++++++------- project/plugins.sbt | 4 +- 7 files changed, 119 insertions(+), 70 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c762c4a6..7c15e862 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,7 +1,10 @@ version: 2.1 +scala_211: &scala_211 + SCALA_VERSION: 2.11.12 + scala_212: &scala_212 - SCALA_VERSION: 2.12.8 + SCALA_VERSION: 2.12.10 scala_213: &scala_213 SCALA_VERSION: 2.13.1 @@ -58,6 +61,10 @@ install_nodejs: &install_nodejs nvm use node -v +filter_tags: &filter_tags + tags: + only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ + compile: &compile steps: - checkout @@ -105,10 +112,28 @@ release: &release name: Fetch git tags command: git fetch --tags - <<: *load_cache - - run: echo -n "${PGP_PUBLIC}" | base64 -d > /tmp/public.asc - - run: echo -n "${PGP_SECRET}" | base64 -d > /tmp/secret.asc - - run: echo "credentials += Credentials(\"Sonatype Nexus Repository Manager\", \"oss.sonatype.org\", \"$SONATYPE_USER\", \"$SONATYPE_PASSWORD\")" > ~/.sbt/1.0/sonatype.sbt - - run: ./sbt ++${SCALA_VERSION}! clean sonatypeBundleClean +publishSigned sonatypeBundleRelease + - run: + name: Write PGP public key + command: echo -n "${PGP_PUBLIC}" | base64 -di > /tmp/public.asc + - run: + name: Write PGP secret key + command: echo -n "${PGP_SECRET}" | base64 -di > /tmp/secret.asc + - run: + name: Write Sonatype credentials + command: echo "credentials += Credentials(\"Sonatype Nexus Repository Manager\", \"oss.sonatype.org\", \"$SONATYPE_USER\", \"$SONATYPE_PASSWORD\")" > ~/.sbt/1.0/sonatype.sbt + - run: + name: Release artifacts + command: | + mkdir -p $HOME/bin + sudo apt-get update && sudo apt-get -y install gnupg2 + echo pinentry-mode loopback >> ~/.gnupg/gpg.conf + echo allow-loopback-pinentry >> ~/.gnupg/gpg-agent.conf + chmod 600 ~/.gnupg/* + ln -s /usr/bin/gpg2 $HOME/bin/gpg + $HOME/bin/gpg --version + echo RELOADAGENT | gpg-connect-agent + echo $PGP_SECRET | base64 -di | gpg2 --import --no-tty --batch --yes + PATH=$HOME/bin:$PATH ./sbt ++${SCALA_VERSION}! ci-release microsite: µsite steps: @@ -153,6 +178,20 @@ jobs: - <<: *scala_212 - <<: *jdk_8 + test_211_jdk8: + <<: *test + <<: *machine_ubuntu + environment: + - <<: *scala_211 + - <<: *jdk_8 + + test_211_jdk11: + <<: *test + <<: *machine_ubuntu + environment: + - <<: *scala_211 + - <<: *jdk_11 + test_212_jdk8: <<: *test <<: *machine_ubuntu @@ -200,57 +239,62 @@ workflows: jobs: - lint: filters: - tags: - only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ + <<: *filter_tags - mdoc: requires: - lint filters: - tags: - only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ + <<: *filter_tags + - test_211_jdk8: + requires: + - lint + filters: + <<: *filter_tags + - test_211_jdk11: + requires: + - lint + filters: + <<: *filter_tags - test_212_jdk8: requires: - lint filters: - tags: - only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ + <<: *filter_tags - test_212_jdk11: requires: - lint filters: - tags: - only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ + <<: *filter_tags - test_213_jdk8: requires: - lint filters: - tags: - only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ + <<: *filter_tags - test_213_jdk11: requires: - lint filters: - tags: - only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ + <<: *filter_tags - release: - context: Sonatype + context: Sonatype2 requires: - mdoc + - test_211_jdk8 + - test_211_jdk11 - test_212_jdk8 - test_212_jdk11 - test_213_jdk8 - test_213_jdk11 filters: + <<: *filter_tags branches: - ignore: /.*/ - tags: - only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ + only: + - master - microsite: context: Website requires: - release filters: + <<: *filter_tags branches: ignore: /.*/ - tags: - only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ diff --git a/nio-core/src/main/scala/zio/nio/core/channels/Selector.scala b/nio-core/src/main/scala/zio/nio/core/channels/Selector.scala index 4a2662d3..8f9258f3 100644 --- a/nio-core/src/main/scala/zio/nio/core/channels/Selector.scala +++ b/nio-core/src/main/scala/zio/nio/core/channels/Selector.scala @@ -1,7 +1,7 @@ package zio.nio.core.channels import java.io.IOException -import java.nio.channels.{ ClosedSelectorException, Selector => JSelector } +import java.nio.channels.{ ClosedSelectorException, Selector => JSelector, SelectionKey => JSelectionKey } import zio.{ IO, UIO } import com.github.ghik.silencer.silent @@ -9,7 +9,7 @@ import zio.duration.Duration import zio.nio.core.channels.spi.SelectorProvider import zio.{ IO, UIO } -import scala.collection.JavaConverters +import scala.jdk.CollectionConverters._ class Selector(private[nio] val selector: JSelector) { final val isOpen: UIO[Boolean] = IO.effectTotal(selector.isOpen) @@ -20,13 +20,13 @@ class Selector(private[nio] val selector: JSelector) { @silent final val keys: IO[ClosedSelectorException, Set[SelectionKey]] = IO.effect(selector.keys()) - .map(keys => JavaConverters.asScalaSet(keys).toSet.map(new SelectionKey(_))) + .map(_.asScala.toSet[JSelectionKey].map(new SelectionKey(_))) .refineToOrDie[ClosedSelectorException] @silent final val selectedKeys: IO[ClosedSelectorException, Set[SelectionKey]] = IO.effect(selector.selectedKeys()) - .map(keys => JavaConverters.asScalaSet(keys).toSet.map(new SelectionKey(_))) + .map(_.asScala.toSet[JSelectionKey].map(new SelectionKey(_))) .refineToOrDie[ClosedSelectorException] final def removeKey(key: SelectionKey): IO[ClosedSelectorException, Unit] = diff --git a/nio-core/src/test/scala/zio/nio/core/channels/SelectorSpec.scala b/nio-core/src/test/scala/zio/nio/core/channels/SelectorSpec.scala index 44a7b055..6ed5b944 100644 --- a/nio-core/src/test/scala/zio/nio/core/channels/SelectorSpec.scala +++ b/nio-core/src/test/scala/zio/nio/core/channels/SelectorSpec.scala @@ -28,7 +28,7 @@ object SelectorSpec extends BaseSpec { array.takeWhile(_ != 10).map(_.toChar).mkString.trim def safeStatusCheck(statusCheck: IO[CancelledKeyException, Boolean]): IO[Nothing, Boolean] = - statusCheck.either.map(_.getOrElse(false)) + statusCheck.fold(_ => false, identity) def server(started: Promise[Nothing, SocketAddress]): ZIO[Clock, Exception, Unit] = { def serverLoop( diff --git a/nio/src/main/scala/zio/nio/channels/Selector.scala b/nio/src/main/scala/zio/nio/channels/Selector.scala index 562d574d..91ab8538 100644 --- a/nio/src/main/scala/zio/nio/channels/Selector.scala +++ b/nio/src/main/scala/zio/nio/channels/Selector.scala @@ -1,7 +1,7 @@ package zio.nio.channels import java.io.IOException -import java.nio.channels.{ ClosedSelectorException, Selector => JSelector } +import java.nio.channels.{ ClosedSelectorException, Selector => JSelector, SelectionKey => JSelectionKey } import zio.{ IO, Managed, UIO } import com.github.ghik.silencer.silent @@ -10,7 +10,7 @@ import zio.nio.channels.spi.SelectorProvider import zio.nio.core.channels.SelectionKey import zio.{ IO, Managed, UIO } -import scala.collection.JavaConverters +import scala.jdk.CollectionConverters._ class Selector(private[nio] val selector: JSelector) { @@ -20,13 +20,13 @@ class Selector(private[nio] val selector: JSelector) { @silent final val keys: IO[ClosedSelectorException, Set[SelectionKey]] = IO.effect(selector.keys()) - .map(keys => JavaConverters.asScalaSet(keys).toSet.map(new SelectionKey(_))) + .map(_.asScala.toSet[JSelectionKey].map(new SelectionKey(_))) .refineToOrDie[ClosedSelectorException] @silent final val selectedKeys: IO[ClosedSelectorException, Set[SelectionKey]] = IO.effect(selector.selectedKeys()) - .map(keys => JavaConverters.asScalaSet(keys).toSet.map(new SelectionKey(_))) + .map(_.asScala.toSet[JSelectionKey].map(new SelectionKey(_))) .refineToOrDie[ClosedSelectorException] final def removeKey(key: SelectionKey): IO[ClosedSelectorException, Unit] = diff --git a/nio/src/test/scala/zio/nio/channels/SelectorSpec.scala b/nio/src/test/scala/zio/nio/channels/SelectorSpec.scala index 6167ff8a..1b0e3099 100644 --- a/nio/src/test/scala/zio/nio/channels/SelectorSpec.scala +++ b/nio/src/test/scala/zio/nio/channels/SelectorSpec.scala @@ -29,7 +29,7 @@ object SelectorSpec extends BaseSpec { array.takeWhile(_ != 10).map(_.toChar).mkString.trim def safeStatusCheck(statusCheck: IO[CancelledKeyException, Boolean]): IO[Nothing, Boolean] = - statusCheck.either.map(_.getOrElse(false)) + statusCheck.fold(_ => false, identity) def server(started: Promise[Nothing, SocketAddress]): ZIO[Clock, Exception, Unit] = { def serverLoop( diff --git a/project/BuildHelper.scala b/project/BuildHelper.scala index aab73471..392485de 100644 --- a/project/BuildHelper.scala +++ b/project/BuildHelper.scala @@ -6,24 +6,22 @@ object BuildHelper { def stdSettings(prjName: String) = Seq( name := s"$prjName", scalacOptions := stdOptions, - crossScalaVersions := Seq(Scala212, Scala213), + crossScalaVersions := Seq(Scala211, Scala212, Scala213), scalaVersion in ThisBuild := Scala212, scalacOptions := stdOptions ++ extraOptions(scalaVersion.value), libraryDependencies ++= Seq( - ("com.github.ghik" % "silencer-lib" % SilencerVersion % Provided) - .cross(CrossVersion.full), - compilerPlugin(("com.github.ghik" % "silencer-plugin" % SilencerVersion).cross(CrossVersion.full)), - compilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3") + ("com.github.ghik" % "silencer-lib" % "1.4.4" % Provided).cross(CrossVersion.full), + compilerPlugin(("com.github.ghik" % "silencer-plugin" % "1.4.4").cross(CrossVersion.full)) ), incOptions ~= (_.withLogRecompileOnMacro(false)) ) val ZioCoreVersion = "1.0.0-RC18-2" - private val SilencerVersion = "1.6.0" - private val Scala212 = "2.12.10" - private val Scala213 = "2.13.1" + private val Scala211 = "2.11.12" + private val Scala212 = "2.12.10" + private val Scala213 = "2.13.1" private val stdOptions = Seq( "-encoding", @@ -43,31 +41,18 @@ object BuildHelper { "-Xfatal-warnings" ) - private val stdOpts213 = Seq( - "-Wunused:imports", - "-Wvalue-discard", - "-Wunused:patvars", - "-Wunused:privates", - "-Wunused:params", - "-Wvalue-discard", - "-Wdead-code" - ) - - private val stdOptsUpto212 = Seq( - "-Xfuture", - "-Ypartial-unification", - "-Ywarn-nullary-override", - "-Yno-adapted-args", - "-Ywarn-infer-any", - "-Ywarn-inaccessible", - "-Ywarn-nullary-unit", - "-Ywarn-unused-import" - ) - private def extraOptions(scalaVersion: String) = CrossVersion.partialVersion(scalaVersion) match { case Some((2, 13)) => - stdOpts213 + Seq( + "-Wunused:imports", + "-Wvalue-discard", + "-Wunused:patvars", + "-Wunused:privates", + "-Wunused:params", + "-Wvalue-discard", + "-Wdead-code" + ) case Some((2, 12)) => Seq( "-opt-warnings", @@ -75,9 +60,31 @@ object BuildHelper { "-Ywarn-unused:_,imports", "-Ywarn-unused:imports", "-opt:l:inline", - "-opt-inline-from:" - ) ++ stdOptsUpto212 - case _ => - Seq("-Xexperimental") ++ stdOptsUpto212 + "-opt-inline-from:", + "-Xfuture", + "-Ypartial-unification", + "-Ywarn-nullary-override", + "-Yno-adapted-args", + "-Ywarn-infer-any", + "-Ywarn-inaccessible", + "-Ywarn-nullary-unit", + "-Ywarn-unused-import" + ) + case Some((2, 11)) => + Seq( + "-Ypartial-unification", + "-Yno-adapted-args", + "-Ywarn-inaccessible", + "-Ywarn-infer-any", + "-Ywarn-nullary-override", + "-Ywarn-nullary-unit", + "-Xexperimental", + "-Ywarn-unused-import", + "-Xfuture", + "-Xsource:2.13", + "-Xmax-classfile-name", + "242" + ) + case _ => Seq.empty } } diff --git a/project/plugins.sbt b/project/plugins.sbt index 595943b7..7d1b7430 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,8 +1,6 @@ -addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.0.0") addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.3.5") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.2") addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.10") addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.1.5") -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2") -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8.1") addSbtPlugin("com.thoughtworks.sbt-api-mappings" % "sbt-api-mappings" % "3.0.0") +addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.2")