Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

Support multiple versions of Scalaz Stream at the same time #29

Merged
merged 5 commits into from
Apr 27, 2016
Merged
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
24 changes: 19 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
language: scala
scala:
- 2.10.5
- 2.11.6
jdk:
- oraclejdk8

sudo: required

matrix:
include:
# scala 2.10
- jdk: oraclejdk8
scala: 2.10.5
env: SCALAZ_STREAM_VERSION=0.7.3a
- jdk: oraclejdk8
scala: 2.10.5
env: SCALAZ_STREAM_VERSION=0.8.1a
# scala 2.11
- jdk: oraclejdk8
scala: 2.11.8
env: SCALAZ_STREAM_VERSION=0.8.1a
- jdk: oraclejdk8
scala: 2.11.8
env: SCALAZ_STREAM_VERSION=0.7.3a

script: sbt ++$TRAVIS_SCALA_VERSION +test
16 changes: 12 additions & 4 deletions core/build.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@

import common.scalazStreamVersion

common.settings

resolvers ++= Seq(
"scalaz.bintray" at "http://dl.bintray.com/scalaz/releases",
"oncue.bintray" at "http://dl.bintray.com/oncue/releases"
)

libraryDependencies ++= Seq(
"org.scalaz.stream" %% "scalaz-stream" % "0.7.3a",
"oncue.ermine" %% "ermine-parser" % "0.2.1-2"
)
libraryDependencies ++= {
val ermineVersion =
if(scalazStreamVersion.value.startsWith("0.7")) "0.2.1-2"
else "0.3.0"

Seq(
"org.scalaz.stream" %% "scalaz-stream" % scalazStreamVersion.value,
"oncue.ermine" %% "ermine-parser" % ermineVersion
)
}
3 changes: 2 additions & 1 deletion core/src/main/scala/knobs/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import java.util.concurrent.ExecutorService

package object knobs {
import Resource._
import knobs.compatibility._

private [knobs] type Loaded = Map[KnobsResource, (List[Directive], Process[Task, Unit])]

Expand Down Expand Up @@ -111,7 +112,7 @@ package object knobs {
s <- IORef(Map[Pattern, List[ChangeHandler]]())
bc = BaseConfig(paths = p, cfgMap = m, subs = s)
ticks = mergeN(Process.emitAll(loaded.values.map(_._2).toSeq))
_ <- Task(ticks.evalMap(_ => bc.reload).run.runAsync(_.fold(_ => (), _ => ())))(pool)
_ <- Task(ticks.evalMap(_ => bc.reload).run.unsafePerformAsync(_.fold(_ => (), _ => ())))(pool)
} yield bc

private [knobs] def addDot(p: String): String =
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/scalaz-stream-0.7/knobs/compatibility.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package knobs

import scalaz.\/
import scalaz.concurrent.Task

object compatibility {
implicit class BedazledTask[A](task: Task[A]){ self =>
def unsafePerformAsync(g: (Throwable \/ A) => Unit): Unit = task.runAsync(g)
def unsafePerformSync: A = task.run
}
}
7 changes: 7 additions & 0 deletions core/src/main/scalaz-stream-0.8/knobs/compatibility.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package knobs

import scalaz.concurrent.Task

object compatibility {
// for source compatibility in both scalaz versions
}
3 changes: 2 additions & 1 deletion core/src/test/scala/knobs/FileWatcherTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import scala.concurrent.duration._
import scala.io.Source
import scalaz.concurrent.Task
import Resource._
import compatibility._

object FileWatcherTests extends Properties("FileWatch") {

Expand All @@ -47,6 +48,6 @@ object FileWatcherTests extends Properties("FileWatch") {
_ <- Task.delay(latch.await)
r <- ref.read
} yield r == "\"bar\""
prg.run
prg.unsafePerformSync
}
}
18 changes: 10 additions & 8 deletions core/src/test/scala/knobs/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import org.scalacheck._
import scalaz.concurrent.Task
import Prop._
import scala.concurrent.duration._
import compatibility._

object Test extends Properties("Knobs") {

def withLoad[A](files: List[KnobsResource])(
t: MutableConfig => Task[A]): Task[A] = for {
mb <- load(files)
Expand Down Expand Up @@ -104,21 +106,21 @@ object Test extends Properties("Knobs") {
case _ => false
}

property("load-pathological-config") = loadTest.run
property("load-pathological-config") = loadTest.unsafePerformSync

property("interpolation") = interpTest.run
property("interpolation") = interpTest.unsafePerformSync

property("import") = importTest.run
property("import") = importTest.unsafePerformSync

property("load-system-properties") = loadPropertiesTest.run
property("load-system-properties") = loadPropertiesTest.unsafePerformSync

property("load-fallback-chain") = fallbackTest.run
property("load-fallback-chain") = fallbackTest.unsafePerformSync

property("fallback-chain-errors") = fallbackErrorTest.run
property("fallback-chain-errors") = fallbackErrorTest.unsafePerformSync

property("load-uri") = uriTest.run
property("load-uri") = uriTest.unsafePerformSync

property("classloader") = classLoaderTest.run
property("classloader") = classLoaderTest.unsafePerformSync


}
29 changes: 26 additions & 3 deletions project/common.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ object common {
bintraySettings ++
releaseSettings ++
publishingSettings ++
testSettings
testSettings ++
customSettings

val scalaTestVersion = SettingKey[String]("scalatest version")
val scalaCheckVersion = SettingKey[String]("scalacheck version")
val scalaTestVersion = SettingKey[String]("scalatest version")
val scalaCheckVersion = SettingKey[String]("scalacheck version")
val scalazStreamVersion = SettingKey[String]("scalaz stream version")

def testSettings = Seq(
scalaTestVersion := "2.2.5",
Expand Down Expand Up @@ -88,4 +90,25 @@ object common {
pomIncludeRepository := { _ => false },
publishArtifact in Test := false
)

def customSettings = Seq(
// "0.8.1a" "0.7.3a"
scalazStreamVersion := {
if(sys.env.get("TRAVIS").nonEmpty){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't just check if SCALAZ_STREAM_VERSION is present? maybe it's useful for development.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because for development you can just do: set scalazStreamVersion := "0.8.1a" or whatever

sys.env("SCALAZ_STREAM_VERSION")
} else {
"0.7.3a"
}
},
unmanagedSourceDirectories in Compile += (sourceDirectory in Compile).value / s"scalaz-stream-${scalazStreamVersion.value.take(3)}",
artifactName := { (scalaVersion: ScalaVersion, module: ModuleID, artifact: Artifact) =>
val classifierStr = artifact.classifier.fold("")("-"+_)
val cross = CrossVersion(module.crossVersion, scalaVersion.full, scalaVersion.binary)
val base = CrossVersion.applyCross(artifact.name, cross)
val suffix =
if(scalazStreamVersion.value.startsWith("0.7")) "a"
else ""
base + "-" + module.revision + suffix + classifierStr + "." + artifact.extension
}
)
}
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.5.3")
addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.4.0")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.8")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")

scalacOptions += "-deprecation"
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "3.3.5-SNAPSHOT"
version in ThisBuild := "3.6.0-SNAPSHOT"
3 changes: 2 additions & 1 deletion zookeeper/src/main/scala/knobs/Zookeeper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import java.io.File
case class ZNode(client: CuratorFramework, path: Path)

object ZooKeeper {
import compatibility._

private val defaultCfg = List(Required(FileResource(new File("/usr/share/oncue/etc/zookeeper.cfg")) or
ClassPathResource("oncue/zookeeper.cfg")))
Expand Down Expand Up @@ -176,7 +177,7 @@ object ZooKeeper {
def unsafeFromResource(customConfig: List[KnobsResource]): (ResourceBox, Task[Unit]) = unsafe(customConfig)

protected def unsafe(config: List[KnobsResource] = defaultCfg): (ResourceBox, Task[Unit]) = {
val (box, c) = doZK(config).run
val (box, c) = doZK(config).unsafePerformSync
(box, Task.delay(c.close))
}

Expand Down
5 changes: 3 additions & 2 deletions zookeeper/src/test/scala/knobs/ZookeeperTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.apache.curator.framework.api._
import org.apache.curator.framework._
import org.apache.curator.retry._
import java.util.concurrent.CountDownLatch
import compatibility._

object ZooKeeperTests extends Properties("ZooKeeper") {

Expand All @@ -41,7 +42,7 @@ object ZooKeeperTests extends Properties("ZooKeeper") {
c.start
c.create.forPath("/knobs.cfg", "foo = 10\n".toArray.map(_.toByte))
val n = load(List(ZNode(c, "/knobs.cfg").required)).flatMap(cfg =>
cfg.require[Int]("foo")).run
cfg.require[Int]("foo")).unsafePerformSync
c.close
server.close
n == 10
Expand Down Expand Up @@ -70,7 +71,7 @@ object ZooKeeperTests extends Properties("ZooKeeper") {
}
n2 <- ref.read
} yield n1 == 10 && n2 == 20
val r = prg.run
val r = prg.unsafePerformSync
c.close
server.close
r
Expand Down