Adapt to API change in Gerrit core
Change I1c24da1378 in Gerrit core moved the Accounts.byEmail(String)
and Accounts.byEmails(String...) methods into a new Emails class. These
methods are now called Emails.getAccountFor(String) and
Emails.getAccountsFor(String...).
Change-Id: If63202ff7bcefa1f6bd0af4dc07b7303a8e2273d
Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
index 0eba65b..f4dbca4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
@@ -27,7 +27,7 @@
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountCache;
-import com.google.gerrit.server.account.Accounts;
+import com.google.gerrit.server.account.Emails;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.change.RevisionResource;
import com.google.gerrit.server.config.PluginConfigFactory;
@@ -55,7 +55,7 @@
private static final Logger log = LoggerFactory.getLogger(Action.class);
private AccountCache accountCache;
- private Accounts accounts;
+ private Emails emails;
private ChangeData.Factory changeDataFactory;
private GitRepositoryManager repoManager;
private Provider<CurrentUser> userProvider;
@@ -74,13 +74,13 @@
SchemaFactory<ReviewDb> reviewDbProvider,
ChangeData.Factory changeDataFactory,
AccountCache accountCache,
- Accounts accounts,
+ Emails emails,
GitRepositoryManager repoManager) {
this.userProvider = userProvider;
this.reviewDbProvider = reviewDbProvider;
this.changeDataFactory = changeDataFactory;
this.accountCache = accountCache;
- this.accounts = accounts;
+ this.emails = emails;
this.repoManager = repoManager;
Config.setVariables(pluginName, configFactory);
Cache.getInstance(); // Create a single Cache.
@@ -171,7 +171,7 @@
Repository repository, Parameters params, ChangeData changeData)
throws OrmException, BadRequestException {
int patchset = getValidPatchsetNum(changeData, params.patchset);
- OwnersDb db = Cache.getInstance().get(accountCache, accounts, repository, changeData, patchset);
+ OwnersDb db = Cache.getInstance().get(accountCache, emails, repository, changeData, patchset);
Collection<String> changedFiles = changeData.currentFilePaths();
Map<String, Set<String>> file2Owners = db.findOwners(changedFiles);
@@ -216,7 +216,7 @@
if (needFindOwners && !Config.getAlwaysShowButton()) {
needFindOwners = false; // Show button only if some owner is found.
try (Repository repo = repoManager.openRepository(change.getProject())) {
- OwnersDb db = Cache.getInstance().get(accountCache, accounts, repo, changeData);
+ OwnersDb db = Cache.getInstance().get(accountCache, emails, repo, changeData);
log.trace("getDescription db key = " + db.key);
needFindOwners = db.getNumOwners() > 0;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/Cache.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/Cache.java
index 10fdebf..b9e1f43 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Cache.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Cache.java
@@ -19,7 +19,7 @@
import com.google.common.cache.CacheBuilder;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.account.AccountCache;
-import com.google.gerrit.server.account.Accounts;
+import com.google.gerrit.server.account.Emails;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
import java.util.Collection;
@@ -87,16 +87,16 @@
}
/** Returns a cached or new OwnersDb, for the current patchset. */
- OwnersDb get(AccountCache accountCache, Accounts accounts, Repository repo, ChangeData changeData)
+ OwnersDb get(AccountCache accountCache, Emails emails, Repository repo, ChangeData changeData)
throws OrmException {
return get(
- accountCache, accounts, repo, changeData, changeData.currentPatchSet().getId().get());
+ accountCache, emails, repo, changeData, changeData.currentPatchSet().getId().get());
}
/** Returns a cached or new OwnersDb, for the specified patchset. */
OwnersDb get(
AccountCache accountCache,
- Accounts accounts,
+ Emails emails,
Repository repository,
ChangeData changeData,
int patchset)
@@ -106,13 +106,13 @@
String dbKey = Cache.makeKey(changeData.getId().get(), patchset, branch);
// TODO: get changed files of the given patchset?
return get(
- accountCache, accounts, dbKey, repository, project, branch, changeData.currentFilePaths());
+ accountCache, emails, dbKey, repository, project, branch, changeData.currentFilePaths());
}
/** Returns a cached or new OwnersDb, for the specified branch and changed files. */
OwnersDb get(
AccountCache accountCache,
- Accounts accounts,
+ Emails emails,
String key,
Repository repository,
Project.NameKey project,
@@ -120,7 +120,7 @@
Collection<String> files) {
if (dbCache == null) { // Do not cache OwnersDb
log.trace("Create new OwnersDb, key=" + key);
- return new OwnersDb(accountCache, accounts, key, repository, project, branch, files);
+ return new OwnersDb(accountCache, emails, key, repository, project, branch, files);
}
try {
log.trace("Get from cash " + dbCache + ", key=" + key + ", cache size=" + dbCache.size());
@@ -130,12 +130,12 @@
@Override
public OwnersDb call() {
log.trace("Create new OwnersDb, key=" + key);
- return new OwnersDb(accountCache, accounts, key, repository, project, branch, files);
+ return new OwnersDb(accountCache, emails, key, repository, project, branch, files);
}
});
} catch (ExecutionException e) {
log.error("Cache.get has exception: " + e);
- return new OwnersDb(accountCache, accounts, key, repository, project, branch, files);
+ return new OwnersDb(accountCache, emails, key, repository, project, branch, files);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/Checker.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/Checker.java
index 6b9897d..8ecca66 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Checker.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Checker.java
@@ -18,7 +18,7 @@
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.rules.StoredValues;
import com.google.gerrit.server.account.AccountCache;
-import com.google.gerrit.server.account.Accounts;
+import com.google.gerrit.server.account.Emails;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
import com.googlecode.prolog_cafe.lang.Prolog;
@@ -103,10 +103,10 @@
public static int findApproval(Prolog engine, int minVoteLevel) {
try {
AccountCache accountCache = StoredValues.ACCOUNT_CACHE.get(engine);
- Accounts accounts = StoredValues.ACCOUNTS.get(engine);
+ Emails emails = StoredValues.EMAILS.get(engine);
ChangeData changeData = StoredValues.CHANGE_DATA.get(engine);
Repository repository = StoredValues.REPOSITORY.get(engine);
- return new Checker(repository, changeData, minVoteLevel).findApproval(accountCache, accounts);
+ return new Checker(repository, changeData, minVoteLevel).findApproval(accountCache, emails);
} catch (OrmException e) {
log.error("Exception", e);
return 0; // owner approval may or may not be required.
@@ -129,13 +129,13 @@
return (status == Status.ABANDONED || status == Status.MERGED);
}
- int findApproval(AccountCache accountCache, Accounts accounts) throws OrmException {
+ int findApproval(AccountCache accountCache, Emails emails) throws OrmException {
if (isExemptFromOwnerApproval(changeData)) {
return 0;
}
// One update to a Gerrit change can call submit_rule or submit_filter
// many times. So this function should use cached values.
- OwnersDb db = Cache.getInstance().get(accountCache, accounts, repository, changeData);
+ OwnersDb db = Cache.getInstance().get(accountCache, emails, repository, changeData);
if (db.getNumOwners() <= 0) {
return 0;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/GetOwners.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/GetOwners.java
index e918be7..fd60850 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/GetOwners.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/GetOwners.java
@@ -21,7 +21,7 @@
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.account.AccountCache;
-import com.google.gerrit.server.account.Accounts;
+import com.google.gerrit.server.account.Emails;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.config.PluginConfigFactory;
import com.google.gerrit.server.git.GitRepositoryManager;
@@ -57,7 +57,7 @@
SchemaFactory<ReviewDb> reviewDbProvider,
ChangeData.Factory dataFactory,
AccountCache accountCache,
- Accounts accounts,
+ Emails emails,
GitRepositoryManager repoManager) {
this.action =
new Action(
@@ -67,7 +67,7 @@
reviewDbProvider,
dataFactory,
accountCache,
- accounts,
+ emails,
repoManager);
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java
index 381430d..3d4eb82 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java
@@ -20,7 +20,7 @@
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.account.AccountCache;
-import com.google.gerrit.server.account.Accounts;
+import com.google.gerrit.server.account.Emails;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.PathMatcher;
@@ -46,7 +46,7 @@
private static final Logger log = LoggerFactory.getLogger(OwnersDb.class);
private AccountCache accountCache;
- private Accounts accounts;
+ private Emails emails;
private int numOwners = -1; // # of owners of all given files.
String key = ""; // key to find this OwnersDb in a cache.
@@ -63,14 +63,14 @@
OwnersDb(
AccountCache accountCache,
- Accounts accounts,
+ Emails emails,
String key,
Repository repository,
Project.NameKey project,
String branch,
Collection<String> files) {
this.accountCache = accountCache;
- this.accounts = accounts;
+ this.emails = emails;
this.key = key;
preferredEmails.put("*", "*");
String ownersFileName = Config.getOwnersFileName(project);
@@ -132,15 +132,15 @@
List<String> owners = new ArrayList<>(ownerEmails);
owners.removeIf(o -> preferredEmails.get(o) != null);
if (!owners.isEmpty()) {
- String[] emails = new String[owners.size()];
- owners.toArray(emails);
+ String[] ownerEmailsAsArray = new String[owners.size()];
+ owners.toArray(ownerEmailsAsArray);
Multimap<String, Account.Id> email2ids = null;
try {
- email2ids = accounts.byEmails(emails);
+ email2ids = emails.getAccountsFor(ownerEmailsAsArray);
} catch (Exception e) {
log.error("accounts.byEmails failed with exception: ", e);
}
- for (String owner : emails) {
+ for (String owner : ownerEmailsAsArray) {
String email = owner;
try {
if (email2ids == null) {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwnersIT.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwnersIT.java
index b72c860..cc7d73a 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwnersIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwnersIT.java
@@ -32,6 +32,7 @@
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
+import com.google.gerrit.server.account.Emails;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.config.PluginConfigFactory;
import com.google.inject.Inject;
@@ -48,6 +49,7 @@
@TestPlugin(name = "find-owners", sysModule = "com.googlesource.gerrit.plugins.findowners.Module")
public class FindOwnersIT extends LightweightPluginDaemonTest {
+ @Inject private Emails emails;
@Inject private PluginConfigFactory configFactory;
@Test
@@ -186,12 +188,12 @@
gApi.accounts().id(users[i]).addEmail(input);
}
// Find accounts with given first and second email addresses.
- // OwnersDb uses either accounts.byEmail or byEmails to get preferred email addresses.
- Multimap<String, Account.Id> map1 = accounts.byEmails(emails1);
- Multimap<String, Account.Id> map2 = accounts.byEmails(emails2);
+ // OwnersDb uses either emails.getAccountFor or getAccountsFor to get preferred email addresses.
+ Multimap<String, Account.Id> map1 = emails.getAccountsFor(emails1);
+ Multimap<String, Account.Id> map2 = emails.getAccountsFor(emails2);
for (int i = 0; i < users.length; i++) {
- Collection<Account.Id> ids1 = accounts.byEmail(emails1[i]);
- Collection<Account.Id> ids2 = accounts.byEmail(emails2[i]);
+ Collection<Account.Id> ids1 = emails.getAccountFor(emails1[i]);
+ Collection<Account.Id> ids2 = emails.getAccountFor(emails2[i]);
Collection<Account.Id> ids3 = map1.get(emails1[i]);
Collection<Account.Id> ids4 = map2.get(emails2[i]);
assertThat(ids1).hasSize(1);
@@ -210,9 +212,9 @@
}
// Wrong or non-existing email address.
String[] wrongEmails = {"nobody", "@g.com", "nobody@g.com", "*"};
- Multimap<String, Account.Id> email2ids = accounts.byEmails(wrongEmails);
+ Multimap<String, Account.Id> email2ids = emails.getAccountsFor(wrongEmails);
for (String email : wrongEmails) {
- assertThat(accounts.byEmail(email)).isEmpty();
+ assertThat(emails.getAccountFor(email)).isEmpty();
assertThat(email2ids.get(email)).isEmpty();
}
}
@@ -331,7 +333,7 @@
null,
changeDataFactory,
accountCache,
- accounts,
+ emails,
repoManager);
Response<RestResult> response = action.apply(db, cr, param);
RestResult result = response.value();
@@ -443,7 +445,7 @@
private int checkApproval(PushOneCommit.Result r) throws Exception {
Repository repo = repoManager.openRepository(r.getChange().project());
Cache cache = Cache.getInstance().init(0, 0);
- OwnersDb db = cache.get(accountCache, accounts, repo, r.getChange(), 1);
+ OwnersDb db = cache.get(accountCache, emails, repo, r.getChange(), 1);
Checker c = new Checker(repo, r.getChange(), 1);
return c.findApproval(accountCache, db);
}