diff --git a/framework/project/Build.scala b/framework/project/Build.scala index 9240909478c..92277d1a668 100644 --- a/framework/project/Build.scala +++ b/framework/project/Build.scala @@ -67,6 +67,11 @@ 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"), @@ -74,8 +79,8 @@ object PlayBuild extends Build { 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"), @@ -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 ( @@ -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") } } @@ -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", @@ -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") @@ -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") @@ -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" @@ -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") @@ -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" @@ -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 diff --git a/framework/src/play/src/main/scala/play/core/router/Router.scala b/framework/src/play/src/main/scala/play/core/router/Router.scala index aad1a4dbfe6..9f9299a1764 100644 --- a/framework/src/play/src/main/scala/play/core/router/Router.scala +++ b/framework/src/play/src/main/scala/play/core/router/Router.scala @@ -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 diff --git a/framework/src/play/src/main/scala/play/core/system/ApplicationProvider.scala b/framework/src/play/src/main/scala/play/core/system/ApplicationProvider.scala index 51fb815fdb7..6e577c08b35 100644 --- a/framework/src/play/src/main/scala/play/core/system/ApplicationProvider.scala +++ b/framework/src/play/src/main/scala/play/core/system/ApplicationProvider.scala @@ -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]")) } @@ -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 { @@ -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, """""") } diff --git a/framework/src/play/src/test/scala/play/data/FormSpec.scala b/framework/src/play/src/test/scala/play/data/FormSpec.scala index 730eebd5256..7c30856cf88 100644 --- a/framework/src/play/src/test/scala/play/data/FormSpec.scala +++ b/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._ @@ -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 { @@ -64,45 +113,40 @@ 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 } @@ -110,54 +154,14 @@ object FormSpec extends Specification { } "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 { diff --git a/framework/src/templates/src/test/scala/TemplateParserSpec.scala b/framework/src/templates/src/test/scala/TemplateParserSpec.scala index c71942381f6..ed184696ef6 100644 --- a/framework/src/templates/src/test/scala/TemplateParserSpec.scala +++ b/framework/src/templates/src/test/scala/TemplateParserSpec.scala @@ -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) = { diff --git a/framework/test/integrationtest-scala/test/FormSpec.scala b/framework/test/integrationtest-scala/test/FormSpec.scala index 28c36ac192e..420da888763 100644 --- a/framework/test/integrationtest-scala/test/FormSpec.scala +++ b/framework/test/integrationtest-scala/test/FormSpec.scala @@ -1,6 +1,6 @@ package test -import org.specs2.mutable._ +import org.specs2.mutable.Specification import play.api.test._ import play.api.test.Helpers._ @@ -8,16 +8,19 @@ 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 {