Example usage for org.apache.commons.configuration BaseConfiguration addProperty

List of usage examples for org.apache.commons.configuration BaseConfiguration addProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration BaseConfiguration addProperty.

Prototype

public void addProperty(String key, Object value) 

Source Link

Usage

From source file:com.evolveum.midpoint.model.common.expression.ExpressionTestUtil.java

private static Configuration createConfiguration() {
    BaseConfiguration config = new BaseConfiguration();
    config.addProperty("foo", "foobar");
    return config;
}

From source file:com.runwaysdk.configuration.CommonsConfigurationTest.java

@Test
public void testCommonsConfigOverride() {
    BaseConfiguration bc = new BaseConfiguration();
    BaseConfiguration bc2 = new BaseConfiguration();

    bc2.addProperty("test.prop", 52);

    CompositeConfiguration cconfig = new CompositeConfiguration();
    cconfig.addConfiguration(bc);// w  ww .  j av  a 2 s . c om
    cconfig.addConfiguration(bc2);

    bc.addProperty("test.prop", 112);

    Assert.assertEquals(112, cconfig.getInt("test.prop"));
}

From source file:com.runwaysdk.configuration.CommonsConfigurationTest.java

@Test
public void testCommonsConfigOverrideSetVsAdd() {
    BaseConfiguration bc = new BaseConfiguration();
    BaseConfiguration bc2 = new BaseConfiguration();

    bc2.addProperty("test.prop", 52);

    CompositeConfiguration cconfig = new CompositeConfiguration();
    cconfig.addConfiguration(bc);//from  ww w  .  java2  s  . c o m
    cconfig.addConfiguration(bc2);

    bc.setProperty("test.prop", 112);

    Assert.assertEquals(112, cconfig.getInt("test.prop"));
}

From source file:net.riccardocossu.autodoc.maven.AutodocMojo.java

@SuppressWarnings("unchecked")
public void execute() throws MojoExecutionException {
    try {//from  w  ww  .  ja  v  a 2  s.  c  o  m
        Set<URL> urls = new HashSet<URL>();
        List<String> elements = project.getCompileClasspathElements();
        for (String element : elements) {
            urls.add(new File(element).toURI().toURL());
        }

        ClassLoader contextClassLoader = URLClassLoader.newInstance(urls.toArray(new URL[0]),
                Thread.currentThread().getContextClassLoader());

        Thread.currentThread().setContextClassLoader(contextClassLoader);

    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("Error expanding classloader", e);
    } catch (MalformedURLException e) {
        throw new MojoExecutionException("Error expanding classloader", e);
    }
    File f = new File(outputDirectory.getAbsolutePath() + "/autodoc");

    if (!f.exists()) {
        f.mkdirs();
    }

    BaseConfiguration conf = new BaseConfiguration();
    conf.addProperty(Engine.CONFIG_PACKAGES, packages);
    conf.addProperty(Engine.CONFIG_INPUT_PLUGINS, inputPlugins);
    conf.addProperty(Engine.CONFIG_OUTPUT_PLUGINS, outputPlugins);
    conf.addProperty(Engine.CONFIG_BASE_OUTPUT_DIR, f.getAbsolutePath());
    Engine eng = new Engine(conf);
    List<PackageContainer> parsedPackages = eng.execute();
    getLog().info(String.format("Parsed %d packages", parsedPackages.size()));
}

From source file:net.riccardocossu.i18split.maven.I18splitMojo.java

public void execute() throws MojoExecutionException {
    File f = new File(outputBasePath);

    if (!f.exists()) {
        f.mkdirs();/*from   ww w . j  av  a  2 s  .  co  m*/
    }

    BaseConfiguration conf = new BaseConfiguration();
    conf.addProperty(ConfigKeys.INPUT_DRIVER, inputPlugin);
    conf.addProperty(ConfigKeys.OUTPUT_DRIVER, outputPlugin);
    conf.addProperty(ConfigKeys.OUTPUT_BASE_PATH, outputBasePath);
    conf.addProperty(ConfigKeys.INPUT_BASE_PATH, inputBasePath);
    conf.addProperty(ConfigKeys.INPUT_ENCODING, inputEncoding);
    conf.addProperty(ConfigKeys.OUTPUT_ENCODING, outputEncoding);
    if (pluginsConfig != null) {
        @SuppressWarnings("unchecked")
        MapConfiguration mc = new MapConfiguration(pluginsConfig);
        conf.append(mc);
    }
    org.apache.maven.plugin.logging.Log log = getLog();
    Iterator<String> keys = conf.getKeys();
    while (keys.hasNext()) {
        String k = keys.next();
        log.info(String.format("%s = %s", k, conf.getProperty(k)));
    }
    Engine eng = new Engine(conf);
    eng.process();

}

From source file:com.netflix.config.PollingSourceTest.java

@Test
public void testNoneDeletingPollingSource() throws Exception {
    BaseConfiguration config = new BaseConfiguration();
    config.addProperty("prop1", "original");
    DummyPollingSource source = new DummyPollingSource(false);
    source.setFull("");
    FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 10, true);
    ConfigurationWithPollingSource pollingConfig = new ConfigurationWithPollingSource(config, source,
            scheduler);//w ww.  j  av a2s  . co  m
    Thread.sleep(200);
    assertEquals("original", pollingConfig.getProperty("prop1"));
    source.setFull("prop1=changed");
    Thread.sleep(200);
    assertEquals("changed", pollingConfig.getProperty("prop1"));
    source.setFull("prop1=changedagain,prop2=new");
    Thread.sleep(200);
    assertEquals("changedagain", pollingConfig.getProperty("prop1"));
    assertEquals("new", pollingConfig.getProperty("prop2"));
    source.setFull("prop3=new");
    Thread.sleep(200);
    assertEquals("changedagain", pollingConfig.getProperty("prop1"));
    assertEquals("new", pollingConfig.getProperty("prop2"));
    assertEquals("new", pollingConfig.getProperty("prop3"));
}

From source file:com.netflix.config.PollingSourceTest.java

@Test
public void testDeletingPollingSource() throws Exception {
    BaseConfiguration config = new BaseConfiguration();
    config.addProperty("prop1", "original");
    DummyPollingSource source = new DummyPollingSource(false);
    source.setFull("prop1=changed");
    FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 10, false);
    ConfigurationWithPollingSource pollingConfig = new ConfigurationWithPollingSource(config, source,
            scheduler);/*from   ww w . ja va 2  s. c  om*/
    Thread.sleep(200);
    assertEquals("changed", pollingConfig.getProperty("prop1"));

    source.setFull("");
    Thread.sleep(200);
    assertFalse(pollingConfig.containsKey("prop1"));
    source.setFull("prop1=changedagain,prop2=new");
    Thread.sleep(200);
    assertEquals("changedagain", pollingConfig.getProperty("prop1"));
    assertEquals("new", pollingConfig.getProperty("prop2"));
    source.setFull("prop3=new");
    Thread.sleep(200);
    assertFalse(pollingConfig.containsKey("prop1"));
    assertFalse(pollingConfig.containsKey("prop2"));
    assertEquals("new", pollingConfig.getProperty("prop3"));
}

From source file:cz.cas.lib.proarc.common.process.GenericExternalProcessTest.java

@Test
public void testAddInputFile() throws Exception {
    final String inputName = "input.txt";
    final File input = temp.newFile(inputName);
    final BaseConfiguration conf = new BaseConfiguration();
    conf.addProperty(ExternalProcess.PROP_EXEC, "test.sh");
    conf.addProperty(ExternalProcess.PROP_ARG, "-i ${input.file.name}");
    conf.addProperty(ExternalProcess.PROP_ARG, "-path ${input.file}[0]");
    conf.addProperty(ExternalProcess.PROP_ARG, "-o ${input.folder}");
    GenericExternalProcess gp = new GenericExternalProcess(conf).addInputFile(input);
    assertEquals(gp.getParameters().getMap().get(GenericExternalProcess.SRC_NAME_EXT), input.getName());
    assertEquals(gp.getParameters().getMap().get(GenericExternalProcess.SRC_PATH), input.getAbsolutePath());
    assertEquals(gp.getParameters().getMap().get(GenericExternalProcess.SRC_PARENT),
            input.getParentFile().getAbsolutePath());
    List<String> cmdLines = gp.buildCmdLine(conf);
    //        System.out.println(cmdLines.toString());
}

From source file:net.i2cat.netconf.SessionContext.java

private Configuration createDefaultConfiguration() {

    BaseConfiguration baseConfiguration = new BaseConfiguration();
    baseConfiguration.addProperty(LOG_STREAM, "false");
    baseConfiguration.addProperty(LOG_FILE, "server.xml.log");

    /* FIXME WHAT IT IS THE BETTER METHOD PASS STRING OR BOOL */
    baseConfiguration.addProperty(KEEPALIVE, true);

    return baseConfiguration;

}

From source file:com.netflix.config.PollingSourceTest.java

@Test
public void testIncrementalPollingSource() throws Exception {
    BaseConfiguration config = new BaseConfiguration();
    DynamicPropertyFactory.initWithConfigurationSource(config);
    DynamicStringProperty prop1 = new DynamicStringProperty("prop1", null);
    DynamicStringProperty prop2 = new DynamicStringProperty("prop2", null);
    config.addProperty("prop1", "original");
    DummyPollingSource source = new DummyPollingSource(true);
    FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 10, true);
    scheduler.setIgnoreDeletesFromSource(false);
    // ConfigurationWithPollingSource pollingConfig = new ConfigurationWithPollingSource(config, source,scheduler);
    scheduler.startPolling(source, config);
    assertEquals("original", config.getProperty("prop1"));
    assertEquals("original", prop1.get());
    source.setAdded("prop2=new");
    Thread.sleep(200);//  w ww . j  av a 2 s  .c  o  m
    assertEquals("original", config.getProperty("prop1"));
    assertEquals("new", config.getProperty("prop2"));
    assertEquals("new", prop2.get());
    source.setDeleted("prop1=DoesNotMatter");
    source.setChanged("prop2=changed");
    source.setAdded("");
    Thread.sleep(200);
    assertFalse(config.containsKey("prop1"));
    assertNull(prop1.get());
    assertEquals("changed", config.getProperty("prop2"));
    assertEquals("changed", prop2.get());
}