From ad1f43e98b75760c0d4879db2b79e31974fd7728 Mon Sep 17 00:00:00 2001 From: Michael Liarakos Date: Wed, 26 Jan 2022 23:42:17 -0500 Subject: [PATCH 01/12] applied scalafmt and resolved warnings --- .scalafmt.conf | 53 +++++ .travis.yml | 8 +- build.sbt | 75 ++----- .../src/test/scala/{ => tests}/AkkaConf.scala | 4 +- facade/jvm/src/test/scala/AkkaConf.scala | 11 - .../jvm/src/test/scala/tests/AkkaConf.scala | 23 ++ .../scala/com/typesafe/config/Config.scala | 168 +++++++------- .../com/typesafe/config/ConfigException.scala | 9 +- .../com/typesafe/config/ConfigMergeable.scala | 5 +- .../com/typesafe/config/ConfigObject.scala | 10 +- .../com/typesafe/config/ConfigValue.scala | 12 +- .../com/typesafe/config/ConfigValueType.scala | 3 +- .../com/typesafe/config/MemoryUnit.scala | 33 ++- .../scala/com/typesafe/config/package.scala | 8 +- .../org/akkajs/shocon/ConfigLoader.scala | 95 ++++---- .../test/scala/{ => tests}/AkkaConfig.scala | 7 +- .../scala/{ => tests}/SHoconGenericSpec.scala | 170 ++++++-------- plugin/build.sbt | 13 +- plugin/project/build.properties | 2 +- plugin/project/plugins.sbt | 4 +- .../shocon/sbtplugin/ShoconPlugin.scala | 95 ++++---- plugin/src/sbt-test/shocon/basic/build.sbt | 23 +- .../sbt-test/shocon/basic/project/plugins.sbt | 4 +- project/Common.scala | 91 ++++---- project/build.properties | 2 +- project/plugins.sbt | 7 +- publish.sh | 6 +- scalastyle-config.xml | 211 ++++++++---------- .../org/akkajs/shocon/ConfigMacroLoader.scala | 96 ++++---- .../org/akkajs/shocon/ConfigParser.scala | 81 +++---- .../scala/org/akkajs/shocon/Extractors.scala | 71 +++--- .../main/scala/org/akkajs/shocon/SHocon.scala | 123 +++++----- 32 files changed, 767 insertions(+), 756 deletions(-) create mode 100644 .scalafmt.conf rename facade/js/src/test/scala/{ => tests}/AkkaConf.scala (99%) delete mode 100644 facade/jvm/src/test/scala/AkkaConf.scala create mode 100644 facade/jvm/src/test/scala/tests/AkkaConf.scala rename facade/shared/src/test/scala/{ => tests}/AkkaConfig.scala (99%) rename facade/shared/src/test/scala/{ => tests}/SHoconGenericSpec.scala (78%) diff --git a/.scalafmt.conf b/.scalafmt.conf new file mode 100644 index 0000000..4452a40 --- /dev/null +++ b/.scalafmt.conf @@ -0,0 +1,53 @@ +version = 2.1.0 + +style = defaultWithAlign + +docstrings = JavaDoc +indentOperator = spray +maxColumn = 120 +rewrite.rules = [RedundantParens, SortImports, AvoidInfix] +unindentTopLevelOperators = true +align.tokens = [{code = "=>", owner = "Case"}] +align.openParenDefnSite = false +align.openParenCallSite = false +optIn.breakChainOnFirstMethodDot = false +optIn.configStyleArguments = false +danglingParentheses = false +spaces.inImportCurlyBraces = true +rewrite.neverInfix.excludeFilters = [ + and + min + max + until + to + by + eq + ne + "should.*" + "contain.*" + "must.*" + in + ignore + be + taggedAs + thrownBy + synchronized + have + when + size + only + noneOf + oneElementOf + noElementsOf + atLeastOneElementOf + atMostOneElementOf + allElementsOf + inOrderElementsOf + theSameElementsAs + theSameElementsInOrderAs +] +rewriteTokens = { + "⇒": "=>" + "→": "->" + "←": "<-" +} diff --git a/.travis.yml b/.travis.yml index d5bb5d9..15f045d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,15 +6,15 @@ jdk: openjdk8 language: scala scala: - - "2.13.1" - - "2.12.10" + - "2.13.4" + - "2.12.13" jdk: openjdk8 matrix: include: - - env: SBT_VERSION=1.3.8 - scala: "2.12.10" + - env: SBT_VERSION=1.3.13 + scala: "2.12.13" env: - TRAVIS_NODE_VERSION="10.17.0" diff --git a/build.sbt b/build.sbt index b796574..64675ce 100644 --- a/build.sbt +++ b/build.sbt @@ -2,10 +2,7 @@ import xerial.sbt.Sonatype._ import sbtcrossproject.CrossPlugin.autoImport.crossProject -lazy val root = project - .in(file(".")) - .aggregate(parserJS, parserJVM, facadeJS, facadeJVM) - .settings(sonatypeSettings) +lazy val root = project.in(file(".")).aggregate(parserJS, parserJVM, facadeJS, facadeJVM).settings(sonatypeSettings) lazy val fixResources = taskKey[Unit]("Fix application.conf presence on first clean build.") @@ -15,42 +12,28 @@ lazy val parser = crossProject(JSPlatform, JVMPlatform) .settings( name := "shocon-parser", scalacOptions ++= - Seq( - "-feature", - "-unchecked", - "-language:implicitConversions", - "-deprecation", - ), - publishTo := sonatypePublishTo.value - ) + Seq("-feature", "-unchecked", "-language:implicitConversions", "-deprecation"), + publishTo := sonatypePublishTo.value) .settings(sonatypeSettings) .settings( fixResources := { val compileConf = (resourceDirectory in Compile).value / "application.conf" - if (compileConf.exists) - IO.copyFile( - compileConf, - (classDirectory in Compile).value / "application.conf" - ) + if (compileConf.exists) { + IO.copyFile(compileConf, (classDirectory in Compile).value / "application.conf") + } val testConf = (resourceDirectory in Test).value / "application.conf" if (testConf.exists) { - IO.copyFile( - testConf, - (classDirectory in Test).value / "application.conf" - ) + IO.copyFile(testConf, (classDirectory in Test).value / "application.conf") } }, compile in Compile := (compile in Compile).dependsOn(fixResources).value, libraryDependencies ++= Seq( - "org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.4", - "com.lihaoyi" %%% "fastparse" % "2.2.4", - "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided" - ) - ) + "org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.4", + "com.lihaoyi" %%% "fastparse" % "2.2.4", + "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided")) .jsSettings( libraryDependencies += "org.scala-js" %%% "scalajs-java-time" % "1.0.0", - parallelExecution in Test := true - ) + parallelExecution in Test := true) lazy val parserJVM = parser.jvm lazy val parserJS = parser.js @@ -61,44 +44,30 @@ lazy val facade = crossProject(JSPlatform, JVMPlatform) .settings( name := "shocon", scalacOptions ++= - Seq( - "-feature", - "-unchecked", - "-language:implicitConversions", - "-deprecation", - ), - publishTo := sonatypePublishTo.value - ) + Seq("-feature", "-unchecked", "-language:implicitConversions", "-deprecation"), + publishTo := sonatypePublishTo.value) .settings(sonatypeSettings) .settings( fixResources := { val compileConf = (resourceDirectory in Compile).value / "application.conf" - if (compileConf.exists) - IO.copyFile( - compileConf, - (classDirectory in Compile).value / "application.conf" - ) + if (compileConf.exists) { + IO.copyFile(compileConf, (classDirectory in Compile).value / "application.conf") + } val testConf = (resourceDirectory in Test).value / "application.conf" if (testConf.exists) { - IO.copyFile( - testConf, - (classDirectory in Test).value / "application.conf" - ) + IO.copyFile(testConf, (classDirectory in Test).value / "application.conf") } }, compile in Compile := (compile in Compile).dependsOn(fixResources).value, testFrameworks += new TestFramework("utest.runner.Framework"), libraryDependencies ++= Seq( - "org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.4", - "com.lihaoyi" %%% "fastparse" % "2.2.4", - "com.lihaoyi" %%% "utest" % "0.7.4" % "test", - "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided" - ) - ) + "org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.4", + "com.lihaoyi" %%% "fastparse" % "2.2.4", + "com.lihaoyi" %%% "utest" % "0.7.4" % "test", + "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided")) .jsSettings( libraryDependencies += "org.scala-js" %%% "scalajs-java-time" % "1.0.0", - parallelExecution in Test := true - ) + parallelExecution in Test := true) lazy val facadeJVM = facade.jvm lazy val facadeJS = facade.js diff --git a/facade/js/src/test/scala/AkkaConf.scala b/facade/js/src/test/scala/tests/AkkaConf.scala similarity index 99% rename from facade/js/src/test/scala/AkkaConf.scala rename to facade/js/src/test/scala/tests/AkkaConf.scala index 6c9a7a0..9eb2f7c 100644 --- a/facade/js/src/test/scala/AkkaConf.scala +++ b/facade/js/src/test/scala/tests/AkkaConf.scala @@ -1,7 +1,5 @@ package tests -import scala.scalajs.js.Dynamic.global - object AkkaConf { def basic: String = """ @@ -73,7 +71,7 @@ akka { """ - def long = + def long: String = """ # This is an unmodified akka-reference.conf, except for this # comment and quoting one key that contained slashes. diff --git a/facade/jvm/src/test/scala/AkkaConf.scala b/facade/jvm/src/test/scala/AkkaConf.scala deleted file mode 100644 index 631ddc2..0000000 --- a/facade/jvm/src/test/scala/AkkaConf.scala +++ /dev/null @@ -1,11 +0,0 @@ -package tests - -object AkkaConf { - - def basic = - io.Source.fromFile("facade/jvm/src/test/resources/akka.conf").mkString - - def long = - io.Source.fromFile("facade/jvm/src/test/resources/akka-long.conf").mkString - -} diff --git a/facade/jvm/src/test/scala/tests/AkkaConf.scala b/facade/jvm/src/test/scala/tests/AkkaConf.scala new file mode 100644 index 0000000..6c8eb7b --- /dev/null +++ b/facade/jvm/src/test/scala/tests/AkkaConf.scala @@ -0,0 +1,23 @@ +package tests + +object AkkaConf { + + def basic: String = { + val bufferedSource = io.Source.fromFile("facade/jvm/src/test/resources/akka.conf") + try { + bufferedSource.mkString + } finally { + bufferedSource.close() + } + } + + def long: String = { + val bufferedSource = io.Source.fromFile("facade/jvm/src/test/resources/akka-long.conf") + try { + bufferedSource.mkString + } finally { + bufferedSource.close() + } + } + +} diff --git a/facade/shared/src/main/scala/com/typesafe/config/Config.scala b/facade/shared/src/main/scala/com/typesafe/config/Config.scala index c5cd370..89f86d1 100644 --- a/facade/shared/src/main/scala/com/typesafe/config/Config.scala +++ b/facade/shared/src/main/scala/com/typesafe/config/Config.scala @@ -1,16 +1,15 @@ package com.typesafe.config -import java.util.{concurrent => juc} -import java.{time => jt, util => ju} - import org.akkajs.shocon import org.akkajs.shocon.Config.Value import org.akkajs.shocon.Extractor -import scala.jdk.CollectionConverters._ +import java.util.{ concurrent => juc } +import java.{ time => jt, util => ju } import scala.collection.compat._ import scala.collection.mutable import scala.concurrent.duration._ +import scala.jdk.CollectionConverters._ import scala.language.experimental.macros object ConfigFactory { @@ -27,10 +26,10 @@ object ConfigFactory { def defaultReference(cl: ClassLoader): Config = macro ConfigLoader.loadDefaultImplCL - def empty() = Config(shocon.Config.gen("{}")) + def empty(): Config = Config(shocon.Config.gen("{}")) - def parseMap(values: java.util.Map[String, Any]) = - Config(shocon.Config.Object.fromPairs(values.asScala.map{ + def parseMap(values: java.util.Map[String, Any]): Config = + Config(shocon.Config.Object.fromPairs(values.asScala.map { case (k, v) => k -> shocon.Config.StringLiteral(v.toString) }.toSeq)) @@ -47,39 +46,47 @@ case class Config(cfg: shocon.Config.Value) { self => this(shocon.Config.gen("{}")) } - def root() = { + def root(): ConfigObject = { new ConfigObject() { - val inner = self.cfg - def unwrapped = - cfg.as[shocon.Config.Object].get.unwrapped.toMap.asJava + val inner: Value = self.cfg + def unwrapped: ju.Map[String, Any] = cfg.as[shocon.Config.Object].get.unwrapped.toMap.asJava def entrySet(): ju.Set[ju.Map.Entry[String, ConfigValue]] = - cfg.as[shocon.Config.Object].get.fields.view.mapValues(v => new ConfigValue() { - override val inner: Value = v - }).toMap.asJava.entrySet() + cfg + .as[shocon.Config.Object] + .get + .fields + .view + .mapValues(v => + new ConfigValue() { + override val inner: Value = v + }) + .toMap + .asJava + .entrySet() } } - def entrySet(): ju.Set[ju.Map.Entry[String, ConfigValue]] = root.entrySet() + def entrySet(): ju.Set[ju.Map.Entry[String, ConfigValue]] = root().entrySet() def checkValid(c: Config, paths: String*): Unit = {} def resolve(): Config = this - def withFallback(c: Config) = { - if (c != null) + def withFallback(c: Config): Config = { + if (c != null) { c.fallbackStack.foreach(fallback => fallbackStack.enqueue(fallback)) + } this } def getOrReturnNull[T](path: String)(implicit ev: Extractor[T]): T = { lazy val res: T = - scala.util.Try { - ev( - fallbackStack - .find(_.get(path).isDefined) - .flatMap(_.get(path)).get - ) - }.toOption.getOrElse(null.asInstanceOf[T]) + scala.util + .Try { + ev(fallbackStack.find(_.get(path).isDefined).flatMap(_.get(path)).get) + } + .toOption + .getOrElse(null.asInstanceOf[T]) res } @@ -93,29 +100,28 @@ case class Config(cfg: shocon.Config.Value) { self => .filter(_.get(path).isDefined) .map(_.get(path).get) .filter(_ != null) - .map(Config(_)) + .map(Config) .filter(_ != null) - val config = configs(0) - configs.tail.foreach{ c => + val config = configs.head + configs.tail.foreach { c => config.withFallback(c) } config } catch { - case _ : Throwable => - null.asInstanceOf[Config] + case _: Throwable => null.asInstanceOf[Config] } } - def getString(path: String) = getOrReturnNull[String](path) + def getString(path: String): String = getOrReturnNull[String](path) def getBoolean(path: String): Boolean = getOrReturnNull[Boolean](path) - def getInt(path: String) = getOrReturnNull[Int](path) + def getInt(path: String): Int = getOrReturnNull[Int](path) - def getLong(path: String) = getOrReturnNull[Long](path) + def getLong(path: String): Long = getOrReturnNull[Long](path) - def getDouble(path: String) = getOrReturnNull[Double](path) + def getDouble(path: String): Double = getOrReturnNull[Double](path) def getBytes(path: String): Long = { val bytesValue = getString(path) @@ -123,28 +129,24 @@ case class Config(cfg: shocon.Config.Value) { self => } /** - * Parses a size-in-bytes string. If no units are specified in the string, - * it is assumed to be in bytes. The returned value is in bytes. The purpose - * of this function is to implement the size-in-bytes-related methods in the - * Config interface. - * - * @param input - * the string to parse - * @param pathForException - * path to include in exceptions - * @return size in bytes - * @throws ConfigException - * if string is invalid - */ + * Parses a size-in-bytes string. If no units are specified in the string, + * it is assumed to be in bytes. The returned value is in bytes. The purpose + * of this function is to implement the size-in-bytes-related methods in the + * Config interface. + * + * @param input the string to parse + * @param pathForException path to include in exceptions + * @return size in bytes + * @throws ConfigException if string is invalid + */ def parseBytes(input: String, pathForException: String): Long = { val s: String = unicodeTrim(input) val unitString: String = getUnits(s) - val numberString: String = unicodeTrim( - s.substring(0, s.length() - unitString.length())) + val numberString: String = unicodeTrim(s.substring(0, s.length() - unitString.length())) // this would be caught later anyway, but the error message // is more helpful if we check it here. - if (numberString.length() == 0) { + if (numberString.isEmpty) { throw ConfigException.BadValue(pathForException) } val units: Option[MemoryUnit] = MemoryUnit.parseUnit(unitString) @@ -161,8 +163,7 @@ case class Config(cfg: shocon.Config.Value) { self => if (numberString.matches("[0-9]+")) { unitBytes * BigInt(numberString) } else { - val resultDecimal: BigDecimal = BigDecimal(unitBytes) * BigDecimal( - numberString) + val resultDecimal: BigDecimal = BigDecimal(unitBytes) * BigDecimal(numberString) resultDecimal.toBigInt } @@ -172,7 +173,7 @@ case class Config(cfg: shocon.Config.Value) { self => throw ConfigException.BadValue(pathForException) } } catch { - case e: NumberFormatException => + case _: NumberFormatException => throw ConfigException.BadValue(pathForException) } } @@ -180,13 +181,13 @@ case class Config(cfg: shocon.Config.Value) { self => def getStringList(path: String): ju.List[String] = getOrReturnNull[ju.List[String]](path) match { case null => List[String]().asJava - case ret => ret + case ret => ret } def getConfigList(path: String): ju.List[Config] = getOrReturnNull[ju.List[shocon.Config.Value]](path) match { case null => List[Config]().asJava - case ret => ret.asScala.map(Config).asJava + case ret => ret.asScala.map(Config).asJava } def getDuration(path: String, unit: TimeUnit): Long = { @@ -198,7 +199,7 @@ case class Config(cfg: shocon.Config.Value) { self => def getDuration(path: String): jt.Duration = { val durationValue = getString(path) val nanos = parseDurationAsNanos(durationValue) - return jt.Duration.ofNanos(nanos) + jt.Duration.ofNanos(nanos) } def parseDurationAsNanos(input: String): Long = { @@ -207,64 +208,69 @@ case class Config(cfg: shocon.Config.Value) { self => val s: String = unicodeTrim(input) val originalUnitString: String = getUnits(s) var unitString: String = originalUnitString - val numberString: String = unicodeTrim( - s.substring(0, s.length - unitString.length)) + val numberString: String = unicodeTrim(s.substring(0, s.length - unitString.length)) - if (numberString.length == 0) - throw new ConfigException.BadValue( - "No number in duration value '" + input + "'") - if (unitString.length > 2 && !unitString.endsWith("s")) + if (numberString.isEmpty) { + throw ConfigException.BadValue("No number in duration value '" + input + "'") + } + if (unitString.length > 2 && !unitString.endsWith("s")) { unitString = unitString + "s" + } val units = unitString match { case "" | "ms" | "millis" | "milliseconds" => MILLISECONDS - case "us" | "micros" | "microseconds" => MICROSECONDS - case "d" | "days" => DAYS - case "h" | "hours" => HOURS - case "s" | "seconds" => SECONDS - case "m" | "minutes" => MINUTES + case "us" | "micros" | "microseconds" => MICROSECONDS + case "d" | "days" => DAYS + case "h" | "hours" => HOURS + case "s" | "seconds" => SECONDS + case "m" | "minutes" => MINUTES case _ => - throw new ConfigException.BadValue( - "Could not parse time unit '" + originalUnitString + "' (try ns, us, ms, s, m, h, d)") + throw ConfigException.BadValue( + s"""Could not parse time unit '$originalUnitString' (try ns, us, ms, s, m, h, d)""") } try { // return here - if (numberString.matches("[0-9]+")) units.toNanos(numberString.toLong) - else (numberString.toDouble * units.toNanos(1)).toLong - } catch { - case e: NumberFormatException => { - throw new ConfigException.BadValue( - "Could not parse duration number '" + numberString + "'") + if (numberString.matches("[0-9]+")) { + units.toNanos(numberString.toLong) + } else { + (numberString.toDouble * units.toNanos(1)).toLong } + } catch { + case _: NumberFormatException => + throw ConfigException.BadValue(s"Could not parse duration number '$numberString'") } } - def unicodeTrim(s: String) = s.trim() + def unicodeTrim(s: String): String = s.trim() private def getUnits(s: String): String = { var i: Int = s.length - 1 while (i >= 0) { val c: Char = s.charAt(i) - if (!Character.isLetter(c)) return s.substring(i + 1) + if (!Character.isLetter(c)) { + return s.substring(i + 1) + } i -= 1 } - return s.substring(i + 1) + s.substring(i + 1) } - private val millis = Set("ms", "millis", "milliseconds") private val nanos = Set("ns", "nanos", "nanoseconds") - def getMillisDuration(path: String) = { + + @deprecated + def getMillisDuration(path: String): FiniteDuration = { try { val res = parseDurationAsNanos(getString(path)) Duration(res, NANOSECONDS) } catch { - case err: Exception => null + case _: Exception => null } } - def getNanosDuration(path: String) = { + @deprecated + def getNanosDuration(path: String): FiniteDuration = { val res = getString(path) val parts = res.split("[ \t]") assert(parts.size == 2 && (nanos contains parts(1))) diff --git a/facade/shared/src/main/scala/com/typesafe/config/ConfigException.scala b/facade/shared/src/main/scala/com/typesafe/config/ConfigException.scala index 24fba14..60ac7bf 100644 --- a/facade/shared/src/main/scala/com/typesafe/config/ConfigException.scala +++ b/facade/shared/src/main/scala/com/typesafe/config/ConfigException.scala @@ -1,11 +1,10 @@ package com.typesafe.config /** - * Created by evacchi on 27/11/15. - */ - -abstract class ConfigException(message: String, cause: Throwable) extends RuntimeException(message,cause) { - def this(message: String) = this(message,null) + * Created by evacchi on 27/11/15. + */ +abstract class ConfigException(message: String, cause: Throwable) extends RuntimeException(message, cause) { + def this(message: String) = this(message, null) } object ConfigException { diff --git a/facade/shared/src/main/scala/com/typesafe/config/ConfigMergeable.scala b/facade/shared/src/main/scala/com/typesafe/config/ConfigMergeable.scala index 4dd8e1a..67d0522 100644 --- a/facade/shared/src/main/scala/com/typesafe/config/ConfigMergeable.scala +++ b/facade/shared/src/main/scala/com/typesafe/config/ConfigMergeable.scala @@ -1,8 +1,5 @@ package com.typesafe.config trait ConfigMergeable { - - def withFallback(other: ConfigMergeable): ConfigMergeable = - throw new Exception("To be implemented") - + def withFallback(other: ConfigMergeable): ConfigMergeable = ??? } diff --git a/facade/shared/src/main/scala/com/typesafe/config/ConfigObject.scala b/facade/shared/src/main/scala/com/typesafe/config/ConfigObject.scala index bd45b53..796cca6 100644 --- a/facade/shared/src/main/scala/com/typesafe/config/ConfigObject.scala +++ b/facade/shared/src/main/scala/com/typesafe/config/ConfigObject.scala @@ -1,15 +1,15 @@ package com.typesafe.config -import java.{util => ju} - +import java.{ util => ju } import scala.jdk.CollectionConverters._ trait ConfigObject extends ju.AbstractMap[String, ConfigValue] with ConfigValue { - def toConfig = Config(inner) + def toConfig: Config = Config(inner) def unwrapped: ju.Map[String, Any] - override def render: String = this.entrySet().asScala.map(kv => kv.getKey+" -> "+kv.getValue).mkString("[", ",", "]") - override def valueType: ConfigValueType = ConfigValueType.OBJECT + override def render(): String = + this.entrySet().asScala.map(kv => kv.getKey + " -> " + kv.getValue).mkString("[", ",", "]") + override def valueType(): ConfigValueType = ConfigValueType.OBJECT } diff --git a/facade/shared/src/main/scala/com/typesafe/config/ConfigValue.scala b/facade/shared/src/main/scala/com/typesafe/config/ConfigValue.scala index 4ce70a2..7fb8c6d 100644 --- a/facade/shared/src/main/scala/com/typesafe/config/ConfigValue.scala +++ b/facade/shared/src/main/scala/com/typesafe/config/ConfigValue.scala @@ -6,11 +6,11 @@ trait ConfigValue extends ConfigMergeable { val inner: shocon.Config.Value def render(): String = inner.toString def valueType(): ConfigValueType = inner match { - case _: shocon.Config.Object => ConfigValueType.OBJECT - case _: shocon.Config.Array => ConfigValueType.LIST - case _: shocon.Config.NumberLiteral => ConfigValueType.NUMBER - case _: shocon.Config.StringLiteral => ConfigValueType.STRING - case _: shocon.Config.BooleanLiteral => ConfigValueType.BOOLEAN - case _: shocon.Config.NullLiteral.type => ConfigValueType.NULL + case _: shocon.Config.Object => ConfigValueType.OBJECT + case _: shocon.Config.Array => ConfigValueType.LIST + case _: shocon.Config.NumberLiteral => ConfigValueType.NUMBER + case _: shocon.Config.StringLiteral => ConfigValueType.STRING + case _: shocon.Config.BooleanLiteral => ConfigValueType.BOOLEAN + case _: shocon.Config.NullLiteral.type => ConfigValueType.NULL } } diff --git a/facade/shared/src/main/scala/com/typesafe/config/ConfigValueType.scala b/facade/shared/src/main/scala/com/typesafe/config/ConfigValueType.scala index 488348b..b336515 100644 --- a/facade/shared/src/main/scala/com/typesafe/config/ConfigValueType.scala +++ b/facade/shared/src/main/scala/com/typesafe/config/ConfigValueType.scala @@ -1,6 +1,7 @@ package com.typesafe.config -class ConfigValueType private() {} +class ConfigValueType private () {} + object ConfigValueType { val OBJECT, LIST, NUMBER, BOOLEAN, NULL, STRING = new ConfigValueType() } diff --git a/facade/shared/src/main/scala/com/typesafe/config/MemoryUnit.scala b/facade/shared/src/main/scala/com/typesafe/config/MemoryUnit.scala index f454840..3324623 100644 --- a/facade/shared/src/main/scala/com/typesafe/config/MemoryUnit.scala +++ b/facade/shared/src/main/scala/com/typesafe/config/MemoryUnit.scala @@ -1,7 +1,7 @@ package com.typesafe.config -sealed abstract class MemoryUnit(val prefix:String, val powerOf:Int, val power:Int) { - lazy val bytes = BigInt(powerOf).pow(power) +sealed abstract class MemoryUnit(val prefix: String, val powerOf: Int, val power: Int) { + lazy val bytes: BigInt = BigInt(powerOf).pow(power) } object MemoryUnit { @@ -24,10 +24,24 @@ object MemoryUnit { case object ZEBIBYTES extends MemoryUnit("zebi", 1024, 7) case object YOBIBYTES extends MemoryUnit("yobi", 1024, 8) - val values: Vector[MemoryUnit] = Vector(BYTES, KILOBYTES, MEGABYTES, GIGABYTES, TERABYTES, PETABYTES, - EXABYTES, ZETTABYTES, YOTTABYTES, KIBIBYTES, MEBIBYTES, GIBIBYTES, TEBIBYTES, - PEBIBYTES, EXBIBYTES, ZEBIBYTES, YOBIBYTES) - + val values: Vector[MemoryUnit] = Vector( + BYTES, + KILOBYTES, + MEGABYTES, + GIGABYTES, + TERABYTES, + PETABYTES, + EXABYTES, + ZETTABYTES, + YOTTABYTES, + KIBIBYTES, + MEBIBYTES, + GIBIBYTES, + TEBIBYTES, + PEBIBYTES, + EXBIBYTES, + ZEBIBYTES, + YOBIBYTES) lazy val unitsMap: Map[String, MemoryUnit] = { val map = Map.newBuilder[String, MemoryUnit] @@ -35,7 +49,7 @@ object MemoryUnit { MemoryUnit.values.foreach { unit => map += unit.prefix + "byte" -> unit map += unit.prefix + "bytes" -> unit - if (unit.prefix.length() == 0) { + if (unit.prefix.isEmpty) { map += "b" -> unit map += "B" -> unit map += "" -> unit // no unit specified means bytes @@ -56,11 +70,10 @@ object MemoryUnit { } } } - map.result() + map.result() } - - def parseUnit(unit: String):Option[MemoryUnit] = { + def parseUnit(unit: String): Option[MemoryUnit] = { unitsMap.get(unit) } } diff --git a/facade/shared/src/main/scala/com/typesafe/config/package.scala b/facade/shared/src/main/scala/com/typesafe/config/package.scala index d57ec3f..69ac67d 100644 --- a/facade/shared/src/main/scala/com/typesafe/config/package.scala +++ b/facade/shared/src/main/scala/com/typesafe/config/package.scala @@ -1,11 +1,13 @@ package com.typesafe +import scala.language.implicitConversions + package object config { implicit def fromStringToShoconConfig(s: String): org.akkajs.shocon.Config.Value = - org.akkajs.shocon.Config.StringLiteral(s) + org.akkajs.shocon.Config.StringLiteral(s) implicit def fromShoconConfigToString(cv: org.akkajs.shocon.Config.Value): String = - cv.toString + cv.toString -} \ No newline at end of file +} diff --git a/facade/shared/src/main/scala/org/akkajs/shocon/ConfigLoader.scala b/facade/shared/src/main/scala/org/akkajs/shocon/ConfigLoader.scala index 52895d2..ee7b9b1 100644 --- a/facade/shared/src/main/scala/org/akkajs/shocon/ConfigLoader.scala +++ b/facade/shared/src/main/scala/org/akkajs/shocon/ConfigLoader.scala @@ -1,56 +1,68 @@ package org.akkajs.shocon import scala.language.experimental.macros -import scala.reflect.macros.blackbox.Context +import scala.reflect.macros.blackbox object ConfigLoader { import org.akkajs.shocon.verboseLog /// Loads the content of all config files passed with -Xmacro-settings: - private def loadExplicitConfigFiles(c: Context): Option[String] = - // check if config files to be loaded are defined via macro setting -Xmacro-settings:shocon.files=file1.conf;file2.conf - c.settings.find(_.startsWith("shocon.files=")) + private def loadExplicitConfigFiles(c: blackbox.Context): Option[String] = + // check if config files to be loaded are defined via macro setting + // -Xmacro-settings:shocon.files=file1.conf;file2.conf + c.settings + .find(_.startsWith("shocon.files=")) // load these files - .map( _.split("=") match { - case Array(_,paths) => - val (found,notfound) = paths.split(";").toList - .map( new java.io.File(_) ) - .partition( _.canRead ) - - if(notfound.nonEmpty) - c.warning(c.enclosingPosition, s"shocon - could not read configuration files: $notfound") - - c.info(c.enclosingPosition, s"shocon - statically reading configuration from $found", force=false) - found - case _ => Nil - }) + .map(_.split("=") match { + case Array(_, paths) => + val (found, notFound) = paths.split(";").toList.map(new java.io.File(_)).partition(_.canRead) + + if (notFound.nonEmpty) { + c.warning(c.enclosingPosition, s"shocon - could not read configuration files: $notFound") + } + + c.info(c.enclosingPosition, s"shocon - statically reading configuration from $found", force = false) + found + case _ => Nil + }) // concat these files into a single string - .map( _.map(scala.io.Source.fromFile(_).getLines.mkString("\n")).mkString("\n\n") ) + .map { files => + files + .map { file => + val bufferedSource = scala.io.Source.fromFile(file) + try { + bufferedSource.getLines().mkString("\n") + } finally { + bufferedSource.close() + } + } + .mkString("\n\n") + } - def loadDefault(c: Context) = { + def loadDefault(c: blackbox.Context): c.Expr[com.typesafe.config.Config] = { import c.universe._ val configStr: String = // load explicitly defined config files vi -Xmacro-settings:file1.conf;file2.conf;... loadExplicitConfigFiles(c) - // or else load application.conf - .getOrElse{ + // or else load application.conf + .getOrElse { try { - val confPath = new Object {}.getClass - .getResource("/") - .toString + "application.conf" - - c.info(c.enclosingPosition, - s"shocon - statically reading configuration from $confPath", force=false) - - val stream = - new Object {}.getClass.getResourceAsStream("/application.conf") - - scala.io.Source.fromInputStream(stream).getLines.mkString("\n") + val confPath = new Object {}.getClass.getResource("/").toString + "application.conf" + c.info(c.enclosingPosition, s"shocon - statically reading configuration from $confPath", force = false) + + val stream = new Object {}.getClass.getResourceAsStream("/application.conf") + val bufferedSource = scala.io.Source.fromInputStream(stream) + try { + bufferedSource.getLines().mkString("\n") + } finally { + bufferedSource.close() + } } catch { case e: Throwable => - // we use print instead of c.warning, since multiple warnings at the same c.enclosingPosition seem not to work (?) + // we use print instead of c.warning, since multiple warnings at the same c.enclosingPosition + // seem not to work (?) println(c.enclosingPosition, s"WARNING: could not load config file: $e") "{}" } @@ -63,28 +75,31 @@ object ConfigLoader { }""") } + def loadDefaultImpl(c: blackbox.Context)(): c.Expr[com.typesafe.config.Config] = loadDefault(c) - def loadDefaultImpl(c: Context)() = loadDefault(c) - def loadDefaultImplCL(c: Context)(cl: c.Expr[ClassLoader]) = loadDefault(c) + def loadDefaultImplCL(c: blackbox.Context)(cl: c.Expr[ClassLoader]): c.Expr[com.typesafe.config.Config] = + loadDefault(c) - def loadFromString(c: Context)(s: c.Expr[String]) = { + def loadFromString(c: blackbox.Context)(s: c.Expr[String]): c.Expr[com.typesafe.config.Config] = { import c.universe._ s.tree match { case q"""$strLit""" => strLit match { case Literal(Constant(str)) => - if (verboseLog) - c.info(c.enclosingPosition, "[shocon-facade] optimized at compile time", false) - + if (verboseLog) { + c.info(c.enclosingPosition, "[shocon-facade] optimized at compile time", force = false) + } + c.Expr[com.typesafe.config.Config](q"""{ com.typesafe.config.Config( org.akkajs.shocon.Config.gen(${str.toString}) ) }""") case _ => - if (verboseLog) + if (verboseLog) { c.warning(c.enclosingPosition, "[shocon-facade] fallback to runtime parser") + } c.Expr[com.typesafe.config.Config](q"""{ com.typesafe.config.Config( diff --git a/facade/shared/src/test/scala/AkkaConfig.scala b/facade/shared/src/test/scala/tests/AkkaConfig.scala similarity index 99% rename from facade/shared/src/test/scala/AkkaConfig.scala rename to facade/shared/src/test/scala/tests/AkkaConfig.scala index 470a9cc..b0e4866 100644 --- a/facade/shared/src/test/scala/AkkaConfig.scala +++ b/facade/shared/src/test/scala/tests/AkkaConfig.scala @@ -1,8 +1,11 @@ package tests +import com.typesafe.config.{ Config, ConfigFactory } + object AkkaConfig { - val default = """ + val default: String = + """ #################################### # Akka Actor Reference Config File # #################################### @@ -661,8 +664,6 @@ akka { } """ - import com.typesafe.config.{Config, ConfigFactory} - val config: Config = ConfigFactory.parseString(default) } diff --git a/facade/shared/src/test/scala/SHoconGenericSpec.scala b/facade/shared/src/test/scala/tests/SHoconGenericSpec.scala similarity index 78% rename from facade/shared/src/test/scala/SHoconGenericSpec.scala rename to facade/shared/src/test/scala/tests/SHoconGenericSpec.scala index 03916c9..d12b06d 100644 --- a/facade/shared/src/test/scala/SHoconGenericSpec.scala +++ b/facade/shared/src/test/scala/tests/SHoconGenericSpec.scala @@ -1,22 +1,17 @@ package tests -import java.{util => ju} - +import com.typesafe.config.{ Config, ConfigFactory } +import org.akkajs.shocon import utest._ -import scala.util.{Failure, Success} -import com.typesafe.config.{Config, ConfigFactory, ConfigValue} - -import scala.collection.JavaConverters._ import java.util.concurrent.TimeUnit - -import org.akkajs.shocon +import scala.jdk.CollectionConverters._ object SHoconGenericSpec extends TestSuite { val tests = Tests { - 'parseEmptyList - { + test("parseEmptyList") { val config = ConfigFactory.parseString("""{ "a" : [] }""") assert { config != null } @@ -25,7 +20,7 @@ object SHoconGenericSpec extends TestSuite { assert { config.getStringList("a").isEmpty } } - 'parseBasicValues - { + test("parseBasicValues") { val config = ConfigFactory.parseString("""{ "a" : "2" }""") assert { config != null } @@ -34,21 +29,19 @@ object SHoconGenericSpec extends TestSuite { assert { config.getInt("a") == 2 } } - 'parseStringLiteralsWithSlashes - { + test("parseStringLiteralsWithSlashes") { val config = ConfigFactory.parseString("""a = some/path""") assert { config != null } assert { config.getString("a") == "some/path" } } - 'parseLists - { - val config1 = ConfigFactory.parseString( - """l =[ a + test("parseLists") { + val config1 = ConfigFactory.parseString("""l =[ a | | b | c | - | d ]""".stripMargin - ) + | d ]""".stripMargin) val config2 = ConfigFactory.parseString("l = [a,b] \n[c, d]") @@ -58,7 +51,7 @@ object SHoconGenericSpec extends TestSuite { assert { config2.getStringList("l") == config1.getStringList("l") } } - 'parseNestedObjects - { + test("parseNestedObjects") { val config = ConfigFactory.parseString("a = { b = 1 }") assert { config != null } @@ -66,7 +59,7 @@ object SHoconGenericSpec extends TestSuite { assert { config.getConfig("a").getInt("b") == 1 } } - 'pasreNewLinesIsteadOfCommas - { + test("parseNewLinesInsteadOfCommas") { val config = ConfigFactory.parseString("""{ foo = 1 @@ -82,7 +75,7 @@ object SHoconGenericSpec extends TestSuite { assert { config.getInt("baz") == 3 } } - 'parseConcatenatedValues - { + test("parseConcatenatedValues") { val config1 = ConfigFactory.parseString("x = {a:1, b: 2}\n {c: 3, d: 4}") val config2 = ConfigFactory.parseString("x = {a:1, b: 2\nc: 3, d: 4}") @@ -92,7 +85,7 @@ object SHoconGenericSpec extends TestSuite { assert { config1 == config2 } } - 'parseAndConcatenateStringValues - { + test("parseAndConcatenateStringValues") { val config = ConfigFactory.parseString(""" |x = a b c d |y = 10 @@ -103,7 +96,7 @@ object SHoconGenericSpec extends TestSuite { assert { config.getString("x") == "a b c d" } } - 'parseAkkaConfFiles - { + test("parseAkkaConfFiles") { val basic = ConfigFactory.parseString(AkkaConf.basic) val long = ConfigFactory.parseString(AkkaConf.long) @@ -113,22 +106,19 @@ object SHoconGenericSpec extends TestSuite { assert { long.getString("akka.version") == "2.0-SNAPSHOT" } } - 'parseDurations - { - val config = ConfigFactory.parseString( - """ a { + test("parseDurations") { + val config = ConfigFactory.parseString(""" a { |x = 1 ms - |}""".stripMargin - ) + |}""".stripMargin) assert { config != null } - assert { config.getDuration("a.x").toMillis.toLong == 1L } - assert { config.getDuration("a.x", TimeUnit.NANOSECONDS).toLong == 1000000L } + assert { config.getDuration("a.x").toMillis == 1L } + assert { config.getDuration("a.x", TimeUnit.NANOSECONDS) == 1000000L } } - 'parseBytes - { - val config = ConfigFactory.parseString( - """ a { + test("parseBytes") { + val config = ConfigFactory.parseString(""" a { |b = 9 b |B = 9 b |byte = 1 byte @@ -161,8 +151,7 @@ object SHoconGenericSpec extends TestSuite { |G = 1 G |Gi = 1 Gi |GiB = 1 GiB - |}""".stripMargin - ) + |}""".stripMargin) assert { config != null } @@ -197,20 +186,17 @@ object SHoconGenericSpec extends TestSuite { assert { config.getBytes("a.G") == 1024L * 1024L * 1024L } assert { config.getBytes("a.Gi") == 1024L * 1024L * 1024L } assert { config.getBytes("a.GiB") == 1024L * 1024L * 1024L } - } - 'parseBooleans - { - val config = ConfigFactory.parseString( - """ a { + test("parseBooleans") { + val config = ConfigFactory.parseString(""" a { |x1 = true |x2 = on |x3 = yes |x4 = false |x5 = off |x6 = no - |}""".stripMargin - ) + |}""".stripMargin) assert { config != null } @@ -222,7 +208,7 @@ object SHoconGenericSpec extends TestSuite { assert { config.getBoolean("a.x6") == false } } - 'parseAkkaConfiguration - { + test("parseAkkaConfiguration") { val config = AkkaConfig.config assert { config != null } @@ -232,7 +218,7 @@ object SHoconGenericSpec extends TestSuite { () } - 'reloadConfigWithFallback - { + test("reloadConfigWithFallback") { val config1 = ConfigFactory.parseString("""{ "a" : [] }""") val config2 = ConfigFactory.parseString("""{ "b" : [] }""") @@ -245,17 +231,18 @@ object SHoconGenericSpec extends TestSuite { } - 'dottedConfigKey - { + test("dottedConfigKey") { val configAkka = ConfigFactory.parseString("akka.actor.messages = on") assert { configAkka.hasPath("akka.actor.messages") == true } } - 'dottedConfigKeyWithFallback - { + test("dottedConfigKeyWithFallback") { val configAkka = - ConfigFactory.parseString("akka.actor.debug.event-stream = on").withFallback( - ConfigFactory.parseString(""" + ConfigFactory + .parseString("akka.actor.debug.event-stream = on") + .withFallback(ConfigFactory.parseString(""" akka.actor.debug.event-stream = off akka.actor.messages = on """)) @@ -263,7 +250,7 @@ object SHoconGenericSpec extends TestSuite { assert { configAkka.getBoolean("akka.actor.messages") == true } } - 'loadDefaultConfig - { + test("loadDefaultConfig") { val config = ConfigFactory.load() assert { config != null } @@ -271,41 +258,40 @@ object SHoconGenericSpec extends TestSuite { assert { config.getString("loaded") == "DONE" } } - 'unwrappedToStringInMap - { + test("unwrappedToStringInMap") { val config = ConfigFactory.parseString(""" a="b" """) val map = configToMap(config) assert { "b" == map("a") } } - 'unwrappedNumber - { - val map = ConfigFactory.parseString(""" a=2 """).root.unwrapped + test("unwrappedNumber") { + val map = ConfigFactory.parseString(""" a=2 """).root().unwrapped assert { 2 == map.get("a") } } - 'unwrappedDuration - { - val map = ConfigFactory.parseString(""" a=2ns """).root.unwrapped + test("unwrappedDuration") { + val map = ConfigFactory.parseString(""" a=2ns """).root().unwrapped assert { "2ns" == map.get("a") } // Duration is not automatically unwrapped. } - 'unwrappedBoolean - { - val map = ConfigFactory.parseString(""" a=true """).root.unwrapped + test("unwrappedBoolean") { + val map = ConfigFactory.parseString(""" a=true """).root().unwrapped assert { true == map.get("a") } } - 'reparseKey - { + test("reparseKey") { val key = "foo.bar.baz" val value = shocon.Config.StringLiteral("quux") val reparsed = shocon.Config.Object.reparseKey(key, value) val expected = shocon.Config.Object( - Map( - "foo" -> shocon.Config.Object(Map("bar" -> shocon.Config.Object( - Map("baz" -> shocon.Config.StringLiteral("quux"))))))) + Map("foo" -> shocon.Config.Object( + Map("bar" -> shocon.Config.Object(Map("baz" -> shocon.Config.StringLiteral("quux"))))))) assert { expected == reparsed } } - 'mergeConfigValues - { + test("mergeConfigValues") { val key1 = "foo.bar.baz" val value1 = shocon.Config.StringLiteral("quux") val key2 = "foo.bar.bazz" @@ -317,27 +303,21 @@ object SHoconGenericSpec extends TestSuite { import shocon.Config.StringLiteral val merged = shocon.Config.Object.mergeConfigs(reparsed1, reparsed2) val expected = shocon.Config.Object( - Map( - "foo" -> shocon.Config.Object( - Map( - "bar" -> shocon.Config.Object(Map( - "baz" -> StringLiteral("quux"), - "bazz" -> StringLiteral("quuxxx") - )))))) + Map("foo" -> shocon.Config.Object( + Map("bar" -> shocon.Config.Object(Map("baz" -> StringLiteral("quux"), "bazz" -> StringLiteral("quuxxx"))))))) assert { expected == merged } } - 'concatValues - { - val x = ConfigFactory.parseString( - """x="foo" + test("concatValues") { + val x = ConfigFactory.parseString("""x="foo" |y= z "bar" """.stripMargin) assert { "foo" == x.getString("x") } assert { "z bar" == x.getString("y") } } - 'properlyFallback - { + test("properlyFallback") { val conf1 = ConfigFactory.parseString("""x = "1"""") val conf2 = ConfigFactory.parseString("""x = "2"""") @@ -345,31 +325,25 @@ object SHoconGenericSpec extends TestSuite { assert { "1" == conf.getString("x") } } - 'nestedFallback - { - val conf1 = ConfigFactory.parseString( - """ + test("nestedFallback") { + val conf1 = ConfigFactory.parseString(""" |lib { | message = a | state = true | value = 10 |} - |""".stripMargin - ) - val conf2 = ConfigFactory.parseString( - """ + |""".stripMargin) + val conf2 = ConfigFactory.parseString(""" |lib { | message = b | state = false |} - |""".stripMargin - ) - val conf3 = ConfigFactory.parseString( - """ + |""".stripMargin) + val conf3 = ConfigFactory.parseString(""" |lib { | message = c |} - |""".stripMargin - ) + |""".stripMargin) val conf21 = conf2.withFallback(conf1) assert { conf21.getString("lib.message") == "b" } @@ -382,9 +356,8 @@ object SHoconGenericSpec extends TestSuite { assert { conf321.getInt("lib.value") == 10 } } - 'parseComments - { - val conf = ConfigFactory.parseString( - """ + test("parseComments") { + val conf = ConfigFactory.parseString(""" // ignored x = "1" # ignored @@ -394,11 +367,10 @@ object SHoconGenericSpec extends TestSuite { assert { "foo" == conf.getString("y") } } - 'parseListOfObjects - { + test("parseListOfObjects") { // protect against having this parsed at compile time var x = "" - val conf = ConfigFactory.parseString( - s""" + val conf = ConfigFactory.parseString(s""" $x x = [{ foo = 1 @@ -412,11 +384,10 @@ object SHoconGenericSpec extends TestSuite { assert(res.asScala(1).getInt("foo") == 2) } - 'parseListOfObjectsStartingNextLine - { + test("parseListOfObjectsStartingNextLine") { // protect against having this parsed at compile time var x = "" - val conf = ConfigFactory.parseString( - s""" + val conf = ConfigFactory.parseString(s""" $x x = [ { @@ -431,11 +402,10 @@ object SHoconGenericSpec extends TestSuite { assert(res.asScala(1).getInt("foo") == 2) } - 'parseListOfObjectsWithNewLineSeparatedObjects - { + test("parseListOfObjectsWithNewLineSeparatedObjects") { // protect against having this parsed at compile time var x = "" - val conf = ConfigFactory.parseString( - s""" + val conf = ConfigFactory.parseString(s""" $x x = [ { @@ -451,11 +421,10 @@ object SHoconGenericSpec extends TestSuite { assert(res.asScala(1).getInt("foo") == 2) } - 'parseListOfObjectsWithTrailingCommas - { + test("parseListOfObjectsWithTrailingCommas") { // protect against having this parsed at compile time var x = "" - val conf = ConfigFactory.parseString( - s""" + val conf = ConfigFactory.parseString(s""" $x x = [ { @@ -472,7 +441,7 @@ object SHoconGenericSpec extends TestSuite { assert(res.asScala(1).getInt("foo") == 2) } - 'mergeConfigObjects - { + test("mergeConfigObjects") { val conf1 = ConfigFactory.load(ConfigFactory.parseString(""" akka.stream.materializer.initial-input-buffer-size = 2 akka.stream.materializer.max-input-buffer-size = 2 @@ -496,7 +465,7 @@ object SHoconGenericSpec extends TestSuite { """)) val conf = ConfigFactory.load(conf1.withFallback(conf2)) - + assert(conf.getInt("akka.stream.materializer.initial-input-buffer-size") == 2) assert(conf.getConfig("akka.stream.materializer").getInt("initial-input-buffer-size") == 2) assert(conf.getConfig("akka.stream.materializer").getString("subscription-timeout.mode") == "cancel") @@ -504,7 +473,6 @@ object SHoconGenericSpec extends TestSuite { } private final def configToMap(config: Config): Map[String, String] = { - import scala.collection.JavaConverters._ - config.root.unwrapped.asScala.toMap map { case (k, v) ⇒ (k → v.toString) } + config.root().unwrapped.asScala.toMap.map { case (k, v) => k -> v.toString } } } diff --git a/plugin/build.sbt b/plugin/build.sbt index 3eeb162..049128f 100644 --- a/plugin/build.sbt +++ b/plugin/build.sbt @@ -1,6 +1,7 @@ import xerial.sbt.Sonatype._ -lazy val plugin = project.in(file(".")) +lazy val plugin = project + .in(file(".")) .settings(sonatypeSettings) .enablePlugins(ScriptedPlugin) .settings( @@ -10,11 +11,7 @@ lazy val plugin = project.in(file(".")) scalaVersion := "2.12.10", crossSbtVersions := Vector("1.3.8"), addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion), - scalacOptions ++= Seq("-feature", - "-unchecked", - "-language:implicitConversions"), + scalacOptions ++= Seq("-feature", "-unchecked", "-language:implicitConversions"), // configuration for testing with sbt-scripted - scriptedLaunchOpts ++= Seq("-Xmx1024M", - "-Dplugin.version=" + version.value), - scriptedBufferLog := false - ) + scriptedLaunchOpts ++= Seq("-Xmx1024M", "-Dplugin.version=" + version.value), + scriptedBufferLog := false) diff --git a/plugin/project/build.properties b/plugin/project/build.properties index a919a9b..0837f7a 100644 --- a/plugin/project/build.properties +++ b/plugin/project/build.properties @@ -1 +1 @@ -sbt.version=1.3.8 +sbt.version=1.3.13 diff --git a/plugin/project/plugins.sbt b/plugin/project/plugins.sbt index a4dfc6d..05c9dc8 100644 --- a/plugin/project/plugins.sbt +++ b/plugin/project/plugins.sbt @@ -8,9 +8,9 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0") resolvers += Resolver.typesafeIvyRepo("releases") -resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" +resolvers += "Typesafe repository".at("http://repo.typesafe.com/typesafe/releases/") -resolvers += "sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases/" +resolvers += "sonatype-releases".at("https://oss.sonatype.org/content/repositories/releases/") // library for plugin testing libraryDependencies += { "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value } diff --git a/plugin/src/main/scala/org/akkajs/shocon/sbtplugin/ShoconPlugin.scala b/plugin/src/main/scala/org/akkajs/shocon/sbtplugin/ShoconPlugin.scala index e99b77e..7839dfa 100644 --- a/plugin/src/main/scala/org/akkajs/shocon/sbtplugin/ShoconPlugin.scala +++ b/plugin/src/main/scala/org/akkajs/shocon/sbtplugin/ShoconPlugin.scala @@ -1,14 +1,11 @@ package org.akkajs.shocon.sbtplugin -import java.io.{BufferedInputStream, FileInputStream, FileNotFoundException, InputStream} +import java.io.{ BufferedInputStream, FileInputStream, FileNotFoundException, InputStream } import java.net.JarURLConnection -import sbt.Keys._ -import sbt.{AutoPlugin, Def, _} - object ShoconPlugin extends AutoPlugin { - type ShoconFilter = Function1[(String,InputStream),Boolean] + type ShoconFilter = Function1[(String, InputStream), Boolean] object autoImport { val shoconAddLib: SettingKey[Boolean] = @@ -23,8 +20,8 @@ object ShoconPlugin extends AutoPlugin { val shoconConcatFile: SettingKey[File] = settingKey[File]("File to which which all detected configuration files are concatenated") - val shoconFiles: TaskKey[Seq[(String,InputStream)]] = - taskKey[Seq[(String,InputStream)]]("List of HOCON configuration files to be included statically at compile time") + val shoconFiles: TaskKey[Seq[(String, InputStream)]] = + taskKey[Seq[(String, InputStream)]]("List of HOCON configuration files to be included statically at compile time") val shoconConcat: TaskKey[File] = taskKey[File]("Contains all detected configuration files concatenated") @@ -35,31 +32,27 @@ object ShoconPlugin extends AutoPlugin { override def projectSettings: Seq[Def.Setting[_]] = Seq( shoconAddLib := true, - shoconLoadFromJars := true, - - shoconFilter := {_:(String,InputStream) => true}, - + shoconFilter := { _: (String, InputStream) => + true + }, shoconConcatFile := (crossTarget in Compile).value / "shocon.conf", - scalacOptions += "-Xmacro-settings:shocon.files=" + shoconConcatFile.value, - shoconFiles := loadConfigs( - shoconLoadFromJars.value, - (dependencyClasspath in Compile).value, - (unmanagedResources in Compile).value, - shoconFilter.value, - streams.value.log), - + shoconLoadFromJars.value, + (dependencyClasspath in Compile).value, + (unmanagedResources in Compile).value, + shoconFilter.value, + streams.value.log), shoconConcat := { val log = streams.value.log val file = shoconConcatFile.value log.debug(s"Assembling SHOCON files for project '${name.value}'") - val config = shoconFiles.value.map( f => s"# SOURCE ${f._1}\n" + IO.readStream(f._2) ).mkString("\n\n") + val config = shoconFiles.value.map(f => s"# SOURCE ${f._1}\n" + IO.readStream(f._2)).mkString("\n\n") log.debug(s"SHOCON statically compiled into current project:\n$config\n\n") - IO.write( file, config ) + IO.write(file, config) file } @@ -70,55 +63,53 @@ object ShoconPlugin extends AutoPlugin { // compile in Compile := (compile in Compile).dependsOn(shoconConcat).value ) + private def loadConfigs( + loadFromJars: Boolean, + dependecyClassPath: Classpath, + unmanagedResources: Seq[File], + fileFilter: ShoconFilter, + log: Logger): Seq[(String, InputStream)] = + ((if (loadFromJars) loadDepReferenceConfigs(dependecyClassPath, log) + else Nil) ++ loadProjectConfigs(unmanagedResources, log)).filter(fileFilter) - private def loadConfigs(loadFromJars: Boolean, - dependecyClassPath: Classpath, - unmanagedResources: Seq[File], - fileFilter: ShoconFilter, - log: Logger): Seq[(String,InputStream)] = - ((if(loadFromJars) loadDepReferenceConfigs(dependecyClassPath,log) - else Nil) ++ loadProjectConfigs(unmanagedResources,log)) - .filter(fileFilter) - - private def loadProjectConfigs(unmanagedResources: Seq[File], log: Logger): Seq[(String,InputStream)] = { + private def loadProjectConfigs(unmanagedResources: Seq[File], log: Logger): Seq[(String, InputStream)] = { val files = unmanagedResources - .filter( f => f.getName == "reference.conf" || f.getName == "application.conf") + .filter(f => f.getName == "reference.conf" || f.getName == "application.conf") .sorted .reverse - .map( f => (f.getAbsolutePath,fin(f)) ) - log.debug("SHOCON config files found in current project:\n" + files.map( " "+_._1).mkString("","\n","\n\n")) + .map(f => (f.getAbsolutePath, fin(f))) + log.debug("SHOCON config files found in current project:\n" + files.map(" " + _._1).mkString("", "\n", "\n\n")) files } - private def loadDepReferenceConfigs(cp: Classpath, log: Logger): Seq[(String,InputStream)] = { - val (dirs,jars) = cp.files.partition(_.isDirectory) - loadJarReferenceConfigs(jars,log) ++ loadDirReferenceConfigs(dirs,log) + private def loadDepReferenceConfigs(cp: Classpath, log: Logger): Seq[(String, InputStream)] = { + val (dirs, jars) = cp.files.partition(_.isDirectory) + loadJarReferenceConfigs(jars, log) ++ loadDirReferenceConfigs(dirs, log) } - private def loadDirReferenceConfigs(dirs: Seq[File], log: Logger): Seq[(String,InputStream)] = { - val files = dirs - .map( _ / "reference.conf" ) - .filter( _.isFile ) - .map( f => (f.getAbsolutePath, fin(f)) ) - log.debug("SHOCON config files found in project dependencies:\n" + files.map( " "+_._1).mkString("","\n","\n\n")) + private def loadDirReferenceConfigs(dirs: Seq[File], log: Logger): Seq[(String, InputStream)] = { + val files = dirs.map(_ / "reference.conf").filter(_.isFile).map(f => (f.getAbsolutePath, fin(f))) + log.debug( + "SHOCON config files found in project dependencies:\n" + files.map(" " + _._1).mkString("", "\n", "\n\n")) files } - private def loadJarReferenceConfigs(jars: Seq[File], log: Logger): Seq[(String,InputStream)] = { + private def loadJarReferenceConfigs(jars: Seq[File], log: Logger): Seq[(String, InputStream)] = { val files = jars - .map( f => new URL("jar:" + f.toURI + "!/reference.conf").openConnection() ) + .map(f => new URL("jar:" + f.toURI + "!/reference.conf").openConnection()) .map { - case c: JarURLConnection => try{ - Some((c.toString,c.getInputStream)) - } catch { - case _: FileNotFoundException => None - } + case c: JarURLConnection => + try { + Some((c.toString, c.getInputStream)) + } catch { + case _: FileNotFoundException => None + } } - .collect{ + .collect { case Some(in) => in } - log.debug("SHOCON config files found in JAR dependencies:\n" + files.map( " "+_._1).mkString("","\n","\n\n")) + log.debug("SHOCON config files found in JAR dependencies:\n" + files.map(" " + _._1).mkString("", "\n", "\n\n")) files } diff --git a/plugin/src/sbt-test/shocon/basic/build.sbt b/plugin/src/sbt-test/shocon/basic/build.sbt index 37f9a40..332c5e7 100644 --- a/plugin/src/sbt-test/shocon/basic/build.sbt +++ b/plugin/src/sbt-test/shocon/basic/build.sbt @@ -1,5 +1,5 @@ - -lazy val root = crossProject.in(file(".")) +lazy val root = crossProject(JSPlatform, JVMPlatform) + .in(file(".")) .dependsOn(lib) .enablePlugins(ShoconPlugin) .settings( @@ -7,23 +7,18 @@ lazy val root = crossProject.in(file(".")) name := "basic", version := "0.1.0-SNAPSHOT", description := "Basic test for the shocon sbt plugin", - libraryDependencies += "org.akka-js" %%% "shocon" % sys.props.getOrElse("plugin.version", sys.error("'plugin.version' environment variable is not set")), - compile in Compile := (compile in Compile).dependsOn(shoconConcat).value - ) - .jsSettings( - scalaJSUseMainModuleInitializer := true - ) - + libraryDependencies += "org.akka-js" %%% "shocon" % sys.props + .getOrElse("plugin.version", sys.error("'plugin.version' environment variable is not set")), + compile in Compile := (compile in Compile).dependsOn(shoconConcat).value) + .jsSettings(scalaJSUseMainModuleInitializer := true) lazy val rootJVM = root.jvm lazy val rootJS = root.js -lazy val lib = crossProject.in(file("lib")) +lazy val lib = crossProject(JSPlatform, JVMPlatform) + .in(file("lib")) .enablePlugins(ShoconPlugin) - .settings( - scalaVersion := "2.12.2", - name := "lib" - ) + .settings(scalaVersion := "2.12.2", name := "lib") lazy val libJVM = lib.jvm lazy val libJS = lib.js diff --git a/plugin/src/sbt-test/shocon/basic/project/plugins.sbt b/plugin/src/sbt-test/shocon/basic/project/plugins.sbt index f395dc8..e42241d 100644 --- a/plugin/src/sbt-test/shocon/basic/project/plugins.sbt +++ b/plugin/src/sbt-test/shocon/basic/project/plugins.sbt @@ -1,4 +1,6 @@ addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1") -addSbtPlugin("org.akka-js" % "sbt-shocon" % sys.props.getOrElse("plugin.version", sys.error("'plugin.version' environment variable is not set"))) +addSbtPlugin( + "org.akka-js" % "sbt-shocon" % sys.props + .getOrElse("plugin.version", sys.error("'plugin.version' environment variable is not set"))) diff --git a/project/Common.scala b/project/Common.scala index b76888b..786091e 100644 --- a/project/Common.scala +++ b/project/Common.scala @@ -2,49 +2,50 @@ import sbt._ import Keys._ object Common extends AutoPlugin { - override def trigger = allRequirements - override lazy val projectSettings = super.projectSettings ++ Seq( - name := "shocon", - organization := "org.akka-js", - version := "1.0.0", - scalaVersion := "2.13.1", - crossScalaVersions := - Vector("2.12.10", "2.13.1"), - pomExtra := { - https://github.com/akka-js/shocon - - - Apache 2 - http://www.apache.org/licenses/LICENSE-2.0.txt - - - - scm:git:github.com/akka-js/shocon - scm:git:git@github.com:akka-js/shocon - github.com/akka-js/shocon - - - - evacchi - Edoardo Vacchi - https://github.com/evacchi/ - - - andreaTP - Andrea Peruffo - https://github.com/andreaTP/ - - - }, - publishMavenStyle := true, - pomIncludeRepository := { x => false }, - publishTo := { - val nexus = "https://oss.sonatype.org/" - if (isSnapshot.value) - Some("snapshots" at nexus + "content/repositories/snapshots") - else - Some("releases" at nexus + "service/local/staging/deploy/maven2") - }, - credentials += Credentials(Path.userHome / ".ivy2" / "sonatype.credentials") - ) + override def trigger: PluginTrigger = allRequirements + override lazy val projectSettings: Seq[Def.Setting[_]] = super.projectSettings ++ Seq( + name := "shocon", + organization := "org.akka-js", + version := "1.0.0", + scalaVersion := "2.13.1", + crossScalaVersions := Vector("2.12.13", "2.13.4"), + pomExtra := { + https://github.com/akka-js/shocon + + + Apache 2 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + scm:git:github.com/akka-js/shocon + scm:git:git@github.com:akka-js/shocon + github.com/akka-js/shocon + + + + evacchi + Edoardo Vacchi + https://github.com/evacchi/ + + + andreaTP + Andrea Peruffo + https://github.com/andreaTP/ + + + }, + publishMavenStyle := true, + pomIncludeRepository := { _ => + false + }, + publishTo := { + val nexus = "https://oss.sonatype.org/" + if (isSnapshot.value) { + Some("snapshots".at(nexus + "content/repositories/snapshots")) + } else { + Some("releases".at(nexus + "service/local/staging/deploy/maven2")) + } + }, + credentials += Credentials(Path.userHome / ".ivy2" / "sonatype.credentials")) } diff --git a/project/build.properties b/project/build.properties index a919a9b..0837f7a 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.3.8 +sbt.version=1.3.13 diff --git a/project/plugins.sbt b/project/plugins.sbt index 70b9786..17cd2f6 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,11 +1,10 @@ - addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3") addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0") -addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1") +addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1") // addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.15") -resolvers += "sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases/" +resolvers += "sonatype-releases".at("https://oss.sonatype.org/content/repositories/releases/") diff --git a/publish.sh b/publish.sh index 8d2c97e..637977f 100755 --- a/publish.sh +++ b/publish.sh @@ -2,15 +2,15 @@ sbt clean -sbt ";++2.12.10;facadeJVM/publishLocal;parserJVM/publishLocal;facadeJS/publishSigned;facadeJVM/publishSigned;parserJS/publishSigned;parserJVM/publishSigned" +sbt ";++2.12.13;facadeJVM/publishLocal;parserJVM/publishLocal;facadeJS/publishSigned;facadeJVM/publishSigned;parserJS/publishSigned;parserJVM/publishSigned" -sbt ";++2.13.1;facadeJVM/publishLocal;parserJVM/publishLocal;facadeJS/publishSigned;facadeJVM/publishSigned;parserJS/publishSigned;parserJVM/publishSigned" +sbt ";++2.13.4;facadeJVM/publishLocal;parserJVM/publishLocal;facadeJS/publishSigned;facadeJVM/publishSigned;parserJS/publishSigned;parserJVM/publishSigned" sbt sonatypeReleaseAll cd plugin -sbt ";^^1.3.5;publishSigned" +sbt ";^^1.3.13;publishSigned" sbt sonatypeReleaseAll diff --git a/scalastyle-config.xml b/scalastyle-config.xml index 7e3596f..6f7a8a6 100644 --- a/scalastyle-config.xml +++ b/scalastyle-config.xml @@ -1,117 +1,98 @@ - Scalastyle standard configuration - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + Scalastyle standard configuration + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/shared/src/main/scala/org/akkajs/shocon/ConfigMacroLoader.scala b/shared/src/main/scala/org/akkajs/shocon/ConfigMacroLoader.scala index b21af5b..5c258a4 100644 --- a/shared/src/main/scala/org/akkajs/shocon/ConfigMacroLoader.scala +++ b/shared/src/main/scala/org/akkajs/shocon/ConfigMacroLoader.scala @@ -1,15 +1,13 @@ -package org.akkajs +package org.akkajs.shocon import scala.language.experimental.macros -import scala.reflect.macros.blackbox.Context - -import fastparse.Parsed +import scala.reflect.macros.blackbox object ConfigMacroLoader { import org.akkajs.shocon.verboseLog - - def setVerboseLogImpl(c: Context)(): c.Expr[Unit] = { + + def setVerboseLogImpl(c: blackbox.Context)(): c.Expr[Unit] = { import c.universe._ verboseLog = true @@ -17,61 +15,58 @@ object ConfigMacroLoader { c.Expr[Unit](q"{}") } - def parse(c: Context)(input: c.Expr[String]): c.Expr[shocon.Config.Value] = { + def parse(c: blackbox.Context)(input: c.Expr[String]): c.Expr[Config.Value] = { import c.universe._ // inspiration from: https://github.com/scala/scala/blob/v2.12.6/src/reflect/scala/reflect/api/StandardLiftables.scala // thanks @blaisorblade def lift[T: Liftable](value: T): Tree = implicitly[Liftable[T]].apply(value) - def selectShocon(names: Name*) = names.foldLeft(q"_root_.org.akkajs.shocon": Tree) { Select(_, _) } - def callPackage(names: Name*)(args: List[Tree]) = Apply(selectShocon(names: _*), args) - def callConfig(name: Name)(args: List[Tree]) = callPackage(TermName("Config"), name)(args) + def selectShocon(names: Name*): Tree = names.foldLeft(q"_root_.org.akkajs.shocon": Tree) { Select(_, _) } + def callPackage(names: Name*)(args: List[Tree]): Apply = Apply(selectShocon(names: _*), args) + def callConfig(name: Name)(args: List[Tree]): Apply = callPackage(TermName("Config"), name)(args) - def callApply(str: String)(args: List[Tree]) = callConfig(TermName(str))(args) + def callApply(str: String)(args: List[Tree]): Apply = callConfig(TermName(str))(args) - def callPackageConst(names: Name*) = selectShocon(names: _*) - def callConfigConst(name: Name) = - callPackageConst(TermName("Config"), name) + def callPackageConst(names: Name*): Tree = selectShocon(names: _*) + def callConfigConst(name: Name): Tree = callPackageConst(TermName("Config"), name) def callConst(str: String) = callConfigConst(TermName(str)) implicit def liftConfigValue: Liftable[org.akkajs.shocon.Config.Value] = - Liftable { cfg => - cfg match { - case v: org.akkajs.shocon.Config.SimpleValue => - v match { - case nl: org.akkajs.shocon.Config.NumberLiteral => - callApply("NumberLiteral")(lift(nl.value) :: Nil) - case sl: org.akkajs.shocon.Config.StringLiteral => - callApply("StringLiteral")(lift(sl.value) :: Nil) - case bl: org.akkajs.shocon.Config.BooleanLiteral => - callApply("BooleanLiteral")(lift(bl.value) :: Nil) - case _ => - callConst("NullLiteral") - } - case arr: org.akkajs.shocon.Config.Array => - callApply("Array"){ - val arrayBody = arr.elements.map(lift(_)).toList - - q"Seq( ..$arrayBody )" :: Nil + Liftable { + case v: org.akkajs.shocon.Config.SimpleValue => + v match { + case nl: org.akkajs.shocon.Config.NumberLiteral => + callApply("NumberLiteral")(lift(nl.value) :: Nil) + case sl: org.akkajs.shocon.Config.StringLiteral => + callApply("StringLiteral")(lift(sl.value) :: Nil) + case bl: org.akkajs.shocon.Config.BooleanLiteral => + callApply("BooleanLiteral")(lift(bl.value) :: Nil) + case _ => + callConst("NullLiteral") + } + case arr: org.akkajs.shocon.Config.Array => + callApply("Array") { + val arrayBody = arr.elements.map(lift(_)).toList + + q"Seq( ..$arrayBody )" :: Nil + } + case obj: org.akkajs.shocon.Config.Object => + callApply("Object") { + val mapBody = obj.fields.map { + case (k, v) => q"($k, $v)" } - case obj: org.akkajs.shocon.Config.Object => - callApply("Object"){ - val mapBody = obj.fields.map{ - case (k, v) => q"($k, $v)" - } - q"Map( ..$mapBody )" :: Nil - } - } + q"Map( ..$mapBody )" :: Nil + } } - def fallback() = { + def fallback(): c.Expr[Config.Value] = { if (verboseLog) c.warning(c.enclosingPosition, "[shocon-parser] fallback to runtime parser") - c.Expr[shocon.Config.Value](q"""{ + c.Expr[Config.Value](q"""{ org.akkajs.shocon.ConfigParser.root.parse($input) match{ case fastparse.core.Parsed.Success(v,_) => v case f: fastparse.core.Parsed.Failure[_, _] => throw new Error(f.msg) @@ -83,27 +78,22 @@ object ConfigMacroLoader { case q"""$strLit""" => strLit match { case Literal(Constant(str)) => - - val config = - org.akkajs.shocon.Config(str.toString) - + val config = org.akkajs.shocon.Config(str.toString) val ast = liftConfigValue(config) try { c.typecheck(ast) if (verboseLog) - c.info(c.enclosingPosition, "[shocon-parser] optimized at compile time", false) + c.info(c.enclosingPosition, "[shocon-parser] optimized at compile time", force = false) - c.Expr[shocon.Config.Value](ast) + c.Expr[Config.Value](ast) } catch { - case err: Throwable => - fallback() + case _: Throwable => fallback() } - case _ => - fallback() + case _ => fallback() } } } -} \ No newline at end of file +} diff --git a/shared/src/main/scala/org/akkajs/shocon/ConfigParser.scala b/shared/src/main/scala/org/akkajs/shocon/ConfigParser.scala index c7c4177..8d89115 100644 --- a/shared/src/main/scala/org/akkajs/shocon/ConfigParser.scala +++ b/shared/src/main/scala/org/akkajs/shocon/ConfigParser.scala @@ -4,73 +4,74 @@ import fastparse._ import NoWhitespace._ // or we can refactor to use an upstream whitespace handler object ConfigParser { - case class NamedFunction[T, V](f: T => V, name: String) extends (T => V){ - def apply(t: T) = f(t) - override def toString() = name + case class NamedFunction[T, V](f: T => V, name: String) extends (T => V) { + def apply(t: T): V = f(t) + override def toString(): String = name } - val isWhitespace = (c: Char) => - c match { - // try to hit the most common ASCII ones first, then the nonbreaking - // spaces that Java brokenly leaves out of isWhitespace. - case ' '|'\n'|'\u00A0'|'\u2007'|'\u202F'|'\uFEFF' /* BOM */ => true; - case _ => Character.isWhitespace(c); - } + val isWhitespace: Char => Boolean = { + // try to hit the most common ASCII ones first, then the nonbreaking + // spaces that Java brokenly leaves out of isWhitespace. + case ' ' | '\n' | '\u00A0' | '\u2007' | '\u202F' | '\uFEFF' /* BOM */ => true + case c => Character.isWhitespace(c) + } - val isWhitespaceNoNl = (c: Char) => c != '\n' && isWhitespace(c) + val isWhitespaceNoNl: Char => Boolean = (c: Char) => c != '\n' && isWhitespace(c) // *** Lexing *** // val Whitespace = NamedFunction(isWhitespace, "Whitespace") - def letter[_ : P] = P( lowercase | uppercase ) - def lowercase[_ : P] = P( CharIn("a-z") ) - def uppercase[_ : P] = P( CharIn("A-Z") ) - def digit[_ : P] = P( CharIn("0-9") ) + def letter[_: P] = P(lowercase | uppercase) + def lowercase[_: P] = P(CharIn("a-z")) + def uppercase[_: P] = P(CharIn("A-Z")) + def digit[_: P] = P(CharIn("0-9")) val Digits = NamedFunction('0' to '9' contains (_: Char), "Digits") val StringChars = NamedFunction(!"\"\\".contains(_: Char), "StringChars") val UnquotedStringChars = NamedFunction(!isWhitespaceNoNl(_: Char), "UnquotedStringChars ") - def keyValueSeparator[_ : P] = P( CharIn(":=")) + def keyValueSeparator[_: P] = P(CharIn(":=")) // whitespace - def comment[_ : P] = P( ("//" | "#") ~ CharsWhile(_ != '\n', 0) ) - def nlspace[_ : P] = P( (CharsWhile(isWhitespace, 1) | comment ).rep ) - def space[_ : P] = P( ( CharsWhile(isWhitespaceNoNl, 1) | comment ).rep ) + def comment[_: P] = P(("//" | "#") ~ CharsWhile(_ != '\n', 0)) + def nlspace[_: P] = P((CharsWhile(isWhitespace, 1) | comment).rep) + def space[_: P] = P((CharsWhile(isWhitespaceNoNl, 1) | comment).rep) - def hexDigit[_ : P] = P( CharIn("0-9", "a-f", "A-F") ) - def unicodeEscape[_ : P] = P( "u" ~ hexDigit ~ hexDigit ~ hexDigit ~ hexDigit ) - def escape[_ : P] = P( "\\" ~ (CharIn("\"/\\bfnrt") | unicodeEscape) ) + def hexDigit[_: P] = P(CharIn("0-9", "a-f", "A-F")) + def unicodeEscape[_: P] = P("u" ~ hexDigit ~ hexDigit ~ hexDigit ~ hexDigit) + def escape[_: P] = P("\\" ~ (CharIn("\"/\\bfnrt") | unicodeEscape)) // strings - def strChars[_ : P] = P( CharsWhile(StringChars) ) - def quotedString[_ : P] = P( "\"" ~/ (strChars | escape).rep.! ~ "\"") - def unquotedString[_ : P] = P ( ( (letter | digit | "_" | "-" | "." | "/").rep(1).! ).rep(1,CharsWhile(_.isSpaceChar)).! ) - def string[_ : P] = P(nlspace) ~ P(quotedString|unquotedString|CharsWhile(_.isSpaceChar).!) // bit of an hack: this would parse whitespace to the end of line - .rep(1).map(_.mkString.trim) // so we will trim the remaining right-side - .map(Config.StringLiteral) + def strChars[_: P] = P(CharsWhile(StringChars)) + def quotedString[_: P] = P("\"" ~/ (strChars | escape).rep.! ~ "\"") + def unquotedString[_: P] = P(((letter | digit | "_" | "-" | "." | "/").rep(1).!).rep(1, CharsWhile(_.isSpaceChar)).!) + def string[_: P] = + P(nlspace) ~ P(quotedString | unquotedString | CharsWhile(_.isSpaceChar).!) // bit of an hack: this would parse whitespace to the end of line + .rep(1) + .map(_.mkString.trim) // so we will trim the remaining right-side + .map(Config.StringLiteral) // *** Parsing *** - def array[_: P]: P[Seq[Config.Value]] = P( "[" ~ nlspace ~/ jsonExpr.rep(sep=itemSeparator) ~ nlspace ~ ",".? ~ nlspace ~ "]") + def array[_: P]: P[Seq[Config.Value]] = + P("[" ~ nlspace ~/ jsonExpr.rep(sep = itemSeparator) ~ nlspace ~ ",".? ~ nlspace ~ "]") - def repeatedArray[_ :P]: P[Config.Array] = - array.rep(min = 1, sep=nlspace).map( ( arrays: Seq[Seq[Config.Value]] ) => Config.Array ( arrays.flatten ) ) + def repeatedArray[_: P]: P[Config.Array] = + array.rep(min = 1, sep = nlspace).map((arrays: Seq[Seq[Config.Value]]) => Config.Array(arrays.flatten)) - def pair[_: P]: P[(String, Config.Value)] = P( string.map(_.value) ~/ space ~ - ((keyValueSeparator ~/ jsonExpr ) - |(repeatedObj ~ space)) ) + def pair[_: P]: P[(String, Config.Value)] = + P(string.map(_.value) ~/ space ~ ((keyValueSeparator ~/ jsonExpr) | (repeatedObj ~ space))) - def obj[_: P]: P[Seq[(String, Config.Value)]] = P( "{" ~/ objBody ~ "}") + def obj[_: P]: P[Seq[(String, Config.Value)]] = P("{" ~/ objBody ~ "}") def repeatedObj[_: P]: P[Config.Object] = - obj.rep(min = 1, sep=nlspace).map(fields => Config.Object(Map( fields.flatten :_*) )) + obj.rep(min = 1, sep = nlspace).map(fields => Config.Object(Map(fields.flatten: _*))) - def itemSeparator[_: P] = P(("\n" ~ nlspace ~ ",".?)|(("," ~ nlspace).?)) + def itemSeparator[_: P] = P(("\n" ~ nlspace ~ ",".?) | (("," ~ nlspace).?)) - def objBody[_: P] = P( pair.rep(sep=itemSeparator) ~ nlspace ) // .log() + def objBody[_: P] = P(pair.rep(sep = itemSeparator) ~ nlspace) - def jsonExpr[_: P] = P( space ~ (repeatedObj | repeatedArray | string) ~ space ) // .log() + def jsonExpr[_: P] = P(space ~ (repeatedObj | repeatedArray | string) ~ space) - def root[_: P] = P( (&(space ~ "{") ~/ obj )|(objBody) ~ End ).map( x => Config.Object.fromPairs(x) ) // .log() + def root[_: P] = P((&(space ~ "{") ~/ obj) | (objBody) ~ End).map(x => Config.Object.fromPairs(x)) def parseString(str: String) = parse(str, root(_)) diff --git a/shared/src/main/scala/org/akkajs/shocon/Extractors.scala b/shared/src/main/scala/org/akkajs/shocon/Extractors.scala index 12605b3..5298fea 100644 --- a/shared/src/main/scala/org/akkajs/shocon/Extractors.scala +++ b/shared/src/main/scala/org/akkajs/shocon/Extractors.scala @@ -1,50 +1,63 @@ package org.akkajs.shocon -import java.{util => ju} -import scala.collection.compat._ +import java.{ util => ju } import scala.jdk.CollectionConverters._ -case class Extractor[T](pf: PartialFunction[Config.Value, T], val serial: Int) { - def apply(c: Config.Value) = pf.apply(c) - def applyOrElse(c: Config.Value, fallback: PartialFunction[Config.Value, T]) = - pf.applyOrElse(c, fallback) +case class Extractor[T](pf: PartialFunction[Config.Value, T], serial: Int) { + def apply(c: Config.Value): T = pf.apply(c) + def applyOrElse(c: Config.Value, fallback: PartialFunction[Config.Value, T]): T = pf.applyOrElse(c, fallback) } trait Extractors { - implicit val BooleanExtractor: Extractor[Boolean] = Extractor({ - case Config.StringLiteral(v) => v.trim match { - case "true" | "on" | "yes" => true - case "false" | "off" | "no" => false - case _ => throw new IllegalArgumentException(s"Cannot convert '$v' to boolean") - } - }, 1) - implicit val StringExtractor: Extractor[String] = Extractor({ + implicit val BooleanExtractor: Extractor[Boolean] = Extractor( + { + case Config.StringLiteral(v) => + v.trim match { + case "true" | "on" | "yes" => true + case "false" | "off" | "no" => false + case _ => throw new IllegalArgumentException(s"Cannot convert '$v' to boolean") + } + }, + 1) + + implicit val stringExtractor: Extractor[String] = Extractor({ case Config.StringLiteral(v) => v }, 2) - implicit val DoubleExtractor: Extractor[Double] = Extractor({ + + implicit val doubleExtractor: Extractor[Double] = Extractor({ case Config.StringLiteral(v) => v.toDouble }, 3) - implicit val LongExtractor: Extractor[Long] = Extractor({ + + implicit val longExtractor: Extractor[Long] = Extractor({ case Config.StringLiteral(v) => v.toLong }, 4) - implicit val IntExtractor: Extractor[Int] = Extractor({ + + implicit val intExtractor: Extractor[Int] = Extractor({ case Config.StringLiteral(v) => v.toInt }, 5) - implicit def SeqExtractor[T](implicit ex: Extractor[T]): Extractor[Seq[T]] = Extractor({ - case Config.Array(seq) => seq.map(ex.apply(_)) - }, 6) - implicit def juListExtractor[T](implicit ex: Extractor[T]): Extractor[ju.List[T]] = Extractor({ - case Config.Array(seq) => seq.map(ex.apply(_)).asJava - }, 7) - implicit def MapExtractor[T](implicit ex: Extractor[T]): Extractor[Map[String, T]] = Extractor({ - case Config.Object(keyValues) => keyValues.map{ case (k,v) => (k, ex.apply(v)) } - }, 8) - implicit val GenericExtractor: Extractor[Config.Value] = Extractor({ + + implicit def seqExtractor[T](implicit ex: Extractor[T]): Extractor[Seq[T]] = + Extractor({ + case Config.Array(seq) => seq.map(ex.apply) + }, 6) + + implicit def juListExtractor[T](implicit ex: Extractor[T]): Extractor[ju.List[T]] = + Extractor({ + case Config.Array(seq) => seq.map(ex.apply).asJava + }, 7) + + implicit def mapExtractor[T](implicit ex: Extractor[T]): Extractor[Map[String, T]] = + Extractor({ + case Config.Object(keyValues) => keyValues.map { case (k, v) => (k, ex.apply(v)) } + }, 8) + + implicit val genericExtractor: Extractor[Config.Value] = Extractor({ case x => x }, 9) - implicit val ObjectExtractor: Extractor[Config.Object] = Extractor({ - case x : Config.Object => x + + implicit val objectExtractor: Extractor[Config.Object] = Extractor({ + case x: Config.Object => x }, 10) } diff --git a/shared/src/main/scala/org/akkajs/shocon/SHocon.scala b/shared/src/main/scala/org/akkajs/shocon/SHocon.scala index 5a53188..a7b223c 100644 --- a/shared/src/main/scala/org/akkajs/shocon/SHocon.scala +++ b/shared/src/main/scala/org/akkajs/shocon/SHocon.scala @@ -1,10 +1,11 @@ package org.akkajs -import scala.util.Try - -import scala.language.experimental.macros import fastparse.Parsed + +import scala.annotation.tailrec import scala.collection.compat._ +import scala.language.experimental.macros +import scala.util.Try package object shocon extends Extractors { @@ -20,82 +21,90 @@ package object shocon extends Extractors { } case class Array(elements: Seq[Value]) extends Value { - lazy val unwrapped = elements.map(_.unwrapped) + lazy val unwrapped: Seq[Any] = elements.map(_.unwrapped) } case class Object(fields: Map[Key, Value]) extends Value { - lazy val unwrapped = fields.view.mapValues(_.unwrapped).to(Seq) + lazy val unwrapped: Seq[(Key, Any)] = fields.view.mapValues(_.unwrapped).to(Seq) } - trait SimpleValue extends Value + sealed trait SimpleValue extends Value private def unwrapStringAsNumber(value: String): Try[Any] = Try { value.toInt }.recover { - case _ => value.toLong - }.recover { - case _ => value.toDouble - } + case _ => value.toLong + } + .recover { + case _ => value.toDouble + } case class NumberLiteral(value: String) extends SimpleValue { - lazy val unwrapped = unwrapStringAsNumber(value).get + lazy val unwrapped: Any = unwrapStringAsNumber(value).get } case class StringLiteral(value: String) extends SimpleValue { - lazy val unwrapped = - Try(this.as[Boolean].get) - .orElse(unwrapStringAsNumber(value)) - .getOrElse(value) + lazy val unwrapped: Any = + Try(this.as[Boolean].get).orElse(unwrapStringAsNumber(value)).getOrElse(value) } case class BooleanLiteral(value: Boolean) extends SimpleValue { - lazy val unwrapped = value + lazy val unwrapped: Boolean = value } case object NullLiteral extends SimpleValue { - def unwrapped = null + def unwrapped: Null = null } def gen(input: String): Config.Value = macro ConfigMacroLoader.parse /* these methods are here only for retro-compatibility and fallbacks */ - def parse(input: String) = ConfigParser.parseString(input) - def apply(input: String): Config.Value = parse(input) match{ - case Parsed.Success(v,_) => v - case f: Parsed.Failure => throw new Error(f.msg) + def parse(input: String): Parsed[Object] = ConfigParser.parseString(input) + def apply(input: String): Config.Value = parse(input) match { + case Parsed.Success(v, _) => v + case f: Parsed.Failure => throw new Error(f.msg) + } + def fromFile(path: String): Value = { + val bufferedSource = io.Source.fromFile(path) + try { + apply(bufferedSource.mkString) + } finally { + bufferedSource.close() + } } - def fromFile(path: String) = apply(io.Source.fromFile(path).mkString) object Object { + def fromPairs(pairs: Seq[(Key, Value)]): Object = { - val os = pairs.map{ case (k,v) => reparseKey(k,v) } + val os = pairs.map { case (k, v) => reparseKey(k, v) } os.foldLeft(shocon.Config.Object(Map()))(mergeConfigs) } + def reparseKey(key: Key, value: Value): Object = { val pos = key.indexOf('.') - if (pos < 0) shocon.Config.Object(Map(key -> value)) - else { - val splitted = key.split('.').reverse - - splitted.tail.foldLeft(shocon.Config.Object(Map(splitted.head -> value))){ - case (acc, elem) => - shocon.Config.Object(Map(elem -> acc)) + if (pos < 0) { + shocon.Config.Object(Map(key -> value)) + } else { + val split = key.split('.').reverse + split.tail.foldLeft(shocon.Config.Object(Map(split.head -> value))) { + case (acc, elem) => shocon.Config.Object(Map(elem -> acc)) } } } def mergeValues(base: Value, mergeable: Value): Value = { - if (base == mergeable) base - else + if (base == mergeable) { + base + } else { (base, mergeable) match { - case (m1: Object, m2: Object) => - mergeConfigs(m1, m2) - case (Array(seq1), Array(seq2)) => - Array(seq1 ++ seq2) - case (v1, v2) => v2 // always the second wins + case (m1: Object, m2: Object) => mergeConfigs(m1, m2) + case (Array(seq1), Array(seq2)) => Array(seq1 ++ seq2) + case (v1, v2) => v2 // always the second wins } + } } def mergeConfigs(base: Object, mergeable: Object): Object = { - if (base == mergeable) base - else { + if (base == mergeable) { + base + } else { val m1k = base.fields.keys.toSet // all keys in m2 which are not found in m1 val diff = mergeable.fields.keys.filterNot(m1k.contains).toSet @@ -103,34 +112,32 @@ package object shocon extends Extractors { // where if a key is in both, their value is merged val m = base.fields.map { - case (k, v) => - mergeable.fields.get(k) match { - case Some(v2) => - k -> mergeValues(v, v2) - case _ => - k -> v - } - } ++ mergeable.fields.view.filter(e => diff.contains(e._1)) + case (k, v) => + mergeable.fields.get(k) match { + case Some(v2) => k -> mergeValues(v, v2) + case _ => k -> v + } + } ++ mergeable.fields.view.filter(e => diff.contains(e._1)) Object(m) } } } } - - implicit class ConfigOps(val tree: Config.Value) { - def as[T](implicit ev: Extractor[T]): Option[T] = Option( ev.applyOrElse(tree, null) ) + implicit class ConfigOps(val tree: Config.Value) { + def as[T](implicit ev: Extractor[T]): Option[T] = Option(ev.applyOrElse(tree, fallback = null)) def apply(key: String): Config.Value = get(key).get def get(key: String): Option[Config.Value] = { val keys = key.split('.') - def visit(v: Config.Value, keys: Seq[String]): Option[Config.Value] = v match { - case _ if (keys.isEmpty) => Some(v) - case o@Config.Object(fields) => - if (fields.contains(keys.head)) - visit(fields(keys.head), keys.tail) - else { - None - } + @tailrec + def visit(v: Config.Value, keys: Seq[String]): Option[Config.Value] = v match { + case _ if keys.isEmpty => Some(v) + case Config.Object(fields) => + if (fields.contains(keys.head)) { + visit(fields(keys.head), keys.tail) + } else { + None + } } visit(tree, keys.toIndexedSeq) } From 8ed04ee908eb7a03513ea7ba20ca4c949e2f0767 Mon Sep 17 00:00:00 2001 From: Michael Liarakos Date: Thu, 27 Jan 2022 21:44:32 -0500 Subject: [PATCH 02/12] updated versions --- build.sbt | 18 ++++++------------ plugin/build.sbt | 2 +- plugin/project/plugins.sbt | 2 +- plugin/project/project/build.properties | 2 +- project/Common.scala | 2 +- project/plugins.sbt | 4 ++-- 6 files changed, 12 insertions(+), 18 deletions(-) diff --git a/build.sbt b/build.sbt index 64675ce..2f808b7 100644 --- a/build.sbt +++ b/build.sbt @@ -2,7 +2,7 @@ import xerial.sbt.Sonatype._ import sbtcrossproject.CrossPlugin.autoImport.crossProject -lazy val root = project.in(file(".")).aggregate(parserJS, parserJVM, facadeJS, facadeJVM).settings(sonatypeSettings) +lazy val root = project.in(file(".")).aggregate(parser.js, parser.jvm, facade.js, facade.jvm).settings(sonatypeSettings) lazy val fixResources = taskKey[Unit]("Fix application.conf presence on first clean build.") @@ -28,16 +28,13 @@ lazy val parser = crossProject(JSPlatform, JVMPlatform) }, compile in Compile := (compile in Compile).dependsOn(fixResources).value, libraryDependencies ++= Seq( - "org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.4", - "com.lihaoyi" %%% "fastparse" % "2.2.4", + "org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.6", + "com.lihaoyi" %%% "fastparse" % "2.3.0", "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided")) .jsSettings( libraryDependencies += "org.scala-js" %%% "scalajs-java-time" % "1.0.0", parallelExecution in Test := true) -lazy val parserJVM = parser.jvm -lazy val parserJS = parser.js - lazy val facade = crossProject(JSPlatform, JVMPlatform) .in(file("facade")) .dependsOn(parser) @@ -61,13 +58,10 @@ lazy val facade = crossProject(JSPlatform, JVMPlatform) compile in Compile := (compile in Compile).dependsOn(fixResources).value, testFrameworks += new TestFramework("utest.runner.Framework"), libraryDependencies ++= Seq( - "org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.4", - "com.lihaoyi" %%% "fastparse" % "2.2.4", - "com.lihaoyi" %%% "utest" % "0.7.4" % "test", + "org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.6", + "com.lihaoyi" %%% "fastparse" % "2.3.0", + "com.lihaoyi" %%% "utest" % "0.7.5" % "test", "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided")) .jsSettings( libraryDependencies += "org.scala-js" %%% "scalajs-java-time" % "1.0.0", parallelExecution in Test := true) - -lazy val facadeJVM = facade.jvm -lazy val facadeJS = facade.js diff --git a/plugin/build.sbt b/plugin/build.sbt index 049128f..fe669a0 100644 --- a/plugin/build.sbt +++ b/plugin/build.sbt @@ -9,7 +9,7 @@ lazy val plugin = project description := "sbt plugin for shocon", sbtPlugin := true, scalaVersion := "2.12.10", - crossSbtVersions := Vector("1.3.8"), + crossSbtVersions := Vector("1.3.13"), addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion), scalacOptions ++= Seq("-feature", "-unchecked", "-language:implicitConversions"), // configuration for testing with sbt-scripted diff --git a/plugin/project/plugins.sbt b/plugin/project/plugins.sbt index 05c9dc8..f8defe8 100644 --- a/plugin/project/plugins.sbt +++ b/plugin/project/plugins.sbt @@ -4,7 +4,7 @@ addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3") addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0") -// addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.15") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2") resolvers += Resolver.typesafeIvyRepo("releases") diff --git a/plugin/project/project/build.properties b/plugin/project/project/build.properties index a919a9b..0837f7a 100644 --- a/plugin/project/project/build.properties +++ b/plugin/project/project/build.properties @@ -1 +1 @@ -sbt.version=1.3.8 +sbt.version=1.3.13 diff --git a/project/Common.scala b/project/Common.scala index 786091e..5cc10f4 100644 --- a/project/Common.scala +++ b/project/Common.scala @@ -7,7 +7,7 @@ object Common extends AutoPlugin { name := "shocon", organization := "org.akka-js", version := "1.0.0", - scalaVersion := "2.13.1", + scalaVersion := "2.13.4", crossScalaVersions := Vector("2.12.13", "2.13.4"), pomExtra := { https://github.com/akka-js/shocon diff --git a/project/plugins.sbt b/project/plugins.sbt index 17cd2f6..6e84aea 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,9 +2,9 @@ addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3") addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0") -addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0") +addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.1.0") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1") -// addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.15") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2") resolvers += "sonatype-releases".at("https://oss.sonatype.org/content/repositories/releases/") From 1f3fddde1283ac8ef65e3ee524e9754a9fcb7f7e Mon Sep 17 00:00:00 2001 From: Michael Liarakos Date: Thu, 27 Jan 2022 21:58:52 -0500 Subject: [PATCH 03/12] updated format --- facade/shared/src/main/scala/com/typesafe/config/Config.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/facade/shared/src/main/scala/com/typesafe/config/Config.scala b/facade/shared/src/main/scala/com/typesafe/config/Config.scala index 89f86d1..50b2f7d 100644 --- a/facade/shared/src/main/scala/com/typesafe/config/Config.scala +++ b/facade/shared/src/main/scala/com/typesafe/config/Config.scala @@ -211,7 +211,7 @@ case class Config(cfg: shocon.Config.Value) { self => val numberString: String = unicodeTrim(s.substring(0, s.length - unitString.length)) if (numberString.isEmpty) { - throw ConfigException.BadValue("No number in duration value '" + input + "'") + throw ConfigException.BadValue(s"No number in duration value '$input'") } if (unitString.length > 2 && !unitString.endsWith("s")) { unitString = unitString + "s" From 6236a0c2817640c9a5f73aef00beab9d169d8521 Mon Sep 17 00:00:00 2001 From: Michael Liarakos Date: Thu, 27 Jan 2022 22:05:23 -0500 Subject: [PATCH 04/12] fixed removed imports --- plugin/project/plugins.sbt | 2 +- .../main/scala/org/akkajs/shocon/sbtplugin/ShoconPlugin.scala | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/project/plugins.sbt b/plugin/project/plugins.sbt index f8defe8..2e5faee 100644 --- a/plugin/project/plugins.sbt +++ b/plugin/project/plugins.sbt @@ -8,7 +8,7 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2") resolvers += Resolver.typesafeIvyRepo("releases") -resolvers += "Typesafe repository".at("http://repo.typesafe.com/typesafe/releases/") +resolvers += "Typesafe repository".at("https://repo.typesafe.com/typesafe/releases/") resolvers += "sonatype-releases".at("https://oss.sonatype.org/content/repositories/releases/") diff --git a/plugin/src/main/scala/org/akkajs/shocon/sbtplugin/ShoconPlugin.scala b/plugin/src/main/scala/org/akkajs/shocon/sbtplugin/ShoconPlugin.scala index 7839dfa..bafa641 100644 --- a/plugin/src/main/scala/org/akkajs/shocon/sbtplugin/ShoconPlugin.scala +++ b/plugin/src/main/scala/org/akkajs/shocon/sbtplugin/ShoconPlugin.scala @@ -3,6 +3,9 @@ package org.akkajs.shocon.sbtplugin import java.io.{ BufferedInputStream, FileInputStream, FileNotFoundException, InputStream } import java.net.JarURLConnection +import sbt._ +import sbt.Keys._ + object ShoconPlugin extends AutoPlugin { type ShoconFilter = Function1[(String, InputStream), Boolean] From 6d05323ede9784996e1831d47961d3e190dfedf7 Mon Sep 17 00:00:00 2001 From: Michael Liarakos Date: Fri, 28 Jan 2022 23:40:44 -0500 Subject: [PATCH 05/12] updated dependencies --- build.sbt | 10 +++++----- .../jvm/src/test/scala/tests/AkkaConf.scala | 20 ++++--------------- .../org/akkajs/shocon/ConfigLoader.scala | 11 +++------- plugin/build.sbt | 2 +- plugin/project/plugins.sbt | 8 +------- plugin/src/sbt-test/shocon/basic/build.sbt | 10 ++-------- .../sbt-test/shocon/basic/project/plugins.sbt | 4 ++-- project/Common.scala | 4 ++-- project/plugins.sbt | 2 +- publish.sh | 4 ++-- .../main/scala/org/akkajs/shocon/SHocon.scala | 7 ++----- 11 files changed, 25 insertions(+), 57 deletions(-) diff --git a/build.sbt b/build.sbt index 2f808b7..7c7f82f 100644 --- a/build.sbt +++ b/build.sbt @@ -28,8 +28,8 @@ lazy val parser = crossProject(JSPlatform, JVMPlatform) }, compile in Compile := (compile in Compile).dependsOn(fixResources).value, libraryDependencies ++= Seq( - "org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.6", - "com.lihaoyi" %%% "fastparse" % "2.3.0", + "org.scala-lang.modules" %%% "scala-collection-compat" % "2.6.0", + "com.lihaoyi" %%% "fastparse" % "2.3.3", "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided")) .jsSettings( libraryDependencies += "org.scala-js" %%% "scalajs-java-time" % "1.0.0", @@ -58,9 +58,9 @@ lazy val facade = crossProject(JSPlatform, JVMPlatform) compile in Compile := (compile in Compile).dependsOn(fixResources).value, testFrameworks += new TestFramework("utest.runner.Framework"), libraryDependencies ++= Seq( - "org.scala-lang.modules" %%% "scala-collection-compat" % "2.1.6", - "com.lihaoyi" %%% "fastparse" % "2.3.0", - "com.lihaoyi" %%% "utest" % "0.7.5" % "test", + "org.scala-lang.modules" %%% "scala-collection-compat" % "2.6.0", + "com.lihaoyi" %%% "fastparse" % "2.3.3", + "com.lihaoyi" %%% "utest" % "0.7.11" % "test", "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided")) .jsSettings( libraryDependencies += "org.scala-js" %%% "scalajs-java-time" % "1.0.0", diff --git a/facade/jvm/src/test/scala/tests/AkkaConf.scala b/facade/jvm/src/test/scala/tests/AkkaConf.scala index 6c8eb7b..a7d68b0 100644 --- a/facade/jvm/src/test/scala/tests/AkkaConf.scala +++ b/facade/jvm/src/test/scala/tests/AkkaConf.scala @@ -1,23 +1,11 @@ package tests +import scala.util.Using + object AkkaConf { - def basic: String = { - val bufferedSource = io.Source.fromFile("facade/jvm/src/test/resources/akka.conf") - try { - bufferedSource.mkString - } finally { - bufferedSource.close() - } - } + def basic: String = Using.resource(io.Source.fromFile("facade/jvm/src/test/resources/akka.conf")) { _.mkString } - def long: String = { - val bufferedSource = io.Source.fromFile("facade/jvm/src/test/resources/akka-long.conf") - try { - bufferedSource.mkString - } finally { - bufferedSource.close() - } - } + def long: String = Using.resource(io.Source.fromFile("facade/jvm/src/test/resources/akka-long.conf")) { _.mkString } } diff --git a/facade/shared/src/main/scala/org/akkajs/shocon/ConfigLoader.scala b/facade/shared/src/main/scala/org/akkajs/shocon/ConfigLoader.scala index ee7b9b1..a666e39 100644 --- a/facade/shared/src/main/scala/org/akkajs/shocon/ConfigLoader.scala +++ b/facade/shared/src/main/scala/org/akkajs/shocon/ConfigLoader.scala @@ -2,6 +2,7 @@ package org.akkajs.shocon import scala.language.experimental.macros import scala.reflect.macros.blackbox +import scala.util.Using object ConfigLoader { @@ -30,11 +31,8 @@ object ConfigLoader { .map { files => files .map { file => - val bufferedSource = scala.io.Source.fromFile(file) - try { + Using.resource(scala.io.Source.fromFile(file)) { bufferedSource => bufferedSource.getLines().mkString("\n") - } finally { - bufferedSource.close() } } .mkString("\n\n") @@ -53,11 +51,8 @@ object ConfigLoader { c.info(c.enclosingPosition, s"shocon - statically reading configuration from $confPath", force = false) val stream = new Object {}.getClass.getResourceAsStream("/application.conf") - val bufferedSource = scala.io.Source.fromInputStream(stream) - try { + Using.resource(scala.io.Source.fromInputStream(stream)) { bufferedSource => bufferedSource.getLines().mkString("\n") - } finally { - bufferedSource.close() } } catch { case e: Throwable => diff --git a/plugin/build.sbt b/plugin/build.sbt index fe669a0..71e15e6 100644 --- a/plugin/build.sbt +++ b/plugin/build.sbt @@ -8,7 +8,7 @@ lazy val plugin = project name := "sbt-shocon", description := "sbt plugin for shocon", sbtPlugin := true, - scalaVersion := "2.12.10", + scalaVersion := "2.12.15", crossSbtVersions := Vector("1.3.13"), addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion), scalacOptions ++= Seq("-feature", "-unchecked", "-language:implicitConversions"), diff --git a/plugin/project/plugins.sbt b/plugin/project/plugins.sbt index 2e5faee..b17315b 100644 --- a/plugin/project/plugins.sbt +++ b/plugin/project/plugins.sbt @@ -1,4 +1,4 @@ -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.8.0") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3") @@ -6,11 +6,5 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2") -resolvers += Resolver.typesafeIvyRepo("releases") - -resolvers += "Typesafe repository".at("https://repo.typesafe.com/typesafe/releases/") - -resolvers += "sonatype-releases".at("https://oss.sonatype.org/content/repositories/releases/") - // library for plugin testing libraryDependencies += { "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value } diff --git a/plugin/src/sbt-test/shocon/basic/build.sbt b/plugin/src/sbt-test/shocon/basic/build.sbt index 332c5e7..a7585c1 100644 --- a/plugin/src/sbt-test/shocon/basic/build.sbt +++ b/plugin/src/sbt-test/shocon/basic/build.sbt @@ -3,7 +3,7 @@ lazy val root = crossProject(JSPlatform, JVMPlatform) .dependsOn(lib) .enablePlugins(ShoconPlugin) .settings( - scalaVersion := "2.12.4", + scalaVersion := "2.12.15", name := "basic", version := "0.1.0-SNAPSHOT", description := "Basic test for the shocon sbt plugin", @@ -12,13 +12,7 @@ lazy val root = crossProject(JSPlatform, JVMPlatform) compile in Compile := (compile in Compile).dependsOn(shoconConcat).value) .jsSettings(scalaJSUseMainModuleInitializer := true) -lazy val rootJVM = root.jvm -lazy val rootJS = root.js - lazy val lib = crossProject(JSPlatform, JVMPlatform) .in(file("lib")) .enablePlugins(ShoconPlugin) - .settings(scalaVersion := "2.12.2", name := "lib") - -lazy val libJVM = lib.jvm -lazy val libJS = lib.js + .settings(scalaVersion := "2.12.15", name := "lib") diff --git a/plugin/src/sbt-test/shocon/basic/project/plugins.sbt b/plugin/src/sbt-test/shocon/basic/project/plugins.sbt index e42241d..9607b19 100644 --- a/plugin/src/sbt-test/shocon/basic/project/plugins.sbt +++ b/plugin/src/sbt-test/shocon/basic/project/plugins.sbt @@ -1,5 +1,5 @@ -addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1") +addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.1.0") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.8.0") addSbtPlugin( "org.akka-js" % "sbt-shocon" % sys.props diff --git a/project/Common.scala b/project/Common.scala index 5cc10f4..2d84330 100644 --- a/project/Common.scala +++ b/project/Common.scala @@ -7,8 +7,8 @@ object Common extends AutoPlugin { name := "shocon", organization := "org.akka-js", version := "1.0.0", - scalaVersion := "2.13.4", - crossScalaVersions := Vector("2.12.13", "2.13.4"), + scalaVersion := "2.13.8", + crossScalaVersions := Vector("2.12.15", "2.13.8"), pomExtra := { https://github.com/akka-js/shocon diff --git a/project/plugins.sbt b/project/plugins.sbt index 6e84aea..d07398d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -3,7 +3,7 @@ addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3") addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0") addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.1.0") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.8.0") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2") diff --git a/publish.sh b/publish.sh index 637977f..83d56b0 100755 --- a/publish.sh +++ b/publish.sh @@ -2,9 +2,9 @@ sbt clean -sbt ";++2.12.13;facadeJVM/publishLocal;parserJVM/publishLocal;facadeJS/publishSigned;facadeJVM/publishSigned;parserJS/publishSigned;parserJVM/publishSigned" +sbt ";++2.12.15;facadeJVM/publishLocal;parserJVM/publishLocal;facadeJS/publishSigned;facadeJVM/publishSigned;parserJS/publishSigned;parserJVM/publishSigned" -sbt ";++2.13.4;facadeJVM/publishLocal;parserJVM/publishLocal;facadeJS/publishSigned;facadeJVM/publishSigned;parserJS/publishSigned;parserJVM/publishSigned" +sbt ";++2.13.8;facadeJVM/publishLocal;parserJVM/publishLocal;facadeJS/publishSigned;facadeJVM/publishSigned;parserJS/publishSigned;parserJVM/publishSigned" sbt sonatypeReleaseAll diff --git a/shared/src/main/scala/org/akkajs/shocon/SHocon.scala b/shared/src/main/scala/org/akkajs/shocon/SHocon.scala index a7b223c..3776f1b 100644 --- a/shared/src/main/scala/org/akkajs/shocon/SHocon.scala +++ b/shared/src/main/scala/org/akkajs/shocon/SHocon.scala @@ -5,7 +5,7 @@ import fastparse.Parsed import scala.annotation.tailrec import scala.collection.compat._ import scala.language.experimental.macros -import scala.util.Try +import scala.util.{ Try, Using } package object shocon extends Extractors { @@ -62,11 +62,8 @@ package object shocon extends Extractors { case f: Parsed.Failure => throw new Error(f.msg) } def fromFile(path: String): Value = { - val bufferedSource = io.Source.fromFile(path) - try { + Using.resource(io.Source.fromFile(path)) { bufferedSource => apply(bufferedSource.mkString) - } finally { - bufferedSource.close() } } From 7db54d869d96bfc55ce22d624a41c67848d87429 Mon Sep 17 00:00:00 2001 From: Michael Liarakos Date: Fri, 28 Jan 2022 23:45:05 -0500 Subject: [PATCH 06/12] updated travis scala versions --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 15f045d..8f91dd7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,15 +6,15 @@ jdk: openjdk8 language: scala scala: - - "2.13.4" - - "2.12.13" + - "2.13.8" + - "2.12.15" jdk: openjdk8 matrix: include: - env: SBT_VERSION=1.3.13 - scala: "2.12.13" + scala: "2.12.15" env: - TRAVIS_NODE_VERSION="10.17.0" From 6448b780335de00d99c4511c34c29707c35c28db Mon Sep 17 00:00:00 2001 From: Michael Liarakos Date: Sun, 30 Jan 2022 11:38:38 -0500 Subject: [PATCH 07/12] removed travis config duplicates --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8f91dd7..284e8b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,6 @@ scala: - "2.13.8" - "2.12.15" -jdk: openjdk8 - matrix: include: - env: SBT_VERSION=1.3.13 @@ -30,6 +28,3 @@ cache: script: - sbt ++$TRAVIS_SCALA_VERSION test - source travis/testSbtPlugin.sh -cache: - directories: - - $HOME/.cache From 8db2faba54223e03eef902b10d0c2107eca094f9 Mon Sep 17 00:00:00 2001 From: Michael Liarakos Date: Sat, 5 Feb 2022 09:43:34 -0500 Subject: [PATCH 08/12] shellcheck fixes --- travis/setNodeVersion.sh | 6 +++--- travis/testSbtPlugin.sh | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/travis/setNodeVersion.sh b/travis/setNodeVersion.sh index 2224b06..afad4f3 100644 --- a/travis/setNodeVersion.sh +++ b/travis/setNodeVersion.sh @@ -1,10 +1,10 @@ #!/bin/sh -if [ ! -z "$TRAVIS_NODE_VERSION" ]; then +if [ -n "$TRAVIS_NODE_VERSION" ]; then rm -rf ~/.nvm git clone https://github.com/creationix/nvm.git ~/.nvm - (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) + (cd ~/.nvm && git checkout "$(git describe --abbrev=0 --tags)") source ~/.nvm/nvm.sh - nvm install $TRAVIS_NODE_VERSION + nvm install "$TRAVIS_NODE_VERSION" npm install fi; diff --git a/travis/testSbtPlugin.sh b/travis/testSbtPlugin.sh index 03cf5ab..20f4f61 100644 --- a/travis/testSbtPlugin.sh +++ b/travis/testSbtPlugin.sh @@ -1,7 +1,7 @@ #!/bin/sh -if [ ! -z $SBT_VERSION ]; then source test_plugin.sh - sbt ++$TRAVIS_SCALA_VERSION publishLocal - cd plugin - sbt ^^$SBT_VERSION 'scripted shocon/basic' +if [ -n "$SBT_VERSION" ]; then + sbt ++"$TRAVIS_SCALA_VERSION" publishLocal + cd plugin || exit 1 + sbt ^^"$SBT_VERSION" 'scripted shocon/basic' fi; From fefcb0569c5f094cc237f48d8e3a7439a1397d45 Mon Sep 17 00:00:00 2001 From: Michael Liarakos Date: Sat, 5 Feb 2022 09:45:09 -0500 Subject: [PATCH 09/12] updated sbt --- .gitignore | 1 + .travis.yml | 2 +- plugin/project/build.properties | 2 +- project/build.properties | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8cfb1a7..30cf641 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ bin .ensime* shared/src/main/scala/Empty.scala .idea/ +.bsp/ diff --git a/.travis.yml b/.travis.yml index 284e8b6..67d1639 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ scala: matrix: include: - - env: SBT_VERSION=1.3.13 + - env: SBT_VERSION=1.4.9 scala: "2.12.15" env: diff --git a/plugin/project/build.properties b/plugin/project/build.properties index 0837f7a..dbae93b 100644 --- a/plugin/project/build.properties +++ b/plugin/project/build.properties @@ -1 +1 @@ -sbt.version=1.3.13 +sbt.version=1.4.9 diff --git a/project/build.properties b/project/build.properties index 0837f7a..dbae93b 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.3.13 +sbt.version=1.4.9 From aeb200683e773632eab8afbf85cc25d8860d7c12 Mon Sep 17 00:00:00 2001 From: Michael Liarakos Date: Sat, 19 Feb 2022 10:54:38 -0500 Subject: [PATCH 10/12] updated version --- project/Common.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Common.scala b/project/Common.scala index 2d84330..53d821c 100644 --- a/project/Common.scala +++ b/project/Common.scala @@ -6,7 +6,7 @@ object Common extends AutoPlugin { override lazy val projectSettings: Seq[Def.Setting[_]] = super.projectSettings ++ Seq( name := "shocon", organization := "org.akka-js", - version := "1.0.0", + version := "1.1.0-SNAPSHOT", scalaVersion := "2.13.8", crossScalaVersions := Vector("2.12.15", "2.13.8"), pomExtra := { From 574a87ddde8e907b0b9bb767e76f451c0b43ba20 Mon Sep 17 00:00:00 2001 From: Michael Liarakos Date: Sat, 19 Feb 2022 11:29:40 -0500 Subject: [PATCH 11/12] updated plugin sbt version --- plugin/build.sbt | 1 - plugin/project/project/build.properties | 1 - publish.sh | 7 ++----- 3 files changed, 2 insertions(+), 7 deletions(-) delete mode 100644 plugin/project/project/build.properties diff --git a/plugin/build.sbt b/plugin/build.sbt index 71e15e6..c4f02f7 100644 --- a/plugin/build.sbt +++ b/plugin/build.sbt @@ -9,7 +9,6 @@ lazy val plugin = project description := "sbt plugin for shocon", sbtPlugin := true, scalaVersion := "2.12.15", - crossSbtVersions := Vector("1.3.13"), addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion), scalacOptions ++= Seq("-feature", "-unchecked", "-language:implicitConversions"), // configuration for testing with sbt-scripted diff --git a/plugin/project/project/build.properties b/plugin/project/project/build.properties deleted file mode 100644 index 0837f7a..0000000 --- a/plugin/project/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.3.13 diff --git a/publish.sh b/publish.sh index 83d56b0..56b8ba0 100755 --- a/publish.sh +++ b/publish.sh @@ -3,15 +3,12 @@ sbt clean sbt ";++2.12.15;facadeJVM/publishLocal;parserJVM/publishLocal;facadeJS/publishSigned;facadeJVM/publishSigned;parserJS/publishSigned;parserJVM/publishSigned" - sbt ";++2.13.8;facadeJVM/publishLocal;parserJVM/publishLocal;facadeJS/publishSigned;facadeJVM/publishSigned;parserJS/publishSigned;parserJVM/publishSigned" - sbt sonatypeReleaseAll -cd plugin - -sbt ";^^1.3.13;publishSigned" +cd plugin || exit 1 +sbt ";^^1.4.9;publishSigned" sbt sonatypeReleaseAll cd .. From 534fa809a11629de8e005c80e2e6cf57d81f2657 Mon Sep 17 00:00:00 2001 From: Michael Liarakos Date: Sat, 19 Feb 2022 11:51:09 -0500 Subject: [PATCH 12/12] moved parser into directory --- build.sbt | 2 +- .../src/main/scala/org/akkajs/shocon/ConfigMacroLoader.scala | 0 .../shared}/src/main/scala/org/akkajs/shocon/ConfigParser.scala | 0 .../shared}/src/main/scala/org/akkajs/shocon/Extractors.scala | 0 .../shared}/src/main/scala/org/akkajs/shocon/SHocon.scala | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename {shared => parser/shared}/src/main/scala/org/akkajs/shocon/ConfigMacroLoader.scala (100%) rename {shared => parser/shared}/src/main/scala/org/akkajs/shocon/ConfigParser.scala (100%) rename {shared => parser/shared}/src/main/scala/org/akkajs/shocon/Extractors.scala (100%) rename {shared => parser/shared}/src/main/scala/org/akkajs/shocon/SHocon.scala (100%) diff --git a/build.sbt b/build.sbt index 7c7f82f..6389b7b 100644 --- a/build.sbt +++ b/build.sbt @@ -8,7 +8,7 @@ lazy val fixResources = taskKey[Unit]("Fix application.conf presence on first clean build.") lazy val parser = crossProject(JSPlatform, JVMPlatform) - .in(file(".")) + .in(file("parser")) .settings( name := "shocon-parser", scalacOptions ++= diff --git a/shared/src/main/scala/org/akkajs/shocon/ConfigMacroLoader.scala b/parser/shared/src/main/scala/org/akkajs/shocon/ConfigMacroLoader.scala similarity index 100% rename from shared/src/main/scala/org/akkajs/shocon/ConfigMacroLoader.scala rename to parser/shared/src/main/scala/org/akkajs/shocon/ConfigMacroLoader.scala diff --git a/shared/src/main/scala/org/akkajs/shocon/ConfigParser.scala b/parser/shared/src/main/scala/org/akkajs/shocon/ConfigParser.scala similarity index 100% rename from shared/src/main/scala/org/akkajs/shocon/ConfigParser.scala rename to parser/shared/src/main/scala/org/akkajs/shocon/ConfigParser.scala diff --git a/shared/src/main/scala/org/akkajs/shocon/Extractors.scala b/parser/shared/src/main/scala/org/akkajs/shocon/Extractors.scala similarity index 100% rename from shared/src/main/scala/org/akkajs/shocon/Extractors.scala rename to parser/shared/src/main/scala/org/akkajs/shocon/Extractors.scala diff --git a/shared/src/main/scala/org/akkajs/shocon/SHocon.scala b/parser/shared/src/main/scala/org/akkajs/shocon/SHocon.scala similarity index 100% rename from shared/src/main/scala/org/akkajs/shocon/SHocon.scala rename to parser/shared/src/main/scala/org/akkajs/shocon/SHocon.scala