From 18f4f70cdf7ba199a07f32d05c7535921335f740 Mon Sep 17 00:00:00 2001 From: Eric K Richardson Date: Fri, 27 Oct 2023 14:57:35 -0700 Subject: [PATCH] Works good for all platforms, stub for JvmNative --- .../config/ConfigFactoryJvmNativeTests.scala | 1 + .../main/scala/org/ekrich/config/Config.scala | 11 +++--- .../org/ekrich/config/ConfigFactory.scala | 36 +------------------ .../ekrich/config/ConfigFactoryCommon.scala | 36 +++++++++++++++++++ 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/sconfig/jvm-native/src/test/scala/org/ekrich/config/ConfigFactoryJvmNativeTests.scala b/sconfig/jvm-native/src/test/scala/org/ekrich/config/ConfigFactoryJvmNativeTests.scala index 3fcfe73e..3323da11 100644 --- a/sconfig/jvm-native/src/test/scala/org/ekrich/config/ConfigFactoryJvmNativeTests.scala +++ b/sconfig/jvm-native/src/test/scala/org/ekrich/config/ConfigFactoryJvmNativeTests.scala @@ -4,6 +4,7 @@ import org.junit.Assert._ import org.junit.Test class ConfigFactoryJvmNativeTests { + // These are in common test but this is File test will be. @Test def parseString: Unit = { val configStr = """ diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/Config.scala b/sconfig/shared/src/main/scala/org/ekrich/config/Config.scala index bec0b84e..750a58a8 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/Config.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/Config.scala @@ -117,18 +117,17 @@ import scala.annotation.varargs *

Serialization * *

Convert a `Config` to a JSON or HOCON string by calling [[#root root]] to - * get the [[ConfigObject]] and then call - * [[ConfigValue!.render:String render]] on the root object, - * `myConfig.root.render`. There's also a variant + * get the [[ConfigObject]] and then call [[ConfigValue!.render:String render]] + * on the root object, `myConfig.root.render`. There's also a variant * [[ConfigValue!.render(options:org\.ekrich\.config\.ConfigRenderOptions)* render(ConfigRenderOptions)]] * inherited from [[ConfigValue]] which allows you to control the format of the * rendered string. (See [[ConfigRenderOptions]].) Note that `Config` does not * remember the formatting of the original file, so if you load, modify, and * re-save a config file, it will be substantially reformatted. * - *

As an alternative to [[ConfigValue!.render:String render]], the `toString` - * method produces a debug-output-oriented representation (which is not valid - * JSON). + *

As an alternative to [[ConfigValue!.render:String render]], the + * `toString` method produces a debug-output-oriented representation (which is + * not valid JSON). * * Note: no arg render links do not link correctly. See * https://github.com/lampepfl/dotty/issues/14212 diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/ConfigFactory.scala b/sconfig/shared/src/main/scala/org/ekrich/config/ConfigFactory.scala index 55eeadeb..61061963 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/ConfigFactory.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/ConfigFactory.scala @@ -3,7 +3,7 @@ */ package org.ekrich.config -import java.io.{File, Reader} +import java.io.File import java.net.URL import java.{util => ju} import java.util.Properties @@ -615,40 +615,6 @@ object ConfigFactory extends PlatformConfigFactory { def parseProperties(properties: Properties): Config = parseProperties(properties, ConfigParseOptions.defaults) - /** - * Parses a Reader into a Config instance. Does not call - * [[Config!.resolve()* Config.resolve()]] or merge the parsed stream with any - * other configuration; this method parses a single stream and does nothing - * else. It does process "include" statements in the parsed stream, and may - * end up doing other IO due to those statements. - * - * @param reader - * the reader to parse - * @param options - * parse options to control how the reader is interpreted - * @return - * the parsed configuration - * @throws ConfigException - * on IO or parse errors - */ - def parseReader(reader: Reader, options: ConfigParseOptions): Config = - Parseable.newReader(reader, options).parse().toConfig - - /** - * Parses a reader into a Config instance as with - * [[#parseReader(reader:java\.io\.Reader,options:org\.ekrich\.config\.ConfigParseOptions)* parseReader(Reader, ConfigParseOptions)]] - * but always uses the default parse options. - * - * @param reader - * the reader to parse - * @return - * the parsed configuration - * @throws ConfigException - * on IO or parse errors - */ - def parseReader(reader: Reader): Config = - parseReader(reader, ConfigParseOptions.defaults) - /** * Parses a URL into a Config instance. Does not call * [[Config!.resolve()* Config.resolve()]] or merge the parsed stream with any diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/ConfigFactoryCommon.scala b/sconfig/shared/src/main/scala/org/ekrich/config/ConfigFactoryCommon.scala index 4e0a38b8..45a0c5c8 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/ConfigFactoryCommon.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/ConfigFactoryCommon.scala @@ -1,5 +1,7 @@ package org.ekrich.config +import java.io.Reader + import org.ekrich.config.impl.Parseable abstract class ConfigFactoryCommon { @@ -29,4 +31,38 @@ abstract class ConfigFactoryCommon { def parseString(s: String): Config = parseString(s, ConfigParseOptions.defaults) + /** + * Parses a Reader into a Config instance. Does not call + * [[Config!.resolve()* Config.resolve()]] or merge the parsed stream with any + * other configuration; this method parses a single stream and does nothing + * else. It does process "include" statements in the parsed stream, and may + * end up doing other IO due to those statements. + * + * @param reader + * the reader to parse + * @param options + * parse options to control how the reader is interpreted + * @return + * the parsed configuration + * @throws ConfigException + * on IO or parse errors + */ + def parseReader(reader: Reader, options: ConfigParseOptions): Config = + Parseable.newReader(reader, options).parse().toConfig + + /** + * Parses a reader into a Config instance as with + * [[#parseReader(reader:java\.io\.Reader,options:org\.ekrich\.config\.ConfigParseOptions)* parseReader(Reader, ConfigParseOptions)]] + * but always uses the default parse options. + * + * @param reader + * the reader to parse + * @return + * the parsed configuration + * @throws ConfigException + * on IO or parse errors + */ + def parseReader(reader: Reader): Config = + parseReader(reader, ConfigParseOptions.defaults) + }