Skip to content
This repository was archived by the owner on Nov 3, 2022. It is now read-only.

Commit 48fdc70

Browse files
committed
Move ConfigAdapter attachment to before enable phase.
1 parent 4217240 commit 48fdc70

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/main/java/uk/co/drnaylor/quickstart/ModuleContainer.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,22 @@ public void loadModules(boolean failOnOneError) throws QuickStartModuleLoaderExc
259259
throw new QuickStartModuleLoaderException.Construction(null, "No modules were constructed.", null);
260260
}
261261

262+
// Enter Config Adapter phase - attaching before enabling so that enable methods can get any associated configurations.
263+
for (String s : modules.keySet()) {
264+
Module m = modules.get(s);
265+
Optional<AbstractConfigAdapter<?>> a = m.getConfigAdapter();
266+
if (a.isPresent()) {
267+
try {
268+
config.attachConfigAdapter(s, a.get());
269+
} catch (IOException e) {
270+
e.printStackTrace();
271+
if (failOnOneError) {
272+
throw new QuickStartModuleLoaderException.Enabling(m.getClass(), "Failed to attach config.", e);
273+
}
274+
}
275+
}
276+
}
277+
262278
// Enter Enable phase.
263279
Map<String, Module> c = new HashMap<>(modules);
264280
for (String s : c.keySet()) {
@@ -267,18 +283,6 @@ public void loadModules(boolean failOnOneError) throws QuickStartModuleLoaderExc
267283
try {
268284
Module m = modules.get(s);
269285
constructor.enableModule(m);
270-
Optional<AbstractConfigAdapter<?>> a = m.getConfigAdapter();
271-
if (a.isPresent()) {
272-
try {
273-
config.attachConfigAdapter(s, a.get());
274-
} catch (IOException e) {
275-
e.printStackTrace();
276-
if (failOnOneError) {
277-
throw new QuickStartModuleLoaderException.Enabling(m.getClass(), "Failed to attach config.", e);
278-
}
279-
}
280-
}
281-
282286
ms.setPhase(ModulePhase.ENABLED);
283287
} catch (Exception construction) {
284288
construction.printStackTrace();

0 commit comments

Comments
 (0)