Search in sources :

Example 1 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project hadoop by apache.

the class MetricsSystemImpl method currentConfig.

@Override
public synchronized String currentConfig() {
    PropertiesConfiguration saver = new PropertiesConfiguration();
    StringWriter writer = new StringWriter();
    saver.copy(config);
    try {
        saver.write(writer);
    } catch (Exception e) {
        throw new MetricsConfigException("Error stringify config", e);
    }
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) MetricsException(org.apache.hadoop.metrics2.MetricsException)

Example 2 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project hadoop by apache.

the class ConfigUtil method dump.

static void dump(String header, Configuration c, PrintWriter out) {
    PropertiesConfiguration p = new PropertiesConfiguration();
    p.copy(c);
    if (header != null) {
        out.println(header);
    }
    try {
        p.write(out);
    } catch (Exception e) {
        throw new RuntimeException("Error saving config", e);
    }
}
Also used : PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 3 with PropertiesConfiguration

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);
    }
}
Also used : Path(java.nio.file.Path) Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 4 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project xwiki-platform by xwiki.

the class AllTests method setupChannel.

private void setupChannel(XWikiExecutor executor, String channelName) throws Exception {
    if (executor.getExecutionDirectory() != null) {
        PropertiesConfiguration properties = executor.loadXWikiPropertiesConfiguration();
        properties.setProperty("observation.remote.enabled", "true");
        properties.setProperty("observation.remote.channels", channelName);
        executor.saveXWikiProperties();
        setupExecutor(executor);
    }
}
Also used : PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 5 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project xwiki-platform by xwiki.

the class AllITs method preStart.

@XWikiExecutorSuite.PreStart
public void preStart(List<XWikiExecutor> executors) throws Exception {
    XWikiExecutor executor = executors.get(0);
    repositoryUtil = new RepositoryUtils();
    LOGGER.info("Adding repository to xwiki.properties");
    PropertiesConfiguration properties = executor.loadXWikiPropertiesConfiguration();
    // Put self and Maven as extensions repository
    properties.setProperty("extension.repositories", Arrays.asList("self:xwiki:http://localhost:8080/xwiki/rest", "maven-test:maven:" + repositoryUtil.getMavenRepository().toURI()));
    // Disable core extension resolve because Jetty is not ready when it starts
    properties.setProperty("extension.core.resolve", false);
    executor.saveXWikiProperties();
}
Also used : RepositoryUtils(org.xwiki.extension.test.RepositoryUtils) XWikiExecutor(org.xwiki.test.integration.XWikiExecutor) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Aggregations

PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)24 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)8 Path (java.nio.file.Path)6 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)5 File (java.io.File)4 IOException (java.io.IOException)4 Configurations (org.apache.commons.configuration2.builder.fluent.Configurations)4 Configuration (org.apache.commons.configuration2.Configuration)3 FileBasedConfigurationBuilder (org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 BaseConfiguration (org.apache.commons.configuration2.BaseConfiguration)2 PropertiesBuilderParameters (org.apache.commons.configuration2.builder.fluent.PropertiesBuilderParameters)2 DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)2 Preconditions (com.google.common.base.Preconditions)1 BufferedReader (java.io.BufferedReader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1 StringWriter (java.io.StringWriter)1