Search in sources :

Example 91 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project CloudStack-archive by CloudStack-extras.

the class EncryptionSecretKeyChanger method migrateProperties.

private boolean migrateProperties(File dbPropsFile, Properties dbProps, String newMSKey, String newDBKey) {
    System.out.println("Migrating db.properties..");
    StandardPBEStringEncryptor msEncryptor = new StandardPBEStringEncryptor();
    ;
    initEncryptor(msEncryptor, newMSKey);
    try {
        PropertiesConfiguration newDBProps = new PropertiesConfiguration(dbPropsFile);
        if (newDBKey != null && !newDBKey.isEmpty()) {
            newDBProps.setProperty("db.cloud.encrypt.secret", "ENC(" + msEncryptor.encrypt(newDBKey) + ")");
        }
        String prop = dbProps.getProperty("db.cloud.password");
        if (prop != null && !prop.isEmpty()) {
            newDBProps.setProperty("db.cloud.password", "ENC(" + msEncryptor.encrypt(prop) + ")");
        }
        prop = dbProps.getProperty("db.usage.password");
        if (prop != null && !prop.isEmpty()) {
            newDBProps.setProperty("db.usage.password", "ENC(" + msEncryptor.encrypt(prop) + ")");
        }
        newDBProps.save(dbPropsFile.getAbsolutePath());
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    System.out.println("Migrating db.properties Done.");
    return true;
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException)

Example 92 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project jangaroo-tools by CoreMedia.

the class PropertyClassGeneratorTest method testSimplePropertySet.

@Test
public void testSimplePropertySet() throws Exception {
    FileLocations locations = new FileLocations();
    List<File> sourcePath = new ArrayList<File>();
    sourcePath.add(new File(getClass().getResource("/").toURI()));
    locations.setSourcePath(sourcePath);
    locations.addSourceFile("testPackage/subPackage/Properties.properties");
    locations.addSourceFile("testPackage/PropertiesTest.properties");
    locations.addSourceFile("testPackage/PropertiesTest_de.properties");
    locations.addSourceFile("testPackage/PropertiesTest_es_ES.properties");
    locations.addSourceFile("testPackage/PropertiesTest_it_VA_WIN.properties");
    PropertyClassGenerator generator = new PropertyClassGenerator(locations);
    StringWriter writer = new StringWriter();
    ResourceBundleClass rbc = new ResourceBundleClass("testPackage.PropertiesTest");
    PropertiesConfiguration p = new PropertiesConfiguration();
    p.setProperty("key", "Die Platte \"{1}\" enthält {0}.");
    p.setProperty("key2", "Die Platte \"{1}\" enthält {0}.");
    PropertiesClass pc = new PropertiesClass(rbc, null, p, null);
    generator.generatePropertiesClass(pc, writer);
    assertEquals(("package testPackage {\n" + "import joo.ResourceBundleAwareClassLoader;\n" + "import joo.JavaScriptObject;\n" + "\n" + "/**\n" + " * Properties class for ResourceBundle \"PropertiesTest\".\n" + " * @see PropertiesTest_properties#INSTANCE\n" + " */\n" + "[ResourceBundle('PropertiesTest')]\n" + "public class PropertiesTest_properties extends joo.JavaScriptObject {\n" + "\n" + "/**\n" + " * Singleton for the current user Locale's instance of ResourceBundle \"PropertiesTest\".\n" + " * @see PropertiesTest_properties\n" + " */\n" + "public static const INSTANCE:PropertiesTest_properties = ResourceBundleAwareClassLoader.INSTANCE.createSingleton(PropertiesTest_properties) as PropertiesTest_properties;\n" + "\n" + "[Resource(key='key',bundle='PropertiesTest')]\n" + "public native function get key():String;\n" + "[Resource(key='key2',bundle='PropertiesTest')]\n" + "public native function get key2():String;\n" + "\n" + "public function PropertiesTest_properties() {\n" + "  this[\"key\"] = \"Die Platte \\\"{1}\\\" enthält {0}.\";\n" + "  this[\"key2\"] = \"Die Platte \\\"{1}\\\" enthält {0}.\";\n" + "}\n" + "}\n" + "}").replaceAll("\n", LINE_SEPARATOR), writer.toString());
    PropertiesClass psc = new PropertiesClass(rbc, Locale.ENGLISH, p, null);
    writer = new StringWriter();
    generator.generatePropertiesClass(psc, writer);
    assertEquals(("package testPackage {\n" + "\n" + "/**\n" + " * Properties class for ResourceBundle \"PropertiesTest\" and Locale \"en\".\n" + " * @see PropertiesTest_properties#INSTANCE\n" + " */\n" + "[ResourceBundle('PropertiesTest_en')]\n" + "public class PropertiesTest_properties_en extends PropertiesTest_properties {\n" + "\n" + "\n" + "public function PropertiesTest_properties_en() {\n" + "  this[\"key\"] = \"Die Platte \\\"{1}\\\" enthält {0}.\";\n" + "  this[\"key2\"] = \"Die Platte \\\"{1}\\\" enthält {0}.\";\n" + "}\n" + "}\n" + "}").replaceAll("\n", LINE_SEPARATOR), writer.toString());
}
Also used : StringWriter(java.io.StringWriter) ResourceBundleClass(net.jangaroo.properties.model.ResourceBundleClass) ArrayList(java.util.ArrayList) PropertyClassGenerator(net.jangaroo.properties.PropertyClassGenerator) PropertiesClass(net.jangaroo.properties.model.PropertiesClass) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) FileLocations(net.jangaroo.utils.FileLocations) Test(org.junit.Test)

Example 93 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project archaius by Netflix.

the class WebApplicationProperties method initApplicationProperties.

protected static void initApplicationProperties() throws ConfigurationException, MalformedURLException {
    File appPropFile = new File(appConfFolder + "/" + baseConfigFileName + ".properties");
    File appEnvPropOverrideFile = new File(appConfFolder + "/" + baseConfigFileName + getEnvironment() + ".properties");
    // TODO awang, how do we add this to archaius default config?
    PropertiesConfiguration appConf = new PropertiesConfiguration(appPropFile);
    // apply env overrides
    PropertiesConfiguration overrideConf = new PropertiesConfiguration(appEnvPropOverrideFile);
    Properties overrideprops = ConfigurationUtils.getProperties(overrideConf);
    for (Object prop : overrideprops.keySet()) {
        appConf.setProperty("" + prop, overrideprops.getProperty("" + prop));
    }
    String path = appPropFile.toURI().toURL().toString();
    System.setProperty(URLConfigurationSource.CONFIG_URL, path);
    ConfigurationManager.loadPropertiesFromConfiguration(appConf);
}
Also used : Properties(java.util.Properties) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 94 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project archaius by Netflix.

the class OverridingPropertiesConfiguration method loadFromPropertiesFile.

static void loadFromPropertiesFile(AbstractConfiguration config, String baseUrl, Set<String> loaded, String... nextLoadKeys) {
    String nextLoad = getNextLoad(config, nextLoadKeys);
    if (nextLoad == null) {
        return;
    }
    String[] filesToLoad = nextLoad.split(",");
    for (String fileName : filesToLoad) {
        fileName = fileName.trim();
        try {
            URL url = new URL(baseUrl + "/" + fileName);
            // avoid circle
            if (loaded.contains(url.toExternalForm())) {
                logger.warn(url + " is already loaded");
                continue;
            }
            loaded.add(url.toExternalForm());
            PropertiesConfiguration nextConfig = new OverridingPropertiesConfiguration(url);
            copyProperties(nextConfig, config);
            logger.info("Loaded properties file " + url);
            loadFromPropertiesFile(config, baseUrl, loaded, nextLoadKeys);
        } catch (Throwable e) {
            logger.warn("Unable to load properties file", e);
        }
    }
}
Also used : PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) URL(java.net.URL)

Example 95 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project sakuli by ConSol.

the class SakuliPropertyPlaceholderConfigurer method restoreProperties.

@PreDestroy
public void restoreProperties() {
    try {
        for (Map.Entry<String, Map<String, Object>> entry : modifiedSahiConfigProps.entrySet()) {
            String propFile = entry.getKey();
            logger.debug("restore properties file '{}' with properties '{}'", propFile, entry.getValue());
            PropertiesConfiguration propConfig = new PropertiesConfiguration(propFile);
            propConfig.setAutoSave(true);
            for (Map.Entry<String, Object> propEntry : entry.getValue().entrySet()) {
                String propKey = propEntry.getKey();
                if (propConfig.containsKey(propKey)) {
                    propConfig.clearProperty(propKey);
                }
                propConfig.addProperty(propKey, propEntry.getValue());
            }
        }
    } catch (ConfigurationException e) {
        logger.error("Error in restore sahi config properties", e);
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) PreDestroy(javax.annotation.PreDestroy)

Aggregations

PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)118 File (java.io.File)38 Configuration (org.apache.commons.configuration.Configuration)33 ConfigurationException (org.apache.commons.configuration.ConfigurationException)33 IOException (java.io.IOException)12 Test (org.testng.annotations.Test)11 BeforeClass (org.testng.annotations.BeforeClass)10 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)9 IndexLoadingConfigMetadata (com.linkedin.pinot.common.metadata.segment.IndexLoadingConfigMetadata)8 FileBasedInstanceDataManager (com.linkedin.pinot.core.data.manager.offline.FileBasedInstanceDataManager)8 FileInputStream (java.io.FileInputStream)7 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)7 URL (java.net.URL)6 ServerQueryExecutorV1Impl (com.linkedin.pinot.core.query.executor.ServerQueryExecutorV1Impl)5 ServerConf (com.linkedin.pinot.server.conf.ServerConf)5 FileNotFoundException (java.io.FileNotFoundException)5 Path (java.nio.file.Path)5 HashMap (java.util.HashMap)5 Properties (java.util.Properties)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4