Example usage for org.eclipse.jgit.lib Config getNames

List of usage examples for org.eclipse.jgit.lib Config getNames

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Config getNames.

Prototype

public Set<String> getNames(String section, boolean recursive) 

Source Link

Document

Get the list of names defined for this section

Usage

From source file:com.google.gerrit.acceptance.MergeableFileBasedConfig.java

License:Apache License

/**
 * Merge another Config into this Config.
 *
 * In case a configuration parameter exists both in this instance and in the
 * merged instance then the value in this instance will simply replaced by
 * the value from the merged instance.//from  w w w .ja v  a  2 s.  c  o  m
 *
 * @param s Config to merge into this instance
 */
public void merge(Config s) {
    if (s == null) {
        return;
    }
    for (String section : s.getSections()) {
        for (String subsection : s.getSubsections(section)) {
            for (String name : s.getNames(section, subsection)) {
                setStringList(section, subsection, name,
                        Lists.newArrayList(s.getStringList(section, subsection, name)));
            }
        }

        for (String name : s.getNames(section, true)) {
            setStringList(section, null, name, Lists.newArrayList(s.getStringList(section, null, name)));
        }
    }
}

From source file:com.google.gerrit.pgm.init.InitExperimental.java

License:Apache License

private void initNoteDb() {
    ui.message("Use experimental NoteDb for change metadata?\n"
            + "  NoteDb is not recommended for production servers."
            + "  Please familiarize yourself with the documentation:\n"
            + "  https://gerrit-review.googlesource.com/Documentation/dev-note-db.html\n");
    if (!ui.yesno(false, "Enable")) {
        return;/*w  ww .j a  v  a2 s .co m*/
    }

    Config defaultConfig = ConfigNotesMigration.allEnabledConfig();
    for (String name : defaultConfig.getNames(SECTION_NOTE_DB, CHANGES.key())) {
        noteDbChanges.set(name, defaultConfig.getString(SECTION_NOTE_DB, CHANGES.key(), name));
    }
}

From source file:com.google.gerrit.server.git.GarbageCollection.java

License:Apache License

private static String formatConfigValues(Config config, String section, String subsection) {
    StringBuilder b = new StringBuilder();
    Set<String> names = config.getNames(section, subsection);
    for (String name : names) {
        String value = config.getString(section, subsection, name);
        b.append(section);/*from   ww w  . j ava2 s.  c o m*/
        if (subsection != null) {
            b.append(".").append(subsection);
        }
        b.append(".");
        b.append(name).append("=").append(value);
        b.append("; ");
    }
    return b.toString();
}

From source file:com.google.gerrit.server.git.ProjectConfig.java

License:Apache License

private void loadAccessSections(Config rc, Map<String, GroupReference> groupsByName) {
    accessSections = new HashMap<>();
    for (String refName : rc.getSubsections(ACCESS)) {
        if (RefConfigSection.isValid(refName)) {
            AccessSection as = getAccessSection(refName, true);

            for (String varName : rc.getStringList(ACCESS, refName, KEY_GROUP_PERMISSIONS)) {
                for (String n : varName.split("[, \t]{1,}")) {
                    if (isPermission(n)) {
                        as.getPermission(n, true).setExclusiveGroup(true);
                    }//from   ww  w  .  ja v a2s.c  om
                }
            }

            for (String varName : rc.getNames(ACCESS, refName)) {
                if (isPermission(varName)) {
                    Permission perm = as.getPermission(varName, true);
                    loadPermissionRules(rc, ACCESS, refName, varName, groupsByName, perm,
                            Permission.hasRange(varName));
                }
            }
        }
    }

    AccessSection capability = null;
    for (String varName : rc.getNames(CAPABILITY)) {
        if (capability == null) {
            capability = new AccessSection(AccessSection.GLOBAL_CAPABILITIES);
            accessSections.put(AccessSection.GLOBAL_CAPABILITIES, capability);
        }
        Permission perm = capability.getPermission(varName, true);
        loadPermissionRules(rc, CAPABILITY, null, varName, groupsByName, perm,
                GlobalCapability.hasRange(varName));
    }
}

From source file:com.google.gerrit.server.git.ProjectConfig.java

License:Apache License

private void loadPluginSections(Config rc) {
    pluginConfigs = Maps.newHashMap();//from  w  w w  .  j av a 2s .  c  o  m
    for (String plugin : rc.getSubsections(PLUGIN)) {
        Config pluginConfig = new Config();
        pluginConfigs.put(plugin, pluginConfig);
        for (String name : rc.getNames(PLUGIN, plugin)) {
            pluginConfig.setStringList(PLUGIN, plugin, name,
                    Arrays.asList(rc.getStringList(PLUGIN, plugin, name)));
        }
    }
}

From source file:com.google.gerrit.server.git.ProjectConfig.java

License:Apache License

private void savePluginSections(Config rc) {
    List<String> existing = Lists.newArrayList(rc.getSubsections(PLUGIN));
    for (String name : existing) {
        rc.unsetSection(PLUGIN, name);/*from   www . jav  a  2 s .co  m*/
    }

    for (Entry<String, Config> e : pluginConfigs.entrySet()) {
        String plugin = e.getKey();
        Config pluginConfig = e.getValue();
        for (String name : pluginConfig.getNames(PLUGIN, plugin)) {
            rc.setStringList(PLUGIN, plugin, name,
                    Arrays.asList(pluginConfig.getStringList(PLUGIN, plugin, name)));
        }
    }
}

From source file:com.google.gerrit.server.notedb.ConfigNotesMigration.java

License:Apache License

private static void checkConfig(Config cfg) {
    Set<String> keys = new HashSet<>();
    for (NoteDbTable t : NoteDbTable.values()) {
        keys.add(t.key());/*w w  w  . j av a2s .  c  o m*/
    }
    for (String t : cfg.getSubsections(NOTE_DB)) {
        checkArgument(keys.contains(t.toLowerCase()), "invalid NoteDb table: %s", t);
        for (String key : cfg.getNames(NOTE_DB, t)) {
            String lk = key.toLowerCase();
            checkArgument(lk.equals(WRITE) || lk.equals(READ), "invalid NoteDb key: %s.%s", t, key);
        }
        boolean write = cfg.getBoolean(NOTE_DB, t, WRITE, false);
        boolean read = cfg.getBoolean(NOTE_DB, t, READ, false);
        checkArgument(!(read && !write), "must have write enabled when read enabled: %s", t);
    }
}

From source file:com.google.gerrit.server.notedb.NotesMigration.java

License:Apache License

private static void checkConfig(Config cfg) {
    Set<String> keys = new HashSet<>();
    for (Table t : Table.values()) {
        keys.add(t.key());/*from   www. j a  v a 2s  .co  m*/
    }
    for (String t : cfg.getSubsections(NOTEDB)) {
        checkArgument(keys.contains(t.toLowerCase()), "invalid notedb table: %s", t);
        for (String key : cfg.getNames(NOTEDB, t)) {
            String lk = key.toLowerCase();
            checkArgument(lk.equals(WRITE) || lk.equals(READ), "invalid notedb key: %s.%s", t, key);
        }
        boolean write = cfg.getBoolean(NOTEDB, t, WRITE, false);
        boolean read = cfg.getBoolean(NOTEDB, t, READ, false);
        checkArgument(!(read && !write), "must have write enabled when read enabled: %s", t);
    }
}

From source file:com.google.gerrit.sshd.SshModule.java

License:Apache License

@Inject
SshModule(@GerritServerConfig Config cfg) {
    aliases = Maps.newHashMap();/*from   ww  w  .j av a  2  s .  co m*/
    for (String name : cfg.getNames("ssh-alias", true)) {
        aliases.put(name, cfg.getString("ssh-alias", null, name));
    }
}

From source file:com.googlesource.gerrit.plugins.github.oauth.GitHubOAuthConfig.java

License:Apache License

private Map<String, List<Scope>> getScopes(Config config) {
    Map<String, List<Scope>> scopes = Maps.newHashMap();
    Set<String> configKeys = config.getNames(CONF_SECTION, true);
    for (String key : configKeys) {
        if (key.startsWith("scopes")) {
            String scopesString = config.getString(CONF_SECTION, null, key);
            scopes.put(key, parseScopesString(scopesString));
        }//from   w w  w  .j  a  v a2 s  .co  m
    }
    return scopes;
}