Add init step to extract examples for mail templates

Having the example files available in the file system makes it easier to
customize the templates.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I0728536a5277cb8d819ba8c9c38ca61372be4fe2
diff --git a/BUILD b/BUILD
index c28bc66..79ebe56 100644
--- a/BUILD
+++ b/BUILD
@@ -17,6 +17,7 @@
         "Gerrit-PluginName: checks",
         "Gerrit-Module: com.google.gerrit.plugins.checks.Module",
         "Gerrit-HttpModule: com.google.gerrit.plugins.checks.HttpModule",
+        "Gerrit-InitStep: com.google.gerrit.plugins.checks.Init",
     ],
     resource_jars = ["//plugins/checks/gr-checks:gr-checks-static"],
     resource_strip_prefix = "plugins/checks/resources",
diff --git a/java/com/google/gerrit/plugins/checks/Init.java b/java/com/google/gerrit/plugins/checks/Init.java
new file mode 100644
index 0000000..5e7407b
--- /dev/null
+++ b/java/com/google/gerrit/plugins/checks/Init.java
@@ -0,0 +1,45 @@
+// Copyright (C) 2019 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.google.gerrit.plugins.checks;
+
+import static com.google.gerrit.common.FileUtil.chmod;
+import static com.google.gerrit.pgm.init.api.InitUtil.extract;
+
+import com.google.gerrit.pgm.init.api.InitStep;
+import com.google.gerrit.plugins.checks.email.ChecksEmailModule;
+import com.google.gerrit.server.config.SitePaths;
+import com.google.inject.Inject;
+import java.nio.file.Path;
+
+public class Init implements InitStep {
+  private final SitePaths site;
+
+  @Inject
+  Init(SitePaths site) {
+    this.site = site;
+  }
+
+  @Override
+  public void run() throws Exception {
+    extractMailExample("CombinedCheckStateUpdated.soy");
+    extractMailExample("CombinedCheckStateUpdatedHtml.soy");
+  }
+
+  private void extractMailExample(String orig) throws Exception {
+    Path ex = site.mail_dir.resolve(orig + ".example");
+    extract(ex, ChecksEmailModule.class, orig);
+    chmod(0444, ex);
+  }
+}