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

Change to Scala based HOCON config library for JVM #65

Merged
merged 2 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ inThisBuild(
url("https://geirsson.com")
),
scalaVersion := ScalaVersions.head,
crossScalaVersions := ScalaVersions
crossScalaVersions := ScalaVersions,
resolvers += Resolver.sonatypeRepo("snapshots")
)
)

Expand Down Expand Up @@ -115,7 +116,7 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)
lazy val coreJVM = core.jvm
lazy val coreJS = core.js

lazy val typesafeConfig = "com.typesafe" % "config" % "1.2.1"
lazy val typesafeConfig = "org.ekrich" %% "sconfig" % "0.7.0-SNAPSHOT"
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be best to create a new module sconfig and keep the current typesafeConfig module unchanged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I'll change that once I make a first JVM release. Should I leave the original?


lazy val typesafe = project
.in(file("metaconfig-typesafe-config"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object TypesafeConfig2Class {
case lst: ConfigList =>
Conf.Lst(lst.listIterator().asScala.map(loop).toList)
case _ =>
value.unwrapped() match {
value.unwrapped match {
Copy link
Member

Choose a reason for hiding this comment

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

I personally don't mind this change, but I would expect a drop-in Scala replacement to not require this diff even if that means using () to call non-side-effecting methods

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really wasn't sure what to do as the internal tests in Scala where inconsistent how it called Java with or without parens. So overall, I tried to make it more Scala-like. I left them on for obvious side-effecting 0-arity methods. Someone who was really bored could do an entire API review 😆

If it really could have been a drop-in then I think Lightbend should have serious considered the PR - it is close but will probably change again for Scala 3 support etc. I also still have to change the package which will require import changes. ☹️

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind the parenthesis diff, metaconfig touches such a tiny surface of the API anyways.

internal tests in Scala where inconsistent how it called Java with or without parens.

with or without parens works when calling Java methods, but Scala "nullary methods" have additional information in their signatures to prohibit calling

will probably change again for Scala 3 support

I doubt that ;) I suspect it will work without any changes.

This PR is very close to being ready!

  • change package name so it doesn't conflict with com.typesafe.config
  • new module metaconfig-sconfig to avoid conflict with the old one
  • we can copy-paste the metaconfig-typesafe-config tests for sconfig, I hope to remove the typesafe-config tests at some point so duplication is no problem

case x: String => Conf.Str(x)
case x: java.lang.Integer => Conf.Num(BigDecimal(x))
case x: java.lang.Long => Conf.Num(BigDecimal(x))
Expand All @@ -43,14 +43,14 @@ object TypesafeConfig2Class {
)
}
}
getPositionOpt(value.origin(), cache).fold(conf)(conf.withPos)
getPositionOpt(value.origin, cache).fold(conf)(conf.withPos)
}
try {
Configured.Ok(loop(config().resolve().root()))
Configured.Ok(loop(config().resolve().root))
} catch {
case e: ConfigException.Parse =>
Configured.NotOk(
ConfError.parseError(getPosition(e.origin(), cache), e.getMessage)
ConfError.parseError(getPosition(e.origin, cache), e.getMessage)
)
}
}
Expand All @@ -67,8 +67,8 @@ object TypesafeConfig2Class {
): Option[Position] =
for {
origin <- Option(originOrNull)
url <- Option(origin.url())
linePlus1 <- Option(origin.lineNumber())
url <- Option(origin.url)
linePlus1 <- Option(origin.lineNumber)
line = linePlus1 - 1
input = Input.File(new java.io.File(url.toURI))
offsetByLine = cache.getOrElseUpdate(
Expand Down