Skip to content

Commit

Permalink
drop support for scala 2.12 and java 7
Browse files Browse the repository at this point in the history
  • Loading branch information
carueda committed Aug 23, 2024
1 parent fbf169c commit 86775ea
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 54 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,10 @@ Options (default):
--cn <className> (ExampleCfg)
--dd <destDir> (/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)
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
12 changes: 0 additions & 12 deletions src/main/scala/tscfg/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ object Main {
| --cn <className> (${defaultGenOpts.className})
| --dd <destDir> ($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)
Expand All @@ -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,
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/tscfg/gen4tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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" =>
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 2 additions & 4 deletions src/main/scala/tscfg/generators/Generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/main/scala/tscfg/generators/java/JavaGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -680,7 +679,6 @@ object JavaGen {
val genOpts = GenOpts(
"tscfg.example",
className,
j7 = j7,
genGetters = genGetters,
genRecords = genRecords,
useOptionals = useOptionals,
Expand Down
20 changes: 5 additions & 15 deletions src/main/scala/tscfg/generators/scala/ScalaGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"""
}
Expand Down Expand Up @@ -730,22 +726,20 @@ 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)"""
}

private def rec(
lst: ListScalaType,
lt: ListType,
prefix: String,
s12: Boolean
)(implicit
listAccessors: collection.mutable.Map[String, String],
methodNames: MethodNames,
Expand All @@ -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
Expand Down Expand Up @@ -802,7 +795,6 @@ private[scala] class Accessors {
def listMethodDefinition(
elemMethodName: String,
scalaType: ScalaType,
s12: Boolean,
lt: ListType
)(implicit
methodNames: MethodNames,
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/main/tscfg/example/issue59.spec.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// GenOpts: --scala:2.12
# option `--scala:2.12` removed in tscfg 1.1.0
// GenOpts: --scala
foolist = [string]
2 changes: 1 addition & 1 deletion src/test/scala/tscfg/example/ScalaIssue59Cfg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) = {
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/tscfg/generators/java/JavaMainSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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(
Expand Down
14 changes: 2 additions & 12 deletions src/test/scala/tscfg/generators/scala/ScalaMainSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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"))
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 86775ea

Please sign in to comment.