From 3708c0f5d855c085295b45882e4ef56d2df3abbc Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 23 Nov 2010 10:53:59 +0100 Subject: [PATCH] Change loading order of configuration backends. First, try to load an XML configuration file. If that fails, try to create an XML configuration file and load the plugin store. After the core has been created (and if the XML could not be loaded), the newly created XML file is set as configuration on the core, migrating the configuration from the plugin store to the XML file. --- .../net/pterodactylus/sone/main/SonePlugin.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index a57a71e..6d9e3a0 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -148,14 +148,20 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10 /* create a configuration. */ Configuration configuration; + Configuration xmlConfiguration = null; try { - configuration = new Configuration(new PluginStoreConfigurationBackend(pluginRespirator)); - } catch (DatabaseDisabledException dde1) { - logger.log(Level.WARNING, "Could not load plugin store, using XML files."); + configuration = new Configuration(new XMLConfigurationBackend(new File("sone.xml"), false)); + xmlConfiguration = configuration; + } catch (ConfigurationException ce1) { try { - configuration = new Configuration(new XMLConfigurationBackend(new File("sone.xml"), true)); - } catch (ConfigurationException ce1) { - logger.log(Level.SEVERE, "Could not load or create the “sone.xml” configuration file!"); + xmlConfiguration = new Configuration(new XMLConfigurationBackend(new File("sone.xml"), true)); + } catch (ConfigurationException ce2) { + logger.log(Level.SEVERE, "Could not create XML file, using Plugin Store!"); + } + try { + configuration = new Configuration(new PluginStoreConfigurationBackend(pluginRespirator)); + } catch (DatabaseDisabledException dde1) { + logger.log(Level.SEVERE, "Could not load any configuration, using in-memory configuration!"); configuration = new Configuration(new MapConfigurationBackend(Collections. emptyMap())); } } @@ -183,6 +189,9 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10 boolean startupFailed = true; try { core.start(); + if ((xmlConfiguration != null) && (configuration != xmlConfiguration)) { + core.setConfiguration(xmlConfiguration); + } webInterface.start(); identityManager.start(); startupFailed = false; -- 2.7.4