Skip to content

Commit 7b7bddb

Browse files
authored
Provide for better Platform support and testing (#350)
* Add classes to allow migrations of methods to specific platforms * Move some common methods * Move platform to config package * Shared JVM Native tests work * Move parseString to common * Works good for all platforms, stub for JvmNative * Add two Reader tests to Native * Make default build 2.13 and rename ConfigDocumentTest to ConfigDocumentFactoryTest * Move ConfigFactoryTests to impl like other tests * Move tests from ConfigTest to ConfigFactoryJvmTest and then ConfigTest to shared * Make test class names singular * Checkpoint commit for ConfigOrigin setup * Update to more shared tests, add URL for Native, from 189 to 228 tests for Native * Add env vars to shared in anticipation of using them in Native or JS * Move ConfigSubstitutionTests to shared * Json4s almost works * Json4s cleanup * Got json4s test to work * Make comments generic * Json4sTest is now cross platform * Small updates, JS setting commented out * Upgrade to new version of json4s to fix JS ClassCastException problem * Upgrade Scala.js to 1.15.0, allow Reader tests now * Update docs and readme for release
1 parent 43444bc commit 7b7bddb

36 files changed

+4520
-2994
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ At a high level, the process is as follows:
104104
105105
## Versions
106106
107-
Release [1.5.1](https://github.com/ekrich/sconfig/releases/tag/v1.5.1) - (2023-09-14)<br/>
107+
Release [1.6.0](https://github.com/ekrich/sconfig/releases/tag/v1.6.0) - (2023-12-28)<br/>
108+
Release [1.5.1](https://github.com/ekrich/sconfig/releases/tag/v1.5.1) - (2023-09-15)<br/>
108109
Release [1.5.0](https://github.com/ekrich/sconfig/releases/tag/v1.5.0) - (2022-09-19)<br/>
109110
Release [1.4.9](https://github.com/ekrich/sconfig/releases/tag/v1.4.9) - (2022-01-25)<br/>
110111
Release [1.4.8](https://github.com/ekrich/sconfig/releases/tag/v1.4.8) - (2022-01-12)<br/>

build.sbt

+23-15
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ addCommandAlias(
88
).mkString(";", ";", "")
99
)
1010

11-
val prevVersion = "1.5.1"
12-
val nextVersion = "1.5.2"
11+
val prevVersion = "1.6.0"
12+
val nextVersion = "1.7.0"
1313

1414
// stable snapshot is not great for publish local
1515
def versionFmt(out: sbtdynver.GitDescribeOutput): String = {
@@ -53,7 +53,7 @@ val scCompat = "2.11.0"
5353
val versionsBase = Seq(scala212, scala213)
5454
val versions = versionsBase :+ scala3
5555

56-
ThisBuild / scalaVersion := scala3
56+
ThisBuild / scalaVersion := scala213
5757
ThisBuild / crossScalaVersions := versions
5858
ThisBuild / versionScheme := Some("early-semver")
5959
ThisBuild / mimaFailOnNoPrevious := false
@@ -116,14 +116,21 @@ lazy val sconfig = crossProject(JVMPlatform, NativePlatform, JSPlatform)
116116
scalacOptions ++= {
117117
if (isScala3.value) dotcOpts else scalacOpts
118118
},
119-
libraryDependencies += "org.scala-lang.modules" %%% "scala-collection-compat" % scCompat,
120-
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-s", "-v")
119+
libraryDependencies ++= Seq(
120+
"org.scala-lang.modules" %%% "scala-collection-compat" % scCompat,
121+
"org.json4s" %%% "json4s-native-core" % "4.0.7" % Test
122+
),
123+
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-s", "-v"),
124+
// env vars for tests
125+
Test / envVars ++= Map(
126+
"testList.0" -> "0",
127+
"testList.1" -> "1",
128+
"testClassesPath" -> (Test / classDirectory).value.getPath
129+
)
121130
)
122131
.jvmSettings(
123132
crossScalaVersions := versions,
124133
libraryDependencies ++= Seq(
125-
("io.crashbox" %% "spray-json" % "1.3.5-7" % Test)
126-
.cross(CrossVersion.for3Use2_13),
127134
"com.github.sbt" % "junit-interface" % "0.13.3" % Test
128135
// includes junit 4.13.2
129136
),
@@ -141,12 +148,6 @@ lazy val sconfig = crossProject(JVMPlatform, NativePlatform, JSPlatform)
141148
Test / fork := true,
142149
run / fork := true,
143150
Test / run / fork := true,
144-
// env vars for tests
145-
Test / envVars ++= Map(
146-
"testList.0" -> "0",
147-
"testList.1" -> "1",
148-
"testClassesPath" -> (Test / classDirectory).value.getPath
149-
),
150151
// uncomment for debugging
151152
// Test / javaOptions += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005",
152153
// mima settings
@@ -156,14 +157,21 @@ lazy val sconfig = crossProject(JVMPlatform, NativePlatform, JSPlatform)
156157
.nativeConfigure(_.enablePlugins(ScalaNativeJUnitPlugin))
157158
.nativeSettings(
158159
crossScalaVersions := versions,
159-
nativeConfig ~= (_.withLinkStubs(true)),
160+
nativeConfig ~= (
161+
_.withLinkStubs(true)
162+
.withEmbedResources(true)
163+
),
160164
logLevel := Level.Info, // Info or Debug
161165
libraryDependencies += "org.ekrich" %%% "sjavatime" % javaTime % "provided"
162166
)
163167
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
164168
.jsSettings(
165169
crossScalaVersions := versions,
166-
libraryDependencies += "org.ekrich" %%% "sjavatime" % javaTime % "provided"
170+
libraryDependencies ++= Seq(
171+
"org.ekrich" %%% "sjavatime" % javaTime % "provided",
172+
("org.scala-js" %%% "scalajs-weakreferences" % "1.0.0")
173+
.cross(CrossVersion.for3Use2_13)
174+
)
167175
)
168176

169177
lazy val `scalafix-rules` = (project in file("scalafix/rules"))

docs/SCALA-NATIVE.md

+28
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,34 @@ val maxCol = conf.getInt("maxColumn")
4545
val isGit = conf.getBoolean("project.git")
4646
```
4747

48+
## Using Reader - StringReader example
49+
50+
Both JS and Native now support `java.io.Reader` which allows using `sconfig`
51+
to parse all supported formats by passing a filename with extension. See the
52+
following examples from the shared `ConfigFactoryTest` file.
53+
54+
```scala
55+
val filename = "/test01.properties"
56+
val fileStr =
57+
"""
58+
|# test01.properties file
59+
|fromProps.abc=abc
60+
|fromProps.one=1
61+
|fromProps.bool=true
62+
|fromProps.specialChars=hello^^
63+
""".stripMargin
64+
65+
// create Reader
66+
var test01Reader = new StringReader(fileStr)
67+
68+
val config = ConfigFactory.parseReader(
69+
test01Reader,
70+
ConfigParseOptions.defaults
71+
.setSyntaxFromFilename(filename)
72+
)
73+
val specialChars = config.getString("fromProps.specialChars")
74+
```
75+
4876
### How to read a HOCON configuation file into a String for Scala Native
4977

5078
In order to read the configuration file into a `String` you need to know the relative

project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resolvers ++= Resolver.sonatypeOssRepos("snapshots")
33

44
// versions
55
val crossVer = "1.3.2"
6-
val scalaJSVersion = "1.14.0"
6+
val scalaJSVersion = "1.15.0"
77
val scalaNativeVersion = "0.4.16"
88
val scalafix = "0.11.1"
99

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.ekrich.config
2+
3+
/**
4+
* [[ConfigFactory]] methods for Scala.js platform
5+
*/
6+
abstract class PlatformConfigFactory extends ConfigFactoryCommon {}

sconfig/js/src/main/scala/PlatformClassLoader.scala sconfig/js/src/main/scala/org/ekrich/config/impl/PlatformClassLoader.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import java.{util => ju}
66
/**
77
* To workaround missing implementations
88
*/
9-
class PlatformClassLoader(cl: ClassLoader) extends ClassLoaderLike {
9+
class PlatformClassLoader(cl: ClassLoader) extends TraitClassLoader {
1010
def getResources(name: String): ju.Enumeration[URL] = ???
1111
}

sconfig/native/src/main/scala/PlatformThread.scala sconfig/js/src/main/scala/org/ekrich/config/impl/PlatformThread.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package org.ekrich.config.impl
33
/**
44
* To workaround missing implementations
55
*/
6-
class PlatformThread(thread: Thread) extends ThreadLike {
6+
class PlatformThread(thread: Thread) extends TraitThread {
77
def getContextClassLoader(): ClassLoader = ???
88
}

sconfig/js/src/main/scala/PlatformUri.scala sconfig/js/src/main/scala/org/ekrich/config/impl/PlatformUri.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import java.net.{URI, URL}
55
/**
66
* To workaround missing implementations
77
*/
8-
class PlatformUri(uri: URI) extends UriLike {
8+
class PlatformUri(uri: URI) extends TraitUri {
99
def toURL(): URL = ???
1010
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.ekrich.config
2+
3+
/**
4+
* [[ConfigFactory]] methods common to JVM and Native
5+
*/
6+
abstract class ConfigFactoryJvmNative extends ConfigFactoryCommon {}

sconfig/jvm-native/src/main/scala/PlatformClassLoader.scala sconfig/jvm-native/src/main/scala/org/ekrich/config/impl/PlatformClassLoader.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import java.{util => ju}
66
/**
77
* To workaround missing implementations
88
*/
9-
class PlatformClassLoader(cl: ClassLoader) extends ClassLoaderLike {
9+
class PlatformClassLoader(cl: ClassLoader) extends TraitClassLoader {
1010
def getResources(name: String): ju.Enumeration[URL] = cl.getResources(name)
1111
}

sconfig/jvm-native/src/main/scala/PlatformUri.scala sconfig/jvm-native/src/main/scala/org/ekrich/config/impl/PlatformUri.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import java.net.{URI, URL}
55
/**
66
* To workaround missing implementations
77
*/
8-
class PlatformUri(uri: URI) extends UriLike {
8+
class PlatformUri(uri: URI) extends TraitUri {
99
def toURL(): URL = uri.toURL()
1010
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.ekrich.config.impl
2+
3+
// import org.junit.Assert._
4+
// import org.junit.Test
5+
6+
class ConfigFactoryJvmNativeTest {
7+
// Empty for now - Scala.js has parody with Scala Native for now
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.ekrich.config
2+
3+
/**
4+
* [[ConfigFactory]] methods for Scala JVM platform
5+
*/
6+
abstract class PlatformConfigFactory extends ConfigFactoryJvmNative {}

sconfig/jvm/src/main/scala/PlatformThread.scala sconfig/jvm/src/main/scala/org/ekrich/config/impl/PlatformThread.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package org.ekrich.config.impl
33
/**
44
* To workaround missing implementations in Scala.js and Scala Native
55
*/
6-
class PlatformThread(thread: Thread) extends ThreadLike {
6+
class PlatformThread(thread: Thread) extends TraitThread {
77
def getContextClassLoader(): ClassLoader = thread.getContextClassLoader()
88
}

sconfig/jvm/src/test/scala/org/ekrich/config/impl/ConfigDocumentTest.scala sconfig/jvm/src/test/scala/org/ekrich/config/impl/ConfigDocumentFactoryTest.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.junit.Test
1010
import scala.jdk.CollectionConverters._
1111
import FileUtils._
1212

13-
class ConfigDocumentTest extends TestUtils {
13+
class ConfigDocumentFactoryTest extends TestUtils {
1414
private def configDocumentReplaceJsonTest(
1515
origText: String,
1616
finalText: String,

0 commit comments

Comments
 (0)