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

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

Introduction

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

Prototype

public void unset(final String section, final String subsection, final String name) 

Source Link

Document

Remove a configuration value.

Usage

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

License:Apache License

public void store(Config c, X509Metadata metadata) {
    store(c, "new", "organizationalUnit", metadata.getOID("OU", null));
    store(c, "new", "organization", metadata.getOID("O", null));
    store(c, "new", "locality", metadata.getOID("L", null));
    store(c, "new", "stateProvince", metadata.getOID("ST", null));
    store(c, "new", "countryCode", metadata.getOID("C", null));
    if (duration <= 0) {
        c.unset("new", null, "duration");
    } else {/* w  w  w .ja  v a2s.c o  m*/
        c.setInt("new", null, "duration", duration);
    }
}

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

License:Apache License

private void store(Config c, String section, String name, String value) {
    if (StringUtils.isEmpty(value)) {
        c.unset(section, null, name);
    } else {// ww w. ja v a2s. c  o m
        c.setString(section, null, name, value);
    }
}

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

License:Apache License

public void update(Config config) {
    if (expires == null) {
        config.unset("user", user.username, "expires");
    } else {//from   ww w .j  a v a  2  s  .c  o  m
        SimpleDateFormat df = new SimpleDateFormat(Constants.ISO8601);
        config.setString("user", user.username, "expires", df.format(expires));
    }
    if (StringUtils.isEmpty(notes)) {
        config.unset("user", user.username, "notes");
    } else {
        config.setString("user", user.username, "notes", notes);
    }
    if (ArrayUtils.isEmpty(revoked)) {
        config.unset("user", user.username, "revoked");
    } else {
        config.setStringList("user", user.username, "revoked", revoked);
    }
}

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

License:Apache License

private static void mergeTestConfig(Config cfg) {
    String forceEphemeralPort = String.format("%s:0", getLocalHost().getHostName());
    String url = "http://" + forceEphemeralPort + "/";
    cfg.setString("gerrit", null, "canonicalWebUrl", url);
    cfg.setString("httpd", null, "listenUrl", url);
    cfg.setString("sshd", null, "listenAddress", forceEphemeralPort);
    cfg.setBoolean("sshd", null, "testUseInsecureRandom", true);
    cfg.unset("cache", null, "directory");
    cfg.setString("gerrit", null, "basePath", "git");
    cfg.setBoolean("sendemail", null, "enable", true);
    cfg.setInt("sendemail", null, "threadPoolSize", 0);
    cfg.setInt("cache", "projects", "checkFrequency", 0);
    cfg.setInt("plugins", null, "checkFrequency", 0);

    cfg.setInt("sshd", null, "threads", 1);
    cfg.setInt("sshd", null, "commandStartThreads", 1);
    cfg.setInt("receive", null, "threadPoolSize", 1);
    cfg.setInt("index", null, "threads", 1);
}

From source file:com.google.gerrit.acceptance.rest.account.ExternalIdIT.java

License:Apache License

private String insertExternalIdWithoutAccountId(Repository repo, RevWalk rw, String externalId)
        throws IOException {
    ObjectId rev = ExternalIdReader.readRevision(repo);
    NoteMap noteMap = ExternalIdReader.readNoteMap(rw, rev);

    ExternalId extId = ExternalId.create(ExternalId.Key.parse(externalId), admin.id);

    try (ObjectInserter ins = repo.newObjectInserter()) {
        ObjectId noteId = extId.key().sha1();
        Config c = new Config();
        extId.writeToConfig(c);/*  ww  w .  j  av  a2s  .co m*/
        c.unset("externalId", extId.key().get(), "accountId");
        byte[] raw = c.toText().getBytes(UTF_8);
        ObjectId dataBlob = ins.insert(OBJ_BLOB, raw);
        noteMap.set(noteId, dataBlob);

        ExternalIdsUpdate.commit(repo, rw, ins, rev, noteMap, "Add external ID", admin.getIdent(),
                admin.getIdent());
        return noteId.getName();
    }
}

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

License:Apache License

private static void set(Config cfg, String section, String key, String val) {
    if (Strings.isNullOrEmpty(val)) {
        cfg.unset(MY, section, key);
    } else {//w  ww  .  ja v a2 s.com
        cfg.setString(MY, section, key, val);
    }
}

From source file:com.google.gerrit.server.config.ConfigUtil.java

License:Apache License

/**
 * Store section by inspecting Java class attributes.
 * <p>/*from  ww w. ja va  2  s  . c o  m*/
 * Optimize the storage by unsetting a variable if it is
 * being set to default value by the server.
 * <p>
 * Fields marked with final or transient modifiers are skipped.
 *
 * @param cfg config in which the values should be stored
 * @param section section
 * @param sub subsection
 * @param s instance of class with config values
 * @param defaults instance of class with default values
 * @throws ConfigInvalidException
 */
public static <T> void storeSection(Config cfg, String section, String sub, T s, T defaults)
        throws ConfigInvalidException {
    try {
        for (Field f : s.getClass().getDeclaredFields()) {
            if (skipField(f)) {
                continue;
            }
            Class<?> t = f.getType();
            String n = f.getName();
            f.setAccessible(true);
            Object c = f.get(s);
            Object d = f.get(defaults);
            Preconditions.checkNotNull(d, "Default cannot be null");
            if (c == null || c.equals(d)) {
                cfg.unset(section, sub, n);
            } else {
                if (isString(t)) {
                    cfg.setString(section, sub, n, (String) c);
                } else if (isInteger(t)) {
                    cfg.setInt(section, sub, n, (Integer) c);
                } else if (isLong(t)) {
                    cfg.setLong(section, sub, n, (Long) c);
                } else if (isBoolean(t)) {
                    cfg.setBoolean(section, sub, n, (Boolean) c);
                } else if (t.isEnum()) {
                    cfg.setEnum(section, sub, n, (Enum<?>) c);
                } else {
                    throw new ConfigInvalidException("type is unknown: " + t.getName());
                }
            }
        }
    } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
        throw new ConfigInvalidException("cannot save values", e);
    }
}

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

License:Apache License

@Override
protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException {
    if (commit.getMessage() == null || "".equals(commit.getMessage())) {
        commit.setMessage("Updated project configuration\n");
    }/*  w  w w  . j  av  a  2s. com*/

    Config rc = readConfig(PROJECT_CONFIG);
    Project p = project;

    if (p.getDescription() != null && !p.getDescription().isEmpty()) {
        rc.setString(PROJECT, null, KEY_DESCRIPTION, p.getDescription());
    } else {
        rc.unset(PROJECT, null, KEY_DESCRIPTION);
    }
    set(rc, ACCESS, null, KEY_INHERIT_FROM, p.getParentName());

    set(rc, RECEIVE, null, KEY_REQUIRE_CONTRIBUTOR_AGREEMENT, p.getUseContributorAgreements(),
            InheritableBoolean.INHERIT);
    set(rc, RECEIVE, null, KEY_REQUIRE_SIGNED_OFF_BY, p.getUseSignedOffBy(), InheritableBoolean.INHERIT);
    set(rc, RECEIVE, null, KEY_REQUIRE_CHANGE_ID, p.getRequireChangeID(), InheritableBoolean.INHERIT);
    set(rc, RECEIVE, null, KEY_USE_ALL_NOT_IN_TARGET, p.getCreateNewChangeForAllNotInTarget(),
            InheritableBoolean.INHERIT);
    set(rc, RECEIVE, null, KEY_MAX_OBJECT_SIZE_LIMIT, validMaxObjectSizeLimit(p.getMaxObjectSizeLimit()));
    set(rc, RECEIVE, null, KEY_ENABLE_SIGNED_PUSH, p.getEnableSignedPush(), InheritableBoolean.INHERIT);

    set(rc, SUBMIT, null, KEY_ACTION, p.getSubmitType(), defaultSubmitAction);
    set(rc, SUBMIT, null, KEY_MERGE_CONTENT, p.getUseContentMerge(), InheritableBoolean.INHERIT);

    set(rc, PROJECT, null, KEY_STATE, p.getState(), defaultStateValue);

    set(rc, DASHBOARD, null, KEY_DEFAULT, p.getDefaultDashboard());
    set(rc, DASHBOARD, null, KEY_LOCAL_DEFAULT, p.getLocalDefaultDashboard());

    Set<AccountGroup.UUID> keepGroups = new HashSet<>();
    saveAccountsSection(rc, keepGroups);
    saveContributorAgreements(rc, keepGroups);
    saveAccessSections(rc, keepGroups);
    saveNotifySections(rc, keepGroups);
    groupList.retainUUIDs(keepGroups);
    saveLabelSections(rc);
    savePluginSections(rc);

    saveConfig(PROJECT_CONFIG, rc);
    saveGroupList();
    return true;
}

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

License:Apache License

private void saveContributorAgreements(Config rc, Set<AccountGroup.UUID> keepGroups) {
    for (ContributorAgreement ca : sort(contributorAgreements.values())) {
        set(rc, CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_DESCRIPTION, ca.getDescription());
        set(rc, CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_AGREEMENT_URL, ca.getAgreementUrl());

        if (ca.getAutoVerify() != null) {
            if (ca.getAutoVerify().getUUID() != null) {
                keepGroups.add(ca.getAutoVerify().getUUID());
            }//w w  w . j a va  2  s .  com
            String autoVerify = new PermissionRule(ca.getAutoVerify()).asString(false);
            set(rc, CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_AUTO_VERIFY, autoVerify);
        } else {
            rc.unset(CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_AUTO_VERIFY);
        }

        rc.setStringList(CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_ACCEPTED,
                ruleToStringList(ca.getAccepted(), keepGroups));
    }
}

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

License:Apache License

private void saveNotifySections(Config rc, Set<AccountGroup.UUID> keepGroups) {
    for (NotifyConfig nc : sort(notifySections.values())) {
        List<String> email = Lists.newArrayList();
        for (GroupReference gr : nc.getGroups()) {
            if (gr.getUUID() != null) {
                keepGroups.add(gr.getUUID());
            }/*from  ww w  .  ja v a 2 s  . co  m*/
            email.add(new PermissionRule(gr).asString(false));
        }
        Collections.sort(email);

        List<String> addrs = Lists.newArrayList();
        for (Address addr : nc.getAddresses()) {
            addrs.add(addr.toString());
        }
        Collections.sort(addrs);
        email.addAll(addrs);

        set(rc, NOTIFY, nc.getName(), KEY_HEADER, nc.getHeader(), NotifyConfig.Header.BCC);
        if (email.isEmpty()) {
            rc.unset(NOTIFY, nc.getName(), KEY_EMAIL);
        } else {
            rc.setStringList(NOTIFY, nc.getName(), KEY_EMAIL, email);
        }

        if (nc.getNotify().equals(EnumSet.of(NotifyType.ALL))) {
            rc.unset(NOTIFY, nc.getName(), KEY_TYPE);
        } else {
            List<String> types = Lists.newArrayListWithCapacity(4);
            for (NotifyType t : NotifyType.values()) {
                if (nc.isNotify(t)) {
                    types.add(StringUtils.toLowerCase(t.name()));
                }
            }
            rc.setStringList(NOTIFY, nc.getName(), KEY_TYPE, types);
        }

        set(rc, NOTIFY, nc.getName(), KEY_FILTER, nc.getFilter());
    }
}