Skip to content

Commit

Permalink
upgrading scala dependencies ahead of upgrading both scala and sbt
Browse files Browse the repository at this point in the history
- scala_stm, io, arm, specs are all updated to the latest versions that are crossbuilt against 2.9.2 (and potentially 2.10-M2)
- -Dscala.version can be used for crossbuilding against both 2.9.1 and 2.9.2
  • Loading branch information
ph2734 committed May 3, 2012
1 parent 4bdb227 commit 495e101
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 86 deletions.
40 changes: 23 additions & 17 deletions framework/project/Build.scala
Expand Up @@ -67,15 +67,20 @@ object PlayBuild extends Build {
)
).settings(com.typesafe.sbtscalariform.ScalariformPlugin.defaultScalariformSettings: _*).dependsOn(PlayProject)

def registerPlugin(module: ModuleID, localScalaVersion: String= buildScalaVersionForSbt) =
libraryDependencies <+= (sbtVersion) {
sbtVersion => Defaults.sbtPluginExtra(module, sbtVersion, localScalaVersion)
}

lazy val SbtPluginProject = Project(
"SBT-Plugin",
file("src/sbt-plugin"),
settings = buildSettings ++ Seq(
sbtPlugin := true,
publishMavenStyle := false,
libraryDependencies := sbtDependencies,
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-core" % "2.1.0-M2"),
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0-M1-TYPESAFE"),
registerPlugin("com.typesafe.sbteclipse" % "sbteclipse-core" % "2.1.0-M2"),
registerPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0-M1-TYPESAFE"),
unmanagedJars in Compile ++= sbtJars,
publishTo := Some(playIvyRepository),
scalacOptions ++= Seq("-encoding", "UTF-8", "-Xlint","-deprecation", "-unchecked"),
Expand Down Expand Up @@ -120,7 +125,8 @@ object PlayBuild extends Build {

val buildOrganization = "play"
val buildVersion = Option(System.getProperty("play.version")).filterNot(_.isEmpty).getOrElse("2.0-unknown")
val buildScalaVersion = "2.9.1"
val buildScalaVersion = Option(System.getProperty("scala.version")).getOrElse("2.9.1")
val buildScalaVersionForSbt = "2.9.1"
val buildSbtVersion = "0.11.2"

val buildSettings = Defaults.defaultSettings ++ Seq (
Expand All @@ -140,13 +146,13 @@ object PlayBuild extends Build {
def isJar(f:java.io.File) = f.getName.endsWith(".jar")

val sbtJars:Seq[java.io.File] = {
file("sbt/boot/scala-" + buildScalaVersion + "/org.scala-tools.sbt/sbt/" + buildSbtVersion).listFiles.filter(isJar) ++
file("sbt/boot/scala-" + buildScalaVersion + "/org.scala-tools.sbt/sbt/" + buildSbtVersion + "/xsbti").listFiles.filter(isJar) ++
Seq(file("sbt/boot/scala-" + buildScalaVersion + "/lib/jline.jar"))
file("sbt/boot/scala-" + buildScalaVersionForSbt + "/org.scala-tools.sbt/sbt/" + buildSbtVersion).listFiles.filter(isJar) ++
file("sbt/boot/scala-" + buildScalaVersionForSbt + "/org.scala-tools.sbt/sbt/" + buildSbtVersion + "/xsbti").listFiles.filter(isJar) ++
Seq(file("sbt/boot/scala-" + buildScalaVersionForSbt + "/lib/jline.jar"))
}

val compilerJar:java.io.File = {
file("sbt/boot/scala-" + buildScalaVersion + "/lib/scala-compiler.jar")
file("sbt/boot/scala-" + buildScalaVersionForSbt + "/lib/scala-compiler.jar")
}

}
Expand Down Expand Up @@ -176,7 +182,7 @@ object PlayBuild extends Build {
"org.slf4j" % "jcl-over-slf4j" % "1.6.4",
"ch.qos.logback" % "logback-core" % "1.0.0",
"ch.qos.logback" % "logback-classic" % "1.0.0",
"com.github.scala-incubator.io" %% "scala-io-file" % "0.2.0",
"com.github.scala-incubator.io" %% "scala-io-file" % "0.4.0",
"com.typesafe.akka" % "akka-actor" % "2.0.1",
"com.typesafe.akka" % "akka-slf4j" % "2.0.1",

Expand All @@ -192,7 +198,7 @@ object PlayBuild extends Build {

"org.hibernate.javax.persistence" % "hibernate-jpa-2.0-api" % "1.0.1.Final",
"com.h2database" % "h2" % "1.3.158",
"org.scala-tools" %% "scala-stm" % "0.4",
"org.scala-tools" %% "scala-stm" % "0.5",

("com.jolbox" % "bonecp" % "0.7.1.RELEASE" notTransitive())
.exclude("com.google.guava", "guava")
Expand Down Expand Up @@ -229,7 +235,7 @@ object PlayBuild extends Build {
,

"oauth.signpost" % "signpost-core" % "1.2.1.1",
"com.codahale" %% "jerkson" % "0.5.0",
"com.codahale" % "jerkson_2.9.1" % "0.5.0",

("org.reflections" % "reflections" % "0.9.6" notTransitive())
.exclude("com.google.guava", "guava")
Expand All @@ -252,7 +258,7 @@ object PlayBuild extends Build {

"net.sf.ehcache" % "ehcache-core" % "2.5.0",

"org.specs2" %% "specs2" % "1.7.1" % "test",
"org.specs2" %% "specs2" % "1.9" % "test",
"com.novocode" % "junit-interface" % "0.8" % "test",

"org.fluentlenium" % "fluentlenium-festassert" % "0.5.6" % "test"
Expand All @@ -273,7 +279,7 @@ object PlayBuild extends Build {
.exclude("junit", "junit")
,

"com.github.scala-incubator.io" %% "scala-io-file" % "0.2.0",
"com.github.scala-incubator.io" %% "scala-io-file" % "0.4.0",

("org.avaje" % "ebean" % "2.7.3" notTransitive())
.exclude("javax.persistence", "persistence-api")
Expand All @@ -285,19 +291,19 @@ object PlayBuild extends Build {
)

val consoleDependencies = Seq(
"com.github.scala-incubator.io" %% "scala-io-file" % "0.2.0"
"com.github.scala-incubator.io" %% "scala-io-file" % "0.4.0"
)

val templatesDependencies = Seq(
"com.github.scala-incubator.io" %% "scala-io-file" % "0.2.0",
"org.specs2" %% "specs2" % "1.7.1" % "test"
"com.github.scala-incubator.io" %% "scala-io-file" % "0.4.0",
"org.specs2" %% "specs2" % "1.9" % "test"
)

val anormDependencies = Seq(
)

val testDependencies = Seq(
"org.specs2" %% "specs2" % "1.7.1",
"org.specs2" %% "specs2" % "1.9",
"com.novocode" % "junit-interface" % "0.8",

"org.fluentlenium" % "fluentlenium-festassert" % "0.5.6"
Expand Down Expand Up @@ -369,7 +375,7 @@ object PlayBuild extends Build {
(file("src/play-test/src/main/scala") ** "*.scala").get ++
(file("src/play/src/main/scala/views") ** "*.scala").get ++
(file("src/anorm/src/main/scala") ** "*.scala").get ++
(file("src/play/target/scala-2.9.1/src_managed/main/views/html/helper") ** "*.scala").get
(file("src/play/target/scala-" + buildScalaVersion + "/src_managed/main/views/html/helper") ** "*.scala").get
new Scaladoc(10, cs.scalac)("Play " + BuildSettings.buildVersion + " Scala API", sourceFiles, classpath.map(_.data), file("../documentation/api/scala"), Nil, s.log)

// Javadoc
Expand Down
Expand Up @@ -87,7 +87,7 @@ object Router {
case class GeneratedSource(file: File) {

val lines = if (file.exists) Path(file).slurpString.split('\n').toList else Nil
val source = lines.headOption.filter(_.startsWith("// @SOURCE:")).map(m => Path(m.trim.drop(11)))
val source = lines.headOption.filter(_.startsWith("// @SOURCE:")).map(m => Path.fromString(m.trim.drop(11)))

def isGenerated: Boolean = source.isDefined

Expand Down
Expand Up @@ -206,7 +206,7 @@ class ReloadableApplication(sbtLink: SBTLink) extends ApplicationProvider {
documentationHome.flatMap { home =>
Option(new java.io.File(home, "manual/book/Book")).filter(_.exists)
}.map { book =>
val pages = (book: Path).slurpString.split('\n').toSeq.map(_.trim)
val pages = Path(book).slurpString.split('\n').toSeq.map(_.trim)
Ok(views.html.play20.book(pages))
}.getOrElse(NotFound("Resource not found [Book]"))
}
Expand Down Expand Up @@ -246,7 +246,7 @@ class ReloadableApplication(sbtLink: SBTLink) extends ApplicationProvider {
Some {

val pageWithSidebar = documentationHome.flatMap { home =>
(home: Path).descendants().find(_.name == page + ".md").map { pageSource =>
Path(home).descendants().find(_.name == page + ".md").map { pageSource =>

// Recursively search for Sidebar
lazy val findSideBar: (Option[Path] => Option[Path]) = _ match {
Expand Down Expand Up @@ -277,7 +277,7 @@ class ReloadableApplication(sbtLink: SBTLink) extends ApplicationProvider {
val link = image match {
case full if full.startsWith("http://") => full
case absolute if absolute.startsWith("/") => "resources/manual" + absolute
case relative => "resources/" + pageSource.parent.get.relativize(documentationHome.get).path + "/" + relative
case relative => "resources/" + pageSource.parent.get.relativize(Path(documentationHome.get)).path + "/" + relative
}
(link, """<img src="""" + link + """"/>""")
}
Expand Down
122 changes: 63 additions & 59 deletions framework/src/play/src/test/scala/play/data/FormSpec.scala
@@ -1,6 +1,6 @@
package play.data

import org.specs2.mutable._
import org.specs2.mutable.Specification
import play.mvc._
import play.mvc.Http.Context
import scala.collection.JavaConverters._
Expand Down Expand Up @@ -29,6 +29,55 @@ class DummyRequest(data: Map[String, Array[String]]) extends play.mvc.Http.Reque
setUsername("peter")
}

object ScalaForms {
import play.api.data.validation.Constraints._
import play.api.data._
import play.api.data.Forms._
import format.Formats._

case class User(name: String, age: Int)

val userForm = Form(
mapping(
"name" -> of[String].verifying(nonEmpty),
"age" -> of[Int].verifying(min(0), max(100))
)(User.apply)(User.unapply)
)

val loginForm = Form(
tuple(
"email" -> of[String],
"password" -> of[Int])
)

val helloForm = Form(
tuple(
"name" -> nonEmptyText,
"repeat" -> number(min = 1, max = 100),
"color" -> optional(text),
"still works" -> optional(text),
"1" -> optional(text),
"2" -> optional(text),
"3" -> optional(text),
"4" -> optional(text),
"5" -> optional(text),
"6" -> optional(text),
"7" -> optional(text),
"8" -> optional(text),
"9" -> optional(text),
"10" -> optional(text),
"11" -> optional(text),
"12" -> optional(text),
"13" -> optional(text),
"14" -> optional(text)
)
)

val form = Form(
"foo" -> Forms.text.verifying("first.digit", s => (s.headOption map {_ == '3'}) getOrElse false)
.transform[Int](Integer.parseInt _, _.toString).verifying("number.42", _ < 42)
)
}
object FormSpec extends Specification {

"A form" should {
Expand Down Expand Up @@ -64,100 +113,55 @@ object FormSpec extends Specification {
}

"apply constraints on wrapped mappings" in {
import play.api.data._
import play.api.data.Forms._

val form = Form(
"foo" -> text.verifying("first.digit", s => (s.headOption map {_ == '3'}) getOrElse false)
.transform[Int](Integer.parseInt _, _.toString).verifying("number.42", _ < 42)
)


"when it binds data" in {
val f1 = form.bind(Map("foo"->"0"))
val f1 = ScalaForms.form.bind(Map("foo"->"0"))
f1.errors.size must equalTo (1)
f1.errors.find(_.message == "first.digit") must beSome

val f2 = form.bind(Map("foo"->"3"))
val f2 = ScalaForms.form.bind(Map("foo"->"3"))
f2.errors.size must equalTo (0)

val f3 = form.bind(Map("foo"->"50"))
val f3 = ScalaForms.form.bind(Map("foo"->"50"))
f3.errors.size must equalTo (1) // Only one error because "number.42" can’t be applied since wrapped bind failed
f3.errors.find(_.message == "first.digit") must beSome

val f4 = form.bind(Map("foo"->"333"))
val f4 = ScalaForms.form.bind(Map("foo"->"333"))
f4.errors.size must equalTo (1)
f4.errors.find(_.message == "number.42") must beSome
}

"when it is filled with data" in {
val f1 = form.fillAndValidate(0)
val f1 = ScalaForms.form.fillAndValidate(0)
f1.errors.size must equalTo (1)
f1.errors.find(_.message == "first.digit") must beSome

val f2 = form.fillAndValidate(3)
val f2 = ScalaForms.form.fillAndValidate(3)
f2.errors.size must equalTo (0)

val f3 = form.fillAndValidate(50)
val f3 = ScalaForms.form.fillAndValidate(50)
f3.errors.size must equalTo (2)
f3.errors.find(_.message == "first.digit") must beSome
f3.errors.find(_.message == "number.42") must beSome

val f4 = form.fillAndValidate(333)
val f4 = ScalaForms.form.fillAndValidate(333)
f4.errors.size must equalTo (1)
f4.errors.find(_.message == "number.42") must beSome
}
}
}

"render form using field[Type] syntax" in {
import play.api.data.validation.Constraints._
import play.api.data._
import play.api.data.Forms._
import format.Formats._
case class User(name: String, age: Int)

val userForm = Form(
mapping(
"name" -> of[String].verifying(nonEmpty),
"age" -> of[Int].verifying(min(0), max(100))
)(User.apply)(User.unapply)
)
val loginForm = Form(
tuple(
"email" -> of[String],
"password" -> of[Int])
)

val anyData = Map("email" -> "bob@gmail.com", "password" -> "123")
loginForm.bind(anyData).get.toString must equalTo("(bob@gmail.com,123)")
ScalaForms.loginForm.bind(anyData).get.toString must equalTo("(bob@gmail.com,123)")
}

"render a form with max 18 fields" in {
import play.api.data._
import play.api.data.Forms._

val helloForm = Form(
tuple(
"name" -> nonEmptyText,
"repeat" -> number(min = 1, max = 100),
"color" -> optional(text),
"still works" -> optional(text),
"1" -> optional(text),
"2" -> optional(text),
"3" -> optional(text),
"4" -> optional(text),
"5" -> optional(text),
"6" -> optional(text),
"7" -> optional(text),
"8" -> optional(text),
"9" -> optional(text),
"10" -> optional(text),
"11" -> optional(text),
"12" -> optional(text),
"13" -> optional(text),
"14" -> optional(text)
)
)
helloForm.bind(Map("name" -> "foo", "repeat" -> "1")).get.toString must equalTo("(foo,1,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None)")

ScalaForms.helloForm.bind(Map("name" -> "foo", "repeat" -> "1")).get.toString must equalTo("(foo,1,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None)")
}

"render a from using java" in {
Expand Down
Expand Up @@ -13,7 +13,7 @@ object TemplateParserSpec extends Specification {
val parser = ScalaTemplateCompiler.templateParser

def get(templateName: String) = {
new CharSequenceReader(scalax.file.Path("src/templates/src/test/templates/" + templateName).slurpString)
new CharSequenceReader(scalax.file.Path.fromString("src/templates/src/test/templates/" + templateName).slurpString)
}

def parse(templateName: String) = {
Expand Down
13 changes: 8 additions & 5 deletions framework/test/integrationtest-scala/test/FormSpec.scala
@@ -1,23 +1,26 @@
package test

import org.specs2.mutable._
import org.specs2.mutable.Specification

import play.api.test._
import play.api.test.Helpers._

import play.api.data._
import play.api.data.Forms._

class FormSpec extends Specification {

val userForm = Form(
object Dummyform {
def provide = Form(
tuple(
"email" -> text,
"email" -> Forms.text,
"address" -> optional(
single("city" -> nonEmptyText)
)
)
)
}
class FormSpec extends Specification {

val userForm = Dummyform.provide

"the userForm" should {

Expand Down

0 comments on commit 495e101

Please sign in to comment.