Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move scala-xml related code to separate module #610

Merged
merged 5 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ val moduleCrossPlatformMatrix = Map(
"scalaz" -> List(JVMPlatform, JSPlatform, NativePlatform),
"scodec" -> List(JVMPlatform, JSPlatform),
"scopt" -> List(JVMPlatform, JSPlatform),
"shapeless" -> List(JVMPlatform, JSPlatform, NativePlatform)
"shapeless" -> List(JVMPlatform, JSPlatform, NativePlatform),
"scalaxml" -> List(JVMPlatform, JSPlatform, NativePlatform)
)

def allSubprojectsOf(platform: sbtcrossproject.Platform): List[String] =
Expand All @@ -71,7 +72,7 @@ val Scala213 = "2.13.0-M5"
val moduleCrossScalaVersionsMatrix: (String, Platform) => List[String] = {
case (_, NativePlatform) =>
List(Scala211)
case ("cats" | "core" | "scalacheck" | "scalaz" | "shapeless", _) =>
case ("cats" | "core" | "scalacheck" | "scalaz" | "shapeless" | "scalaxml", _) =>
List(Scala211, Scala212, Scala213)
case _ =>
List(Scala211, Scala212)
Expand Down Expand Up @@ -119,7 +120,6 @@ lazy val core = myCrossProject("core")
scalaOrganization.value % "scala-reflect" % scalaVersion.value,
scalaOrganization.value % "scala-compiler" % scalaVersion.value,
"com.chuusai" %%% "shapeless" % shapelessVersion,
"org.scala-lang.modules" %% "scala-xml" % scalaXmlVersion,
scalaCheckDep.value % Test
),
initialCommands += s"""
Expand Down Expand Up @@ -262,6 +262,16 @@ lazy val shapelessJVM = shapeless.jvm
lazy val shapelessJS = shapeless.js
lazy val shapelessNative = shapeless.native

lazy val scalaxml = myCrossProject("scalaxml")
.dependsOn(core % "compile->compile;test->test")
.settings(
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % scalaXmlVersion
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If scala-xml is available for Scala.js and Scala Native, shouldn't this use %%%?

)

lazy val scalaxmlJVM = scalaxml.jvm
lazy val scalaxmlJS = scalaxml.js
lazy val scalaxmlNative = scalaxml.native

/// settings

lazy val commonSettings = Def.settings(
Expand Down Expand Up @@ -330,7 +340,15 @@ def moduleJvmSettings(name: String): Seq[Def.Setting[_]] = Def.settings(
mimaBinaryIssueFilters ++= {
import com.typesafe.tools.mima.core._
Seq(
)
ProblemFilters.exclude[MissingClassProblem]("eu.timepit.refined.string$Xml$"),
ProblemFilters.exclude[MissingClassProblem]("eu.timepit.refined.string$Xml"),
ProblemFilters
.exclude[DirectMissingMethodProblem]("eu.timepit.refined.predicates.StringPredicates.Xml"),
ProblemFilters.exclude[DirectMissingMethodProblem]("eu.timepit.refined.predicates.all.Xml"),
ProblemFilters
.exclude[DirectMissingMethodProblem]("eu.timepit.refined.predicates.string.Xml"),
ProblemFilters.exclude[DirectMissingMethodProblem]("eu.timepit.refined.util.string.xml")
)
}
)

Expand Down
1 change: 1 addition & 0 deletions latestVersion.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ bincompatVersions in ThisBuild := Set(
unreleasedModules in ThisBuild := Set(
// Example:
// "refined-eval"
"refined-scalaxml"
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ class StringUtilSpecJvm extends Properties("util.string") {
true
}

property("xml success") = secure {
xml("<root></root>") == scala.xml.XML.loadString("<root></root>")
}

property("xml failure") = secure {
illTyped("""xml("<root>")""", "Xml predicate failed.*")
true
}

property("xpath success") = secure {
xpath("A//B/*[1]")
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ class StringValidateSpecJvm extends Properties("StringValidate") {
showResult[Url]("htp://example.com") ?= "Url predicate failed: unknown protocol: htp"
}

property("Xml.isValid") = secure {
isValid[Xml]("<root></root>")
}

property("Xml.showResult") = secure {
showResult[Xml]("<root>") ?=
"Xml predicate failed: XML document structures must start and end within the same entity."
}

property("XPath.isValid") = secure {
isValid[XPath]("A//B/*[1]")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ trait StringPredicates {
final type ValidBigDecimal = refined.string.ValidBigDecimal
final val ValidBigDecimal = refined.string.ValidBigDecimal

final type Xml = refined.string.Xml
final val Xml = refined.string.Xml

final type XPath = refined.string.XPath
final val XPath = refined.string.XPath
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ object string extends StringInference {
/** Predicate that checks if a `String` is a parsable `BigDecimal`. */
final case class ValidBigDecimal()

/** Predicate that checks if a `String` is well-formed XML. */
final case class Xml()

/** Predicate that checks if a `String` is a valid XPath expression. */
final case class XPath()

Expand Down Expand Up @@ -230,11 +227,6 @@ object string extends StringInference {
Validate.fromPartial(BigDecimal(_), "ValidBigDecimal", ValidBigDecimal())
}

object Xml {
implicit def xmlValidate: Validate.Plain[String, Xml] =
Validate.fromPartial(scala.xml.XML.loadString, "Xml", Xml())
}

object XPath {
implicit def xpathValidate: Validate.Plain[String, XPath] =
Validate.fromPartial(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ object string {
def uuid(s: String Refined Uuid): java.util.UUID =
java.util.UUID.fromString(s.value)

/** Creates a `scala.xml.Elem` from a validated string. */
def xml(s: String Refined Xml): scala.xml.Elem =
scala.xml.XML.loadString(s.value)

/** Creates a `javax.xml.xpath.XPathExpression` from a validated string. */
def xpath(s: String Refined XPath): javax.xml.xpath.XPathExpression =
javax.xml.xpath.XPathFactory.newInstance().newXPath().compile(s.value)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package eu.timepit.refined.scalaxml

import eu.timepit.refined.api.Validate

object string {

/** Predicate that checks if a `String` is well-formed XML. */
final case class Xml()

object Xml {
implicit def xmlValidate: Validate.Plain[String, Xml] =
Validate.fromPartial(scala.xml.XML.loadString, "Xml", Xml())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package eu.timepit.refined.scalaxml

import eu.timepit.refined.api.Refined
import eu.timepit.refined.scalaxml.string.Xml

object util {

/** Creates a `scala.xml.Elem` from a validated string. */
def xml(s: String Refined Xml): scala.xml.Elem =
scala.xml.XML.loadString(s.value)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package eu.timepit.refined.scalaxml

import eu.timepit.refined.auto._
import eu.timepit.refined.scalaxml.util._
import org.scalacheck.Prop._
import org.scalacheck.Properties
import shapeless.test.illTyped

class XmlUtilSpecJvm extends Properties("scalaxml.util.string") {

property("xml success") = secure {
xml("<root></root>") == scala.xml.XML.loadString("<root></root>")
}

property("xml failure") = secure {
illTyped("""xml("<root>")""", "Xml predicate failed.*")
true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package eu.timepit.refined.scalaxml

import eu.timepit.refined.TestUtils._
import eu.timepit.refined.scalaxml.string._
import org.scalacheck.Prop._
import org.scalacheck.Properties

class XmlValidateSpecJvm extends Properties("XmlValidate") {
property("Xml.isValid") = secure {
isValid[Xml]("<root></root>")
}

property("Xml.showResult") = secure {
showResult[Xml]("<root>") ?=
"Xml predicate failed: XML document structures must start and end within the same entity."
}
}