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

Provide for better Platform support and testing #350

Merged
merged 28 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1d265ff
Add classes to allow migrations of methods to specific platforms
ekrich Sep 28, 2023
38a520f
Move some common methods
ekrich Sep 28, 2023
916578c
Move platform to config package
ekrich Sep 28, 2023
19192b4
Format
ekrich Sep 28, 2023
7ecf0a9
Remove ConfigFactoryCommon
ekrich Sep 28, 2023
b110582
Shared JVM Native tests work
ekrich Sep 28, 2023
e88efed
Add resources to jvm-native, embedded resources, add back common
ekrich Sep 30, 2023
784c2c0
Rollback test file move
ekrich Sep 30, 2023
1da6730
Move parseString to common
ekrich Oct 14, 2023
d6313c8
Works good for all platforms, stub for JvmNative
ekrich Oct 27, 2023
a5dc426
Add two Reader tests to Native
ekrich Oct 31, 2023
c2a92b3
Make default build 2.13 and rename ConfigDocumentTest to ConfigDocume…
ekrich Nov 11, 2023
1599b94
Move ConfigFactoryTests to impl like other tests
ekrich Nov 11, 2023
49ae320
Move tests from ConfigTest to ConfigFactoryJvmTest and then ConfigTes…
ekrich Nov 11, 2023
eae2319
Make test class names singular
ekrich Nov 11, 2023
026e579
Checkpoint commit for ConfigOrigin setup
ekrich Nov 17, 2023
7d9f09f
Update to more shared tests, add URL for Native, from 189 to 228 test…
ekrich Nov 20, 2023
94a39eb
Add env vars to shared in anticipation of using them in Native or JS
ekrich Nov 20, 2023
75652b0
Move ConfigSubstitutionTests to shared
ekrich Nov 20, 2023
afc02f2
Json4s almost works
ekrich Nov 21, 2023
e0f2c52
Json4s cleanup
ekrich Nov 22, 2023
149f2dd
Got json4s test to work
ekrich Nov 23, 2023
e3a7bac
Make comments generic
ekrich Nov 23, 2023
0ac9a11
JsonTest is now cross platform
ekrich Nov 23, 2023
7f896e4
Small updates, JS setting commented out
ekrich Nov 28, 2023
afe558d
Upgrade to new version of json4s to fix JS ClassCastException problem
ekrich Dec 5, 2023
de74512
Upgrade Scala.js to 1.15.0, allow Reader tests now
ekrich Dec 28, 2023
a603982
Update docs and readme for release
ekrich Dec 28, 2023
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ At a high level, the process is as follows:

## Versions

Release [1.5.1](https://github.com/ekrich/sconfig/releases/tag/v1.5.1) - (2023-09-14)<br/>
Release [1.6.0](https://github.com/ekrich/sconfig/releases/tag/v1.6.0) - (2023-12-28)<br/>
Release [1.5.1](https://github.com/ekrich/sconfig/releases/tag/v1.5.1) - (2023-09-15)<br/>
Release [1.5.0](https://github.com/ekrich/sconfig/releases/tag/v1.5.0) - (2022-09-19)<br/>
Release [1.4.9](https://github.com/ekrich/sconfig/releases/tag/v1.4.9) - (2022-01-25)<br/>
Release [1.4.8](https://github.com/ekrich/sconfig/releases/tag/v1.4.8) - (2022-01-12)<br/>
Expand Down
38 changes: 23 additions & 15 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ addCommandAlias(
).mkString(";", ";", "")
)

val prevVersion = "1.5.1"
val nextVersion = "1.5.2"
val prevVersion = "1.6.0"
val nextVersion = "1.7.0"

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

ThisBuild / scalaVersion := scala3
ThisBuild / scalaVersion := scala213
ThisBuild / crossScalaVersions := versions
ThisBuild / versionScheme := Some("early-semver")
ThisBuild / mimaFailOnNoPrevious := false
Expand Down Expand Up @@ -116,14 +116,21 @@ lazy val sconfig = crossProject(JVMPlatform, NativePlatform, JSPlatform)
scalacOptions ++= {
if (isScala3.value) dotcOpts else scalacOpts
},
libraryDependencies += "org.scala-lang.modules" %%% "scala-collection-compat" % scCompat,
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-s", "-v")
libraryDependencies ++= Seq(
"org.scala-lang.modules" %%% "scala-collection-compat" % scCompat,
"org.json4s" %%% "json4s-native-core" % "4.0.7" % Test
),
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-s", "-v"),
// env vars for tests
Test / envVars ++= Map(
"testList.0" -> "0",
"testList.1" -> "1",
"testClassesPath" -> (Test / classDirectory).value.getPath
)
)
.jvmSettings(
crossScalaVersions := versions,
libraryDependencies ++= Seq(
("io.crashbox" %% "spray-json" % "1.3.5-7" % Test)
.cross(CrossVersion.for3Use2_13),
"com.github.sbt" % "junit-interface" % "0.13.3" % Test
// includes junit 4.13.2
),
Expand All @@ -141,12 +148,6 @@ lazy val sconfig = crossProject(JVMPlatform, NativePlatform, JSPlatform)
Test / fork := true,
run / fork := true,
Test / run / fork := true,
// env vars for tests
Test / envVars ++= Map(
"testList.0" -> "0",
"testList.1" -> "1",
"testClassesPath" -> (Test / classDirectory).value.getPath
),
// uncomment for debugging
// Test / javaOptions += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005",
// mima settings
Expand All @@ -156,14 +157,21 @@ lazy val sconfig = crossProject(JVMPlatform, NativePlatform, JSPlatform)
.nativeConfigure(_.enablePlugins(ScalaNativeJUnitPlugin))
.nativeSettings(
crossScalaVersions := versions,
nativeConfig ~= (_.withLinkStubs(true)),
nativeConfig ~= (
_.withLinkStubs(true)
.withEmbedResources(true)
),
logLevel := Level.Info, // Info or Debug
libraryDependencies += "org.ekrich" %%% "sjavatime" % javaTime % "provided"
)
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
.jsSettings(
crossScalaVersions := versions,
libraryDependencies += "org.ekrich" %%% "sjavatime" % javaTime % "provided"
libraryDependencies ++= Seq(
"org.ekrich" %%% "sjavatime" % javaTime % "provided",
("org.scala-js" %%% "scalajs-weakreferences" % "1.0.0")
.cross(CrossVersion.for3Use2_13)
)
)

lazy val `scalafix-rules` = (project in file("scalafix/rules"))
Expand Down
28 changes: 28 additions & 0 deletions docs/SCALA-NATIVE.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,34 @@ val maxCol = conf.getInt("maxColumn")
val isGit = conf.getBoolean("project.git")
```

## Using Reader - StringReader example

Both JS and Native now support `java.io.Reader` which allows using `sconfig`
to parse all supported formats by passing a filename with extension. See the
following examples from the shared `ConfigFactoryTest` file.

```scala
val filename = "/test01.properties"
val fileStr =
"""
|# test01.properties file
|fromProps.abc=abc
|fromProps.one=1
|fromProps.bool=true
|fromProps.specialChars=hello^^
""".stripMargin

// create Reader
var test01Reader = new StringReader(fileStr)

val config = ConfigFactory.parseReader(
test01Reader,
ConfigParseOptions.defaults
.setSyntaxFromFilename(filename)
)
val specialChars = config.getString("fromProps.specialChars")
```

### How to read a HOCON configuation file into a String for Scala Native

In order to read the configuration file into a `String` you need to know the relative
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolvers ++= Resolver.sonatypeOssRepos("snapshots")

// versions
val crossVer = "1.3.2"
val scalaJSVersion = "1.14.0"
val scalaJSVersion = "1.15.0"
val scalaNativeVersion = "0.4.16"
val scalafix = "0.11.1"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.ekrich.config

/**
* [[ConfigFactory]] methods for Scala.js platform
*/
abstract class PlatformConfigFactory extends ConfigFactoryCommon {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import java.{util => ju}
/**
* To workaround missing implementations
*/
class PlatformClassLoader(cl: ClassLoader) extends ClassLoaderLike {
class PlatformClassLoader(cl: ClassLoader) extends TraitClassLoader {
def getResources(name: String): ju.Enumeration[URL] = ???
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package org.ekrich.config.impl
/**
* To workaround missing implementations
*/
class PlatformThread(thread: Thread) extends ThreadLike {
class PlatformThread(thread: Thread) extends TraitThread {
def getContextClassLoader(): ClassLoader = ???
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import java.net.{URI, URL}
/**
* To workaround missing implementations
*/
class PlatformUri(uri: URI) extends UriLike {
class PlatformUri(uri: URI) extends TraitUri {
def toURL(): URL = ???
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.ekrich.config

/**
* [[ConfigFactory]] methods common to JVM and Native
*/
abstract class ConfigFactoryJvmNative extends ConfigFactoryCommon {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import java.{util => ju}
/**
* To workaround missing implementations
*/
class PlatformClassLoader(cl: ClassLoader) extends ClassLoaderLike {
class PlatformClassLoader(cl: ClassLoader) extends TraitClassLoader {
def getResources(name: String): ju.Enumeration[URL] = cl.getResources(name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import java.net.{URI, URL}
/**
* To workaround missing implementations
*/
class PlatformUri(uri: URI) extends UriLike {
class PlatformUri(uri: URI) extends TraitUri {
def toURL(): URL = uri.toURL()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.ekrich.config.impl

// import org.junit.Assert._
// import org.junit.Test

class ConfigFactoryJvmNativeTest {
// Empty for now - Scala.js has parody with Scala Native for now
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.ekrich.config

/**
* [[ConfigFactory]] methods for Scala JVM platform
*/
abstract class PlatformConfigFactory extends ConfigFactoryJvmNative {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package org.ekrich.config.impl
/**
* To workaround missing implementations in Scala.js and Scala Native
*/
class PlatformThread(thread: Thread) extends ThreadLike {
class PlatformThread(thread: Thread) extends TraitThread {
def getContextClassLoader(): ClassLoader = thread.getContextClassLoader()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.junit.Test
import scala.jdk.CollectionConverters._
import FileUtils._

class ConfigDocumentTest extends TestUtils {
class ConfigDocumentFactoryTest extends TestUtils {
private def configDocumentReplaceJsonTest(
origText: String,
finalText: String,
Expand Down
Loading