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

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

Introduction

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

Prototype

public String[] getStringList(final String section, String subsection, final String name) 

Source Link

Document

Get a list of string values

If this instance was created with a base, the base's values are returned first (if any).

Usage

From source file:com.google.gerrit.server.schema.Schema_57.java

License:Apache License

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
    SystemConfig sc = db.systemConfig().get(new SystemConfig.Key());
    Project.NameKey allProjects = sc.wildProjectName;

    FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config, FS.DETECTED);
    boolean cfgDirty = false;
    try {/*ww  w .  jav  a  2s .  c  o  m*/
        cfg.load();
    } catch (ConfigInvalidException err) {
        throw new OrmException("Cannot read " + site.gerrit_config, err);
    } catch (IOException err) {
        throw new OrmException("Cannot read " + site.gerrit_config, err);
    }

    if (!allProjects.get().equals(AllProjectsNameProvider.DEFAULT)) {
        ui.message("Setting gerrit.allProjects = " + allProjects.get());
        cfg.setString("gerrit", null, "allProjects", allProjects.get());
        cfgDirty = true;
    }

    try {
        Repository git = mgr.openRepository(allProjects);
        try {
            MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allProjects, git);
            md.getCommitBuilder().setAuthor(serverUser);
            md.getCommitBuilder().setCommitter(serverUser);

            ProjectConfig config = ProjectConfig.read(md);
            AccessSection cap = config.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true);

            // Move the Administrators group reference to All-Projects.
            cap.getPermission(GlobalCapability.ADMINISTRATE_SERVER, true)
                    .add(new PermissionRule(config.resolve(db.accountGroups().get(sc.adminGroupId))));

            // Move the repository.*.createGroup to Create Project.
            String[] createGroupList = cfg.getStringList("repository", "*", "createGroup");

            // Prepare the account_group_includes query
            PreparedStatement stmt = ((JdbcSchema) db).getConnection()
                    .prepareStatement("SELECT * FROM account_group_includes WHERE group_id = ?");

            for (String name : createGroupList) {
                AccountGroup.NameKey key = new AccountGroup.NameKey(name);
                AccountGroupName groupName = db.accountGroupNames().get(key);
                if (groupName == null) {
                    continue;
                }

                AccountGroup group = db.accountGroups().get(groupName.getId());
                if (group == null) {
                    continue;
                }

                cap.getPermission(GlobalCapability.CREATE_PROJECT, true)
                        .add(new PermissionRule(config.resolve(group)));
            }
            if (createGroupList.length != 0) {
                ui.message("Moved repository.*.createGroup to 'Create Project' capability");
                cfg.unset("repository", "*", "createGroup");
                cfgDirty = true;
            }

            AccountGroup batch = db.accountGroups().get(sc.batchUsersGroupId);
            stmt.setInt(1, sc.batchUsersGroupId.get());
            if (batch != null && db.accountGroupMembers().byGroup(sc.batchUsersGroupId).toList().isEmpty()
                    && stmt.executeQuery().first() != false) {
                // If the batch user group is not used, delete it.
                //
                db.accountGroups().delete(Collections.singleton(batch));

                AccountGroupName name = db.accountGroupNames().get(batch.getNameKey());
                if (name != null) {
                    db.accountGroupNames().delete(Collections.singleton(name));
                }
            } else if (batch != null) {
                cap.getPermission(GlobalCapability.PRIORITY, true).getRule(config.resolve(batch), true)
                        .setAction(Action.BATCH);
            }

            md.setMessage("Upgrade to Gerrit Code Review schema 57\n");
            config.commit(md);
        } catch (SQLException err) {
            throw new OrmException("Cannot read account_group_includes", err);
        } finally {
            git.close();
        }
    } catch (ConfigInvalidException err) {
        throw new OrmException("Cannot read " + allProjects, err);
    } catch (IOException err) {
        throw new OrmException("Cannot update " + allProjects, err);
    }

    if (cfgDirty) {
        try {
            cfg.save();
        } catch (IOException err) {
            throw new OrmException("Cannot update " + site.gerrit_config, err);
        }
    }

    // We cannot set the columns to NULL, so use 0 and a DELETED tag.
    sc.adminGroupId = new AccountGroup.Id(0);
    sc.adminGroupUUID = new AccountGroup.UUID("DELETED");
    sc.anonymousGroupId = new AccountGroup.Id(0);
    sc.registeredGroupId = new AccountGroup.Id(0);
    sc.wildProjectName = new Project.NameKey("DELETED");
    sc.ownerGroupId = new AccountGroup.Id(0);
    sc.batchUsersGroupId = new AccountGroup.Id(0);
    sc.batchUsersGroupUUID = new AccountGroup.UUID("DELETED");
    sc.registerEmailPrivateKey = "DELETED";

    db.systemConfig().update(Collections.singleton(sc));
}

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

License:Apache License

/**
 * Loads the rules for the RuleBase./*from  w ww  .  jav a  2  s . c  om*/
 *
 * 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();
    }
}

From source file:com.googlesource.gerrit.plugins.secureconfig.SecureConfigStore.java

License:Apache License

@Override
public synchronized String[] getListForPlugin(String pluginName, String section, String subsection,
        String name) {/* w  w  w  . j a v a  2  s . c om*/
    FileBasedConfig cfg = null;
    if (pluginSec.containsKey(pluginName)) {
        cfg = pluginSec.get(pluginName);
    } else {
        String filename = pluginName + ".secure.config";
        File pluginConfigFile = site.etc_dir.resolve(filename).toFile();
        if (pluginConfigFile.exists()) {
            cfg = new FileBasedConfig(pluginConfigFile, FS.DETECTED);
            try {
                cfg.load();
                pluginSec.put(pluginName, cfg);
            } catch (IOException | ConfigInvalidException e) {
                throw new RuntimeException("Cannot load " + filename, e);
            }
        }
    }
    return cfg != null
            ? FluentIterable.from(cfg.getStringList(section, subsection, name)).transform(codec::decode)
                    .toArray(String.class)
            : null;
}

From source file:net.polydawn.mdm.Plumbing.java

License:Open Source License

/**
 * Copy in `url` git config keys from the parent repo config into the submodule config.
 * This allows for easily having per-project 'insteadof' url rewrites which apply even
 * when mdm is doing the creation of new repos (which is otherwise a tad hard to get at with git submodules).
 * @return true if module.getRepo().getConfig() has been modified and should be saved.
 * @throws ConfigInvalidException// w  ww .  ja v  a2s  . c  o m
 * @throws IOException
 */
public static boolean initModuleConfig(Repository repo, MdmModule module)
        throws IOException, ConfigInvalidException {
    Config moduleConfig = module.getRepo().getConfig();
    // have to explicitly load the parent repo config in isolate, because `repo.getConfig` includes views of the system and user gitconfig, which we won't want to proxy here.
    FileBasedConfig parentConfig = new FileBasedConfig(new File(repo.getDirectory(), "config"), repo.getFS());
    try {
        parentConfig.load();
    } catch (IOException e) {
        throw new MdmRepositoryIOException(false, "the local git configuration file", e);
    }

    // copy any url_insteadof patterns from the parent repo's git config into the module's git config.
    // note that we do not strip out any additional insteadof's the module may have; if you've added those, it's none of our business (though at this point, we do overwrite).
    // see org.eclipse.jgit.transport.RemoteConfig for how these actually get used.
    for (String url : parentConfig.getSubsections(ConfigConstants.CONFIG_KEY_URL))
        for (String insteadOf : parentConfig.getStringList(ConfigConstants.CONFIG_KEY_URL, url, "insteadof"))
            moduleConfig.setString(ConfigConstants.CONFIG_KEY_URL, url, "insteadof", insteadOf);
    for (String url : parentConfig.getSubsections(ConfigConstants.CONFIG_KEY_URL))
        for (String insteadOf : parentConfig.getStringList(ConfigConstants.CONFIG_KEY_URL, url,
                "pushinsteadof"))
            moduleConfig.setString(ConfigConstants.CONFIG_KEY_URL, url, "pushinsteadof", insteadOf);
    return true;
}

From source file:org.libreoffice.ci.gerrit.buildbot.config.BuildbotConfigProvider.java

License:Mozilla Public License

private BuildbotProject parseProject(BuildbotConfig config, FileBasedConfig cfg, String name) {
    BuildbotProject p = new BuildbotProject(name);
    String[] branches = cfg.getStringList(SECTION_PROJECT, name, KEY_BRANCH);
    String strStrategie = cfg.getString(SECTION_PROJECT, name, KEY_TRIGGER);

    Preconditions.checkNotNull(strStrategie, "strategie must not be null");

    p.setBranches(branches);//from  w  w w  .ja  v a  2  s.  c om

    TriggerStrategy triggerStrategie = TriggerStrategy.valueOf(strStrategie.toUpperCase());
    Preconditions.checkNotNull(triggerStrategie, String.format("unknown strategie %s", strStrategie));

    p.setTriggerStrategy(triggerStrategie);
    if (triggerStrategie == TriggerStrategy.POSITIVE_REVIEW) {
        String reviewerGroupName = cfg.getString(SECTION_PROJECT, name, KEY_REVIEWER_GROUP_NAME);
        Preconditions.checkNotNull(reviewerGroupName, "reviewerGroupName must not be null");
        p.setReviewerGroupId(getGroup(reviewerGroupName));
    }
    String buildbotAdminGroupName = cfg.getString(SECTION_PROJECT, name, KEY_BUILDBOT_ADMIN_GROUP_NAME);
    if (buildbotAdminGroupName != null) {
        p.setBuildbotAdminGroupId(getGroup(buildbotAdminGroupName));
    } else {
        p.setBuildbotAdminGroupId(config.getBuildbotAdminGroupId());
    }
    String buildbotUserGroupName = cfg.getString(SECTION_PROJECT, name, KEY_BUILDBOT_USER_GROUP_NAME);
    p.setBuildbotUserGroupId(
            buildbotUserGroupName == null ? config.getBuildbotUserGroupId() : getGroup(buildbotUserGroupName));
    return p;
}