Search in sources :

Example 1 with SystemConfiguration

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;
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) CompositeConfiguration(org.apache.commons.configuration2.CompositeConfiguration) JBakeException(org.jbake.app.JBakeException) SystemConfiguration(org.apache.commons.configuration2.SystemConfiguration) File(java.io.File) URL(java.net.URL)

Example 2 with SystemConfiguration

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;
}
Also used : MapConfiguration(org.apache.commons.configuration2.MapConfiguration) SystemConfiguration(org.apache.commons.configuration2.SystemConfiguration) CompositeConfiguration(org.apache.commons.configuration2.CompositeConfiguration) Configuration(org.apache.commons.configuration2.Configuration) SystemConfiguration(org.apache.commons.configuration2.SystemConfiguration)

Example 3 with SystemConfiguration

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"));
}
Also used : File(java.io.File) FileHandler(org.apache.commons.configuration2.io.FileHandler) Test(org.junit.Test)

Aggregations

File (java.io.File)2 CompositeConfiguration (org.apache.commons.configuration2.CompositeConfiguration)2 SystemConfiguration (org.apache.commons.configuration2.SystemConfiguration)2 URL (java.net.URL)1 Configuration (org.apache.commons.configuration2.Configuration)1 MapConfiguration (org.apache.commons.configuration2.MapConfiguration)1 DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)1 FileHandler (org.apache.commons.configuration2.io.FileHandler)1 JBakeException (org.jbake.app.JBakeException)1 Test (org.junit.Test)1