Merge branch 'stable-3.0'

* stable-3.0:
  Upgrade bazlets to latest stable-3.0 to build with 3.0.2 API
  Upgrade bazlets to latest stable-2.16 to build with 2.16.11.1 API
  Fixes to build, run, and test on Gerrit 3.0
  Support outputting elapsed evaluation time on tasks
  Rename some local task variable to be more consistent
  Support optional preload-task
  Add optional chainable subtask support
  Allow tasks attributes to be preloaded from other tasks
  Detect and handle non-existing tasks more explicitly.
  Use NOT notation in task tests instead of "-"
  Clarify applicable queries in task tests
  Support exporting properties to task json
  task: add support to set custom properties
  Add duplicate subtask handling and tests
  Move invalid and NA task tests back to bottom.
  Add basic task loop detection test
  task: create property expansion framework
  Tasks: add support for a ${_name} property
  Remove buggy undocumented support to redefine task name
  Upgrade bazlets to latest stable-3.0
  Upgrade bazlets to latest stable-2.16 to build with 2.16.10 API
  Upgrade bazlets to latest stable-3.0 to build with 3.0.1 API
  Upgrade bazlets to latest stable-2.16
  Upgrade bazlets to latest stable-2.16 to build with 2.16.9 API

Change-Id: I58b2615f30d0c588609fad8fe00a752e9c808f9e
diff --git a/WORKSPACE b/WORKSPACE
index 510136c..079970a 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,24 +3,24 @@
 load("//:bazlets.bzl", "load_bazlets")
 
 load_bazlets(
-    commit = "631205bc4f7903d3cf656a844cab2bfd6b03f246",
+    commit = "1ddb1d6c71b77972a89aa0a717f6250ef256d166",
     #local_path = "/home/<user>/projects/bazlets",
 )
 
 # Release Plugin API
-load(
-    "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl",
-    "gerrit_api",
-)
-
-# Snapshot Plugin API
 #load(
-#    "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
-#    "gerrit_api_maven_local",
+#    "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl",
+#    "gerrit_api",
 #)
 
+# Snapshot Plugin API
+load(
+    "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
+    "gerrit_api_maven_local",
+)
+
 # Load release Plugin API
-gerrit_api()
+#gerrit_api()
 
 # Load snapshot Plugin API
-#gerrit_api_maven_local()
+gerrit_api_maven_local()
diff --git a/src/main/java/com/google/gerrit/server/git/meta/AbstractVersionedMetaData.java b/src/main/java/com/google/gerrit/server/git/meta/AbstractVersionedMetaData.java
index e5c1809..9c8f1a4 100644
--- a/src/main/java/com/google/gerrit/server/git/meta/AbstractVersionedMetaData.java
+++ b/src/main/java/com/google/gerrit/server/git/meta/AbstractVersionedMetaData.java
@@ -14,7 +14,7 @@
 
 package com.google.gerrit.server.git.meta;
 
-import com.google.gerrit.reviewdb.client.Branch;
+import com.google.gerrit.reviewdb.client.BranchNameKey;
 import java.io.IOException;
 import org.eclipse.jgit.errors.ConfigInvalidException;
 import org.eclipse.jgit.lib.CommitBuilder;
@@ -22,18 +22,18 @@
 
 /** Versioned Configuration file living in git */
 public class AbstractVersionedMetaData extends VersionedMetaData {
-  protected final Branch.NameKey branch;
+  protected final BranchNameKey branch;
   protected final String fileName;
   protected Config cfg;
 
-  public AbstractVersionedMetaData(Branch.NameKey branch, String fileName) {
+  public AbstractVersionedMetaData(BranchNameKey branch, String fileName) {
     this.branch = branch;
     this.fileName = fileName;
   }
 
   @Override
   protected String getRefName() {
-    return branch.get();
+    return branch.branch();
   }
 
   protected String getFileName() {
@@ -52,7 +52,7 @@
     return cfg;
   }
 
-  public Branch.NameKey getBranch() {
+  public BranchNameKey getBranch() {
     return branch;
   }
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfig.java b/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfig.java
index 5fcc8f1..62abfcb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfig.java
@@ -15,7 +15,7 @@
 package com.googlesource.gerrit.plugins.task;
 
 import com.google.gerrit.common.Container;
-import com.google.gerrit.reviewdb.client.Branch;
+import com.google.gerrit.reviewdb.client.BranchNameKey;
 import com.google.gerrit.server.git.meta.AbstractVersionedMetaData;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -112,7 +112,7 @@
   public boolean isVisible;
   public boolean isTrusted;
 
-  public TaskConfig(Branch.NameKey branch, String fileName, boolean isVisible, boolean isTrusted) {
+  public TaskConfig(BranchNameKey branch, String fileName, boolean isVisible, boolean isTrusted) {
     super(branch, fileName);
     this.isVisible = isVisible;
     this.isTrusted = isTrusted;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfigFactory.java b/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfigFactory.java
index d5003b4..a9fcea6 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfigFactory.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/TaskConfigFactory.java
@@ -16,7 +16,7 @@
 
 import com.google.common.flogger.FluentLogger;
 import com.google.gerrit.extensions.restapi.AuthException;
-import com.google.gerrit.reviewdb.client.Branch;
+import com.google.gerrit.reviewdb.client.BranchNameKey;
 import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.config.AllProjectsName;
@@ -44,7 +44,7 @@
   protected final CurrentUser user;
   protected final AllProjectsName allProjects;
 
-  protected final Map<Branch.NameKey, PatchSetArgument> psaMasquerades = new HashMap<>();
+  protected final Map<BranchNameKey, PatchSetArgument> psaMasquerades = new HashMap<>();
 
   @Inject
   protected TaskConfigFactory(
@@ -66,11 +66,11 @@
     psaMasquerades.put(psa.change.getDest(), psa);
   }
 
-  protected Branch.NameKey getRootBranch() {
-    return new Branch.NameKey(allProjects, "refs/meta/config");
+  protected BranchNameKey getRootBranch() {
+    return BranchNameKey.create(allProjects, "refs/meta/config");
   }
 
-  public TaskConfig getTaskConfig(Branch.NameKey branch, String fileName, boolean isTrusted)
+  public TaskConfig getTaskConfig(BranchNameKey branch, String fileName, boolean isTrusted)
       throws ConfigInvalidException, IOException {
     PatchSetArgument psa = psaMasquerades.get(branch);
     boolean visible = true; // invisible psas are filtered out by commandline
@@ -78,10 +78,10 @@
       visible = canRead(branch);
     } else {
       isTrusted = false;
-      branch = new Branch.NameKey(psa.change.getProject(), psa.patchSet.getId().toRefName());
+      branch = BranchNameKey.create(psa.change.getProject(), psa.patchSet.refName());
     }
 
-    Project.NameKey project = branch.getParentKey();
+    Project.NameKey project = branch.project();
     TaskConfig cfg = new TaskConfig(branch, fileName, visible, isTrusted);
     try (Repository git = gitMgr.openRepository(project)) {
       cfg.load(project, git);
@@ -94,11 +94,11 @@
     return cfg;
   }
 
-  public boolean canRead(Branch.NameKey branch) {
+  public boolean canRead(BranchNameKey branch) {
     try {
       PermissionBackend.ForProject permissions =
-          permissionBackend.user(user).project(branch.getParentKey());
-      permissions.ref(branch.get()).check(RefPermission.READ);
+          permissionBackend.user(user).project(branch.project());
+      permissions.ref(branch.branch()).check(RefPermission.READ);
       return true;
     } catch (AuthException | PermissionBackendException e) {
       return false;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/TaskTree.java b/src/main/java/com/googlesource/gerrit/plugins/task/TaskTree.java
index 9a0770e..4157e38 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/TaskTree.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/TaskTree.java
@@ -16,7 +16,7 @@
 
 import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
 import com.google.gerrit.reviewdb.client.Account;
-import com.google.gerrit.reviewdb.client.Branch;
+import com.google.gerrit.reviewdb.client.BranchNameKey;
 import com.google.gerrit.reviewdb.client.RefNames;
 import com.google.gerrit.server.AnonymousUser;
 import com.google.gerrit.server.CurrentUser;
@@ -184,7 +184,7 @@
       return getTasks(resolveUserBranch(external.user), external.file);
     }
 
-    protected List<Task> getTasks(Branch.NameKey branch, String file)
+    protected List<Task> getTasks(BranchNameKey branch, String file)
         throws ConfigInvalidException, IOException {
       return taskFactory
           .getTaskConfig(branch, resolveTaskFileName(file), definition.isTrusted)
@@ -202,18 +202,18 @@
       return p.toString();
     }
 
-    protected Branch.NameKey resolveUserBranch(String user)
+    protected BranchNameKey resolveUserBranch(String user)
         throws ConfigInvalidException, IOException {
       if (user == null) {
         throw new ConfigInvalidException("External user not defined");
       }
       Account.Id acct;
       try {
-        acct = accountResolver.resolve(user).asUnique().getAccount().getId();
+        acct = accountResolver.resolve(user).asUnique().getAccount().id();
       } catch (UnprocessableEntityException e) {
         throw new ConfigInvalidException("Cannot resolve user: " + user);
       }
-      return new Branch.NameKey(allUsers.get(), RefNames.refsUsers(acct));
+      return BranchNameKey.create(allUsers.get(), RefNames.refsUsers(acct));
     }
   }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/task/cli/PatchSetArgument.java b/src/main/java/com/googlesource/gerrit/plugins/task/cli/PatchSetArgument.java
index 9fbddeb..f641816 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/task/cli/PatchSetArgument.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/task/cli/PatchSetArgument.java
@@ -48,7 +48,7 @@
     public PatchSetArgument createForArgument(String token) {
       try {
         PatchSet.Id patchSetId = parsePatchSet(token);
-        ChangeNotes changeNotes = notesFactory.createChecked(patchSetId.getParentKey());
+        ChangeNotes changeNotes = notesFactory.createChecked(patchSetId.changeId());
         permissionBackend.user(user).change(changeNotes).check(ChangePermission.READ);
         return new PatchSetArgument(changeNotes.getChange(), psUtil.get(changeNotes, patchSetId));
       } catch (PermissionBackendException | AuthException e) {
@@ -90,7 +90,7 @@
   }
 
   public void ensureLatest() {
-    if (!change.currentPatchSetId().equals(patchSet.getId())) {
+    if (!change.currentPatchSetId().equals(patchSet.id())) {
       throw new IllegalArgumentException(patchSet + " is not the latest patch set");
     }
   }