From 3d3d21cdaefd57426245b553b421ecafb6e5073f Mon Sep 17 00:00:00 2001 From: Ben Plommer Date: Fri, 10 Jun 2022 16:53:47 +0100 Subject: [PATCH 1/5] Add scalaxml module --- build.sbt | 17 +++++++++++++-- .../scalaxml/src/main/scala/XmlCodecs.scala | 20 ++++++++++++++++++ .../src/test/scala/codec/XmlCodecTest.scala | 21 +++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 modules/scalaxml/src/main/scala/XmlCodecs.scala create mode 100644 modules/tests/shared/src/test/scala/codec/XmlCodecTest.scala diff --git a/build.sbt b/build.sbt index 3d6c040b..ca903ad6 100644 --- a/build.sbt +++ b/build.sbt @@ -136,7 +136,7 @@ lazy val commonSettings = Seq( lazy val skunk = tlCrossRootProject .settings(name := "skunk") - .aggregate(core, tests, circe, refined, example) + .aggregate(core, tests, circe, refined, example, `scala-xml`) .settings(commonSettings) lazy val core = crossProject(JVMPlatform, JSPlatform) @@ -198,10 +198,23 @@ lazy val circe = crossProject(JVMPlatform, JSPlatform) ) ) +lazy val `scala-xml` = crossProject(JVMPlatform, JSPlatform) + .crossType(CrossType.Pure) + .in(file("modules/scalaxml")) + .dependsOn(core) + .enablePlugins(AutomateHeaderPlugin) + .settings(commonSettings) + .settings( + name := "skunk-scala-xml", + libraryDependencies ++= Seq( + "org.scala-lang.modules" %%% "scala-xml" % "2.1.0" + ) + ) + lazy val tests = crossProject(JVMPlatform, JSPlatform) .crossType(CrossType.Full) .in(file("modules/tests")) - .dependsOn(core, circe) + .dependsOn(core, circe, `scala-xml`) .enablePlugins(AutomateHeaderPlugin, NoPublishPlugin) .settings(commonSettings) .settings( diff --git a/modules/scalaxml/src/main/scala/XmlCodecs.scala b/modules/scalaxml/src/main/scala/XmlCodecs.scala new file mode 100644 index 00000000..a5f8a74f --- /dev/null +++ b/modules/scalaxml/src/main/scala/XmlCodecs.scala @@ -0,0 +1,20 @@ +// Copyright (c) 2018-2021 by Rob Norris +// This software is licensed under the MIT License (MIT). +// For more information see LICENSE or https://opensource.org/licenses/MIT + +package skunk +package scalaxml.codec + +import cats.syntax.all._ + +import scala.xml._ +import skunk.data.{Arr, Type} + +trait XmlCodecs { + val xml: Codec[Elem] = Codec.simple(_.toString, s => Either.catchNonFatal(XML.loadString(s)).leftMap(_.getMessage), Type.xml) + val _xml: Codec[Arr[Elem]] = Codec.array(_.toString, s => Either.catchNonFatal(XML.loadString(s)).leftMap(_.getMessage), Type._xml) +} + +object xml extends XmlCodecs + +object all extends XmlCodecs diff --git a/modules/tests/shared/src/test/scala/codec/XmlCodecTest.scala b/modules/tests/shared/src/test/scala/codec/XmlCodecTest.scala new file mode 100644 index 00000000..eab57535 --- /dev/null +++ b/modules/tests/shared/src/test/scala/codec/XmlCodecTest.scala @@ -0,0 +1,21 @@ +// Copyright (c) 2018-2021 by Rob Norris +// This software is licensed under the MIT License (MIT). +// For more information see LICENSE or https://opensource.org/licenses/MIT + +package tests +package codec + +import cats.Eq +import skunk.scalaxml.codec.all._ + +import scala.xml.{Elem, XML} + +class XmlCodecTest extends CodecTest { + implicit val eq: Eq[Elem] = Eq.fromUniversalEquals + + val x: Elem = XML.loadString("bar") + + roundtripTest(xml)(x) +} + + From 525f6b6cc9c08d59eb27ce7cd047b9ddf5b07c6f Mon Sep 17 00:00:00 2001 From: Ben Plommer Date: Mon, 13 Jun 2022 16:49:05 +0100 Subject: [PATCH 2/5] update github workflow --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39359f4d..4bcf5886 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,11 +92,11 @@ jobs: - name: Make target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') - run: mkdir -p modules/circe/.jvm/target target .js/target modules/docs/target modules/core/js/target modules/circe/.js/target modules/core/jvm/target modules/tests/js/target .jvm/target .native/target modules/refined/.js/target modules/refined/.jvm/target modules/tests/jvm/target modules/example/target project/target + run: mkdir -p modules/scalaxml/.jvm/target modules/circe/.jvm/target target .js/target modules/docs/target modules/scalaxml/.js/target modules/core/js/target modules/circe/.js/target modules/core/jvm/target modules/tests/js/target .jvm/target .native/target modules/refined/.js/target modules/refined/.jvm/target modules/tests/jvm/target modules/example/target project/target - name: Compress target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') - run: tar cf targets.tar modules/circe/.jvm/target target .js/target modules/docs/target modules/core/js/target modules/circe/.js/target modules/core/jvm/target modules/tests/js/target .jvm/target .native/target modules/refined/.js/target modules/refined/.jvm/target modules/tests/jvm/target modules/example/target project/target + run: tar cf targets.tar modules/scalaxml/.jvm/target modules/circe/.jvm/target target .js/target modules/docs/target modules/scalaxml/.js/target modules/core/js/target modules/circe/.js/target modules/core/jvm/target modules/tests/js/target .jvm/target .native/target modules/refined/.js/target modules/refined/.jvm/target modules/tests/jvm/target modules/example/target project/target - name: Upload target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') From 84f56a0949757b74b563b7186fa462643f365b17 Mon Sep 17 00:00:00 2001 From: Ben Plommer Date: Mon, 13 Jun 2022 17:26:34 +0100 Subject: [PATCH 3/5] make xml codec test js-only --- .../tests/{shared => jvm}/src/test/scala/codec/XmlCodecTest.scala | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename modules/tests/{shared => jvm}/src/test/scala/codec/XmlCodecTest.scala (100%) diff --git a/modules/tests/shared/src/test/scala/codec/XmlCodecTest.scala b/modules/tests/jvm/src/test/scala/codec/XmlCodecTest.scala similarity index 100% rename from modules/tests/shared/src/test/scala/codec/XmlCodecTest.scala rename to modules/tests/jvm/src/test/scala/codec/XmlCodecTest.scala From 6c593e65ca1e709c79e7a91be2c2d363fd7193f3 Mon Sep 17 00:00:00 2001 From: Ben Plommer Date: Tue, 14 Jun 2022 09:43:27 +0100 Subject: [PATCH 4/5] Make scala-xml jvm only --- .github/workflows/ci.yml | 4 ++-- build.sbt | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4bcf5886..1cf4d4bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,11 +92,11 @@ jobs: - name: Make target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') - run: mkdir -p modules/scalaxml/.jvm/target modules/circe/.jvm/target target .js/target modules/docs/target modules/scalaxml/.js/target modules/core/js/target modules/circe/.js/target modules/core/jvm/target modules/tests/js/target .jvm/target .native/target modules/refined/.js/target modules/refined/.jvm/target modules/tests/jvm/target modules/example/target project/target + run: mkdir -p modules/circe/.jvm/target target .js/target modules/docs/target modules/core/js/target modules/circe/.js/target modules/core/jvm/target modules/tests/js/target .jvm/target .native/target modules/refined/.js/target modules/refined/.jvm/target modules/tests/jvm/target modules/scalaxml/target modules/example/target project/target - name: Compress target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') - run: tar cf targets.tar modules/scalaxml/.jvm/target modules/circe/.jvm/target target .js/target modules/docs/target modules/scalaxml/.js/target modules/core/js/target modules/circe/.js/target modules/core/jvm/target modules/tests/js/target .jvm/target .native/target modules/refined/.js/target modules/refined/.jvm/target modules/tests/jvm/target modules/example/target project/target + run: tar cf targets.tar modules/circe/.jvm/target target .js/target modules/docs/target modules/core/js/target modules/circe/.js/target modules/core/jvm/target modules/tests/js/target .jvm/target .native/target modules/refined/.js/target modules/refined/.jvm/target modules/tests/jvm/target modules/scalaxml/target modules/example/target project/target - name: Upload target directories if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') diff --git a/build.sbt b/build.sbt index ca903ad6..73865c06 100644 --- a/build.sbt +++ b/build.sbt @@ -198,23 +198,24 @@ lazy val circe = crossProject(JVMPlatform, JSPlatform) ) ) -lazy val `scala-xml` = crossProject(JVMPlatform, JSPlatform) - .crossType(CrossType.Pure) +lazy val `scala-xml` = project .in(file("modules/scalaxml")) - .dependsOn(core) + .dependsOn(core.jvm) + .settings(tlVersionIntroduced := Seq(`scala-2.12`, `scala-2.13`, `scala-3.0`).map(_ -> "0.3.2").toMap) .enablePlugins(AutomateHeaderPlugin) .settings(commonSettings) .settings( name := "skunk-scala-xml", libraryDependencies ++= Seq( - "org.scala-lang.modules" %%% "scala-xml" % "2.1.0" + "org.scala-lang.modules" %% "scala-xml" % "2.1.0" ) ) lazy val tests = crossProject(JVMPlatform, JSPlatform) .crossType(CrossType.Full) .in(file("modules/tests")) - .dependsOn(core, circe, `scala-xml`) + .dependsOn(core, circe) + .jvmConfigure(_.dependsOn(`scala-xml`)) .enablePlugins(AutomateHeaderPlugin, NoPublishPlugin) .settings(commonSettings) .settings( From 89426bb19b46d73e37aa25297db4cb8b00400de5 Mon Sep 17 00:00:00 2001 From: Ben Plommer Date: Tue, 14 Jun 2022 10:00:17 +0100 Subject: [PATCH 5/5] Fix mima --- build.sbt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 73865c06..eaeeff79 100644 --- a/build.sbt +++ b/build.sbt @@ -201,7 +201,9 @@ lazy val circe = crossProject(JVMPlatform, JSPlatform) lazy val `scala-xml` = project .in(file("modules/scalaxml")) .dependsOn(core.jvm) - .settings(tlVersionIntroduced := Seq(`scala-2.12`, `scala-2.13`, `scala-3.0`).map(_ -> "0.3.2").toMap) + .settings( + tlVersionIntroduced := List("2.12", "2.13", "3").map(_ -> "0.3.2").toMap + ) .enablePlugins(AutomateHeaderPlugin) .settings(commonSettings) .settings(