Merge branch 'stable-2.16' into stable-3.0

* stable-2.16:
  Extend CommitMessageFetcher to handle non-commit objects

Change-Id: I6f4b9c7ab5992619094754484c1f57093a529b03
diff --git a/BUILD b/BUILD
index 401da87..03f8e0a 100644
--- a/BUILD
+++ b/BUILD
@@ -42,6 +42,5 @@
     exports = PLUGIN_DEPS + PLUGIN_TEST_DEPS + [
         ":its-base__plugin",
         ":its-base_tests-utils",
-        "@mockito//jar",
     ],
 )
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
deleted file mode 100644
index 5eafc37..0000000
--- a/external_plugin_deps.bzl
+++ /dev/null
@@ -1,33 +0,0 @@
-load("//tools/bzl:maven_jar.bzl", "maven_jar")
-
-def external_plugin_deps():
-    maven_jar(
-        name = "mockito",
-        artifact = "org.mockito:mockito-core:2.27.0",
-        sha1 = "835fc3283b481f4758b8ef464cd560c649c08b00",
-        deps = [
-            "@byte-buddy//jar",
-            "@byte-buddy-agent//jar",
-            "@objenesis//jar",
-        ],
-    )
-
-    BYTE_BUDDY_VER = "1.9.10"
-
-    maven_jar(
-        name = "byte-buddy",
-        artifact = "net.bytebuddy:byte-buddy:" + BYTE_BUDDY_VER,
-        sha1 = "211a2b4d3df1eeef2a6cacf78d74a1f725e7a840",
-    )
-
-    maven_jar(
-        name = "byte-buddy-agent",
-        artifact = "net.bytebuddy:byte-buddy-agent:" + BYTE_BUDDY_VER,
-        sha1 = "9674aba5ee793e54b864952b001166848da0f26b",
-    )
-
-    maven_jar(
-        name = "objenesis",
-        artifact = "org.objenesis:objenesis:2.6",
-        sha1 = "639033469776fd37c08358c6b92a4761feb2af4b",
-    )
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/its/InitIts.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/its/InitIts.java
index 9fb2b3d..fbb6e39 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/its/InitIts.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/its/InitIts.java
@@ -15,7 +15,7 @@
 package com.googlesource.gerrit.plugins.its.base.its;
 
 import com.google.common.base.Strings;
-import com.google.gerrit.common.data.RefConfigSection;
+import com.google.gerrit.common.data.AccessSection;
 import com.google.gerrit.pgm.init.api.AllProjectsConfig;
 import com.google.gerrit.pgm.init.api.AllProjectsNameOnInitProvider;
 import com.google.gerrit.pgm.init.api.ConsoleUI;
@@ -140,7 +140,7 @@
               branch,
               "Branches for which the issue tracker integration"
                   + " should be enabled (ref, ref pattern or regular expression)");
-      validRef = RefConfigSection.isValid(v);
+      validRef = AccessSection.isValidRefSectionName(v);
       if (validRef) {
         branch = v;
       } else {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfig.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfig.java
index 552065e..6a5eda4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfig.java
@@ -16,7 +16,7 @@
 
 import static java.util.stream.Collectors.toList;
 
-import com.google.gerrit.common.data.RefConfigSection;
+import com.google.gerrit.common.data.AccessSection;
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.api.projects.CommentLinkInfo;
 import com.google.gerrit.reviewdb.client.Project;
@@ -134,7 +134,7 @@
       return true;
     }
     for (String refPattern : refPatterns) {
-      if (RefConfigSection.isValid(refPattern) && match(refName, refPattern)) {
+      if (AccessSection.isValidRefSectionName(refPattern) && match(refName, refPattern)) {
         return true;
       }
     }
@@ -182,8 +182,7 @@
    */
   public Pattern getIssuePattern() {
     Optional<String> match =
-        getCommentLinkInfo(getCommentLinkName())
-            .stream()
+        getCommentLinkInfo(getCommentLinkName()).stream()
             .filter(input -> input.match != null && !input.match.trim().isEmpty())
             .map(input -> input.match)
             .reduce((a, b) -> b);
@@ -268,8 +267,7 @@
     NameKey projectName = currentProjectName.get();
     if (projectName != null) {
       List<CommentLinkInfo> commentlinks = projectCache.get(projectName).getCommentLinks();
-      return commentlinks
-          .stream()
+      return commentlinks.stream()
           .filter(input -> input.name.equals(commentlinkName))
           .collect(toList());
     }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/CommitMessageFetcher.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/CommitMessageFetcher.java
index 7066f59..ed1c6b3 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/CommitMessageFetcher.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/CommitMessageFetcher.java
@@ -1,6 +1,6 @@
 package com.googlesource.gerrit.plugins.its.base.util;
 
-import com.google.gerrit.reviewdb.client.Project.NameKey;
+import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.server.git.GitRepositoryManager;
 import com.google.inject.Inject;
 import java.io.IOException;
@@ -23,7 +23,7 @@
   }
 
   public String fetch(String projectName, String objectId) throws IOException {
-    try (Repository repo = repoManager.openRepository(new NameKey(projectName))) {
+    try (Repository repo = repoManager.openRepository(Project.nameKey(projectName))) {
       try (RevWalk revWalk = new RevWalk(repo)) {
         RevObject obj = revWalk.peel(revWalk.parseAny(ObjectId.fromString(objectId)));
         if (obj instanceof RevCommit) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/ItsProjectExtractor.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/ItsProjectExtractor.java
index e872f8d..734582a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/ItsProjectExtractor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/ItsProjectExtractor.java
@@ -29,6 +29,6 @@
   }
 
   public Optional<String> getItsProject(String gerritProjectName) {
-    return itsConfig.getItsProjectName(new Project.NameKey(gerritProjectName));
+    return itsConfig.getItsProjectName(Project.nameKey(gerritProjectName));
   }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractor.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractor.java
index f87f7b5..f1b2c0d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractor.java
@@ -15,6 +15,7 @@
 package com.googlesource.gerrit.plugins.its.base.util;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.gerrit.reviewdb.client.RefNames;
 import com.google.gerrit.server.data.AccountAttribute;
 import com.google.gerrit.server.data.ApprovalAttribute;
 import com.google.gerrit.server.data.ChangeAttribute;
@@ -86,10 +87,14 @@
   }
 
   Map<String, String> extractFrom(RefUpdateAttribute refUpdateAttribute) {
+    String refName = refUpdateAttribute.refName;
+    String refShortName = RefNames.shortName(refName);
     return ImmutableMap.<String, String>builder()
         .put("revision", refUpdateAttribute.newRev)
         .put("revisionOld", refUpdateAttribute.oldRev)
         .put("ref", refUpdateAttribute.refName)
+        .put("refSuffix", refShortName)
+        .put("refPrefix", refName.substring(0, refName.length() - refShortName.length()))
         .build();
   }
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionExecutor.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionExecutor.java
index 355d1f3..33e82ae 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionExecutor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionExecutor.java
@@ -80,7 +80,7 @@
   private void execute(
       Action action, String target, ActionRequest actionRequest, Map<String, String> properties)
       throws IOException {
-    ItsFacade its = itsFactory.getFacade(new Project.NameKey(properties.get("project")));
+    ItsFacade its = itsFactory.getFacade(Project.nameKey(properties.get("project")));
     action.execute(its, target, actionRequest, properties);
   }
 
@@ -89,7 +89,7 @@
     try {
       Action action = getAction(actionRequest.getName());
       if (action == null) {
-        ItsFacade its = itsFactory.getFacade(new Project.NameKey(properties.get("project")));
+        ItsFacade its = itsFactory.getFacade(Project.nameKey(properties.get("project")));
         its.performAction(issue, actionRequest.getUnparsed());
       } else if (action.getType() == ActionType.ISSUE) {
         execute(action, issue, actionRequest, properties);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheImpl.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheImpl.java
index 7e37397..14307a0 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheImpl.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheImpl.java
@@ -98,7 +98,7 @@
 
     @Override
     public List<Rule> load(String projectName) throws IOException {
-      ProjectState project = projectCache.checkedGet(new Project.NameKey(projectName));
+      ProjectState project = projectCache.checkedGet(Project.nameKey(projectName));
       List<Rule> projectRules = readRulesFrom(project);
       if (projectRules.isEmpty()) {
         for (ProjectState parent : project.parents()) {
diff --git a/src/main/resources/Documentation/config-rulebase-common.md b/src/main/resources/Documentation/config-rulebase-common.md
index 17baf77..1220751 100644
--- a/src/main/resources/Documentation/config-rulebase-common.md
+++ b/src/main/resources/Documentation/config-rulebase-common.md
@@ -281,7 +281,7 @@
 `added@<Association-Value>`
 :	(only for events that allow to determine the patch set number.
 	So for example, this `association` property is not set for
-	RevUpdatedEvents)
+	RefUpdatedEvents)
 
 issue id occurs at `<Association-Value>` in the most recent
 patch set of the change, and either the event is for patch set
@@ -425,8 +425,15 @@
 : full name of the project from which a ref was updated.
 
 `ref`
-: git ref that has been updated (Typcially the branch, as for example
-  `master`).
+: git ref that has been updated (Typically the branch, as for example
+  `refs/heads/master`).
+
+`refSuffix`
+: short name of the git ref that has been updated (Typically the branch or the
+tag, as for example `master`).
+
+`refPrefix`
+: prefix of the git ref that has been updated (Example for a branch `refs/heads/`).
 
 `revision`
 : git commit hash the rev is pointing to now.
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/base/util/CommitMessageFetcherTest.java b/src/test/java/com/googlesource/gerrit/plugins/its/base/util/CommitMessageFetcherTest.java
index e833951..890e182 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/its/base/util/CommitMessageFetcherTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/its/base/util/CommitMessageFetcherTest.java
@@ -151,7 +151,7 @@
     when(repo.newObjectReader()).thenReturn(objectReader);
 
     repoManager = mock(GitRepositoryManager.class);
-    when(repoManager.openRepository(eq(new Project.NameKey("ProjectFoo")))).thenReturn(repo);
+    when(repoManager.openRepository(eq(Project.nameKey("ProjectFoo")))).thenReturn(repo);
   }
 
   private CommitMessageFetcher createCommitMessageFetcher() {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractorTest.java b/src/test/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractorTest.java
index 3e61bc1..df88c2f 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractorTest.java
@@ -260,7 +260,7 @@
     RefUpdateAttribute refUpdateAttribute = new RefUpdateAttribute();
     refUpdateAttribute.newRev = "1234567891123456789212345678931234567894";
     refUpdateAttribute.oldRev = "9876543211987654321298765432139876543214";
-    refUpdateAttribute.refName = "testRef";
+    refUpdateAttribute.refName = "refs/heads/master";
 
     replayMocks();
 
@@ -272,7 +272,9 @@
         new ImmutableMap.Builder<String, String>()
             .put("revision", "1234567891123456789212345678931234567894")
             .put("revisionOld", "9876543211987654321298765432139876543214")
-            .put("ref", "testRef")
+            .put("ref", "refs/heads/master")
+            .put("refSuffix", "master")
+            .put("refPrefix", "refs/heads/")
             .build();
     assertEquals("Properties do not match", expected, actual);
   }