Example usage for org.apache.commons.configuration Configuration setProperty

List of usage examples for org.apache.commons.configuration Configuration setProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration setProperty.

Prototype

void setProperty(String key, Object value);

Source Link

Document

Set a property, this will replace any previously set values.

Usage

From source file:co.turnus.analysis.profiler.orcc.dynamic.OrccDynamicProfilerOptions.java

public static Configuration getConfiguration(CommandLine cli) {
    try {/*from   w ww.  j av  a2s .  com*/
        Configuration conf = new BaseConfiguration();
        conf.setProperty(VERBOSE, cli.hasOption("v"));

        conf.setProperty(SIMULATOR_NAME, NAME);

        String stmp = cli.getOptionValue("p", "");
        conf.setProperty(ORCC_PROJECT, stmp);

        stmp = cli.getOptionValue("x", "");
        conf.setProperty(ORCC_XDF, stmp);

        Boolean btmp = cli.hasOption("i");
        if (btmp) {
            stmp = cli.getOptionValue("i", "");
            conf.setProperty(ORCC_SOURCE_USE, !stmp.isEmpty());
            conf.setProperty(ORCC_SOURCE_FILE, stmp);
        } else {
            conf.setProperty(ORCC_SOURCE_USE, false);
            conf.setProperty(ORCC_SOURCE_FILE, "");
        }

        btmp = cli.hasOption("t");
        if (btmp) {
            stmp = cli.getOptionValue("t", "");
            conf.setProperty(CREATE_TRACE_PROJECT, !stmp.isEmpty());
            conf.setProperty(TRACE_PROJECT_NAME, stmp);
        } else {
            conf.setProperty(CREATE_TRACE_PROJECT, false);
            conf.setProperty(TRACE_PROJECT_NAME, "");
        }

        btmp = cli.hasOption("stack-protector");
        conf.setProperty(STACK_PROTECTION, btmp);

        btmp = cli.hasOption("z");
        conf.setProperty(TRACE_COMPRESS, btmp);

        btmp = cli.hasOption("prof");
        conf.setProperty(EXPORT_PROFILING, btmp);

        stmp = cli.getOptionValue("versioner", GitVersioner.NAME);
        conf.setProperty(VERSIONER, stmp);

        stmp = cli.getOptionValue("scheduler", RoundRobinScheduler.NAME);
        conf.setProperty(ORCC_SCHEDULER, stmp);

        boolean resize[] = { false, false, false };
        if (cli.hasOption("resizer")) {
            String[] buff = cli.getOptionValues("resizer");
            for (int i = 0; i < resize.length; i++) {
                resize[i] = Boolean.parseBoolean(buff[i]);
            }
        }

        conf.setProperty(TYPE_RESIZE_NATIVEPORTS, resize[0]);
        conf.setProperty(TYPE_RESIZE_TO32BITS, resize[1]);
        conf.setProperty(TYPE_RESIZE_TONBITS, resize[2]);

        boolean transfo[] = { false, false, false, false, false, false };
        if (cli.hasOption("transfo")) {
            String[] buff = cli.getOptionValues("transfo");
            for (int i = 0; i < transfo.length; i++) {
                transfo[i] = Boolean.parseBoolean(buff[i]);
            }
        }
        conf.setProperty(TRANSFO_CONSTANTFOLDING, transfo[0]);
        conf.setProperty(TRANSFO_CONSTANTPROPAGATION, transfo[1]);
        conf.setProperty(TRANSFO_DEADACTIONS, transfo[2]);
        conf.setProperty(TRANSFO_EXPREVAL, transfo[3]);
        conf.setProperty(TRANSFO_DEADCODE, transfo[4]);
        conf.setProperty(TRANSFO_VARINIT, transfo[5]);

        int itmp = Integer.parseInt(cli.getOptionValue("b", "512"));
        conf.setProperty(FIFO_DEFAULT, itmp);

        // set the output path
        stmp = cli.getOptionValue("o", "");
        setOutputPath(conf, stmp);

        // set the gantt chart options
        btmp = cli.hasOption("gantt");
        conf.setProperty(EXPORT_GANTT, btmp);
        if (btmp) {
            stmp = conf.getString(OUTPUT_PATH);
            stmp = new File(stmp, "ganttChart." + TurnusExtension.VCD).getAbsolutePath();
            conf.setProperty(VCD_FILE, stmp);
        }

        return conf;

    } catch (Exception e) {
        throw new TurnusRuntimeException("Error parsing the launch configuration options", e);
    }
}

From source file:co.turnus.analysis.profiler.orcc.dynamic.OrccDynamicProfilerOptions.java

public static Configuration getConfiguration(ILaunchConfiguration configuration, String mode) {
    Configuration conf = new BaseConfiguration();

    try {/*from  w  w  w .  jav  a 2 s.  c o m*/

        conf.setProperty(SIMULATOR_NAME, NAME);

        conf.setProperty(VERBOSE, mode.equals("debug"));

        String stmp = configuration.getAttribute(ORCC_PROJECT, "");
        conf.setProperty(ORCC_PROJECT, stmp);

        stmp = configuration.getAttribute(ORCC_XDF, "");
        conf.setProperty(ORCC_XDF, stmp);

        Boolean btmp = configuration.getAttribute(ORCC_SOURCE_USE, false);
        conf.setProperty(ORCC_SOURCE_USE, btmp);

        stmp = configuration.getAttribute(ORCC_SOURCE_FILE, "");
        conf.setProperty(ORCC_SOURCE_FILE, stmp);

        btmp = configuration.getAttribute(CREATE_TRACE_PROJECT, false);
        conf.setProperty(CREATE_TRACE_PROJECT, btmp);

        stmp = configuration.getAttribute(TRACE_PROJECT_NAME, "");
        conf.setProperty(TRACE_PROJECT_NAME, stmp);

        btmp = configuration.getAttribute(TRACE_COMPRESS, false);
        conf.setProperty(TRACE_COMPRESS, btmp);

        btmp = configuration.getAttribute(EXPORT_PROFILING, false);
        conf.setProperty(EXPORT_PROFILING, btmp);

        stmp = configuration.getAttribute(VERSIONER, "");
        conf.setProperty(VERSIONER, stmp);

        stmp = configuration.getAttribute(ORCC_SCHEDULER, "");
        conf.setProperty(ORCC_SCHEDULER, stmp);

        btmp = configuration.getAttribute(TYPE_RESIZE_NATIVEPORTS, false);
        conf.setProperty(TYPE_RESIZE_NATIVEPORTS, btmp);
        btmp = configuration.getAttribute(TYPE_RESIZE_TO32BITS, false);
        conf.setProperty(TYPE_RESIZE_TO32BITS, btmp);
        btmp = configuration.getAttribute(TYPE_RESIZE_TONBITS, false);
        conf.setProperty(TYPE_RESIZE_TONBITS, btmp);

        btmp = configuration.getAttribute(TRANSFO_CONSTANTFOLDING, false);
        conf.setProperty(TRANSFO_CONSTANTFOLDING, btmp);
        btmp = configuration.getAttribute(TRANSFO_CONSTANTPROPAGATION, false);
        conf.setProperty(TRANSFO_CONSTANTPROPAGATION, btmp);
        btmp = configuration.getAttribute(TRANSFO_DEADACTIONS, false);
        conf.setProperty(TRANSFO_DEADACTIONS, btmp);
        btmp = configuration.getAttribute(TRANSFO_EXPREVAL, false);
        conf.setProperty(TRANSFO_EXPREVAL, btmp);
        btmp = configuration.getAttribute(TRANSFO_DEADCODE, false);
        conf.setProperty(TRANSFO_DEADCODE, btmp);
        btmp = configuration.getAttribute(TRANSFO_VARINIT, false);
        conf.setProperty(TRANSFO_VARINIT, btmp);

        int itmp = Integer.parseInt(configuration.getAttribute(FIFO_DEFAULT, "512"));
        conf.setProperty(FIFO_DEFAULT, itmp);

        btmp = configuration.getAttribute(STACK_PROTECTION, true);
        conf.setProperty(STACK_PROTECTION, btmp);

        // parse the FIFO size mapping
        Map<String, String> tmpMap = configuration.getAttribute(ORCC_FIFO_MAPPING,
                new HashMap<String, String>());
        Map<String, Integer> fifoMapping = new HashMap<String, Integer>();
        for (Entry<String, String> entry : tmpMap.entrySet()) {
            fifoMapping.put(entry.getKey(), Integer.parseInt(entry.getValue()));
        }
        conf.setProperty(ORCC_FIFO_MAPPING, fifoMapping);

        // store the users notes
        stmp = configuration.getAttribute(NOTES, "");
        conf.setProperty(NOTES, stmp);

        // set the output path
        stmp = configuration.getAttribute(OUTPUT_PATH_CUSTOM_USE, false)
                ? configuration.getAttribute(OUTPUT_PATH_CUSTOM_VALUE, "")
                : "";
        setOutputPath(conf, stmp);

        // set the export gantt chart options
        btmp = configuration.getAttribute(EXPORT_GANTT, false);
        conf.setProperty(EXPORT_GANTT, btmp);
        if (btmp) {
            stmp = conf.getString(OUTPUT_PATH);
            stmp = new File(stmp, "ganttChart." + TurnusExtension.VCD).getAbsolutePath();
            conf.setProperty(VCD_FILE, stmp);
        }

        return conf;

    } catch (Exception e) {
        throw new TurnusRuntimeException("Error parsing the launch configuration options", e);
    }
}

From source file:com.netflix.config.util.ConfigurationUtils.java

public static void copyProperties(Configuration from, Configuration to) {
    for (Iterator<String> i = from.getKeys(); i.hasNext();) {
        String key = i.next();/*www . j a  v  a 2s.  c o  m*/
        if (key != null) {
            Object value = from.getProperty(key);
            if (value != null) {
                to.setProperty(key, value);
            }
        }
    }
}

From source file:co.turnus.analysis.profiler.orcc.code.OrccStaticProfilerOptions.java

private static void setOutputPath(Configuration conf, String customPath) {
    // store the root path for the output.
    File outPath = null;// w w w .  ja v  a  2s.c o m
    if (customPath != null && !customPath.isEmpty()) {
        outPath = new File(customPath);
    } else {
        String project = conf.getString(ORCC_PROJECT);
        IProject pojo = EcoreHelper.getProject(project);
        outPath = pojo.getRawLocation().makeAbsolute().toFile();
        outPath = new File(outPath, "turnus");
        outPath = new File(outPath, "code");

    }

    conf.setProperty(OUTPUT_PATH, outPath.getAbsolutePath());

}

From source file:maltcms.ui.fileHandles.properties.tools.SceneParser.java

/**
 * Supports both absolute and relative paths and also arbitrary combinations
 * of the two. In case of relative paths, the location of the file
 * containing the pipeline configuration is used as basedir to resolve the
 * relative path./*from w  w w.  j av  a 2  s .co  m*/
 *
 * Example for relative path:
 * <pre>pipelines.properties = fragmentCommands/myClassName.properties</pre>
 * Example for absolute path:
 * <pre>pipelines.properties = /home/juser/myFunkyDir/myClassName.properties</pre>
 *
 * <pre>pipeline.properties</pre> accepts multiple entries, separated by a
 * ',' (comma) character. Example:
 * <pre>pipeline.properties = fragmentCommands/myClassName.properties,/home/juser/myFunkyDir/myClassName.properties</pre>
 *
 * @param filename the filename of the base configuration, which contains
 * the pipeline= and pipeline.properties keys.
 * @param cfg the configuration object resembling the content of filename.
 * @param scene the graph scene into which to load the configuration.
 */
public static void parseIntoScene(String filename, Configuration cfg, PipelineGraphScene scene) {
    Logger.getLogger(SceneParser.class.getName())
            .info("###################################################################");
    Logger.getLogger(SceneParser.class.getName()).info("Creating graph scene from file");
    File f = new File(filename);
    //Get pipeline from configuration
    cfg.addProperty("config.basedir", f.getParentFile().getAbsoluteFile().toURI().getPath());
    String pipelineXml = cfg.getString("pipeline.xml");

    FileSystemXmlApplicationContext fsxmac = new FileSystemXmlApplicationContext(new String[] { pipelineXml },
            true);
    ICommandSequence commandSequence = fsxmac.getBean("commandPipeline",
            cross.datastructures.pipeline.CommandPipeline.class);
    //        String[] pipes = pipeline.toArray(new String[]{});
    Logger.getLogger(SceneParser.class.getName()).log(Level.INFO, "Pipeline elements: {0}",
            commandSequence.getCommands());
    PipelineGeneralConfigWidget pgcw = (PipelineGeneralConfigWidget) scene.createGeneralWidget();
    pgcw.setProperties(cfg);
    String lastNode = null;
    String edge;
    int edgeCounter = 0;
    int nodeCounter = 0;
    Configuration pipeHash = new PropertiesConfiguration();
    for (IFragmentCommand command : commandSequence.getCommands()) {
        Collection<String> configKeys = cross.annotations.AnnotationInspector
                .getRequiredConfigKeys(command.getClass());
        //        for (String pipe : pipes) {
        String nodeId = command.getClass().getCanonicalName() + "" + nodeCounter;
        PipelineElementWidget node = (PipelineElementWidget) scene.addNode(nodeId);
        //            node.setPropertyFile();

        //            System.out.println("Parsing pipeline element " + pipeCfg.getAbsolutePath());
        node.setBean(command);
        node.setLabel(command.getClass().getSimpleName());
        node.setCurrentClassProperties();
        Configuration prop = node.getProperties();
        //            pipeHash = PropertyLoader.getHash(pipeCfg.getAbsolutePath());
        //            node.setPropertyFile(pipeCfg.getAbsolutePath());
        Iterator iter = pipeHash.getKeys();
        while (iter.hasNext()) {
            String key = (String) iter.next();
            prop.setProperty(key, pipeHash.getProperty(key));
        }
        node.setProperties(prop);

        if (lastNode != null) {
            edge = "Ledge" + edgeCounter++;
            scene.addEdge(edge);
            Logger.getLogger(SceneParser.class.getName()).log(Level.INFO,
                    "Adding edge between lastNode {0} and {1}", new Object[] { lastNode, nodeId });
            scene.setEdgeSource(edge, lastNode);
            scene.setEdgeTarget(edge, nodeId);
            scene.validate();
        }
        //                x += dx;
        //                y += dy;
        scene.validate();
        lastNode = nodeId;
        nodeCounter++;
    }

    scene.validate();
    SceneLayouter.layoutVertical(scene);
}

From source file:com.springrts.springls.CmdLineArgs.java

/**
 * Processes all command line arguments in 'args'.
 * Raises an exception in case of errors.
 * @return whether to exit the application after this method
 *//*from w  w  w  .j  a v a 2  s  .  c o m*/
private static boolean apply(Configuration configuration, CommandLineParser parser, Options options,
        String[] args) throws ParseException {
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(Server.getApplicationName(), options);
        return true;
    }

    if (cmd.hasOption("port")) {
        String portStr = cmd.getOptionValue("port");
        int port = Integer.parseInt(portStr);
        if ((port < 1) || (port > 65535)) {
            throw new ParseException("Invalid port specified: " + portStr);
        }
        configuration.setProperty(ServerConfiguration.PORT, port);
    }
    if (cmd.hasOption("database")) {
        configuration.setProperty(ServerConfiguration.USE_DATABASE, true);
    } else if (cmd.hasOption("file-storage")) {
        configuration.setProperty(ServerConfiguration.USE_DATABASE, false);
    } else {
        configuration.setProperty(ServerConfiguration.LAN_MODE, true);
    }
    if (cmd.hasOption("statistics")) {
        configuration.setProperty(ServerConfiguration.STATISTICS_STORE, true);
    }
    if (cmd.hasOption("nat-port")) {
        String portStr = cmd.getOptionValue("port");
        int port = Integer.parseInt(portStr);
        if ((port < 1) || (port > 65535)) {
            throw new ParseException("Invalid NAT traversal port" + " specified: " + portStr);
        }
        configuration.setProperty(ServerConfiguration.NAT_PORT, port);
    }
    if (cmd.hasOption("log-main")) {
        configuration.setProperty(ServerConfiguration.CHANNELS_LOG_REGEX, "^main$");
    }
    if (cmd.hasOption("lan-admin")) {
        String[] usernamePassword = cmd.getOptionValues("lan-admin");

        if (usernamePassword.length < 1) {
            throw new MissingArgumentException("LAN admin user name is missing");
        }
        String username = usernamePassword[0];
        String password = (usernamePassword.length > 1) ? usernamePassword[0]
                : ServerConfiguration.getDefaults().getString(ServerConfiguration.LAN_ADMIN_PASSWORD);

        String error = Account.isOldUsernameValid(username);
        if (error != null) {
            throw new ParseException("LAN admin user name is not valid: " + error);
        }
        error = Account.isPasswordValid(password);
        if (error != null) {
            throw new ParseException("LAN admin password is not valid: " + error);
        }
        configuration.setProperty(ServerConfiguration.LAN_ADMIN_USERNAME, username);
        configuration.setProperty(ServerConfiguration.LAN_ADMIN_PASSWORD, password);
    }
    if (cmd.hasOption("load-args")) {
        File argsFile = new File(cmd.getOptionValue("load-args"));
        Reader inF = null;
        BufferedReader in = null;
        try {
            try {
                inF = new FileReader(argsFile);
                in = new BufferedReader(inF);
                String line;
                List<String> argsList = new LinkedList<String>();
                while ((line = in.readLine()) != null) {
                    String[] argsLine = line.split("[ \t]+");
                    argsList.addAll(Arrays.asList(argsLine));
                }
                String[] args2 = argsList.toArray(new String[argsList.size()]);
                apply(configuration, parser, options, args2);
            } finally {
                if (in != null) {
                    in.close();
                } else if (inF != null) {
                    inF.close();
                }
            }
        } catch (Exception ex) {
            throw new ParseException("invalid load-args argument: " + ex.getMessage());
        }
    }
    if (cmd.hasOption("spring-version")) {
        String version = cmd.getOptionValue("spring-version");
        configuration.setProperty(ServerConfiguration.ENGINE_VERSION, version);
    }

    return false;
}

From source file:com.shmsoft.dmass.main.ParameterProcessing.java

/**
 * Echo configuration, save configuration, and update application log
 *
 * @param configuration processing parameters
 * @throws ConfigurationException//from  w ww . java 2s .  c om
 * @throws MalformedURLException
 */
public static void echoProcessingParameters(Configuration configuration)
        throws ConfigurationException, MalformedURLException {
    SimpleDateFormat fileNameFormat = new SimpleDateFormat("yyMMdd_HHmmss");
    String runParameterFileName = "freeeed.parameters." + fileNameFormat.format(new Date()) + ".project";

    // save configuration
    SHMcloudConfiguration configToSave = new SHMcloudConfiguration();
    configToSave.cleanup();
    configToSave.append(configuration);
    configToSave.setProperty("processed_by ", Version.getVersionAndBuild());
    String paramPath = SHMcloudLogging.logDir + "/" + runParameterFileName;
    configToSave.save(paramPath);
    configToSave.restore();

    // update application log
    History.appendToHistory("Processing parameters were saved to " + paramPath);
    configuration.setProperty(ParameterProcessing.RUN_PARAMETERS_FILE, paramPath);
}

From source file:io.fluo.stress.TrieStopLevelIT.java

@Override
protected void setAppConfig(Configuration config) {
    config.setProperty(Constants.STOP_LEVEL_PROP, 7);
    config.setProperty(Constants.NODE_SIZE_PROP, 8);
}

From source file:backup.store.s3.S3BackupStoreMiniClusterTest.java

@Override
protected void setupBackupStore(Configuration conf) throws Exception {
    conf.setProperty(BackupConstants.DFS_BACKUP_STORE_KEY, "backup.store.s3.S3BackupStore");
    conf.setProperty(S3BackupStoreContants.DFS_BACKUP_S3_BUCKET_NAME_KEY, backupBucket);
    conf.setProperty(S3BackupStoreContants.DFS_BACKUP_S3_OBJECT_PREFIX_KEY, prefix);
}

From source file:backup.store.local.LocalBackupStoreMiniClusterTest.java

@Override
protected void setupBackupStore(Configuration conf) {
    backup.mkdirs();/*from  w w w  .  jav a  2 s .  c o  m*/
    conf.setProperty(BackupConstants.DFS_BACKUP_STORE_KEY, "backup.store.local.LocalBackupStore");
    conf.setProperty(LocalBackupStoreConstants.DFS_BACKUP_LOCALBACKUPSTORE_PATH, backup.getAbsolutePath());
}