use of org.apache.commons.configuration2.builder.fluent.Parameters in project xwiki-platform by xwiki.
the class XWikiPropertiesConfigurationSource method loadConfiguration.
private Configuration loadConfiguration() {
// Looking for /etc/xwiki/xwiki.properties first
File file = new File("/etc/xwiki/" + XWIKI_PROPERTIES_FILE);
if (file.exists()) {
try {
return new Configurations().properties(file);
} catch (Exception e) {
// Note: if we cannot read the configuration file for any reason we log a warning but continue since
// XWiki will use default values for all configurable elements.
this.logger.warn("Failed to load configuration file [{}]", file, e.getMessage());
}
}
// Register the Commons Properties Configuration, looking for a xwiki.properties file
// in the XWiki path somewhere.
URL xwikiPropertiesUrl = null;
try {
xwikiPropertiesUrl = this.environment.getResource(XWIKI_PROPERTIES_WARPATH);
if (xwikiPropertiesUrl != null) {
FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class).configure(new Parameters().properties().setListDelimiterHandler(new DefaultListDelimiterHandler(',')).setURL(xwikiPropertiesUrl));
return builder.getConfiguration();
} else {
// We use a debug logging level here since we consider it's ok that there's no XWIKI_PROPERTIES_FILE
// available, in which case default values are used.
this.logger.debug("No configuration file [{}] found. Using default configuration values.", XWIKI_PROPERTIES_WARPATH);
}
} catch (Exception e) {
// Note: if we cannot read the configuration file for any reason we log a warning but continue since XWiki
// will use default values for all configurable elements.
this.logger.warn("Failed to load configuration file [{}]. Using default configuration values. " + "Internal error [{}]", XWIKI_PROPERTIES_WARPATH, e.getMessage());
}
// implementation.
return new BaseConfiguration();
}
use of org.apache.commons.configuration2.builder.fluent.Parameters in project scheduling by ow2-proactive.
the class NodeCommandLineProperties method loadConfig.
/**
* loads NodeSource configuration.
*
* @return NodeSource configuration
*/
public static Configuration loadConfig() throws ConfigurationException {
Configuration config;
File propertiesFile = new File(NodeCommandLineProperties.class.getClassLoader().getResource(PROPERTIES_FILE).getFile());
PropertiesBuilderParameters propertyParameters = new Parameters().properties();
propertyParameters.setFile(propertiesFile);
propertyParameters.setThrowExceptionOnMissing(true);
propertyParameters.setListDelimiterHandler(DELIMITER);
FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class);
builder.configure(propertyParameters);
config = builder.getConfiguration();
LOGGER.debug("NodeSources configuration loaded");
return config;
}
use of org.apache.commons.configuration2.builder.fluent.Parameters in project data-prep by Talend.
the class PropertiesEncryption method modifyAndSave.
/**
* Applies the specified function to the specified set of parameters contained in the input file.
*
* @param input The specified name of file to encrypt
* @param mustBeModified the specified set of parameters
* @param function the specified function to apply to the set of specified parameters
*/
private void modifyAndSave(String input, Set<String> mustBeModified, Function<String, String> function) {
Path inputFilePath = Paths.get(input);
if (Files.exists(inputFilePath) && Files.isRegularFile(inputFilePath) && Files.isReadable(inputFilePath)) {
try {
Parameters params = new Parameters();
//
FileBasedConfigurationBuilder<PropertiesConfiguration> builder = //
new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class).configure(params.fileBased().setFile(//
inputFilePath.toFile()));
PropertiesConfiguration config = builder.getConfiguration();
mustBeModified.stream().filter(config::containsKey).forEach(key -> config.setProperty(key, function.apply(config.getString(key))));
builder.save();
} catch (ConfigurationException e) {
LOGGER.error("unable to read {} {}", input, e);
}
} else {
LOGGER.debug("No readable file at {}", input);
}
}
use of org.apache.commons.configuration2.builder.fluent.Parameters in project ranger by apache.
the class LdapConfig method updateInputPropFile.
public void updateInputPropFile(String ldapUrl, String bindDn, String bindPassword, String userSearchBase, String userSearchFilter, String authUser, String authPass) {
try {
Parameters params = new Parameters();
FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class).configure(params.fileBased().setFileName(CONFIG_FILE));
FileBasedConfiguration config = builder.getConfiguration();
// Update properties in memory and update the file as well
prop.setProperty(LGSYNC_LDAP_URL, ldapUrl);
prop.setProperty(LGSYNC_LDAP_BIND_DN, bindDn);
prop.setProperty(LGSYNC_LDAP_BIND_PASSWORD, bindPassword);
prop.setProperty(LGSYNC_USER_SEARCH_BASE, userSearchBase);
prop.setProperty(LGSYNC_USER_SEARCH_FILTER, userSearchFilter);
prop.setProperty(AUTH_USERNAME, authUser);
prop.setProperty(AUTH_PASSWORD, authPass);
config.setProperty(LGSYNC_LDAP_URL, ldapUrl);
config.setProperty(LGSYNC_LDAP_BIND_DN, bindDn);
// config.setProperty(LGSYNC_LDAP_BIND_PASSWORD, bindPassword);
config.setProperty(LGSYNC_USER_SEARCH_BASE, userSearchBase);
config.setProperty(LGSYNC_USER_SEARCH_FILTER, userSearchFilter);
config.setProperty(AUTH_USERNAME, authUser);
// config.setProperty(AUTH_PASSWORD, authPass);
builder.save();
} catch (ConfigurationException e) {
System.out.println("Failed to update " + CONFIG_FILE + ": " + e);
}
}
use of org.apache.commons.configuration2.builder.fluent.Parameters in project vcell by virtualcell.
the class VCellConfiguration method getConfiguration.
private static synchronized Configuration getConfiguration() throws ConfigurationException {
if (configurationBuilder == null) {
Parameters params = new Parameters();
File propertiesFile = new File(ResourceUtil.getVcellHome(), "vcellconfig.properties");
if (!propertiesFile.exists()) {
try {
propertiesFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileBasedBuilderParameters thing = params.fileBased().setFile(propertiesFile);
configurationBuilder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class).configure(thing);
configurationBuilder.setAutoSave(true);
try {
propertiesConfiguration = configurationBuilder.getConfiguration();
propertiesConfiguration.setSynchronizer(new ReadWriteSynchronizer());
} catch (org.apache.commons.configuration2.ex.ConfigurationException e) {
e.printStackTrace();
throw new ConfigurationException("failed to create configuration from file " + propertiesFile + ": " + e.getMessage());
}
}
return propertiesConfiguration;
}
Aggregations