Merge branch 'stable-2.14' into stable-2.15

* stable-2.14:
  Implement change-deleted hook

Change-Id: I6a4b39a3332aa773a977a51a9544c2fb99cb772b
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/ChangeDeleted.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/ChangeDeleted.java
new file mode 100644
index 0000000..ae117f8
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/ChangeDeleted.java
@@ -0,0 +1,48 @@
+// Copyright (C) 2018 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.googlesource.gerrit.plugins.hooks;
+
+import com.google.gerrit.extensions.common.ChangeInfo;
+import com.google.gerrit.extensions.events.ChangeDeletedListener;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+@Singleton
+public class ChangeDeleted implements ChangeDeletedListener {
+  private final Hook hook;
+  private final HookFactory hookFactory;
+
+  @Inject
+  ChangeDeleted(HookFactory hookFactory) {
+    this.hook = hookFactory.createAsync("changeDeletedHook", "change-deleted");
+    this.hookFactory = hookFactory;
+  }
+
+  @Override
+  public void onChangeDeleted(ChangeDeletedListener.Event event) {
+    HookArgs args = hookFactory.createArgs();
+
+    ChangeInfo c = event.getChange();
+    args.add("--change", c.id);
+    args.addUrl(c);
+    args.add("--change-owner", c.owner);
+    args.add("--project", c.project);
+    args.add("--branch", c.branch);
+    args.add("--topic", c.topic);
+    args.add("--deleter", event.getWho());
+
+    hook.execute(c.project, args);
+  }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/Module.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/Module.java
index aeea41e..fac480b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/Module.java
@@ -17,6 +17,7 @@
 import com.google.gerrit.extensions.config.FactoryModule;
 import com.google.gerrit.extensions.events.AgreementSignupListener;
 import com.google.gerrit.extensions.events.ChangeAbandonedListener;
+import com.google.gerrit.extensions.events.ChangeDeletedListener;
 import com.google.gerrit.extensions.events.ChangeMergedListener;
 import com.google.gerrit.extensions.events.ChangeRestoredListener;
 import com.google.gerrit.extensions.events.CommentAddedListener;
@@ -47,6 +48,7 @@
 
     DynamicSet.bind(binder(), AgreementSignupListener.class).to(AgreementSignup.class);
     DynamicSet.bind(binder(), ChangeAbandonedListener.class).to(ChangeAbandoned.class);
+    DynamicSet.bind(binder(), ChangeDeletedListener.class).to(ChangeDeleted.class);
     DynamicSet.bind(binder(), ChangeMergedListener.class).to(ChangeMerged.class);
     DynamicSet.bind(binder(), ChangeRestoredListener.class).to(ChangeRestored.class);
     DynamicSet.bind(binder(), CommentAddedListener.class).to(CommentAdded.class);
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index 7a1cbd2..1e5502a 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -39,6 +39,9 @@
 hooks.changeAbandonedHook
 :	Filename for the change abandoned hook. If not set, defaults to `change-abandoned`.
 
+hooks.changeDeletedHook
+:	Filename for the change deleted hook. If not set, defaults to `change-deleted`.
+
 hooks.changeMergedHook
 :	Filename for the change merged hook. If not set, defaults to `change-merged`.
 
diff --git a/src/main/resources/Documentation/hooks.md b/src/main/resources/Documentation/hooks.md
index fd92b63..324f842 100644
--- a/src/main/resources/Documentation/hooks.md
+++ b/src/main/resources/Documentation/hooks.md
@@ -85,6 +85,14 @@
   change-abandoned --change <change id> --change-url <change url> --change-owner <change owner> --change-owner-username <username> --project <project name> --branch <branch> --topic <topic> --abandoner <abandoner> --abandoner-username <username> --commit <sha1> --reason <reason>
 ```
 
+### change-deleted
+
+Called whenever a change has been deleted.
+
+```
+  change-deleted --change <change id> --change-url <change url> --change-owner <change owner> --project <project name> --branch <branch> --topic <topic> --deleter <deleter>
+```
+
 ### change-restored
 
 Called whenever a change has been restored.