use of org.apache.commons.configuration2.PropertiesConfiguration 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.PropertiesConfiguration 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.PropertiesConfiguration in project accumulo by apache.
the class ClientConfiguration method loadFromSearchPath.
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "process runs in same security context as user who provided path")
private static ClientConfiguration loadFromSearchPath(List<String> paths) {
List<Configuration> configs = new LinkedList<>();
for (String path : paths) {
File conf = new File(path);
if (conf.isFile() && conf.canRead()) {
var config = new PropertiesConfiguration();
try (var reader = new FileReader(conf, UTF_8)) {
config.read(reader);
} catch (ConfigurationException | IOException e) {
throw new IllegalStateException("Error loading client configuration file " + conf, e);
}
configs.add(config);
log.info("Loaded client configuration file {}", conf);
}
}
// We couldn't find the client configuration anywhere
if (configs.isEmpty()) {
log.debug("Found no client.conf in default paths. Using default client configuration values.");
}
return new ClientConfiguration(configs);
}
use of org.apache.commons.configuration2.PropertiesConfiguration in project hadoop by apache.
the class MetricsConfig method toString.
static String toString(Configuration c) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try {
PrintWriter pw = new PrintWriter(buffer, false);
PropertiesConfiguration tmp = new PropertiesConfiguration();
tmp.copy(c);
tmp.write(pw);
return buffer.toString("UTF-8");
} catch (Exception e) {
throw new MetricsConfigException(e);
}
}
use of org.apache.commons.configuration2.PropertiesConfiguration in project hadoop by apache.
the class MetricsConfig method loadFirst.
/**
* Load configuration from a list of files until the first successful load
* @param conf the configuration object
* @param files the list of filenames to try
* @return the configuration object
*/
static MetricsConfig loadFirst(String prefix, String... fileNames) {
for (String fname : fileNames) {
try {
Configuration cf = new Configurations().propertiesBuilder(fname).configure(new Parameters().properties().setFileName(fname).setListDelimiterHandler(new DefaultListDelimiterHandler(','))).getConfiguration().interpolatedConfiguration();
LOG.info("loaded properties from " + fname);
LOG.debug(toString(cf));
MetricsConfig mc = new MetricsConfig(cf, prefix);
LOG.debug(mc);
return mc;
} catch (ConfigurationException e) {
// Commons Configuration defines the message text when file not found
if (e.getMessage().startsWith("Could not locate")) {
continue;
}
throw new MetricsConfigException(e);
}
}
LOG.warn("Cannot locate configuration: tried " + Joiner.on(",").join(fileNames));
// default to an empty configuration
return new MetricsConfig(new PropertiesConfiguration(), prefix);
}
Aggregations