Search in sources :

Example 1 with ConfigParameterInfo

use of com.google.gerrit.extensions.api.projects.ConfigInfo.ConfigParameterInfo in project gerrit by GerritCodeReview.

the class ConfigInfoCreator method getPluginConfig.

private static Map<String, Map<String, ConfigParameterInfo>> getPluginConfig(ProjectState project, DynamicMap<ProjectConfigEntry> pluginConfigEntries, PluginConfigFactory cfgFactory, AllProjectsName allProjects) {
    TreeMap<String, Map<String, ConfigParameterInfo>> pluginConfig = new TreeMap<>();
    for (Extension<ProjectConfigEntry> e : pluginConfigEntries) {
        ProjectConfigEntry configEntry = e.getProvider().get();
        PluginConfig cfg = cfgFactory.getFromProjectConfig(project, e.getPluginName());
        String configuredValue = cfg.getString(e.getExportName());
        ConfigParameterInfo p = new ConfigParameterInfo();
        p.displayName = configEntry.getDisplayName();
        p.description = configEntry.getDescription();
        p.warning = configEntry.getWarning(project);
        p.type = configEntry.getType();
        p.permittedValues = configEntry.getPermittedValues();
        p.editable = configEntry.isEditable(project) ? true : null;
        if (configEntry.isInheritable() && !allProjects.equals(project.getNameKey())) {
            PluginConfig cfgWithInheritance = cfgFactory.getFromProjectConfigWithInheritance(project, e.getPluginName());
            p.inheritable = true;
            p.value = configEntry.onRead(project, cfgWithInheritance.getString(e.getExportName(), configEntry.getDefaultValue()));
            p.configuredValue = configuredValue;
            p.inheritedValue = getInheritedValue(project, cfgFactory, e);
        } else {
            if (configEntry.getType() == ProjectConfigEntryType.ARRAY) {
                p.values = configEntry.onRead(project, Arrays.asList(cfg.getStringList(e.getExportName())));
            } else {
                p.value = configEntry.onRead(project, configuredValue != null ? configuredValue : configEntry.getDefaultValue());
            }
        }
        Map<String, ConfigParameterInfo> pc = pluginConfig.get(e.getPluginName());
        if (pc == null) {
            pc = new TreeMap<>();
            pluginConfig.put(e.getPluginName(), pc);
        }
        pc.put(e.getExportName(), p);
    }
    return !pluginConfig.isEmpty() ? pluginConfig : null;
}
Also used : PluginConfig(com.google.gerrit.server.config.PluginConfig) ProjectConfigEntry(com.google.gerrit.server.config.ProjectConfigEntry) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) ConfigParameterInfo(com.google.gerrit.extensions.api.projects.ConfigInfo.ConfigParameterInfo)

Aggregations

ConfigParameterInfo (com.google.gerrit.extensions.api.projects.ConfigInfo.ConfigParameterInfo)1 DynamicMap (com.google.gerrit.extensions.registration.DynamicMap)1 PluginConfig (com.google.gerrit.server.config.PluginConfig)1 ProjectConfigEntry (com.google.gerrit.server.config.ProjectConfigEntry)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1