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

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

Introduction

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

Prototype

public Set<String> getSubsections(String section) 

Source Link

Document

Get set of all subsections of specified section within this configuration and its base configuration

Usage

From source file:ch.uzh.ifi.seal.permo.history.git.core.model.jgit.util.JGitUtil.java

License:Apache License

/**
 * Returns a list of all remote references (e.g. 'refs/remotes/origin') of the given repository.
 * //  w  w  w .j a  v  a2  s  . c o m
 * @param repository
 *          the repository
 * @return the list of all remote references of the given repository.
 */
public static Set<String> getRemotes(final Repository repository) {
    final Config storedConfig = repository.getConfig();
    return storedConfig.getSubsections(REMOTE);
}

From source file:com.buildautomation.jgit.api.PrintRemotes.java

License:Apache License

public static void printRemotes() throws IOException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
        Config storedConfig = repository.getConfig();
        Set<String> remotes = storedConfig.getSubsections("remote");

        for (String remoteName : remotes) {
            String url = storedConfig.getString("remote", remoteName, "url");
            System.out.println(remoteName + " " + url);
        }//ww w .ja  v a  2 s.c om
    }
}

From source file:com.gitblit.authority.UserCertificateConfig.java

License:Apache License

private UserCertificateConfig(final Config c) {
    SimpleDateFormat df = new SimpleDateFormat(Constants.ISO8601);
    list = new ArrayList<UserCertificateModel>();
    for (String username : c.getSubsections("user")) {
        UserCertificateModel uc = new UserCertificateModel(new UserModel(username));
        try {/*www  .j av a  2 s . c o  m*/
            uc.expires = df.parse(c.getString("user", username, "expires"));
        } catch (ParseException e) {
            LoggerFactory.getLogger(UserCertificateConfig.class).error("Failed to parse date!", e);
        } catch (NullPointerException e) {
        }
        uc.notes = c.getString("user", username, "notes");
        uc.revoked = new ArrayList<String>(Arrays.asList(c.getStringList("user", username, "revoked")));
        list.add(uc);
    }
}

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./* ww  w.  ja  v a2s  .  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.elasticsearch.ElasticConfiguration.java

License:Apache License

@Inject
ElasticConfiguration(@GerritServerConfig Config cfg) {
    this.username = cfg.getString("elasticsearch", null, "username");
    this.password = cfg.getString("elasticsearch", null, "password");
    this.requestCompression = cfg.getBoolean("elasticsearch", null, "requestCompression", false);
    this.connectionTimeout = cfg.getTimeUnit("elasticsearch", null, "connectionTimeout", 3000,
            TimeUnit.MILLISECONDS);
    this.maxConnectionIdleTime = cfg.getTimeUnit("elasticsearch", null, "maxConnectionIdleTime", 3000,
            TimeUnit.MILLISECONDS);
    this.maxTotalConnection = cfg.getInt("elasticsearch", null, "maxTotalConnection", 1);
    this.readTimeout = (int) cfg.getTimeUnit("elasticsearch", null, "readTimeout", 3000, TimeUnit.MICROSECONDS);

    Set<String> subsections = cfg.getSubsections("elasticsearch");
    if (subsections.isEmpty()) {
        this.urls = Arrays.asList(buildUrl(DEFAULT_PROTOCOL, DEFAULT_HOST, DEFAULT_PORT));
    } else {//from  w  w w  .  j  ava  2s  . co m
        this.urls = new ArrayList<>(subsections.size());
        for (String subsection : subsections) {
            String port = getString(cfg, subsection, "port", DEFAULT_PORT);
            String host = getString(cfg, subsection, "hostname", DEFAULT_HOST);
            String protocol = getString(cfg, subsection, "protocol", DEFAULT_PROTOCOL);
            this.urls.add(buildUrl(protocol, host, port));
        }
    }
}

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

License:Apache License

@Override
public void run() throws Exception {
    Config cfg = allProjectsConfig.load().getConfig();
    if (cfg == null || !cfg.getSubsections(KEY_LABEL).contains(LABEL_VERIFIED)) {
        ui.header("Review Labels");
        installVerified = ui.yesno(false, "Install Verified label");
    }//from w  w w .ja  va2  s . co m
}

From source file:com.google.gerrit.server.account.externalids.ExternalId.java

License:Apache License

/**
 * Parses an external ID from a byte array that contain the external ID as an Git config file
 * text./*  w  w w  .  j  ava2  s  .  co m*/
 *
 * <p>The Git config must have exactly one externalId subsection with an accountId and optionally
 * email and password:
 *
 * <pre>
 * [externalId "username:jdoe"]
 *   accountId = 1003407
 *   email = jdoe@example.com
 *   password = bcrypt:4:LCbmSBDivK/hhGVQMfkDpA==:XcWn0pKYSVU/UJgOvhidkEtmqCp6oKB7
 * </pre>
 */
public static ExternalId parse(String noteId, byte[] raw) throws ConfigInvalidException {
    Config externalIdConfig = new Config();
    try {
        externalIdConfig.fromText(new String(raw, UTF_8));
    } catch (ConfigInvalidException e) {
        throw invalidConfig(noteId, e.getMessage());
    }

    Set<String> externalIdKeys = externalIdConfig.getSubsections(EXTERNAL_ID_SECTION);
    if (externalIdKeys.size() != 1) {
        throw invalidConfig(noteId, String.format("Expected exactly 1 '%s' section, found %d",
                EXTERNAL_ID_SECTION, externalIdKeys.size()));
    }

    String externalIdKeyStr = Iterables.getOnlyElement(externalIdKeys);
    Key externalIdKey = Key.parse(externalIdKeyStr);
    if (externalIdKey == null) {
        throw invalidConfig(noteId, String.format("External ID %s is invalid", externalIdKeyStr));
    }

    if (!externalIdKey.sha1().getName().equals(noteId)) {
        throw invalidConfig(noteId, String.format("SHA1 of external ID '%s' does not match note ID '%s'",
                externalIdKeyStr, noteId));
    }

    String email = externalIdConfig.getString(EXTERNAL_ID_SECTION, externalIdKeyStr, EMAIL_KEY);
    String password = externalIdConfig.getString(EXTERNAL_ID_SECTION, externalIdKeyStr, PASSWORD_KEY);
    int accountId = readAccountId(noteId, externalIdConfig, externalIdKeyStr);

    return new AutoValue_ExternalId(externalIdKey, new Account.Id(accountId), Strings.emptyToNull(email),
            Strings.emptyToNull(password));
}

From source file:com.google.gerrit.server.account.GeneralPreferencesLoader.java

License:Apache License

private static List<MenuItem> my(VersionedAccountPreferences v) {
    List<MenuItem> my = new ArrayList<>();
    Config cfg = v.getConfig();
    for (String subsection : cfg.getSubsections(UserConfigSections.MY)) {
        String url = my(cfg, subsection, KEY_URL, "#/");
        String target = my(cfg, subsection, KEY_TARGET, url.startsWith("#") ? null : "_blank");
        my.add(new MenuItem(subsection, url, target, my(cfg, subsection, KEY_ID, null)));
    }//from w w  w.  jav  a 2 s.c o m
    return my;
}

From source file:com.google.gerrit.server.account.GeneralPreferencesLoader.java

License:Apache License

private static Map<String, String> urlAliases(VersionedAccountPreferences v) {
    HashMap<String, String> urlAliases = new HashMap<>();
    Config cfg = v.getConfig();
    for (String subsection : cfg.getSubsections(URL_ALIAS)) {
        urlAliases.put(cfg.getString(URL_ALIAS, subsection, KEY_MATCH),
                cfg.getString(URL_ALIAS, subsection, KEY_TOKEN));
    }//from w  w  w  .jav a2 s  .  c om
    return !urlAliases.isEmpty() ? urlAliases : null;
}

From source file:com.google.gerrit.server.account.SetPreferences.java

License:Apache License

private static void unsetSection(Config cfg, String section) {
    cfg.unsetSection(section, null);//ww  w .  j a v a2 s .c  o  m
    for (String subsection : cfg.getSubsections(section)) {
        cfg.unsetSection(section, subsection);
    }
}