use of org.apache.commons.configuration2.SystemConfiguration in project jbake by jbake-org.
the class ConfigUtil method load.
private CompositeConfiguration load(File source, File propertiesFile) throws ConfigurationException {
if (!source.exists()) {
throw new JBakeException(SystemExit.CONFIGURATION_ERROR, "The given source folder '" + source.getAbsolutePath() + "' does not exist.");
}
if (!source.isDirectory()) {
throw new JBakeException(SystemExit.CONFIGURATION_ERROR, "The given source folder is not a directory.");
}
File legacyConfigFile = new File(source, LEGACY_CONFIG_FILE);
File customConfigFile = propertiesFile != null ? propertiesFile : new File(source, CONFIG_FILE);
CompositeConfiguration config = new CompositeConfiguration();
config.setListDelimiterHandler(new DefaultListDelimiterHandler(LIST_DELIMITER));
if (legacyConfigFile.exists()) {
displayLegacyConfigFileWarningIfRequired();
config.addConfiguration(getFileBasedPropertiesConfiguration(legacyConfigFile));
}
if (customConfigFile.exists()) {
config.addConfiguration(getFileBasedPropertiesConfiguration(customConfigFile));
}
URL defaultPropertiesLocation = this.getClass().getClassLoader().getResource(DEFAULT_CONFIG_FILE);
if (defaultPropertiesLocation != null) {
config.addConfiguration(getFileBasedPropertiesConfiguration(defaultPropertiesLocation));
}
config.addConfiguration(new SystemConfiguration());
return config;
}
use of org.apache.commons.configuration2.SystemConfiguration in project jbake by jbake-org.
the class DefaultJBakeConfiguration method getJbakeProperties.
public List<Property> getJbakeProperties() {
List<Property> jbakeKeys = new ArrayList<>();
for (int i = 0; i < compositeConfiguration.getNumberOfConfigurations(); i++) {
Configuration configuration = compositeConfiguration.getConfiguration(i);
if (!(configuration instanceof SystemConfiguration)) {
for (Iterator<String> it = configuration.getKeys(); it.hasNext(); ) {
String key = it.next();
Property property = PropertyList.getPropertyByKey(key);
if (!jbakeKeys.contains(property)) {
jbakeKeys.add(property);
}
}
}
}
Collections.sort(jbakeKeys);
return jbakeKeys;
}
use of org.apache.commons.configuration2.SystemConfiguration in project commons-configuration by apache.
the class TestSystemConfiguration method testSetSystemPropertiesFromPropertiesFile.
/**
* Tests whether system properties can be set from a configuration file.
*/
@Test
public void testSetSystemPropertiesFromPropertiesFile() throws ConfigurationException, IOException {
final File file = folder.newFile("sys.properties");
final PropertiesConfiguration pconfig = new PropertiesConfiguration();
final FileHandler handler = new FileHandler(pconfig);
pconfig.addProperty("fromFile", Boolean.TRUE);
handler.setFile(file);
handler.save();
SystemConfiguration.setSystemProperties(handler.getBasePath(), handler.getFileName());
final SystemConfiguration sconf = new SystemConfiguration();
assertTrue("Property from file not found", sconf.getBoolean("fromFile"));
}
Aggregations