From 4173033497529cf7d0e114d1caf98c4532706b4a Mon Sep 17 00:00:00 2001 From: Timothy Perrett Date: Tue, 26 Apr 2016 22:51:04 -0700 Subject: [PATCH 1/5] support multiple versions of scalaz at the same time --- .travis.yml | 22 ++++++++++++++----- core/build.sbt | 6 +++-- core/src/main/scala/knobs/package.scala | 3 ++- .../knobs/compatibility.scala | 11 ++++++++++ .../knobs/compatibility.scala | 7 ++++++ .../test/scala/knobs/FileWatcherTest.scala | 3 ++- core/src/test/scala/knobs/Test.scala | 18 ++++++++------- project/common.scala | 14 +++++++++--- .../src/main/scala/knobs/Zookeeper.scala | 3 ++- 9 files changed, 66 insertions(+), 21 deletions(-) create mode 100644 core/src/main/scalaz-stream-0.7/knobs/compatibility.scala create mode 100644 core/src/main/scalaz-stream-0.8/knobs/compatibility.scala diff --git a/.travis.yml b/.travis.yml index 45177a4..ba91c52 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,20 @@ language: scala -scala: - - 2.10.5 - - 2.11.6 -jdk: - - oraclejdk8 + +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 diff --git a/core/build.sbt b/core/build.sbt index f7b4140..424fb6c 100644 --- a/core/build.sbt +++ b/core/build.sbt @@ -1,4 +1,6 @@ +import common.scalazStreamVersion + common.settings resolvers ++= Seq( @@ -7,6 +9,6 @@ resolvers ++= Seq( ) libraryDependencies ++= Seq( - "org.scalaz.stream" %% "scalaz-stream" % "0.7.3a", - "oncue.ermine" %% "ermine-parser" % "0.2.1-2" + "org.scalaz.stream" %% "scalaz-stream" % scalazStreamVersion.value, + "oncue.ermine" %% "ermine-parser" % "0.3.0" ) diff --git a/core/src/main/scala/knobs/package.scala b/core/src/main/scala/knobs/package.scala index 84719d0..acc7540 100644 --- a/core/src/main/scala/knobs/package.scala +++ b/core/src/main/scala/knobs/package.scala @@ -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])] @@ -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 = diff --git a/core/src/main/scalaz-stream-0.7/knobs/compatibility.scala b/core/src/main/scalaz-stream-0.7/knobs/compatibility.scala new file mode 100644 index 0000000..e2c93c7 --- /dev/null +++ b/core/src/main/scalaz-stream-0.7/knobs/compatibility.scala @@ -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 + } +} diff --git a/core/src/main/scalaz-stream-0.8/knobs/compatibility.scala b/core/src/main/scalaz-stream-0.8/knobs/compatibility.scala new file mode 100644 index 0000000..338825c --- /dev/null +++ b/core/src/main/scalaz-stream-0.8/knobs/compatibility.scala @@ -0,0 +1,7 @@ +package knobs + +import scalaz.concurrent.Task + +object compatibility { + // for source compatibility in both scalaz versions +} diff --git a/core/src/test/scala/knobs/FileWatcherTest.scala b/core/src/test/scala/knobs/FileWatcherTest.scala index 3ab266d..1d0e916 100644 --- a/core/src/test/scala/knobs/FileWatcherTest.scala +++ b/core/src/test/scala/knobs/FileWatcherTest.scala @@ -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") { @@ -47,6 +48,6 @@ object FileWatcherTests extends Properties("FileWatch") { _ <- Task.delay(latch.await) r <- ref.read } yield r == "\"bar\"" - prg.run + prg.unsafePerformSync } } diff --git a/core/src/test/scala/knobs/Test.scala b/core/src/test/scala/knobs/Test.scala index 174f1b7..3590737 100644 --- a/core/src/test/scala/knobs/Test.scala +++ b/core/src/test/scala/knobs/Test.scala @@ -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) @@ -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 } diff --git a/project/common.scala b/project/common.scala index 56ab7d4..977d0ff 100644 --- a/project/common.scala +++ b/project/common.scala @@ -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", @@ -88,4 +90,10 @@ object common { pomIncludeRepository := { _ => false }, publishArtifact in Test := false ) + + def customSettings = Seq( + // "0.8.1a" "0.7.3a" + scalazStreamVersion := sys.env.get("SCALAZ_STREAM_VERSION").getOrElse("0.7.3a"), + unmanagedSourceDirectories in Compile += (sourceDirectory in Compile).value / s"scalaz-stream-${scalazStreamVersion.value.take(3)}" + ) } diff --git a/zookeeper/src/main/scala/knobs/Zookeeper.scala b/zookeeper/src/main/scala/knobs/Zookeeper.scala index d95bac5..1f14b22 100644 --- a/zookeeper/src/main/scala/knobs/Zookeeper.scala +++ b/zookeeper/src/main/scala/knobs/Zookeeper.scala @@ -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"))) @@ -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)) } From a96902d263992d75d666d1e38dd84259525c2d38 Mon Sep 17 00:00:00 2001 From: Timothy Perrett Date: Tue, 26 Apr 2016 22:58:18 -0700 Subject: [PATCH 2/5] =?UTF-8?q?don=E2=80=99t=20forget=20to=20make=20the=20?= =?UTF-8?q?version=20of=20ermine=20dynamic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/build.sbt | 14 ++++++++++---- project/common.scala | 8 +++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/core/build.sbt b/core/build.sbt index 424fb6c..147f5fa 100644 --- a/core/build.sbt +++ b/core/build.sbt @@ -8,7 +8,13 @@ resolvers ++= Seq( "oncue.bintray" at "http://dl.bintray.com/oncue/releases" ) -libraryDependencies ++= Seq( - "org.scalaz.stream" %% "scalaz-stream" % scalazStreamVersion.value, - "oncue.ermine" %% "ermine-parser" % "0.3.0" -) +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 + ) +} diff --git a/project/common.scala b/project/common.scala index 977d0ff..8ded99a 100644 --- a/project/common.scala +++ b/project/common.scala @@ -93,7 +93,13 @@ object common { def customSettings = Seq( // "0.8.1a" "0.7.3a" - scalazStreamVersion := sys.env.get("SCALAZ_STREAM_VERSION").getOrElse("0.7.3a"), + scalazStreamVersion := { + if(sys.env.get("TRAVIS").nonEmpty){ + sys.env("SCALAZ_STREAM_VERSION") + } else { + "0.7.3a" + } + }, unmanagedSourceDirectories in Compile += (sourceDirectory in Compile).value / s"scalaz-stream-${scalazStreamVersion.value.take(3)}" ) } From 2532b29a6248c58ddcc92ceabecfc28c187949da Mon Sep 17 00:00:00 2001 From: Timothy Perrett Date: Tue, 26 Apr 2016 23:07:18 -0700 Subject: [PATCH 3/5] missed some test cases --- zookeeper/src/test/scala/knobs/ZookeeperTest.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zookeeper/src/test/scala/knobs/ZookeeperTest.scala b/zookeeper/src/test/scala/knobs/ZookeeperTest.scala index 5bcafa4..8ecb008 100644 --- a/zookeeper/src/test/scala/knobs/ZookeeperTest.scala +++ b/zookeeper/src/test/scala/knobs/ZookeeperTest.scala @@ -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") { @@ -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 @@ -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 From f2477c31b2510c419f7bf00f69db926b3851afbf Mon Sep 17 00:00:00 2001 From: Timothy Perrett Date: Tue, 26 Apr 2016 23:44:50 -0700 Subject: [PATCH 4/5] force travis to use GCE --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index ba91c52..c68637a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ language: scala +sudo: required + matrix: include: # scala 2.10 From 69b0c55ce6724e0778b164fd5aac14aa543f5795 Mon Sep 17 00:00:00 2001 From: Timothy Perrett Date: Wed, 27 Apr 2016 00:03:44 -0700 Subject: [PATCH 5/5] =?UTF-8?q?+=20bump=20version=20+=20use=20the=20idioma?= =?UTF-8?q?tic=20scalaz=20=E2=80=98a=E2=80=99=20suffix=20for=207.1=20scala?= =?UTF-8?q?z?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/common.scala | 11 ++++++++++- project/plugins.sbt | 2 ++ version.sbt | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/project/common.scala b/project/common.scala index 8ded99a..bff5867 100644 --- a/project/common.scala +++ b/project/common.scala @@ -100,6 +100,15 @@ object common { "0.7.3a" } }, - unmanagedSourceDirectories in Compile += (sourceDirectory in Compile).value / s"scalaz-stream-${scalazStreamVersion.value.take(3)}" + 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 + } ) } diff --git a/project/plugins.sbt b/project/plugins.sbt index fb83715..3a7ed36 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -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" diff --git a/version.sbt b/version.sbt index e259ae6..34e1d3b 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version in ThisBuild := "3.3.5-SNAPSHOT" +version in ThisBuild := "3.6.0-SNAPSHOT"