use of org.apache.commons.configuration2.YAMLConfiguration in project studio by craftercms.
the class StudioConfigurationImpl method loadConfig.
@Override
public void loadConfig() {
YamlConfiguration baseConfig = new YamlConfiguration();
YamlConfiguration overrideConfig = new YamlConfiguration();
Resource resource = new ClassPathResource(configLocation);
try (InputStream in = resource.getInputStream()) {
baseConfig.setExpressionEngine(getExpressionEngine());
baseConfig.read(in);
logger.debug("Loaded configuration from location: {0} \n {1}", configLocation, baseConfig);
} catch (IOException | ConfigurationException e) {
logger.error("Failed to load studio configuration from: " + configLocation, e);
}
if (baseConfig.containsKey(STUDIO_CONFIG_OVERRIDE_CONFIG)) {
String overrideConfigLocation = baseConfig.getString(STUDIO_CONFIG_OVERRIDE_CONFIG);
resource = new ClassPathResource(overrideConfigLocation);
try (InputStream in = resource.getInputStream()) {
overrideConfig.setExpressionEngine(getExpressionEngine());
overrideConfig.read(in);
if (!overrideConfig.isEmpty()) {
logger.debug("Loaded additional configuration from location: {0} \n {1}", overrideConfigLocation, overrideConfig);
}
} catch (IOException | ConfigurationException e) {
logger.error("Failed to load studio configuration from: " + overrideConfigLocation, e);
}
}
// Merge the base properties and additional properties
if (!overrideConfig.isEmpty()) {
CombinedConfiguration combinedConfig = new CombinedConfiguration(new OverrideCombiner());
combinedConfig.setExpressionEngine(getExpressionEngine());
combinedConfig.addConfiguration(overrideConfig);
combinedConfig.addConfiguration(baseConfig);
systemConfig = combinedConfig;
} else {
systemConfig = baseConfig;
}
}
use of org.apache.commons.configuration2.YAMLConfiguration in project incubator-hugegraph by apache.
the class ConfigUtil method checkGremlinConfig.
public static void checkGremlinConfig(String conf) {
Parameters params = new Parameters();
try {
FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder(YAMLConfiguration.class).configure(params.fileBased().setFileName(conf));
YAMLConfiguration config = (YAMLConfiguration) builder.getConfiguration();
List<HierarchicalConfiguration<ImmutableNode>> nodes = config.childConfigurationsAt(NODE_GRAPHS);
if (nodes == null || nodes.isEmpty()) {
return;
}
E.checkArgument(nodes.size() == 1, "Not allowed to specify multiple '%s' " + "nodes in config file '%s'", NODE_GRAPHS, conf);
ImmutableNode root = null;
NodeHandler<ImmutableNode> nodeHandler = null;
for (HierarchicalConfiguration<ImmutableNode> node : nodes) {
NodeModel<ImmutableNode> nodeModel = node.getNodeModel();
E.checkArgument(nodeModel != null && (nodeHandler = nodeModel.getNodeHandler()) != null && (root = nodeHandler.getRootNode()) != null, "Node '%s' must contain root", node);
}
} catch (ConfigurationException e) {
throw new HugeException("Failed to load yaml config file '%s'", conf);
}
}
use of org.apache.commons.configuration2.YAMLConfiguration in project winery by eclipse.
the class EnvironmentTest method testSave.
/**
* This test checks whether changes made to the configuration are persisted correctly. and whenever the file is
* reloaded when a change occurs
*/
@Test
public void testSave() {
YAMLConfiguration configuration = Environment.getInstance().getConfiguration();
configuration.setProperty("ui.features.foo", false);
configuration.setProperty("ui.features.bar", true);
configuration.setProperty("ui.endpoints.quaz", "");
Environment.getInstance().save();
Environment.getInstance().setConfiguration(null);
configuration = Environment.getInstance().getConfiguration();
assertFalse(configuration.getBoolean("ui.features.foo"));
assertTrue(configuration.getBoolean("ui.features.bar"));
assertEquals(configuration.getString("ui.endpoints.quaz"), "");
}
use of org.apache.commons.configuration2.YAMLConfiguration in project winery by eclipse.
the class EnvironmentTest method testReload.
/**
* Tests whenever a change in the configuration file is detected.
*/
@Test
@Disabled("This test seems to fail transiently on test infrastructure")
public void testReload() {
YAMLConfiguration configuration = Environment.getInstance().getConfiguration();
assertFalse(Environment.getInstance().checkConfigurationForUpdate());
configuration.setProperty("ui.features.foo", false);
Environment.getInstance().save();
assertTrue(Environment.getInstance().checkConfigurationForUpdate());
}
use of org.apache.commons.configuration2.YAMLConfiguration in project winery by eclipse.
the class EnvironmentTest method testConfigValues.
/**
* This test checks for correctness of the retrieved values from the config file. Also tests whether or not the
* properties in the config file are found.
*/
@Test
public void testConfigValues() {
YAMLConfiguration tested = Environment.getInstance().getConfiguration();
assertTrue(tested.getBoolean("ui.features.foo"));
assertFalse(tested.getBoolean("ui.features.bar"));
assertEquals("http://quaz:8080", tested.getString("ui.endpoints.quaz"));
}
Aggregations