Skip to content

Commit

Permalink
Cross compile for Scala 3 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
theon committed Sep 14, 2021
1 parent 47188d1 commit 4765b4e
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 107 deletions.
21 changes: 12 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import com.typesafe.tools.mima.plugin.MimaKeys.{mimaBinaryIssueFilters, mimaPrev

name := "scala-uri root"

ThisBuild / scalaVersion := "2.13.6"
ThisBuild / crossScalaVersions := Seq("2.12.14", scalaVersion.value)
ThisBuild / scalaVersion := "3.0.1"
ThisBuild / crossScalaVersions := Seq("2.12.14", "2.13.6", scalaVersion.value)
publish / skip := true // Do not publish the root project

val simulacrumScalafixVersion = "0.5.4"
Expand All @@ -25,7 +25,7 @@ val sharedSettings = Seq(
libraryDependencies ++= Seq(
"org.typelevel" %%% "simulacrum-scalafix-annotations" % simulacrumScalafixVersion,
"org.scalatest" %%% "scalatest" % "3.2.9" % Test,
"org.scalatestplus" %%% "scalacheck-1-14" % "3.2.2.0" % Test,
"org.scalatestplus" %%% "scalacheck-1-15" % "3.2.9.0" % Test,
"org.scalacheck" %%% "scalacheck" % "1.15.4" % Test,
"org.typelevel" %%% "cats-laws" % "2.6.1" % Test
),
Expand All @@ -36,16 +36,17 @@ val sharedSettings = Seq(
"utf8",
"-feature",
"-Xfatal-warnings",
"-language:higherKinds"
"-language:higherKinds,implicitConversions"
) ++ (
VersionNumber(scalaVersion.value) match {
case v if v.matchesSemVer(SemanticSelector(">=2.13")) => Seq("-Ymacro-annotations")
case v if v.matchesSemVer(SemanticSelector("=2.13")) => Seq("-Ymacro-annotations")
case v if v.matchesSemVer(SemanticSelector("<=2.12")) => Seq("-Ypartial-unification")
case _ => Nil
}
),
addCompilerPlugin(scalafixSemanticdb),
scalacOptions ++= Seq(s"-P:semanticdb:targetroot:${baseDirectory.value}/target/.semanticdb", "-Yrangepos"),
semanticdbEnabled := true,
// addCompilerPlugin(scalafixSemanticdb),
// scalacOptions ++= Seq(s"-P:semanticdb:targetroot:${baseDirectory.value}/target/.semanticdb", "-Yrangepos"),
Test / parallelExecution := false,
scalafmtOnCompile := true,
coverageExcludedPackages := "(io.lemonlabs.uri.inet.Trie.*|io.lemonlabs.uri.inet.PublicSuffixes.*|io.lemonlabs.uri.inet.PublicSuffixTrie.*|io.lemonlabs.uri.inet.PunycodeSupport.*)"
Expand All @@ -63,7 +64,8 @@ val scalaUriSettings = Seq(
name := "scala-uri",
description := "Simple scala library for building and parsing URIs",
libraryDependencies ++= Seq(
"com.chuusai" %%% "shapeless" % "2.3.7",
// TODO: Remove for3Use2_13 when scala3 version available https://github.com/milessabin/shapeless/issues/1043
("com.chuusai" %%% "shapeless" % "2.3.7").cross(CrossVersion.for3Use2_13),
"org.typelevel" %%% "cats-core" % "2.6.1",
"org.typelevel" %%% "cats-parse" % "0.3.4"
),
Expand Down Expand Up @@ -162,7 +164,8 @@ lazy val scalaUri =
Test / fork := true
)
.jsSettings(
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "1.2.0"
// TODO: Remove for3Use2_13 when scala3 version available https://github.com/scala-js/scala-js-dom/issues/451
libraryDependencies += ("org.scala-js" %%% "scalajs-dom" % "1.2.0").cross(CrossVersion.for3Use2_13)
)

lazy val docs = project
Expand Down
6 changes: 3 additions & 3 deletions project/UpdatePublicSuffixes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ object UpdatePublicSuffixes {
p.println("")
p.println("object PublicSuffixes {")

p.println(" lazy val exceptions = Set(")
p.println(" lazy val exceptions: Set[String] = Set(")
p.println(exceptions.map(_.tail).map(e => s""" "$e"""").mkString(",\n"))
p.println(" )\n")

p.println(" lazy val wildcardPrefixes = Set(")
p.println(" lazy val wildcardPrefixes: Set[String] = Set(")
p.println(wildcardPrefixes.map(_.drop(2)).map(w => s""" "$w"""").mkString(",\n"))
p.println(" )\n")

p.println(" lazy val set = " + groups.keys.map(i => s"publicSuffixes$i").mkString(" ++ "))
p.println(" lazy val set: Set[String] = " + groups.keys.map(i => s"publicSuffixes$i").mkString(" ++ "))
groups.foreach { case (index, group) =>
val setArgs = group.map(suffix => s""" "$suffix"""").mkString(",\n")
p.println(s" private def publicSuffixes$index =\n Set(\n" + setArgs + "\n )")
Expand Down
4 changes: 2 additions & 2 deletions shared/src/main/scala/io/lemonlabs/uri/Authority.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ case class Authority(userInfo: Option[UserInfo], host: Host, port: Option[Int])(
toString(config, _.toStringPunycode)

override def toString: String =
toString(config, _.toString)
toString(config, _.toString())

def toStringRaw: String =
toString(config.withNoEncoding, _.toString)
toString(config.withNoEncoding, _.toString())

/** Returns this authority normalized according to
* <a href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>
Expand Down
16 changes: 8 additions & 8 deletions shared/src/main/scala/io/lemonlabs/uri/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import scala.util.Try
sealed trait Path extends Product with Serializable {
def config: UriConfig
def parts: Vector[String]
private[uri] def toString(config: UriConfig): String
private[uri] def toStringWithConfig(config: UriConfig): String

def isEmpty: Boolean
def nonEmpty: Boolean = !isEmpty
Expand All @@ -24,10 +24,10 @@ sealed trait Path extends Product with Serializable {
* @return String containing the raw path for this Uri
*/
def toStringRaw: String =
toString(config.withNoEncoding)
toStringWithConfig(config.withNoEncoding)

override def toString: String =
toString(config)
toStringWithConfig(config)
}

object Path {
Expand Down Expand Up @@ -94,7 +94,7 @@ sealed trait UrlPath extends Path {
/** Returns the encoded path. By default non ASCII characters in the path are percent encoded.
* @return String containing the path for this Uri
*/
private[uri] def toString(c: UriConfig): String = {
private[uri] def toStringWithConfig(c: UriConfig): String = {
val encodedParts = parts.map(p => c.pathEncoder.encode(p, c.charset))
encodedParts.mkString("/")
}
Expand Down Expand Up @@ -233,7 +233,7 @@ case object EmptyPath extends AbsoluteOrEmptyPath {
def unapply(path: UrlPath): Boolean =
path.isEmpty

override private[uri] def toString(c: UriConfig): String = ""
override private[uri] def toStringWithConfig(c: UriConfig): String = ""

override def isSlashTerminated: Boolean = false
}
Expand Down Expand Up @@ -287,8 +287,8 @@ final case class AbsolutePath(parts: Vector[String])(implicit val config: UriCon
def isEmpty: Boolean =
false

override private[uri] def toString(c: UriConfig): String =
"/" + super.toString(c)
override private[uri] def toStringWithConfig(c: UriConfig): String =
"/" + super.toStringWithConfig(c)

override def isSlashTerminated: Boolean =
parts.lastOption.fold(true)(_ == "")
Expand All @@ -314,7 +314,7 @@ final case class UrnPath(nid: String, nss: String)(implicit val config: UriConfi
def isEmpty: Boolean =
false

private[uri] def toString(c: UriConfig): String =
private[uri] def toStringWithConfig(c: UriConfig): String =
nid + ":" + c.pathEncoder.encode(nss, c.charset)
}

Expand Down
48 changes: 25 additions & 23 deletions shared/src/main/scala/io/lemonlabs/uri/Uri.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sealed trait Uri extends Product with Serializable {
* @return a `java.net.URI` matching this `io.lemonlabs.uri.Uri`
*/
def toJavaURI: java.net.URI =
new java.net.URI(toString(config))
new java.net.URI(toStringWithConfig(config))

/** Similar to `==` but ignores the ordering of any query string parameters
*/
Expand All @@ -82,12 +82,12 @@ sealed trait Uri extends Product with Serializable {
* @return String containing the raw path for this Uri
*/
def toStringRaw: String =
toString(config.withNoEncoding)
toStringWithConfig(config.withNoEncoding)

override def toString: String =
toString(config)
toStringWithConfig(config)

private[uri] def toString(config: UriConfig): String
private[uri] def toStringWithConfig(config: UriConfig): String
}

object Uri {
Expand Down Expand Up @@ -479,7 +479,7 @@ sealed trait Url extends Uri {
* <a href="http://www.ietf.org/rfc/rfc3490.txt">RFC 3490</a>.
*/
def toStringPunycode: String =
toString(config)
toStringWithConfig(config)

protected def queryToString(config: UriConfig): String =
query.toString(config) match {
Expand All @@ -488,7 +488,7 @@ sealed trait Url extends Uri {
}

def toRedactedString(redactor: Redactor)(implicit conf: UriConfig = UriConfig.default): String =
redactor.apply(this).toString(conf)
redactor.apply(this).toStringWithConfig(conf)

/** Similar to `==` but ignores the ordering of any query string parameters
*/
Expand Down Expand Up @@ -657,8 +657,8 @@ final case class RelativeUrl(path: UrlPath, query: QueryString, fragment: Option
def withQueryString(query: QueryString): RelativeUrl =
copy(query = query)

private[uri] def toString(c: UriConfig): String =
path.toString(c) + queryToString(c) + fragmentToString(c)
private[uri] def toStringWithConfig(c: UriConfig): String =
path.toStringWithConfig(c) + queryToString(c) + fragmentToString(c)

def removeUserInfo(): RelativeUrl = this
def removePassword(): RelativeUrl = this
Expand Down Expand Up @@ -844,12 +844,12 @@ sealed trait UrlWithAuthority extends Url {
* <a href="http://www.ietf.org/rfc/rfc3490.txt">RFC 3490</a>.
*/
override def toStringPunycode: String =
toString(config, _.toStringPunycode)
toStringWithConfig(config, _.toStringPunycode)

private[uri] def toString(c: UriConfig): String =
toString(c, _.toString)
private[uri] def toStringWithConfig(c: UriConfig): String =
toStringWithConfig(c, _.toString())

private[uri] def toString(c: UriConfig, hostToString: Host => String): String
private[uri] def toStringWithConfig(c: UriConfig, hostToString: Host => String): String
}

object UrlWithAuthority {
Expand Down Expand Up @@ -913,8 +913,8 @@ final case class ProtocolRelativeUrl(authority: Authority,
def withQueryString(query: QueryString): ProtocolRelativeUrl =
copy(query = query)

private[uri] def toString(c: UriConfig, hostToString: Host => String): String =
"//" + authority.toString(c, hostToString) + path.toString(c) + queryToString(c) + fragmentToString(c)
private[uri] def toStringWithConfig(c: UriConfig, hostToString: Host => String): String =
"//" + authority.toString(c, hostToString) + path.toStringWithConfig(c) + queryToString(c) + fragmentToString(c)

def normalize(removeEmptyPathParts: Boolean = false,
slashTermination: SlashTermination = SlashTermination.AddForEmptyPath
Expand Down Expand Up @@ -988,8 +988,10 @@ final case class AbsoluteUrl(scheme: String,
def withQueryString(query: QueryString): AbsoluteUrl =
copy(query = query)

private[uri] def toString(c: UriConfig, hostToString: Host => String): String =
scheme + "://" + authority.toString(c, hostToString) + path.toString(c) + queryToString(c) + fragmentToString(c)
private[uri] def toStringWithConfig(c: UriConfig, hostToString: Host => String): String =
scheme + "://" + authority.toString(c, hostToString) + path.toStringWithConfig(c) + queryToString(
c
) + fragmentToString(c)

def normalize(removeEmptyPathParts: Boolean = false,
slashTermination: SlashTermination = SlashTermination.AddForEmptyPath
Expand Down Expand Up @@ -1132,8 +1134,8 @@ final case class SimpleUrlWithoutAuthority(scheme: String, path: UrlPath, query:
def withQueryString(query: QueryString): SimpleUrlWithoutAuthority =
copy(query = query)

private[uri] def toString(c: UriConfig): String =
scheme + ":" + path.toString(c) + queryToString(c) + fragmentToString(c)
private[uri] def toStringWithConfig(c: UriConfig): String =
scheme + ":" + path.toStringWithConfig(c) + queryToString(c) + fragmentToString(c)

def normalize(removeEmptyPathParts: Boolean = false,
slashTermination: SlashTermination = SlashTermination.AddForEmptyPath
Expand Down Expand Up @@ -1240,7 +1242,7 @@ final case class DataUrl(mediaType: MediaType, base64: Boolean, data: Array[Byte
def withQueryString(query: QueryString): DataUrl =
this

private[uri] def toString(c: UriConfig): String =
private[uri] def toStringWithConfig(c: UriConfig): String =
scheme + ":" + pathString(c)

override def equals(obj: Any): Boolean = obj match {
Expand Down Expand Up @@ -1342,9 +1344,9 @@ final case class ScpLikeUrl(override val user: Option[String], override val host
def withScheme(scheme: String): AbsoluteUrl =
AbsoluteUrl(scheme, authority, path.toAbsoluteOrEmpty, QueryString.empty, None)

private[uri] def toString(c: UriConfig, hostToString: Host => String): String = {
private[uri] def toStringWithConfig(c: UriConfig, hostToString: Host => String): String = {
// Don't do percent encoding. Can't find any reference to it being
user.fold("")(_ + "@") + hostToString(host) + ":" + path.toString(config.withNoEncoding)
user.fold("")(_ + "@") + hostToString(host) + ":" + path.toStringWithConfig(config.withNoEncoding)
}

/** For ScpLikeUrls this method is exactly the same as `==`
Expand Down Expand Up @@ -1402,8 +1404,8 @@ final case class Urn(path: UrnPath)(implicit val config: UriConfig = UriConfig.d
def toUrl: Url = throw new UriConversionException("Urn cannot be converted to Url")
def toUrn: Urn = this

private[uri] def toString(c: UriConfig): String =
scheme + ":" + path.toString(c)
private[uri] def toStringWithConfig(c: UriConfig): String =
scheme + ":" + path.toStringWithConfig(c)

/** For URNs this method is exactly the same as `==`
*/
Expand Down
50 changes: 0 additions & 50 deletions shared/src/main/scala/io/lemonlabs/uri/config/UriConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,6 @@ case class UriConfig(userInfoEncoder: UriEncoder,
defaultPorts: Map[String, Int]
) {

def this(userInfoEncoder: UriEncoder,
pathEncoder: UriEncoder,
queryEncoder: UriEncoder,
fragmentEncoder: UriEncoder,
userInfoDecoder: UriDecoder,
pathDecoder: UriDecoder,
queryDecoder: UriDecoder,
fragmentDecoder: UriDecoder,
charset: String,
renderQuery: RenderQuery
) =
this(
userInfoEncoder,
pathEncoder,
queryEncoder,
fragmentEncoder,
userInfoDecoder,
pathDecoder,
queryDecoder,
fragmentDecoder,
charset,
renderQuery,
UriConfig.defaultPorts
)

def copy(userInfoEncoder: UriEncoder = this.userInfoEncoder,
pathEncoder: UriEncoder = this.pathEncoder,
queryEncoder: UriEncoder = this.queryEncoder,
fragmentEncoder: UriEncoder = this.fragmentEncoder,
userInfoDecoder: UriDecoder = this.userInfoDecoder,
pathDecoder: UriDecoder = this.pathDecoder,
queryDecoder: UriDecoder = this.queryDecoder,
fragmentDecoder: UriDecoder = this.fragmentDecoder,
charset: String = this.charset,
renderQuery: RenderQuery = this.renderQuery
): UriConfig =
UriConfig(
userInfoEncoder,
pathEncoder,
queryEncoder,
fragmentEncoder,
userInfoDecoder,
pathDecoder,
queryDecoder,
fragmentDecoder,
charset,
renderQuery,
defaultPorts
)

def withDefaultPorts(newDefaultPorts: Map[String, Int]): UriConfig =
UriConfig(
userInfoEncoder,
Expand Down
Loading

0 comments on commit 4765b4e

Please sign in to comment.