List of usage examples for org.eclipse.jgit.lib Config getNames
public Set<String> getNames(String section)
From source file:com.google.gerrit.server.git.ProjectConfig.java
License:Apache License
private void saveAccessSections(Config rc, Set<AccountGroup.UUID> keepGroups) { AccessSection capability = accessSections.get(AccessSection.GLOBAL_CAPABILITIES); if (capability != null) { Set<String> have = new HashSet<>(); for (Permission permission : sort(capability.getPermissions())) { have.add(permission.getName().toLowerCase()); boolean needRange = GlobalCapability.hasRange(permission.getName()); List<String> rules = new ArrayList<>(); for (PermissionRule rule : sort(permission.getRules())) { GroupReference group = rule.getGroup(); if (group.getUUID() != null) { keepGroups.add(group.getUUID()); }/*from w w w . j a v a 2 s . c o m*/ rules.add(rule.asString(needRange)); } rc.setStringList(CAPABILITY, null, permission.getName(), rules); } for (String varName : rc.getNames(CAPABILITY)) { if (!have.contains(varName.toLowerCase())) { rc.unset(CAPABILITY, null, varName); } } } else { rc.unsetSection(CAPABILITY, null); } for (AccessSection as : sort(accessSections.values())) { String refName = as.getName(); if (AccessSection.GLOBAL_CAPABILITIES.equals(refName)) { continue; } StringBuilder doNotInherit = new StringBuilder(); for (Permission perm : sort(as.getPermissions())) { if (perm.getExclusiveGroup()) { if (0 < doNotInherit.length()) { doNotInherit.append(' '); } doNotInherit.append(perm.getName()); } } if (0 < doNotInherit.length()) { rc.setString(ACCESS, refName, KEY_GROUP_PERMISSIONS, doNotInherit.toString()); } else { rc.unset(ACCESS, refName, KEY_GROUP_PERMISSIONS); } Set<String> have = new HashSet<>(); for (Permission permission : sort(as.getPermissions())) { have.add(permission.getName().toLowerCase()); boolean needRange = Permission.hasRange(permission.getName()); List<String> rules = new ArrayList<>(); for (PermissionRule rule : sort(permission.getRules())) { GroupReference group = rule.getGroup(); if (group.getUUID() != null) { keepGroups.add(group.getUUID()); } rules.add(rule.asString(needRange)); } rc.setStringList(ACCESS, refName, permission.getName(), rules); } for (String varName : rc.getNames(ACCESS, refName)) { if (isPermission(varName) && !have.contains(varName.toLowerCase())) { rc.unset(ACCESS, refName, varName); } } } for (String name : rc.getSubsections(ACCESS)) { if (RefConfigSection.isValid(name) && !accessSections.containsKey(name)) { rc.unsetSection(ACCESS, name); } } }
From source file:com.google.gerrit.server.git.ProjectLevelConfig.java
License:Apache License
public Config getWithInheritance() { Config cfgWithInheritance = new Config(); try {/*from www. j a v a 2 s .c om*/ cfgWithInheritance.fromText(get().toText()); } catch (ConfigInvalidException e) { // cannot happen } ProjectState parent = Iterables.getFirst(project.parents(), null); if (parent != null) { Config parentCfg = parent.getConfig(fileName).getWithInheritance(); for (String section : parentCfg.getSections()) { Set<String> allNames = get().getNames(section); for (String name : parentCfg.getNames(section)) { if (!allNames.contains(name)) { cfgWithInheritance.setStringList(section, null, name, Arrays.asList(parentCfg.getStringList(section, null, name))); } } for (String subsection : parentCfg.getSubsections(section)) { allNames = get().getNames(section, subsection); for (String name : parentCfg.getNames(section, subsection)) { if (!allNames.contains(name)) { cfgWithInheritance.setStringList(section, subsection, name, Arrays.asList(parentCfg.getStringList(section, subsection, name))); } } } } } return cfgWithInheritance; }
From source file:com.googlesource.gerrit.plugins.rabbitmq.config.section.Sections.java
License:Apache License
public static <T extends Section> Section fromConfig(T section, Config... configs) { for (Config config : configs) { if (config != null) { Set<String> names = config.getNames(getName(section)); Field[] fs = section.getClass().getFields(); for (Field f : fs) { try { if (names.contains(f.getName())) { Class<?> type = f.getType(); if (type == String.class) { f.set(section, config.getString(getName(section), null, f.getName())); } else if (type == Integer.class) { f.set(section, config.getInt(getName(section), null, f.getName(), 0)); } else if (type == Long.class) { f.set(section, config.getLong(getName(section), null, f.getName(), 0)); } else if (type == Boolean.class) { f.set(section, config.getBoolean(getName(section), null, f.getName(), false)); }//w w w . j av a2 s.c o m } } catch (IllegalAccessException ex) { LOGGER.warn("Cannot access field {}. Cause: {}", f.getName(), ex.getMessage()); } } } } return section; }
From source file:org.eclipse.orion.server.git.servlets.GitConfigHandlerV1.java
License:Open Source License
/** * Converts whole config to JSON representation. *//*from www. j av a2 s .c o m*/ JSONObject configToJSON(Config config, URI baseLocation, BaseToConfigEntryConverter uriConverter) throws JSONException, URISyntaxException { JSONObject result = new JSONObject(); JSONArray children = new JSONArray(); for (String section : config.getSections()) { // proceed configuration entries: section.name for (String name : config.getNames(section)) children.put(configEntryToJSON(config, new String[] { section, null, name }, baseLocation, uriConverter)); // proceed configuration entries: section.subsection.name for (String subsection : config.getSubsections(section)) for (String name : config.getNames(section, subsection)) children.put(configEntryToJSON(config, new String[] { section, subsection, name }, baseLocation, uriConverter)); } result.put(ProtocolConstants.KEY_CHILDREN, children); return result; }