Merge changes I711cc455,If1b3c188,I8c59564b,Ia7896a1a

* changes:
  GroupIT: Rename createGroup(name) to createUniqueGroup
  CmdLineParser: Suppress raw type warnings related to args4j classes
  Remove unnecessary UiType enum
  CmdLineParser: Fix Javadoc warnings
This commit is contained in:
David Pursehouse
2018-11-18 06:49:01 +00:00
committed by Gerrit Code Review
5 changed files with 46 additions and 74 deletions

View File

@@ -1,32 +0,0 @@
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.extensions.client;
public enum UiType {
NONE,
GWT,
POLYGERRIT;
public static UiType parse(String str) {
if (str != null) {
for (UiType type : UiType.values()) {
if (type.name().equalsIgnoreCase(str)) {
return type;
}
}
}
return null;
}
}

View File

@@ -14,9 +14,6 @@
package com.google.gerrit.extensions.common;
import com.google.gerrit.extensions.client.UiType;
import java.util.Set;
public class GerritInfo {
public String allProjects;
public String allUsers;
@@ -25,5 +22,4 @@ public class GerritInfo {
public Boolean editGpgKeys;
public String reportBugUrl;
public String reportBugText;
public Set<UiType> webUis;
}

View File

@@ -20,7 +20,6 @@ import com.google.common.base.CharMatcher;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.gerrit.common.data.ContributorAgreement;
import com.google.gerrit.extensions.client.UiType;
import com.google.gerrit.extensions.common.AccountsInfo;
import com.google.gerrit.extensions.common.AuthInfo;
import com.google.gerrit.extensions.common.ChangeConfigInfo;
@@ -66,7 +65,6 @@ import com.google.inject.Inject;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
@@ -304,7 +302,6 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
info.docSearch = docSearcher.isAvailable();
info.editGpgKeys =
toBoolean(enableSignedPush && config.getBoolean("gerrit", null, "editGpgKeys", true));
info.webUis = EnumSet.noneOf(UiType.class);
return info;
}

View File

@@ -124,7 +124,6 @@ public class CmdLineParser {
/**
* get and consume (consider parsed) a parameter
*
* @param name name
* @return the consumed parameter
*/
public String consumeParameter() throws CmdLineException {
@@ -158,7 +157,7 @@ public class CmdLineParser {
* Use during parsing to call additional parameters simulating as if they had been passed from
* the command line originally.
*
* @param String... args A variable amount of parameters to call immediately
* @param args A variable amount of parameters to call immediately
* <p>The parameters will be parsed immediately, before the remaining parameter will be
* parsed.
* <p>Note: Since this is done outside of the arg4j parsing loop, it will not match exactly
@@ -504,10 +503,16 @@ public class CmdLineParser {
private class QueuedOption {
public final Option option;
@SuppressWarnings("rawtypes")
public final Setter setter;
public final String[] requiredOptions;
private QueuedOption(Option option, Setter setter, RequiresOptions requiresOptions) {
private QueuedOption(
Option option,
@SuppressWarnings("rawtypes") Setter setter,
RequiresOptions requiresOptions) {
this.option = option;
this.setter = setter;
this.requiredOptions = requiresOptions != null ? requiresOptions.value() : new String[0];
@@ -625,6 +630,7 @@ public class CmdLineParser {
* <p>Note: this is cut & pasted from the parent class in arg4j, it was private and it
* needed to be exposed.
*/
@SuppressWarnings("rawtypes")
public OptionHandler findOptionByName(String name) {
for (OptionHandler h : optionsList) {
NamedOptionDef option = (NamedOptionDef) h.option;
@@ -640,7 +646,10 @@ public class CmdLineParser {
return null;
}
private void queueOption(Option option, Setter setter, RequiresOptions requiresOptions) {
private void queueOption(
Option option,
@SuppressWarnings("rawtypes") Setter setter,
RequiresOptions requiresOptions) {
if (queuedOptionsByName.put(option.name(), new QueuedOption(option, setter, requiresOptions))
!= null) {
throw new IllegalAnnotationError(

View File

@@ -147,7 +147,7 @@ public class GroupsIT extends AbstractDaemonTest {
}
// Creates a group, but with uniquified name.
protected String createGroup(String name) throws Exception {
protected String createUniqueGroup() throws Exception {
// TODO(hanwen): rewrite this test in terms of UUID. This requires redoing the assertion helpers
// too.
AccountGroup.UUID g = groupOperations.newGroup().ownerGroupUuid(adminGroupUuid()).create();
@@ -155,6 +155,8 @@ public class GroupsIT extends AbstractDaemonTest {
}
protected String createGroup(String name, String owner) throws Exception {
// TODO(hanwen): rewrite to use groupOperations. This requires passing the owner
// group's UUID rathen than its name.
name = name(name);
GroupInput in = new GroupInput();
in.name = name;
@@ -191,7 +193,7 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void addRemoveMember() throws Exception {
String g = createGroup("users");
String g = createUniqueGroup();
gApi.groups().id(g).addMembers("user");
assertMembers(g, user);
@@ -206,7 +208,7 @@ public class GroupsIT extends AbstractDaemonTest {
// Fill the cache for the observed account.
groupIncludeCache.getGroupsWithMember(accountId);
String groupName = createGroup("users");
String groupName = createUniqueGroup();
AccountGroup.UUID groupUuid = new AccountGroup.UUID(gApi.groups().id(groupName).get().id);
gApi.groups().id(groupName).addMembers(username);
@@ -238,7 +240,7 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void addMultipleMembers() throws Exception {
String g = createGroup("users");
String g = createUniqueGroup();
String u1 = name("u1");
accountOperations.newAccount().username(u1).create();
@@ -255,7 +257,7 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void membersWithAtSignInUsernameCanBeAdded() throws Exception {
String g = createGroup("users");
String g = createUniqueGroup();
String usernameWithAt = name("u1@something");
accountOperations.newAccount().username(usernameWithAt).create();
@@ -269,7 +271,7 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void membersWithAtSignInUsernameAreNotConfusedWithSimilarUsernames() throws Exception {
String g = createGroup("users");
String g = createUniqueGroup();
String usernameWithAt = name("u1@something");
accountOperations.newAccount().username(usernameWithAt).create();
String usernameWithoutAt = name("u1something");
@@ -291,8 +293,8 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void includeRemoveGroup() throws Exception {
String p = createGroup("parent");
String g = createGroup("newGroup");
String p = createUniqueGroup();
String g = createUniqueGroup();
gApi.groups().id(p).addGroups(g);
assertIncludes(p, g);
@@ -302,7 +304,7 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void includeExternalGroup() throws Exception {
String g = createGroup("group");
String g = createUniqueGroup();
String subgroupUuid = SystemGroupBackend.REGISTERED_USERS.get();
gApi.groups().id(g).addGroups(subgroupUuid);
@@ -319,8 +321,8 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void includeExistingGroup_OK() throws Exception {
String p = createGroup("parent");
String g = createGroup("newGroup");
String p = createUniqueGroup();
String g = createUniqueGroup();
gApi.groups().id(p).addGroups(g);
assertIncludes(p, g);
gApi.groups().id(p).addGroups(g);
@@ -329,9 +331,9 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void addMultipleIncludes() throws Exception {
String p = createGroup("parent");
String g1 = createGroup("newGroup1");
String g2 = createGroup("newGroup2");
String p = createUniqueGroup();
String g1 = createUniqueGroup();
String g2 = createUniqueGroup();
List<String> groups = new ArrayList<>();
groups.add(g1);
groups.add(g2);
@@ -637,22 +639,22 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void listEmptyGroupIncludes() throws Exception {
String gx = createGroup("gx");
String gx = createUniqueGroup();
assertThat(gApi.groups().id(gx).includedGroups()).isEmpty();
}
@Test
public void includeNonExistingGroup() throws Exception {
String gx = createGroup("gx");
String gx = createUniqueGroup();
exception.expect(UnprocessableEntityException.class);
gApi.groups().id(gx).addGroups("non-existing");
}
@Test
public void listNonEmptyGroupIncludes() throws Exception {
String gx = createGroup("gx");
String gy = createGroup("gy");
String gz = createGroup("gz");
String gx = createUniqueGroup();
String gy = createUniqueGroup();
String gz = createUniqueGroup();
gApi.groups().id(gx).addGroups(gy);
gApi.groups().id(gx).addGroups(gz);
assertIncludes(gApi.groups().id(gx).includedGroups(), gy, gz);
@@ -660,8 +662,8 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void listOneIncludeMember() throws Exception {
String gx = createGroup("gx");
String gy = createGroup("gy");
String gx = createUniqueGroup();
String gy = createUniqueGroup();
gApi.groups().id(gx).addGroups(gy);
assertIncludes(gApi.groups().id(gx).includedGroups(), gy);
}
@@ -674,13 +676,13 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void listEmptyGroupMembers() throws Exception {
String group = createGroup("empty");
String group = createUniqueGroup();
assertThat(gApi.groups().id(group).members()).isEmpty();
}
@Test
public void listNonEmptyGroupMembers() throws Exception {
String group = createGroup("group");
String group = createUniqueGroup();
String user1 = name("user1");
accountOperations.newAccount().username(user1).create();
String user2 = name("user2");
@@ -692,7 +694,7 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void listOneGroupMember() throws Exception {
String group = createGroup("group");
String group = createUniqueGroup();
String user = name("user1");
accountOperations.newAccount().username(user).create();
gApi.groups().id(group).addMembers(user);
@@ -702,17 +704,17 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void listGroupMembersRecursively() throws Exception {
String gx = createGroup("gx");
String gx = createUniqueGroup();
String ux = name("ux");
accountOperations.newAccount().username(ux).create();
gApi.groups().id(gx).addMembers(ux);
String gy = createGroup("gy");
String gy = createUniqueGroup();
String uy = name("uy");
accountOperations.newAccount().username(uy).create();
gApi.groups().id(gy).addMembers(uy);
String gz = createGroup("gz");
String gz = createUniqueGroup();
String uz = name("uz");
accountOperations.newAccount().username(uz).create();
gApi.groups().id(gz).addMembers(uz);
@@ -725,7 +727,7 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void usersSeeTheirDirectMembershipWhenListingMembersRecursively() throws Exception {
String group = createGroup("group");
String group = createUniqueGroup();
gApi.groups().id(group).addMembers(user.username);
setApiUser(user);
@@ -734,8 +736,8 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void usersDoNotSeeTheirIndirectMembershipWhenListingMembersRecursively() throws Exception {
String group1 = createGroup("group1");
String group2 = createGroup("group2");
String group1 = createUniqueGroup();
String group2 = createUniqueGroup();
gApi.groups().id(group1).addGroups(group2);
gApi.groups().id(group2).addMembers(user.username);
@@ -791,7 +793,7 @@ public class GroupsIT extends AbstractDaemonTest {
@Test
public void getGroupsByOwner() throws Exception {
String parent = createGroup("test-parent");
String parent = createUniqueGroup();
List<String> children =
Arrays.asList(createGroup("test-child1", parent), createGroup("test-child2", parent));