Merge branch 'stable-3.0' into stable-3.1

* stable-3.0:
  HookExecutor: Add missing licence header

Change-Id: Ie79f03e7cade3d3fb7f2d71cde6ebaf27caab748
diff --git a/BUILD b/BUILD
index cfdc295..35312a7 100644
--- a/BUILD
+++ b/BUILD
@@ -16,7 +16,6 @@
     srcs = glob(["src/test/java/**/*.java"]),
     tags = ["hooks"],
     visibility = ["//visibility:public"],
-    deps = PLUGIN_TEST_DEPS + PLUGIN_DEPS + [
-        ":hooks__plugin",
-    ],
+    runtime_deps = [":hooks__plugin"],
+    deps = PLUGIN_TEST_DEPS + PLUGIN_DEPS,
 )
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookArgs.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookArgs.java
index 87d4291..a85144d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookArgs.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookArgs.java
@@ -18,13 +18,13 @@
 
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
+import com.google.gerrit.entities.Account;
+import com.google.gerrit.entities.Change;
+import com.google.gerrit.entities.Project;
 import com.google.gerrit.extensions.common.AccountInfo;
 import com.google.gerrit.extensions.common.ApprovalInfo;
 import com.google.gerrit.extensions.common.ChangeInfo;
 import com.google.gerrit.extensions.registration.DynamicItem;
-import com.google.gerrit.reviewdb.client.Account;
-import com.google.gerrit.reviewdb.client.Change;
-import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.server.IdentifiedUser;
 import com.google.gerrit.server.config.SitePaths;
 import com.google.gerrit.server.config.UrlFormatter;
@@ -105,7 +105,7 @@
           uf.flatMap(
                   f ->
                       f.getChangeViewUrl(
-                          new Project.NameKey(change.project), new Change.Id(change._number)))
+                          Project.nameKey(change.project), Change.id(change._number)))
               .orElse(""));
     } else {
       args.add("");
@@ -131,7 +131,7 @@
 
   private String format(AccountInfo account) {
     return String.format(
-        "\"%s\"", identifiedUserFactory.create(new Account.Id(account._accountId)).getNameEmail());
+        "\"%s\"", identifiedUserFactory.create(Account.id(account._accountId)).getNameEmail());
   }
 
   @Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookMetrics.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookMetrics.java
index 9b0bc82..02bd55e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookMetrics.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookMetrics.java
@@ -14,11 +14,13 @@
 
 package com.googlesource.gerrit.plugins.hooks;
 
+import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.metrics.Counter1;
 import com.google.gerrit.metrics.Description;
 import com.google.gerrit.metrics.Field;
 import com.google.gerrit.metrics.MetricMaker;
 import com.google.gerrit.metrics.Timer1;
+import com.google.gerrit.server.logging.PluginMetadata;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
@@ -30,8 +32,15 @@
   private final Counter1<String> timeout;
 
   @Inject
-  HookMetrics(MetricMaker metricMaker) {
-    Field<String> field = Field.ofString("hook");
+  HookMetrics(@PluginName String pluginName, MetricMaker metricMaker) {
+    Field<String> field =
+        Field.ofString(
+                "hook",
+                (metadataBuilder, fieldValue) ->
+                    metadataBuilder
+                        .pluginName(pluginName)
+                        .addPluginMetadata(PluginMetadata.create("hook", fieldValue)))
+            .build();
     latency =
         metricMaker.newTimer(
             "latency",
@@ -47,7 +56,7 @@
             "timeout", new Description("Hook execution timeouts").setRate(), field);
   }
 
-  public Timer1.Context start(String name) {
+  public Timer1.Context<String> start(String name) {
     return latency.start(name);
   }
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookQueue.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookQueue.java
index 50ba975..c8f154a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookQueue.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookQueue.java
@@ -21,6 +21,7 @@
 import com.google.inject.Inject;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.concurrent.Future;
 import java.util.concurrent.ScheduledExecutorService;
 import org.eclipse.jgit.lib.Config;
 
@@ -47,7 +48,8 @@
       logger.atFine().log("Hook file not found: %s", hook.toAbsolutePath());
       return;
     }
-    queue.submit(new HookTask.Async(projectName, hook, args));
+    @SuppressWarnings("unused")
+    Future<?> ignored = queue.submit(new HookTask.Async(projectName, hook, args));
   }
 
   @Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java
index 8b06a24..02dfd08 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java
@@ -18,8 +18,8 @@
 
 import com.google.common.flogger.FluentLogger;
 import com.google.common.io.ByteStreams;
+import com.google.gerrit.entities.Project;
 import com.google.gerrit.metrics.Timer1;
-import com.google.gerrit.reviewdb.client.Project;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.StringReader;
@@ -85,7 +85,7 @@
   public HookResult runHook() {
     HookResult result = null;
     String name = getName();
-    try (Timer1.Context timer = args.metrics.start(name)) {
+    try (Timer1.Context<String> timer = args.metrics.start(name)) {
       args.metrics.count(name);
       List<String> argv = new ArrayList<>(1 + args.get().size());
       argv.add(hook.toAbsolutePath().toString());
@@ -98,7 +98,7 @@
       env.put("GERRIT_SITE", sitePath.toAbsolutePath().toString());
 
       if (projectName != null) {
-        try (Repository git = args.gitManager.openRepository(new Project.NameKey(projectName))) {
+        try (Repository git = args.gitManager.openRepository(Project.nameKey(projectName))) {
           pb.directory(git.getDirectory());
           env.put("GIT_DIR", git.getDirectory().getAbsolutePath());
         }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/Submit.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/Submit.java
index 4d87287..1358d0a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/Submit.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/Submit.java
@@ -14,8 +14,8 @@
 
 package com.googlesource.gerrit.plugins.hooks;
 
-import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.PatchSet;
+import com.google.gerrit.entities.BranchNameKey;
+import com.google.gerrit.entities.PatchSet;
 import com.google.gerrit.server.IdentifiedUser;
 import com.google.gerrit.server.git.CodeReviewCommit;
 import com.google.gerrit.server.git.validators.MergeValidationException;
@@ -41,16 +41,16 @@
       Repository repo,
       CodeReviewCommit commit,
       ProjectState destProject,
-      Branch.NameKey destBranch,
+      BranchNameKey destBranch,
       PatchSet.Id patchSetId,
       IdentifiedUser caller)
       throws MergeValidationException {
     String projectName = destProject.getProject().getName();
 
     HookArgs args = hookFactory.createArgs();
-    args.add("--change", patchSetId.changeId.get());
+    args.add("--change", patchSetId.changeId().get());
     args.add("--project", projectName);
-    args.add("--branch", destBranch.get());
+    args.add("--branch", destBranch.branch());
     args.add("--submitter", caller.getNameEmail());
     args.add("--submitter-username", caller.getUserName().orElse(null));
     args.add("--patchset", patchSetId.get());