Support to enable/disable the Bugzilla integration per project

It can now be configured per project whether the Bugzilla integration is
enabled or not. To enable the Bugzilla integration for a project the
project must have the following entry in its `project.config` file in
the `refs/meta/config` branch:

```
  [plugin "its-bugzilla"]
    enabled = true
```

If `plugin.its-bugzilla.enabled` is not specified in the `project.config` file
the value is inherited from the parent project. If it is also not set
on any parent project the Bugzilla integration is disabled for this
project.

By setting `plugin.its-bugzilla.enabled` to true in the `project.config` of the
`All-Projects` project the Bugzilla integration can be enabled by default
for all projects. During the initialization of the plugin you are asked
if the Bugzilla integration should be enabled by default for all projects
and if yes this setting in the `project.config` of the `All-Projects`
project is done automatically.

Change-Id: I7afe1c6fdbd60df283415ef36cd819ecfdc0c3b0
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/bz/InitBugzilla.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/bz/InitBugzilla.java
index f2b1dc4..273597d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/bz/InitBugzilla.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/bz/InitBugzilla.java
@@ -15,12 +15,10 @@
 package com.googlesource.gerrit.plugins.hooks.bz;
 
 import com.google.gerrit.extensions.annotations.PluginName;
-import com.google.gerrit.pgm.init.InitStep;
+import com.google.gerrit.pgm.init.AllProjectsConfig;
 import com.google.gerrit.pgm.init.Section;
-import com.google.gerrit.pgm.init.Section.Factory;
 import com.google.gerrit.pgm.util.ConsoleUI;
 import com.google.inject.Inject;
-import com.google.inject.Injector;
 import com.google.inject.Singleton;
 
 import com.googlesource.gerrit.plugins.hooks.its.InitIts;
@@ -28,12 +26,15 @@
 import com.j2bugzilla.base.BugzillaException;
 import com.j2bugzilla.base.ConnectionException;
 
+import org.eclipse.jgit.errors.ConfigInvalidException;
+
+import java.io.IOException;
+
 /** Initialize the GitRepositoryManager configuration section. */
 @Singleton
-class InitBugzilla extends InitIts implements InitStep {
+class InitBugzilla extends InitIts {
   private final String pluginName;
-  private final ConsoleUI ui;
-  private final Factory sections;
+  private final Section.Factory sections;
   private Section bugzilla;
   private Section bugzillaComment;
   private String bugzillaUrl;
@@ -41,14 +42,16 @@
   private String bugzillaPassword;
 
   @Inject
-  InitBugzilla(final @PluginName String pluginName, final ConsoleUI ui,
-      final Injector injector, final Section.Factory sections) {
+  InitBugzilla(@PluginName String pluginName, ConsoleUI ui, Section.Factory sections,
+      AllProjectsConfig allProjectsConfig) {
+    super(pluginName, "Bugzilla", ui, allProjectsConfig);
     this.pluginName = pluginName;
     this.sections = sections;
-    this.ui = ui;
   }
 
-  public void run() {
+  public void postRun() throws IOException, ConfigInvalidException {
+    super.postRun();
+
     this.bugzilla = sections.get(pluginName, null);
     this.bugzillaComment = sections.get(COMMENT_LINK_SECTION, pluginName);
 
@@ -58,7 +61,7 @@
     do {
       enterBugzillaConnectivity();
     } while (bugzillaUrl != null
-        && (isConnectivityRequested(ui, bugzillaUrl) && !isBugzillaConnectSuccessful()));
+        && (isConnectivityRequested(bugzillaUrl) && !isBugzillaConnectSuccessful()));
 
     if (bugzillaUrl == null) {
       return;
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index ecde689..40def47 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -4,6 +4,28 @@
 This plugin allows to associate Bugzilla bugs to Git commits thanks to
 the Gerrit listener interface.
 
+It can be configured per project whether the Bugzilla integration is
+enabled or not. To enable the Bugzilla integration for a project the
+project must have the following entry in its `project.config` file in
+the `refs/meta/config` branch:
+
+```
+  [plugin "its-bugzilla"]
+    enabled = true
+```
+
+If `plugin.its-bugzilla.enabled` is not specified in the `project.config` file
+the value is inherited from the parent project. If it is also not set
+on any parent project the Bugzilla integration is disabled for this
+project.
+
+By setting `plugin.its-bugzilla.enabled` to true in the `project.config` of the
+`All-Projects` project the Bugzilla integration can be enabled by default
+for all projects. During the initialization of the plugin you are asked
+if the Bugzilla integration should be enabled by default for all projects
+and if yes this setting in the `project.config` of the `All-Projects`
+project is done automatically.
+
 Comment links
 ----------------
 
@@ -68,6 +90,11 @@
 
 Gerrit init example:
 
+    *** Bugzilla Integration
+    ***
+
+    By default enabled for all projects [Y/n]?
+
     *** Bugzilla connectivity
     ***