Skip to content

Commit

Permalink
Support cask again
Browse files Browse the repository at this point in the history
  • Loading branch information
lolgab committed Aug 22, 2024
1 parent 7d123c9 commit a488182
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.11
0.11.12
62 changes: 31 additions & 31 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import $ivy.`com.lihaoyi::mill-contrib-buildinfo:`
import $ivy.`com.github.lolgab::mill-mima::0.1.0`

import mill._, mill.scalalib._, mill.scalanativelib._, mill.scalanativelib.api._
import mill.scalalib.api.ZincWorkerUtil.isScala3
import mill.scalalib.publish._
import com.goyeau.mill.scalafix.ScalafixModule
import io.kipp.mill.ci.release.CiReleaseModule
Expand Down Expand Up @@ -41,8 +40,7 @@ object Common {
def crossScalaVersion: String

def scalacOptions = super.scalacOptions() ++
Seq("-deprecation") ++
(if (isScala3(crossScalaVersion)) Seq() else Seq("-Ywarn-unused"))
Seq("-deprecation")
}
trait SharedNative extends Shared with ScalaNativeModule {
def scalaNativeVersion = versions.Versions.scalaNative
Expand Down Expand Up @@ -165,24 +163,26 @@ def caskSources = T {
os.proc("git", "apply", T.workspace / "cask.patch").call(cwd = dest / "cask")
PathRef(dest)
}
// object `snunit-cask` extends Cross[SNUnitCaskModule](scalaVersions)
// trait SNUnitCaskModule extends Common.Cross with Publish {
// override def generatedSources = T {
// val cask = caskSources().path / "cask"
// val util = cask / "util"
// val scala2 = cask / "src-2"
// val scala3 = cask / "src-3"
// val scalaVersionSpecific = if (isScala3(crossScalaVersion)) scala3 else scala2
// Seq(cask / "src", util / "src", scalaVersionSpecific).map(PathRef(_))
// }
// def moduleDeps = Seq(`snunit-undertow`(crossScalaVersion))
// def ivyDeps = super.ivyDeps() ++ Agg(
// upickle,
// ivy"com.lihaoyi::castor::${Versions.castor}",
// ivy"org.ekrich::sjavatime::${Versions.sjavatime}",
// ivy"com.lihaoyi::pprint::${Versions.pprint}"
// )
// }
def castorSources = T {
val dest = T.dest
os.proc("git", "clone", "--branch", Versions.castor, "--depth", "1", "https://github.com/com-lihaoyi/castor", dest)
.call()
PathRef(dest)
}
object `snunit-cask` extends Cross[SNUnitCaskModule](scalaVersions)
trait SNUnitCaskModule extends Common.Cross with Publish {
override def generatedSources = T {
val cask = caskSources().path / "cask"
val castor = castorSources().path / "castor"
Seq(cask / "src", cask / "util" / "src", cask / "src-3", castor / "src", castor / "src-js-native").map(PathRef(_))
}
def moduleDeps = Seq(`snunit-undertow`(crossScalaVersion))
def ivyDeps = super.ivyDeps() ++ Agg(
upickle,
ivy"io.github.cquiroz::scala-java-time::${Versions.scalaJavaTime}",
ivy"com.lihaoyi::pprint::${Versions.pprint}"
)
}

object integration extends ScalaModule {
object tests extends Module {
Expand All @@ -204,16 +204,16 @@ object integration extends ScalaModule {
def ivyDeps = super.ivyDeps() ++ Agg(undertow)
}
}
// object `cask-helloworld` extends CrossPlatform {
// object jvm extends CrossPlatformScalaModule with Common.Scala3OnlyJvm {
// def ivyDeps = super.ivyDeps() ++ Agg(
// ivy"com.lihaoyi::cask:${Versions.cask}"
// )
// }
// object native extends CrossPlatformScalaModule with Common.Scala3Only {
// def moduleDeps = Seq(`snunit-cask`(crossScalaVersion))
// }
// }
object `cask-helloworld` extends CrossPlatform {
object jvm extends CrossPlatformScalaModule with Common.Scala3OnlyJvm {
def ivyDeps = super.ivyDeps() ++ Agg(
ivy"com.lihaoyi::cask:${Versions.cask}"
)
}
object native extends CrossPlatformScalaModule with Common.Scala3Only {
def moduleDeps = Seq(`snunit-cask`(crossScalaVersion))
}
}
object `tapir-helloworld` extends Common.Scala3Only {
override def moduleDeps = Seq(`snunit-tapir`(crossScalaVersion))
}
Expand Down
51 changes: 26 additions & 25 deletions cask.patch
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ index 71f4bb4..ab833e1 100644
.flatMap(_.asScala)
.flatMap(_.split(", "))
diff --git a/cask/src/cask/endpoints/JsonEndpoint.scala b/cask/src/cask/endpoints/JsonEndpoint.scala
index fbab2fa..8218adc 100644
index 50591a9..9d8c5b4 100644
--- a/cask/src/cask/endpoints/JsonEndpoint.scala
+++ b/cask/src/cask/endpoints/JsonEndpoint.scala
@@ -51,7 +51,7 @@ class postJson(val path: String, override val subpath: Boolean = false)
str <-
try {
val boas = new ByteArrayOutputStream()
- Util.transferTo(ctx.exchange.getInputStream, boas)
+ Util.transferTo(ctx.exchange.getInputStream(), boas)
Right(new String(boas.toByteArray))
}
@@ -52,7 +52,7 @@ abstract class postJsonBase(val path: String, override val subpath: Boolean = fa
def wrapFunction(ctx: Request, delegate: Delegate): Result[Response.Raw] = {
val obj = for{
json <-
- try Right(ujson.read(if (cacheBody) ctx.bytes else ctx.exchange.getInputStream))
+ try Right(ujson.read(if (cacheBody) ctx.bytes else ctx.exchange.getInputStream()))
catch{case e: Throwable => Left(cask.model.Response(
"Input text is invalid JSON: " + e + "\n" + Util.stackTraceString(e),
statusCode = 400
diff --git a/cask/src/cask/endpoints/WebEndpoints.scala b/cask/src/cask/endpoints/WebEndpoints.scala
index 9951628..afd46c5 100644
index b2b9731..b831155 100644
--- a/cask/src/cask/endpoints/WebEndpoints.scala
+++ b/cask/src/cask/endpoints/WebEndpoints.scala
@@ -18,7 +18,7 @@ trait WebEndpoint extends HttpEndpoint[Response.Raw, Seq[String]]{
Expand Down Expand Up @@ -80,10 +80,10 @@ index ea5bbd6..b59217f 100644
}
)
diff --git a/cask/src/cask/main/Main.scala b/cask/src/cask/main/Main.scala
index 9bf7132..e93f66e 100644
index 15c3656..5a0282c 100644
--- a/cask/src/cask/main/Main.scala
+++ b/cask/src/cask/main/Main.scala
@@ -62,10 +62,10 @@ abstract class Main{
@@ -63,10 +63,10 @@ abstract class Main{

def main(args: Array[String]): Unit = {
if (!verbose) Main.silenceJboss()
Expand All @@ -96,7 +96,7 @@ index 9bf7132..e93f66e 100644
server.start()
}

@@ -81,7 +81,7 @@ object Main{
@@ -82,7 +82,7 @@ object Main{
(implicit log: Logger) extends HttpHandler() {
def handleRequest(exchange: HttpServerExchange): Unit = try {
// println("Handling Request: " + exchange.getRequestPath)
Expand All @@ -105,7 +105,7 @@ index 9bf7132..e93f66e 100644
Tuple2(
"websocket",
(r: Any) =>
@@ -95,11 +95,11 @@ object Main{
@@ -96,12 +96,12 @@ object Main{
}
)
} else Tuple2(
Expand All @@ -114,12 +114,13 @@ index 9bf7132..e93f66e 100644
(r: Any) => Main.writeResponse(exchange, r.asInstanceOf[Response.Raw])
)

- dispatchTrie.lookup(Util.splitPath(exchange.getRequestPath).toList, Map()) match {
+ dispatchTrie.lookup(Util.splitPath(exchange.getRequestPath()).toList, Map()) match {
case None => Main.writeResponse(exchange, handleNotFound())
case Some((methodMap, routeBindings, remaining)) =>
methodMap.get(effectiveMethod) match {
@@ -164,24 +164,24 @@ object Main{
val decodedSegments = Util
- .splitPath(exchange.getRequestURI)
+ .splitPath(exchange.getRequestURI())
.iterator
.map(java.net.URLDecoder.decode(_, "UTF-8"))
.toList
@@ -176,24 +176,24 @@ object Main{

def writeResponse(exchange: HttpServerExchange, response: Response.Raw) = {
response.data.headers.foreach{case (k, v) =>
Expand Down Expand Up @@ -150,10 +151,10 @@ index 9bf7132..e93f66e 100644
})
}
diff --git a/cask/src/cask/model/Params.scala b/cask/src/cask/model/Params.scala
index 3d8d4dd..6fbae2b 100644
index 56a7135..710c31a 100644
--- a/cask/src/cask/model/Params.scala
+++ b/cask/src/cask/model/Params.scala
@@ -10,9 +10,9 @@ case class Request(exchange: HttpServerExchange, remainingPathSegments: Seq[Stri
@@ -13,9 +13,9 @@ case class Request(exchange: HttpServerExchange, remainingPathSegments: Seq[Stri
extends geny.ByteData with geny.Readable {
import collection.JavaConverters._
lazy val cookies: Map[String, Cookie] = {
Expand All @@ -165,7 +166,7 @@ index 3d8d4dd..6fbae2b 100644

/**
* Read all the bytes of the incoming request *with* caching
@@ -28,11 +28,11 @@ extends geny.ByteData with geny.Readable {
@@ -31,11 +31,11 @@ extends geny.ByteData with geny.Readable {
baos.toByteArray
}
lazy val queryParams: Map[String, collection.Seq[String]] = {
Expand All @@ -180,7 +181,7 @@ index 3d8d4dd..6fbae2b 100644
.toMap
}

@@ -42,18 +42,18 @@ object Cookie{
@@ -45,18 +45,18 @@ object Cookie{

def fromUndertow(from: io.undertow.server.handlers.Cookie): Cookie = {
Cookie(
Expand Down Expand Up @@ -211,7 +212,7 @@ index 3d8d4dd..6fbae2b 100644
)
}
def toUndertow(from: Cookie): io.undertow.server.handlers.Cookie = {
@@ -96,8 +96,8 @@ sealed trait FormEntry{
@@ -99,8 +99,8 @@ sealed trait FormEntry{
}
object FormEntry{
def fromUndertow(from: io.undertow.server.handlers.form.FormData.FormValue) = {
Expand Down
72 changes: 36 additions & 36 deletions integration/test/src/UndertowCaskTests.scala
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
// package snunit.test
package snunit.test

// import utest._
import utest._

// object UndertowCaskTests extends TestSuite {
// val tests = Tests {
// test("undertow-helloworld") {
// withDeployedExampleMultiplatform("undertow-helloworld") {
// runOnAllPlatforms { baseUrl =>
// val result = request.get(baseUrl).text()
// val expectedResult = "Hello World"
// assert(result == expectedResult)
// }
// }
// }
// test("cask-helloworld") {
// withDeployedExampleMultiplatform("cask-helloworld") {
// runOnAllPlatforms { baseUrl =>
// locally {
// val result = request.get(baseUrl).text()
// val expectedResult = "Hello World!"
// assert(result == expectedResult)
// }
object UndertowCaskTests extends TestSuite {
val tests = Tests {
test("undertow-helloworld") {
withDeployedExampleMultiplatform("undertow-helloworld") {
runOnAllPlatforms { baseUrl =>
val result = request.get(baseUrl).text()
val expectedResult = "Hello World"
assert(result == expectedResult)
}
}
}
test("cask-helloworld") {
withDeployedExampleMultiplatform("cask-helloworld") {
runOnAllPlatforms { baseUrl =>
locally {
val result = request.get(baseUrl).text()
val expectedResult = "Hello World!"
assert(result == expectedResult)
}

// locally {
// val result = request.get(uri"$baseUrl/hello?name=Lorenzo").text()
// val expectedResult = "Hello Lorenzo!"
// assert(result == expectedResult)
// }
locally {
val result = request.get(uri"$baseUrl/hello?name=Lorenzo").text()
val expectedResult = "Hello Lorenzo!"
assert(result == expectedResult)
}

// locally {
// val result = request.post(uri"$baseUrl/do-thing").body("hello").text()
// val expectedResult = "olleh"
// assert(result == expectedResult)
// }
// }
// }
// }
// }
// }
locally {
val result = request.post(uri"$baseUrl/do-thing").body("hello").text()
val expectedResult = "olleh"
assert(result == expectedResult)
}
}
}
}
}
}
10 changes: 5 additions & 5 deletions versions.sc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// This file is system-linked in sbt-plugin/project/Versions.scala
// It needs to be a valid Scala file so we can't use top level `val`s
object Versions {
val scalaNative = "0.5.4"
val upickle = "3.2.0"
val scalaNative = "0.5.5"
val upickle = "4.0.1"
val undertow = "2.3.10.Final"
val scala212 = "2.12.19"
val scala3 = "3.3.3"
val scala3 = "3.4.2"
val tapir = "1.11.1"
val cask = "0.9.4"
val catsEffect = "3.6-623178c"
Expand All @@ -15,7 +15,7 @@ object Versions {
val utest = "0.8.4"
val osLib = "0.9.2"
val sttp = "3.9.6"
val pprint = "0.8.1"
val pprint = "0.9.0"
val castor = "0.3.0"
val sjavatime = "1.1.9"
val scalaJavaTime = "2.6.0"
}

0 comments on commit a488182

Please sign in to comment.