Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update to json4s 3.2.0 and scalaz 7.0.0-M9. Remove import Scalaz._ an…

…d use more granular imports
  • Loading branch information...
commit f647cf7ce0f9a3b29ff2fbc4398de89e4a14c775 2 parents e401425 + 6a09d35
@casualjim casualjim authored
View
3  commands/src/main/scala/org/scalatra/commands/CommandHandler.scala
@@ -5,7 +5,8 @@ import scala.util.control.Exception.allCatch
import grizzled.slf4j.Logger
import validation._
import scalaz._
-import Scalaz._
+import syntax.std.option._
+import syntax.validation._
@deprecated("This approach is not fully type-safe. The compiler can't enforce that the handle method returns a `S`. Please use the `>>` or `apply` method on a command.", "2.2.1")
trait CommandHandler {
View
4 commands/src/main/scala/org/scalatra/commands/binding.scala
@@ -5,10 +5,8 @@ import org.scalatra.util.conversion._
import validation._
import java.util.Date
import scalaz._
-import Scalaz._
+import syntax.std.option._
import org.joda.time.DateTime
-import java.util.concurrent.atomic.AtomicReference
-import scala.util.matching.Regex
class BindingException(message: String) extends ScalatraException(message)
View
11 commands/src/main/scala/org/scalatra/commands/executors.scala
@@ -1,7 +1,7 @@
package org.scalatra.commands
import scalaz._
-import Scalaz._
+import syntax.validation._
import org.scalatra.validation._
import grizzled.slf4j.Logger
import mojolly.inflector.InflectorImports._
@@ -55,8 +55,9 @@ abstract class BlockingExecutor[T <: Command, S](handle: T => ModelValidation[S]
res match {
case Succ(r)
+ def plur(count: Int) = if (count == 1) "failure" else "failures"
val resultLog = r.fold(
- { failures s"with ${failures.tail.size + 1} failures\n${failures.list}" },
+ { failures s"with ${failures.tail.size + 1} ${failures.list.size}\n${failures.list}" },
{ _ "successfully" })
logger.debug(s"Command [${cmd.getClass.getName}] executed $resultLog")
r
@@ -109,8 +110,9 @@ abstract class AsyncExecutor[T <: Command, S](handle: T => Future[ModelValidatio
res onSuccess {
case r
+ def plur(count: Int) = if (count == 1) "failure" else "failures"
val resultLog = r.fold(
- { failures s"with ${failures.list.size} ${"failure".plural(failures.list.size)}.\n${failures.list}" },
+ { failures s"with ${failures.list.size} ${plur(failures.list.size)}.\n${failures.list}" },
{ _ "successfully" })
logger.debug(s"Command [${cmd.getClass.getName}] executed $resultLog")
}
@@ -124,7 +126,8 @@ abstract class AsyncExecutor[T <: Command, S](handle: T => Future[ModelValidatio
val f = cmd.errors.map(_.validation) collect {
case Failure(e) e
}
- logger.debug(s"Command [${cmd.getClass.getName}] executed with ${f.size} ${"failure".plural(f.size)}.\n${f.toList}")
+ def failures = if (f.size == 1) "failure" else "failures"
+ logger.debug(s"Command [${cmd.getClass.getName}] executed with ${f.size} ${failures}.\n${f.toList}")
Future.successful(NonEmptyList(f.head, f.tail: _*).fail)
}
}
View
3  commands/src/main/scala/org/scalatra/commands/field.scala
@@ -4,7 +4,8 @@ package commands
import validation._
import util.conversion._
import scalaz._
-import Scalaz._
+import syntax.validation._
+import syntax.std.option._
import mojolly.inflector.InflectorImports._
import org.scalatra.util.RicherString._
View
4 commands/src/main/scala/org/scalatra/commands/package.scala
@@ -2,7 +2,7 @@ package org.scalatra
import validation.ValidationError
import scalaz._
-import Scalaz._
+import scalaz.syntax.validation._
import org.json4s.JsonAST.{JValue, JNothing}
import java.util.Date
import org.joda.time.{ DateTime, DateTimeZone }
@@ -11,7 +11,7 @@ package object commands extends DefaultValues {
type FieldValidation[T] = Validation[ValidationError, T]
- type ModelValidation[T] = ValidationNEL[ValidationError, T]
+ type ModelValidation[T] = ValidationNel[ValidationError, T]
type Validator[T] = FieldValidation[T] => FieldValidation[T]
View
29 core/src/main/scala/org/scalatra/ScalatraServlet.scala
@@ -7,26 +7,31 @@ import org.scalatra.util.RicherString._
import scala.util.control.Exception.catching
object ScalatraServlet {
+
+ val RequestPathKey = "org.scalatra.ScalatraServlet.requestPath"
import servlet.ServletApiImplicits._
- def requestPath(request: HttpServletRequest) = {
+ def requestPath(request: HttpServletRequest): String = {
require(request != null, "The request can't be null for getting the request path")
+ def startIndex(r: HttpServletRequest) =
+ r.getContextPath.blankOption.map(_.length).getOrElse(0) + r.getServletPath.blankOption.map(_.length).getOrElse(0)
def getRequestPath(r: HttpServletRequest) = {
val u = (catching(classOf[NullPointerException]) opt { r.getRequestURI } getOrElse "/")
- val u2 = (u.blankOption map { uri =>
- val uu = if (r.getContextPath.nonBlank) uri.substring(r.getContextPath.length) else uri
- if (r.getServletPath.nonBlank) uu.substring(r.getServletPath.length) else uu
- } flatMap(_.blankOption) getOrElse "/")
- val pos = u2.indexOf(';')
- val u3 = if (pos > -1) u2.substring(0, pos) else u2
- UriDecoder.firstStep(u3)
+ requestPath(u, startIndex(r))
}
- request.get("org.scalatra.ScalatraServlet.requestPath") map (_.toString) getOrElse {
- val requestPath = getRequestPath(request)
- request("org.scalatra.ScalatraServlet.requestPath") = requestPath
- requestPath
+ request.get(RequestPathKey) map (_.toString) getOrElse {
+ val rp = getRequestPath(request)
+ request(RequestPathKey) = rp
+ rp
}
}
+
+ def requestPath(uri: String, idx: Int): String = {
+ val u2 = (uri.blankOption map { _.substring(idx) } flatMap(_.blankOption) getOrElse "/")
+ val pos = u2.indexOf(';')
+ val u3 = if (pos > -1) u2.substring(0, pos) else u2
+ UriDecoder.firstStep(u3)
+ }
}
/**
View
12 project/build.scala
@@ -53,6 +53,7 @@ object ScalatraBuild extends Build {
settings = scalatraSettings ++ Seq(
libraryDependencies <++= scalaVersion(sv => Seq(
servletApi % "provided;test",
+ slf4jApi,
grizzledSlf4j(sv),
rl,
jUniversalChardet,
@@ -281,9 +282,10 @@ object ScalatraBuild extends Build {
lazy val scalajCollection = "org.scalaj" %% "scalaj-collection" % "1.2"
lazy val scalate: MM = sv => "org.fusesource.scalate" % scalateArtifact(sv) % scalateVersion(sv)
lazy val scalatest: MM = sv => "org.scalatest" %% "scalatest" % scalatestVersion(sv)
- lazy val scalaz = "org.scalaz" %% "scalaz-core" % "7.0.0-M8"
+ lazy val scalaz = "org.scalaz" %% "scalaz-core" % "7.0.0-M9"
lazy val servletApi = "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" artifacts (Artifact("javax.servlet", "jar", "jar"))
- lazy val slf4jSimple = "org.slf4j" % "slf4j-simple" % "1.7.2"
+ lazy val slf4jApi = "org.slf4j" % "slf4j-api" % "1.7.3"
+ lazy val slf4jSimple = "org.slf4j" % "slf4j-simple" % "1.7.3"
lazy val specs: MM = sv => "org.scala-tools.testing" % "specs" % specsVersion(sv) cross specsCross
lazy val specs2: MM = sv => "org.specs2" %% "specs2" % specs2Version(sv)
lazy val swaggerAnnotations = "com.wordnik" % "swagger-annotations" % swaggerVersion cross swaggerCross
@@ -306,9 +308,9 @@ object ScalatraBuild extends Build {
private val httpcomponentsVersion = "4.2.3"
- private val jettyVersion = "8.1.8.v20121106"
+ private val jettyVersion = "8.1.10.v20130312"
- private val json4sVersion = "3.1.0"
+ private val json4sVersion = "3.2.0"
private val scalateArtifact: String => String = {
case sv if sv startsWith "2.8." => "scalate-core"
@@ -346,7 +348,7 @@ object ScalatraBuild extends Build {
case sv if sv startsWith "2.8." => "1.5"
case "2.9.0-1" => "1.8.2"
case sv if sv startsWith "2.9." => "1.12.3"
- case _ => "1.13"
+ case _ => "1.14"
}
private val swaggerCross = CrossVersion.binaryMapped {
View
1  test/src/main/scala/org/scalatra/test/EmbeddedJettyContainer.scala
@@ -39,6 +39,7 @@ trait EmbeddedJettyContainer extends JettyContainer {
case Some(conn) =>
val host = Option(conn.getHost) getOrElse "localhost"
val port = conn.getLocalPort
+ require(port > 0, "The detected local port is < 1, that's not allowed")
"http://%s:%d".format(host, port)
case None =>
sys.error("can't calculate base URL: no connector")
Please sign in to comment.
Something went wrong with that request. Please try again.