diff --git a/build.sbt b/build.sbt index e588843a702f..08020ac19c43 100644 --- a/build.sbt +++ b/build.sbt @@ -970,7 +970,8 @@ lazy val pkg = (project in file("lib/scala/pkg")) (`editions` / Compile / exportedModule).value, (`semver` / Compile / exportedModule).value, (`scala-yaml` / Compile / exportedModule).value, - (`scala-libs-wrapper` / Compile / exportedModule).value + (`scala-libs-wrapper` / Compile / exportedModule).value, + (`version-output` / Compile / exportedModule).value ) ) .dependsOn(editions) diff --git a/lib/scala/pkg/src/main/java/module-info.java b/lib/scala/pkg/src/main/java/module-info.java index 4a9ef4ce6d96..c9f68c6d208b 100644 --- a/lib/scala/pkg/src/main/java/module-info.java +++ b/lib/scala/pkg/src/main/java/module-info.java @@ -3,6 +3,7 @@ requires org.apache.commons.compress; requires org.enso.editions; requires org.enso.semver; + requires org.enso.version.output; requires org.enso.scala.yaml; // For io.circe requires org.enso.scala.wrapper; diff --git a/lib/scala/pkg/src/main/scala/org/enso/pkg/Config.scala b/lib/scala/pkg/src/main/scala/org/enso/pkg/Config.scala index 46435a9b6544..3adb2ecfd257 100644 --- a/lib/scala/pkg/src/main/scala/org/enso/pkg/Config.scala +++ b/lib/scala/pkg/src/main/scala/org/enso/pkg/Config.scala @@ -5,6 +5,7 @@ import org.enso.semver.SemVer import org.enso.editions.{EditionName, Editions} import org.enso.pkg.validation.NameValidation import org.enso.scala.yaml.{YamlDecoder, YamlEncoder} +import org.enso.version.BuildVersion import org.yaml.snakeyaml.{DumperOptions, Yaml} import org.yaml.snakeyaml.error.YAMLException import org.yaml.snakeyaml.nodes.{MappingNode, Node} @@ -114,7 +115,19 @@ case class Config( /** Converts the configuration into a YAML representation. */ def toYaml: String = { - val node = implicitly[YamlEncoder[Config]].encode(this) + val config: Config = this + val noDevEdition: Config = + if ( + config.edition.exists( + _.parent + .exists(p => p.toString == BuildVersion.defaultDevEnsoVersion()) + ) + ) { + config.copy(edition = None) + } else { + config + } + val node = implicitly[YamlEncoder[Config]].encode(noDevEdition) val dumperOptions = new DumperOptions() dumperOptions.setIndent(2) dumperOptions.setPrettyFlow(true) diff --git a/lib/scala/pkg/src/test/scala/org/enso/pkg/ConfigSpec.scala b/lib/scala/pkg/src/test/scala/org/enso/pkg/ConfigSpec.scala index d813d7fc0912..aabdbeafb5bf 100644 --- a/lib/scala/pkg/src/test/scala/org/enso/pkg/ConfigSpec.scala +++ b/lib/scala/pkg/src/test/scala/org/enso/pkg/ConfigSpec.scala @@ -46,6 +46,26 @@ class ConfigSpec parsed.edition shouldBe empty } + "persist normal edition" in { + val parsed = Config.fromYaml("name: fooBar\nedition: 2024.4.2").get + parsed.name shouldEqual "fooBar" + parsed.normalizedName shouldEqual None + parsed.moduleName shouldEqual "FooBar" + + val ser = parsed.toYaml + ser shouldEqual "name: fooBar\nnamespace: local\nedition: 2024.4.2\n" + } + + "don't persist dev edition" in { + val parsed = Config.fromYaml("name: fooBar\nedition: 0.0.0-dev").get + parsed.name shouldEqual "fooBar" + parsed.normalizedName shouldEqual None + parsed.moduleName shouldEqual "FooBar" + + val ser = parsed.toYaml + ser shouldEqual "name: fooBar\nnamespace: local\n" + } + "correctly de-serialize and serialize back the shortened edition syntax " + "if there are no overrides" in { val config =