Skip to content

Commit

Permalink
Add support for Scala 2.11 (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
mijicd authored Mar 24, 2020
1 parent c5dba61 commit 4e040e0
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 70 deletions.
90 changes: 67 additions & 23 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: &microsite
steps:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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-]+)*))?$/
8 changes: 4 additions & 4 deletions nio-core/src/main/scala/zio/nio/core/channels/Selector.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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
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)
Expand All @@ -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] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions nio/src/main/scala/zio/nio/channels/Selector.scala
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) {

Expand All @@ -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] =
Expand Down
2 changes: 1 addition & 1 deletion nio/src/test/scala/zio/nio/channels/SelectorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
75 changes: 41 additions & 34 deletions project/BuildHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -43,41 +41,50 @@ 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",
"-Ywarn-extra-implicit",
"-Ywarn-unused:_,imports",
"-Ywarn-unused:imports",
"-opt:l:inline",
"-opt-inline-from:<source>"
) ++ stdOptsUpto212
case _ =>
Seq("-Xexperimental") ++ stdOptsUpto212
"-opt-inline-from:<source>",
"-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
}
}
4 changes: 1 addition & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 4e040e0

Please sign in to comment.