use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class GroupReferenceTest method testEquals.
@Test
public void testEquals() {
AccountGroup.UUID uuid1 = AccountGroup.uuid("uuid-foo");
AccountGroup.UUID uuid2 = AccountGroup.uuid("uuid-bar");
String name1 = "foo";
String name2 = "bar";
GroupReference groupReference1 = GroupReference.create(uuid1, name1);
GroupReference groupReference2 = GroupReference.create(uuid1, name2);
GroupReference groupReference3 = GroupReference.create(uuid2, name1);
assertThat(groupReference1.equals(groupReference2)).isTrue();
assertThat(groupReference1.equals(groupReference3)).isFalse();
assertThat(groupReference2.equals(groupReference3)).isFalse();
}
use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class ProjectConfig method savePluginSections.
private void savePluginSections(Config rc, Set<AccountGroup.UUID> keepGroups) {
unsetSection(rc, PLUGIN);
for (Map.Entry<String, Config> e : pluginConfigs.entrySet()) {
String plugin = e.getKey();
Config pluginConfig = e.getValue();
for (String name : pluginConfig.getNames(PLUGIN, plugin)) {
String value = pluginConfig.getString(PLUGIN, plugin, name);
String groupName = GroupReference.extractGroupName(value);
if (groupName != null) {
GroupReference ref = groupList.byName(groupName);
if (ref != null && ref.getUUID() != null) {
keepGroups.add(ref.getUUID());
pluginConfig.setString(PLUGIN, plugin, name, "group " + ref.getName());
}
}
rc.setStringList(PLUGIN, plugin, name, Arrays.asList(pluginConfig.getStringList(PLUGIN, plugin, name)));
}
}
}
use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class ProjectConfig method loadNotifySections.
/**
* Parses the [notify] sections out of the configuration file.
*
* <pre>
* [notify "reviewers"]
* email = group Reviewers
* type = new_changes
*
* [notify "dev-team"]
* email = dev-team@example.com
* filter = branch:master
*
* [notify "qa"]
* email = qa@example.com
* filter = branch:\"^(maint|stable)-.*\"
* type = submitted_changes
* </pre>
*/
private void loadNotifySections(Config rc) {
notifySections = new HashMap<>();
for (String sectionName : rc.getSubsections(NOTIFY)) {
NotifyConfig.Builder n = NotifyConfig.builder();
n.setName(sectionName);
n.setFilter(rc.getString(NOTIFY, sectionName, KEY_FILTER));
EnumSet<NotifyType> types = EnumSet.noneOf(NotifyType.class);
types.addAll(ConfigUtil.getEnumList(rc, NOTIFY, sectionName, KEY_TYPE, NotifyType.ALL));
n.setNotify(types);
n.setHeader(rc.getEnum(NOTIFY, sectionName, KEY_HEADER, NotifyConfig.Header.BCC));
for (String dst : rc.getStringList(NOTIFY, sectionName, KEY_EMAIL)) {
String groupName = GroupReference.extractGroupName(dst);
if (groupName != null) {
GroupReference ref = groupList.byName(groupName);
if (ref == null) {
ref = groupList.resolve(GroupReference.create(groupName));
}
if (ref.getUUID() != null) {
n.addGroup(ref);
} else {
error(String.format("group \"%s\" not in %s", ref.getName(), GroupList.FILE_NAME));
}
} else if (dst.startsWith("user ")) {
error(String.format("%s not supported", dst));
} else {
try {
n.addAddress(Address.parse(dst));
} catch (IllegalArgumentException err) {
error(String.format("notify section \"%s\" has invalid email \"%s\"", sectionName, dst));
}
}
}
notifySections.put(sectionName, n.build());
}
}
use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class ProjectCreator method createProjectConfig.
private void createProjectConfig(CreateProjectArgs args) throws IOException, ConfigInvalidException {
try (MetaDataUpdate md = metaDataUpdateFactory.create(args.getProject())) {
ProjectConfig config = projectConfigFactory.read(md);
config.updateProject(newProject -> {
newProject.setDescription(Strings.nullToEmpty(args.projectDescription));
newProject.setSubmitType(MoreObjects.firstNonNull(args.submitType, repositoryCfg.getDefaultSubmitType(args.getProject())));
newProject.setBooleanConfig(BooleanProjectConfig.USE_CONTRIBUTOR_AGREEMENTS, args.contributorAgreements);
newProject.setBooleanConfig(BooleanProjectConfig.USE_SIGNED_OFF_BY, args.signedOffBy);
newProject.setBooleanConfig(BooleanProjectConfig.USE_CONTENT_MERGE, args.contentMerge);
newProject.setBooleanConfig(BooleanProjectConfig.CREATE_NEW_CHANGE_FOR_ALL_NOT_IN_TARGET, args.newChangeForAllNotInTarget);
newProject.setBooleanConfig(BooleanProjectConfig.REQUIRE_CHANGE_ID, args.changeIdRequired);
newProject.setBooleanConfig(BooleanProjectConfig.REJECT_EMPTY_COMMIT, args.rejectEmptyCommit);
newProject.setMaxObjectSizeLimit(args.maxObjectSizeLimit);
newProject.setBooleanConfig(BooleanProjectConfig.ENABLE_SIGNED_PUSH, args.enableSignedPush);
newProject.setBooleanConfig(BooleanProjectConfig.REQUIRE_SIGNED_PUSH, args.requireSignedPush);
if (args.newParent != null) {
newProject.setParent(args.newParent);
}
});
if (!args.ownerIds.isEmpty()) {
config.upsertAccessSection(AccessSection.ALL, all -> {
for (AccountGroup.UUID ownerId : args.ownerIds) {
GroupDescription.Basic g = groupBackend.get(ownerId);
if (g != null) {
GroupReference group = config.resolve(GroupReference.forGroup(g));
all.upsertPermission(Permission.OWNER).add(PermissionRule.builder(group));
}
}
});
}
md.setMessage("Created project\n");
config.commit(md);
md.getRepository().setGitwebDescription(args.projectDescription);
}
projectCache.onCreateProject(args.getProject());
}
use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class GroupList method resolve.
/**
* Returns the {@link GroupReference} instance that {@link GroupList} holds on to that has the
* same {@link com.google.gerrit.entities.AccountGroup.UUID} as the argument. Will store the
* argument internally, if no group with this {@link com.google.gerrit.entities.AccountGroup.UUID}
* was stored previously.
*/
public GroupReference resolve(GroupReference group) {
if (group != null) {
if (group.getUUID() == null || group.getUUID().get() == null) {
// results, nor return null the set from #uuids.
return group;
}
GroupReference ref = byUUID.get(group.getUUID());
if (ref != null) {
return ref;
}
byUUID.put(group.getUUID(), group);
}
return group;
}
Aggregations