diff --git a/ChangeLog.md b/CHANGELOG.md similarity index 99% rename from ChangeLog.md rename to CHANGELOG.md index c3c0d910..95bb4d22 100644 --- a/ChangeLog.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ 2024-08 +- 1.1.0: dropped support for scala 2.12 and java 7. + - maintenance: - dependency updates, more cross-builds, expanded ci; cleanup most compile warnings. diff --git a/README.md b/README.md index 80014ce9..b00cbfab 100644 --- a/README.md +++ b/README.md @@ -199,12 +199,10 @@ Options (default): --cn (ExampleCfg) --dd (/tmp if existing or OS dependent temp dir) --java generate java code (the default) - --j7 generate code for java <= 7 (>= 8) --java:getters generate getters (see #31) (false) --java:records generate records (false) --java:optionals use optionals (false) --scala generate scala code (java) - --scala:2.12 generate code for scala 2.12 (2.13) --scala:bt use backticks (see #30) (false) --durations use java.time.Duration (false) --all-required assume all properties are required (see #47) diff --git a/build.sbt b/build.sbt index efb9f390..034b663c 100644 --- a/build.sbt +++ b/build.sbt @@ -2,7 +2,7 @@ enablePlugins(BuildInfoPlugin) organization := "com.github.carueda" name := "tscfg" -version := "1.0.2" +version := "1.1.0" scalaVersion := "3.3.3" crossScalaVersions := Seq("2.13.9", "3.3.3", "3.4.3", "3.5.0") diff --git a/src/main/scala/tscfg/Main.scala b/src/main/scala/tscfg/Main.scala index 79621a5f..70e02f3a 100644 --- a/src/main/scala/tscfg/Main.scala +++ b/src/main/scala/tscfg/Main.scala @@ -36,12 +36,10 @@ object Main { | --cn (${defaultGenOpts.className}) | --dd ($defaultDestDir) | --java generate java code (the default) - | --j7 generate code for java <= 7 (8) | --java:getters generate getters (see #31) (false) | --java:records generate records (false) | --java:optionals use optionals (false) | --scala generate scala code (java) - | --scala:2.12 generate code for scala 2.12 (2.13) | --scala:bt use backticks (see #30) (false) | --durations use java.time.Duration (false) | --all-required assume all properties are required (see #47) @@ -60,9 +58,7 @@ object Main { className: String = defaultGenOpts.className, destDir: String = defaultDestDir, assumeAllRequired: Boolean = false, - j7: Boolean = false, language: String = "java", - s12: Boolean = false, useBackticks: Boolean = false, genGetters: Boolean = false, genRecords: Boolean = false, @@ -128,15 +124,9 @@ object Main { case "--all-required" :: rest => traverseList(rest, opts.copy(assumeAllRequired = true)) - case "--j7" :: rest => - traverseList(rest, opts.copy(j7 = true)) - case "--scala" :: rest => traverseList(rest, opts.copy(language = "scala")) - case "--scala:2.12" :: rest => - traverseList(rest, opts.copy(s12 = true)) - case "--scala:bt" :: rest => traverseList(rest, opts.copy(useBackticks = true)) @@ -208,8 +198,6 @@ object Main { opts.packageName, opts.className, assumeAllRequired = opts.assumeAllRequired, - j7 = opts.j7, - s12 = opts.s12, useBackticks = opts.useBackticks, genGetters = opts.genGetters, genRecords = opts.genRecords, diff --git a/src/main/scala/tscfg/gen4tests.scala b/src/main/scala/tscfg/gen4tests.scala index fd941f55..4d175c13 100644 --- a/src/main/scala/tscfg/gen4tests.scala +++ b/src/main/scala/tscfg/gen4tests.scala @@ -65,7 +65,7 @@ object gen4tests { .collect { case linePat(xs) => xs.trim } .flatMap(_.split("\\s+")) .map { - case opt @ "--scala:2.12" => + case opt @ "--scala" => OptFromFile(opt, Some("scala")) case opt @ "--scala:bt" => @@ -107,7 +107,7 @@ object gen4tests { val baseGenOpts: GenOpts = { var genOpts = GenOpts("tscfg.example", "?") optsFromFile foreach { - case "--scala:2.12" => genOpts = genOpts.copy(s12 = true) + case "--scala" => () case "--scala:bt" => genOpts = genOpts.copy(useBackticks = true) diff --git a/src/main/scala/tscfg/generators/Generator.scala b/src/main/scala/tscfg/generators/Generator.scala index b52fbc8c..b2fe4de4 100644 --- a/src/main/scala/tscfg/generators/Generator.scala +++ b/src/main/scala/tscfg/generators/Generator.scala @@ -11,8 +11,8 @@ abstract class Generator(genOpts: GenOpts) { def generate(objectType: ObjectType): GenResult - protected val className: String = genOpts.className - protected val hasPath: String = if (genOpts.j7) "hasPath" else "hasPathOrNull" + protected val className: String = genOpts.className + protected val hasPath: String = "hasPathOrNull" protected var genResults: GenResult = GenResult() // allows to insert special marks in generated code to facilitate debugging. @@ -28,8 +28,6 @@ case class GenOpts( packageName: String, className: String, assumeAllRequired: Boolean = false, - j7: Boolean = false, - s12: Boolean = false, useBackticks: Boolean = false, genGetters: Boolean = false, genRecords: Boolean = false, diff --git a/src/main/scala/tscfg/generators/java/JavaGen.scala b/src/main/scala/tscfg/generators/java/JavaGen.scala index 75a8a182..e0027edf 100644 --- a/src/main/scala/tscfg/generators/java/JavaGen.scala +++ b/src/main/scala/tscfg/generators/java/JavaGen.scala @@ -638,7 +638,6 @@ object JavaGen { def generate( filename: String, showOut: Boolean = false, - j7: Boolean = false, assumeAllRequired: Boolean = false, genGetters: Boolean = false, genRecords: Boolean = false, @@ -680,7 +679,6 @@ object JavaGen { val genOpts = GenOpts( "tscfg.example", className, - j7 = j7, genGetters = genGetters, genRecords = genRecords, useOptionals = useOptionals, diff --git a/src/main/scala/tscfg/generators/scala/ScalaGen.scala b/src/main/scala/tscfg/generators/scala/ScalaGen.scala index da77f6d7..5fa0bbcc 100644 --- a/src/main/scala/tscfg/generators/scala/ScalaGen.scala +++ b/src/main/scala/tscfg/generators/scala/ScalaGen.scala @@ -474,10 +474,8 @@ object ScalaGen { // $COVERAGE-OFF$ def generate( filename: String, - j7: Boolean = false, assumeAllRequired: Boolean = false, showOut: Boolean = false, - s12: Boolean = false, useDurations: Boolean = false, useBackticks: Boolean = false ): GenResult = { @@ -522,10 +520,8 @@ object ScalaGen { val genOpts = GenOpts( "tscfg.example", className, - j7 = j7, useBackticks = useBackticks, useDurations = useDurations, - s12 = s12 ) val generator = new ScalaGen(genOpts, rootNamespace) @@ -678,7 +674,7 @@ private[scala] case class Getter( implicit listAccessors: collection.mutable.Map[String, String] ): String = { val scalaType: ListScalaType = res.scalaType.asInstanceOf[ListScalaType] - val base = accessors.listMethodName(scalaType, lt, path, genOpts.s12) + val base = accessors.listMethodName(scalaType, lt, path) if (a.optional) { s"""if(c.$hasPath("$path")) scala.Some($base) else None""" } @@ -730,14 +726,13 @@ private[scala] class Accessors { scalaType: ListScalaType, lt: ListType, path: String, - s12: Boolean )(implicit listAccessors: collection.mutable.Map[String, String], methodNames: MethodNames, rootNamespace: NamespaceMan ): String = { - val (_, methodName) = rec(scalaType, lt, "", s12) + val (_, methodName) = rec(scalaType, lt, "") methodName + s"""(c.getList("$path"), parentPath, $$tsCfgValidator)""" } @@ -745,7 +740,6 @@ private[scala] class Accessors { lst: ListScalaType, lt: ListType, prefix: String, - s12: Boolean )(implicit listAccessors: collection.mutable.Map[String, String], methodNames: MethodNames, @@ -768,12 +762,11 @@ private[scala] class Accessors { lst, lt.t.asInstanceOf[ListType], prefix + methodNames.listPrefix, - s12 ) } val (methodName, methodBody) = - listMethodDefinition(elemMethodName, lst.st, s12, lt) + listMethodDefinition(elemMethodName, lst.st, lt) if (isBasic) rootListAccessors += methodName -> methodBody @@ -802,7 +795,6 @@ private[scala] class Accessors { def listMethodDefinition( elemMethodName: String, scalaType: ScalaType, - s12: Boolean, lt: ListType )(implicit methodNames: MethodNames, @@ -838,10 +830,8 @@ private[scala] class Accessors { } } - val methodName = methodNames.listPrefix + elemMethodName - val scalaCollectionConverter = - if (s12) "scala.collection.JavaConverters._" - else "scala.jdk.CollectionConverters._" + val methodName = methodNames.listPrefix + elemMethodName + val scalaCollectionConverter = "scala.jdk.CollectionConverters._" val methodDef = s""" private def $methodName(cl:com.typesafe.config.ConfigList, parentPath: java.lang.String, $$tsCfgValidator: $$TsCfgValidator): scala.List[$scalaType] = { | import $scalaCollectionConverter diff --git a/src/main/tscfg/example/issue59.spec.conf b/src/main/tscfg/example/issue59.spec.conf index 07f00db4..cb894160 100644 --- a/src/main/tscfg/example/issue59.spec.conf +++ b/src/main/tscfg/example/issue59.spec.conf @@ -1,2 +1,3 @@ -// GenOpts: --scala:2.12 +# option `--scala:2.12` removed in tscfg 1.1.0 +// GenOpts: --scala foolist = [string] diff --git a/src/test/scala/tscfg/example/ScalaIssue59Cfg.scala b/src/test/scala/tscfg/example/ScalaIssue59Cfg.scala index 0c2105f4..c2d502c5 100644 --- a/src/test/scala/tscfg/example/ScalaIssue59Cfg.scala +++ b/src/test/scala/tscfg/example/ScalaIssue59Cfg.scala @@ -15,7 +15,7 @@ object ScalaIssue59Cfg { } private def $_L$_str(cl:com.typesafe.config.ConfigList, parentPath: java.lang.String, $tsCfgValidator: $TsCfgValidator): scala.List[java.lang.String] = { - import scala.collection.JavaConverters._ + import scala.jdk.CollectionConverters._ cl.asScala.map(cv => $_str(cv)).toList } private def $_expE(cv:com.typesafe.config.ConfigValue, exp:java.lang.String) = { diff --git a/src/test/scala/tscfg/generators/java/JavaMainSpec.scala b/src/test/scala/tscfg/generators/java/JavaMainSpec.scala index c151039b..3b0e24bd 100644 --- a/src/test/scala/tscfg/generators/java/JavaMainSpec.scala +++ b/src/test/scala/tscfg/generators/java/JavaMainSpec.scala @@ -540,7 +540,7 @@ class JavaMainSpec extends AnyWordSpec { "(java) given class name starting with $_" should { "generate warning" in { - val genOpts = GenOpts("tscfg.example", "Classy", j7 = true) + val genOpts = GenOpts("tscfg.example", "Classy") val r = new JavaGen(genOpts).generate(ObjectType()) assert(r.classNames === Set("Classy")) assert(r.fields === Map()) @@ -557,7 +557,7 @@ class JavaMainSpec extends AnyWordSpec { ) "generate warnings" in { - val genOpts = GenOpts("tscfg.example", "Classy", j7 = true) + val genOpts = GenOpts("tscfg.example", "Classy") val r = new JavaGen(genOpts).generate(objectType) assert(r.classNames === Set("Classy", "Other")) assert( diff --git a/src/test/scala/tscfg/generators/scala/ScalaMainSpec.scala b/src/test/scala/tscfg/generators/scala/ScalaMainSpec.scala index a588ed65..6ca340ba 100644 --- a/src/test/scala/tscfg/generators/scala/ScalaMainSpec.scala +++ b/src/test/scala/tscfg/generators/scala/ScalaMainSpec.scala @@ -492,7 +492,7 @@ class ScalaMainSpec extends AnyWordSpec { "(scala) given class name starting with $_" should { "generate warning" in { - val genOpts = GenOpts("tscfg.example", "Classy", j7 = true) + val genOpts = GenOpts("tscfg.example", "Classy") val r = new ScalaGen(genOpts).generate(ObjectType()) assert(r.classNames === Set("Classy")) assert(r.fields === Map()) @@ -509,7 +509,7 @@ class ScalaMainSpec extends AnyWordSpec { ) "generate warnings" in { - val genOpts = GenOpts("tscfg.example", "Classy", j7 = true) + val genOpts = GenOpts("tscfg.example", "Classy") val r = new ScalaGen(genOpts).generate(objectType) assert(r.classNames === Set("Classy", "Other")) @@ -865,16 +865,6 @@ class ScalaMainSpec extends AnyWordSpec { r.code.contains("import scala.collection.JavaConverters._") === false ) } - - "generate a scala 2.12 config with corresponding imports if --scala:2.12 is provided" in { - val r = ScalaGen.generate("example/issue59.spec.conf", s12 = true) - assert( - r.code.contains("import scala.collection.JavaConverters._") === true - ) - assert( - r.code.contains("import scala.jdk.CollectionConverters._") === false - ) - } } "(scala) issue 62 - shared enumeration" when {