From 3f809ddd123800712de16bf635e80936a9c8d7f0 Mon Sep 17 00:00:00 2001 From: Michael Bryzek Date: Sat, 6 Jul 2024 10:51:55 -0400 Subject: [PATCH] Remove joda from anorm --- generator/app/controllers/Generators.scala | 8 +-- .../generator/anorm/ParserGenerator.scala | 55 ++++++++++++------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/generator/app/controllers/Generators.scala b/generator/app/controllers/Generators.scala index 1c57c9d8..440037ed 100644 --- a/generator/app/controllers/Generators.scala +++ b/generator/app/controllers/Generators.scala @@ -79,14 +79,14 @@ object Generators { ), CodeGenTarget( metaData = Generator( - key = "anorm_2_8_scala_3_parsers", - name = "Anorm 2.8 Scala 3 parsers", - description = Some("Generates anorm parsers. Depends on apidoc_0_x_libs generators. See https://playframework.github.io/anorm/"), + key = "anorm_2_9_scala_3_parsers", + name = "Anorm 2.9 Scala 3 parsers", + description = Some("Generates anorm parsers. See https://playframework.github.io/anorm/"), language = Some("Scala"), attributes = Seq("scala_generator") ), status = lib.generator.Status.Alpha, - codeGenerator = Some(scala.generator.anorm.ParserGenerator28Scala3) + codeGenerator = Some(scala.generator.anorm.ParserGenerator29Scala3) ), CodeGenTarget( metaData = Generator( diff --git a/scala-generator/src/main/scala/models/generator/anorm/ParserGenerator.scala b/scala-generator/src/main/scala/models/generator/anorm/ParserGenerator.scala index 0de0ece7..f29a455b 100644 --- a/scala-generator/src/main/scala/models/generator/anorm/ParserGenerator.scala +++ b/scala-generator/src/main/scala/models/generator/anorm/ParserGenerator.scala @@ -21,36 +21,49 @@ object ParserGenerator24 extends ParserGenerator { ) } -object ParserGenerator26 extends ParserGenerator { - override val version: ScalaVersion = ScalaVersion(2) +object ParserGenerator26 extends AbstractParserGenerator26(ScalaVersion(2)) + +class AbstractParserGenerator26(override val version: ScalaVersion) extends ParserGenerator { override def attributes(ssd: ScalaService): ParserGeneratorPlayVersionSpecificAttributes = { - val dateImports = ssd.attributes.dateType match { - case DateTypeConfig.JodaLocalDate => Seq( - "play.api.libs.json.JodaReads._", - ) - case _ => Nil - } - val dateTimeImports = ssd.attributes.dateTimeType match { - case DateTimeTypeConfig.JodaDateTime => Seq( - "play.api.libs.json.JodaReads._", - ) - case _ => Nil - } ParserGeneratorPlayVersionSpecificAttributes( - imports = Seq( - "anorm.{Column, MetaDataItem, TypeDoesNotMatch}", - "play.api.libs.json.{JsArray, JsObject, JsValue}", - "scala.util.{Failure, Success, Try}", - ) ++ (dateImports ++ dateTimeImports).distinct + baseImports ++ jodaImports(ssd) + ) + } + + private[this] val baseImports: Seq[String] = { + Seq( + "anorm.{Column, MetaDataItem, TypeDoesNotMatch}", + "play.api.libs.json.{JsArray, JsObject, JsValue}", + "scala.util.{Failure, Success, Try}", ) } + + private[this] def jodaImports(ssd: ScalaService): Seq[String] = { + if (version.major >= 3) { + Nil + } else { + val dateImports = ssd.attributes.dateType match { + case DateTypeConfig.JodaLocalDate => Seq( + "play.api.libs.json.JodaReads._", + ) + case _ => Nil + } + val dateTimeImports = ssd.attributes.dateTimeType match { + case DateTimeTypeConfig.JodaDateTime => Seq( + "play.api.libs.json.JodaReads._", + ) + case _ => Nil + } + (dateImports ++ dateTimeImports).distinct + } + } } object ParserGenerator28Scala2 extends AbstractParserGenerator(ScalaVersion(2)) -object ParserGenerator28Scala3 extends AbstractParserGenerator(ScalaVersion(3)) +object ParserGenerator29Scala3 extends AbstractParserGenerator(ScalaVersion(3)) abstract class AbstractParserGenerator(override val version: ScalaVersion) extends ParserGenerator { override def attributes(ssd: ScalaService): ParserGeneratorPlayVersionSpecificAttributes = - ParserGenerator26.attributes(ssd) + new AbstractParserGenerator26(version).attributes(ssd) } case class ParserGeneratorPlayVersionSpecificAttributes(imports: Seq[String])