Example usage for org.eclipse.jgit.storage.file FileBasedConfig getNames

List of usage examples for org.eclipse.jgit.storage.file FileBasedConfig getNames

Introduction

In this page you can find the example usage for org.eclipse.jgit.storage.file FileBasedConfig getNames.

Prototype

public Set<String> getNames(String section, String subsection) 

Source Link

Document

Get the list of names defined for this subsection

Usage

From source file:com.googlesource.gerrit.plugins.hooks.workflow.GerritHookFilterChangeState.java

License:Apache License

private List<Transition> loadTransitions() {
    File configFile = new File(sitePath, "etc/issue-state-transition.config");
    FileBasedConfig cfg = new FileBasedConfig(configFile, FS.DETECTED);
    try {/*from  w ww .j av  a 2 s  . c om*/
        cfg.load();
    } catch (IOException e) {
        log.error("Cannot load transitions configuration file " + cfg, e);
        return Collections.emptyList();
    } catch (ConfigInvalidException e) {
        log.error("Invalid transitions configuration file" + cfg, e);
        return Collections.emptyList();
    }

    List<Transition> transitions = new ArrayList<Transition>();
    Set<String> sections = cfg.getSubsections("action");
    for (String section : sections) {
        List<Condition> conditions = new ArrayList<Condition>();
        Set<String> keys = cfg.getNames("action", section);
        for (String key : keys) {
            String val = cfg.getString("action", section, key);
            conditions.add(new Condition(key.trim(), val.trim().split(",")));
        }
        transitions.add(new Transition(toAction(section), conditions));
    }
    return transitions;
}

From source file:com.googlesource.gerrit.plugins.hooks.workflow.RuleBase.java

License:Apache License

/**
 * Loads the rules for the RuleBase.//from   w  w  w .ja  v a2  s.  c  o  m
 *
 * Consider using {@link #loadRules()@}, as that method only loads the rules,
 * if they have not yet been loaded.
 */
private void forceLoadRules() throws Exception {
    File configFile = new File(sitePath, ITS_CONFIG_FILE);
    if (configFile.exists()) {
        FileBasedConfig cfg = new FileBasedConfig(configFile, FS.DETECTED);
        cfg.load();

        rules = Lists.newArrayList();
        Collection<String> subsections = cfg.getSubsections(RULE_SECTION);
        for (String subsection : subsections) {
            Rule rule = ruleFactory.create(subsection);
            Collection<String> keys = cfg.getNames(RULE_SECTION, subsection);
            for (String key : keys) {
                String values[] = cfg.getStringList(RULE_SECTION, subsection, key);
                if (ACTION_KEY.equals(key)) {
                    for (String value : values) {
                        ActionRequest actionRequest = actionRequestFactory.create(value);
                        rule.addActionRequest(actionRequest);
                    }
                } else {
                    for (String value : values) {
                        Condition condition = conditionFactory.create(key, value);
                        rule.addCondition(condition);
                    }
                }
            }
            rules.add(rule);
        }
    } else {
        // configFile does not exist.
        log.warn("ITS actions configuration file (" + configFile + ") does not exist.");
        rules = Collections.emptySet();
    }
}