Search in sources :

Example 21 with PropertiesConfiguration

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

the class AllTests method setupRepositories.

private void setupRepositories(XWikiExecutor executor) throws Exception {
    LOGGER.info("Adding repository to xwiki.properties");
    if (executor.getExecutionDirectory() != null) {
        PropertiesConfiguration properties = executor.loadXWikiPropertiesConfiguration();
        // Put self and Maven as extensions repository
        properties.setProperty("extension.repositories", "maven-test:maven:" + repositoryUtil.getMavenRepository().toURI());
        executor.saveXWikiProperties();
    }
}
Also used : PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 22 with PropertiesConfiguration

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

the class AllTests method preStart.

@XWikiExecutorSuite.PreStart
public void preStart(List<XWikiExecutor> executors) throws Exception {
    XWikiExecutor executor = executors.get(0);
    repositoryUtil = new RepositoryUtils();
    LOGGER.info("Adding maven repository to xwiki.properties");
    PropertiesConfiguration properties = executor.loadXWikiPropertiesConfiguration();
    // Put self as extensions repository
    properties.setProperty("extension.repositories", "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)

Example 23 with PropertiesConfiguration

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

the class SingleXWikiExecutor method start.

/**
 * {@inheritDoc}
 *
 * Starts the server on the first call, subsequent calls only increase the internal counter by one.
 */
@Override
public synchronized void start() throws Exception {
    if (counter == 0) {
        if (!VERIFY_RUNNING_XWIKI_AT_START.equals("true") || isXWikiStarted(getURL(), 15).timedOut) {
            // Disable extensions manager external repositories
            PropertiesConfiguration properties = loadXWikiPropertiesConfiguration();
            if (!properties.containsKey("extension.repositories")) {
                properties.setProperty("extension.repositories", "");
            }
            saveXWikiProperties();
        }
        super.start();
    }
    counter++;
}
Also used : PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 24 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project winery by eclipse.

the class AbstractFileBasedRepository method getConfiguration.

@Override
public Configuration getConfiguration(RepositoryFileReference ref) {
    Path path = this.ref2AbsolutePath(ref);
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    if (Files.exists(path)) {
        try (Reader r = Files.newBufferedReader(path, Charset.defaultCharset())) {
            configuration.read(r);
        } catch (ConfigurationException | IOException e) {
            LOGGER.error("Could not read config file", e);
            throw new IllegalStateException("Could not read config file", e);
        }
    }
    configuration.addEventListener(ConfigurationEvent.ANY, new AutoSaveListener(path, configuration));
    return configuration;
}
Also used : Path(java.nio.file.Path) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) Reader(java.io.Reader) IOException(java.io.IOException) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 25 with PropertiesConfiguration

use of org.apache.commons.configuration2.PropertiesConfiguration in project janusgraph by JanusGraph.

the class ConfigurationLint method validate.

public static Status validate(String filename) throws IOException {
    try (final FileInputStream fis = new FileInputStream(filename)) {
        new Properties().load(fis);
    }
    final PropertiesConfiguration apc;
    try {
        apc = ConfigurationUtil.loadPropertiesConfig(filename);
    } catch (ConfigurationException e) {
        throw new IOException(e);
    }
    // new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,
    // , BasicConfiguration.Restriction.NONE);
    Iterator<String> iterator = apc.getKeys();
    int totalKeys = 0;
    int keysVerified = 0;
    while (iterator.hasNext()) {
        totalKeys++;
        String key = iterator.next();
        String value = apc.getString(key);
        try {
            ConfigElement.PathIdentifier pid = ConfigElement.parse(GraphDatabaseConfiguration.ROOT_NS, key);
            // ConfigElement shouldn't return null; failure here probably relates to janusgraph-core, not the file
            Preconditions.checkNotNull(pid);
            Preconditions.checkNotNull(pid.element);
            if (!pid.element.isOption()) {
                log.warn("Config key {} is a namespace (only options can be keys)", key);
                continue;
            }
            final ConfigOption<?> opt;
            try {
                opt = (ConfigOption<?>) pid.element;
            } catch (RuntimeException re) {
                // This shouldn't happen given the preceding check, but catch it anyway
                log.warn("Config key {} maps to the element {}, but it could not be cast to an option", key, pid.element, re);
                continue;
            }
            try {
                Object o = new CommonsConfiguration(apc).get(key, opt.getDatatype());
                opt.verify(o);
                keysVerified++;
            } catch (RuntimeException re) {
                log.warn("Config key {} is recognized, but its value {} could not be validated", key, value);
                log.debug("Validation exception on {}={} follows", key, value, re);
            }
        } catch (RuntimeException re) {
            log.warn("Unknown config key {}", key);
        }
    }
    return new Status(totalKeys, totalKeys - keysVerified);
}
Also used : ConfigElement(org.janusgraph.diskstorage.configuration.ConfigElement) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) IOException(java.io.IOException) Properties(java.util.Properties) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) FileInputStream(java.io.FileInputStream) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException)

Aggregations

PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)28 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)10 File (java.io.File)7 IOException (java.io.IOException)6 Path (java.nio.file.Path)6 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)5 Configuration (org.apache.commons.configuration2.Configuration)4 Configurations (org.apache.commons.configuration2.builder.fluent.Configurations)4 FileReader (java.io.FileReader)3 FileBasedConfigurationBuilder (org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 StringWriter (java.io.StringWriter)2 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