From 820717c3b798402643b4a767cc6e121b67223431 Mon Sep 17 00:00:00 2001 From: Paul S Date: Sat, 7 Oct 2023 23:30:16 +0300 Subject: [PATCH] Config loader always loads configs for all the available roles (#2021) This fixes issues with ConfigWriter and run-all meta-roles caused by axis defined in role-local configs --- .../framework/services/ConfigLoader.scala | 10 ++--- .../test/resources/testrole05-reference.conf | 3 ++ .../roles/test/fixtures/TestPlugin.scala | 1 + .../roles/test/fixtures/TestRole00.scala | 1 + .../roles/test/fixtures/TestRole05.scala | 45 +++++++++++++++++++ 5 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 distage/distage-framework/.jvm/src/test/resources/testrole05-reference.conf create mode 100644 distage/distage-framework/.jvm/src/test/scala/izumi/distage/roles/test/fixtures/TestRole05.scala diff --git a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/services/ConfigLoader.scala b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/services/ConfigLoader.scala index c1ddfdff48..b8d9b04966 100644 --- a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/services/ConfigLoader.scala +++ b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/services/ConfigLoader.scala @@ -17,8 +17,6 @@ import java.io.{File, FileNotFoundException} import scala.jdk.CollectionConverters.* import scala.util.{Failure, Success, Try} - - /** * Default config resources: * - `\${roleName}.conf` @@ -51,9 +49,7 @@ import scala.util.{Failure, Success, Try} * @see [[ConfigLoader.ConfigLocation]] * @see [[ConfigLoader.LocalFSImpl]] */ -trait ConfigLoader extends AbstractConfigLoader { - -} +trait ConfigLoader extends AbstractConfigLoader {} object ConfigLoader { def empty: ConfigLoader = () => AppConfig(ConfigFactory.empty()) @@ -89,11 +85,11 @@ object ConfigLoader { rolesInfo: RolesInfo, ): ConfigLoader.Args = { val maybeGlobalConfig = parameters.globalParameters.findValue(RoleAppMain.Options.configParam).asFile - val emptyRoleConfigs = rolesInfo.requiredRoleNames.map(_ -> None).toMap + val emptyRoleConfigs = rolesInfo.availableRoleNames.map(_ -> None).toMap val specifiedRoleConfigs = parameters.roles.iterator .map(roleParams => roleParams.role -> roleParams.roleParameters.findValue(RoleAppMain.Options.configParam).asFile) .toMap - ConfigLoader.Args(maybeGlobalConfig, (emptyRoleConfigs ++ specifiedRoleConfigs).view.filterKeys(rolesInfo.requiredRoleNames).toMap) + ConfigLoader.Args(maybeGlobalConfig, (emptyRoleConfigs ++ specifiedRoleConfigs).view.toMap) } def empty: ConfigLoader.Args = ConfigLoader.Args(None, Map.empty) diff --git a/distage/distage-framework/.jvm/src/test/resources/testrole05-reference.conf b/distage/distage-framework/.jvm/src/test/resources/testrole05-reference.conf new file mode 100644 index 0000000000..b4aabb760b --- /dev/null +++ b/distage/distage-framework/.jvm/src/test/resources/testrole05-reference.conf @@ -0,0 +1,3 @@ +activation { + role05localaxis = rolelocal1 +} diff --git a/distage/distage-framework/.jvm/src/test/scala/izumi/distage/roles/test/fixtures/TestPlugin.scala b/distage/distage-framework/.jvm/src/test/scala/izumi/distage/roles/test/fixtures/TestPlugin.scala index 7958a3c28b..72a254728a 100644 --- a/distage/distage-framework/.jvm/src/test/scala/izumi/distage/roles/test/fixtures/TestPlugin.scala +++ b/distage/distage-framework/.jvm/src/test/scala/izumi/distage/roles/test/fixtures/TestPlugin.scala @@ -42,6 +42,7 @@ class TestPluginBase[F[_]: TagK] extends PluginDef with ConfigModuleDef with Rol makeRole[TestRole03[F]] makeRole[TestRole04[F]] + include(new TestRole05.Role05Module[F]) makeRole[FailingRole01[F]] makeRole[FailingRole02[F]] diff --git a/distage/distage-framework/.jvm/src/test/scala/izumi/distage/roles/test/fixtures/TestRole00.scala b/distage/distage-framework/.jvm/src/test/scala/izumi/distage/roles/test/fixtures/TestRole00.scala index f18aed3236..32660c903e 100644 --- a/distage/distage-framework/.jvm/src/test/scala/izumi/distage/roles/test/fixtures/TestRole00.scala +++ b/distage/distage-framework/.jvm/src/test/scala/izumi/distage/roles/test/fixtures/TestRole00.scala @@ -179,3 +179,4 @@ class FailingRole02[F[_]: QuasiIO]( object FailingRole02 extends RoleDescriptor { override final val id = "failingrole02" } + diff --git a/distage/distage-framework/.jvm/src/test/scala/izumi/distage/roles/test/fixtures/TestRole05.scala b/distage/distage-framework/.jvm/src/test/scala/izumi/distage/roles/test/fixtures/TestRole05.scala new file mode 100644 index 0000000000..1cee8662d5 --- /dev/null +++ b/distage/distage-framework/.jvm/src/test/scala/izumi/distage/roles/test/fixtures/TestRole05.scala @@ -0,0 +1,45 @@ +package izumi.distage.roles.test.fixtures + +import distage.{Axis, ModuleDef} +import izumi.distage.config.ConfigModuleDef +import izumi.distage.model.definition.Lifecycle +import izumi.distage.roles.model.{RoleDescriptor, RoleService} +import izumi.distage.roles.model.definition.RoleModuleDef +import izumi.distage.roles.test.fixtures.TestRole05.{TestRole05Dependency, TestRole05DependencyImpl1} +import izumi.functional.quasi.QuasiIO +import izumi.fundamentals.platform.cli.model.raw.RawEntrypointParams +import izumi.reflect.TagK + +class TestRole05[F[_] : QuasiIO]( + dependency: TestRole05Dependency + ) extends RoleService[F] { + override def start(roleParameters: RawEntrypointParams, freeArgs: Vector[String]): Lifecycle[F, Unit] = Lifecycle.make(QuasiIO[F].maybeSuspend { + assert(dependency.isInstanceOf[TestRole05DependencyImpl1]) + }) { + _ => + QuasiIO[F].unit + } +} + +object TestRole05 extends RoleDescriptor { + override final val id = "testrole05" + + trait TestRole05Dependency + + class TestRole05DependencyImpl1 extends TestRole05Dependency + + class TestRole05DependencyImpl2 extends TestRole05Dependency + + object Role05LocalAxis extends Axis { + case object Rolelocal2 extends AxisChoiceDef + + case object Rolelocal1 extends AxisChoiceDef + } + + class Role05Module[F[_] : TagK] extends ModuleDef with ConfigModuleDef with RoleModuleDef { + makeRole[TestRole05[F]] + make[TestRole05Dependency].from[TestRole05DependencyImpl1].tagged(Role05LocalAxis.Rolelocal1) + make[TestRole05Dependency].from[TestRole05DependencyImpl2].tagged(Role05LocalAxis.Rolelocal2) + } + +}