Support to enable/disable the Jira integration per project

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

  [plugin "its-jira"]
    enabled = true

If `plugin.its-jira.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 Jira integration is disabled for this
project.

By setting `plugin.its-jira.enabled` to true in the `project.config` of the
`All-Projects` project the Jira integration can be enabled by default
for all projects. During the initialization of the plugin you are asked
if the Jira 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: I3cd61fe010d226f4947b79da0f038b4e75e38263
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/jira/InitJira.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/jira/InitJira.java
index c17a5fd..e3edba5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/jira/InitJira.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/jira/InitJira.java
@@ -14,27 +14,27 @@
 
 package com.googlesource.gerrit.plugins.hooks.jira;
 
+import java.io.IOException;
 import java.rmi.RemoteException;
 
 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;
 import com.googlesource.gerrit.plugins.hooks.validation.ItsAssociationPolicy;
 
+import org.eclipse.jgit.errors.ConfigInvalidException;
+
 /** Initialize the GitRepositoryManager configuration section. */
 @Singleton
-class InitJira extends InitIts implements InitStep {
+class InitJira extends InitIts {
   private static final String COMMENT_LINK_SECTION = "commentLink";
   private final String pluginName;
-  private final ConsoleUI ui;
-  private final Factory sections;
+  private final Section.Factory sections;
   private Section jira;
   private Section jiraComment;
   private String jiraUrl;
@@ -42,14 +42,17 @@
   private String jiraPassword;
 
   @Inject
-  InitJira(final @PluginName String pluginName, final ConsoleUI ui,
-      final Injector injector, final Section.Factory sections) {
+  InitJira(@PluginName String pluginName, ConsoleUI ui,
+      Section.Factory sections, AllProjectsConfig allProjectsConfig) {
+    super(pluginName, "Jira", ui, allProjectsConfig);
     this.pluginName = pluginName;
     this.sections = sections;
-    this.ui = ui;
   }
 
-  public void run() {
+  @Override
+  public void postRun() throws IOException, ConfigInvalidException {
+    super.postRun();
+
     this.jira = sections.get(pluginName, null);
     this.jiraComment = sections.get(COMMENT_LINK_SECTION, pluginName);
 
@@ -59,7 +62,7 @@
     do {
       enterJiraConnectivity();
     } while (jiraUrl != null
-        && (isConnectivityRequested(ui, jiraUrl) && !isJiraConnectSuccessful()));
+        && (isConnectivityRequested(jiraUrl) && !isJiraConnectSuccessful()));
 
     if (jiraUrl == null) {
       return;
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index 1ce37c2..64372b2 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -3,6 +3,28 @@
 
 This plugin allows to associate Jira issues to Git commits.
 
+It can be configured per project whether the Jira integration is
+enabled or not. To enable the Jira integration for a project the
+project must have the following entry in its `project.config` file in
+the `refs/meta/config` branch:
+
+```
+  [plugin "its-jira"]
+    enabled = true
+```
+
+If `plugin.its-jira.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 Jira integration is disabled for this
+project.
+
+By setting `plugin.its-jira.enabled` to true in the `project.config` of the
+`All-Projects` project the Jira integration can be enabled by default
+for all projects. During the initialization of the plugin you are asked
+if the Jira 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
 ----------------
 
@@ -102,6 +124,11 @@
 
 Gerrit init example:
 
+    *** Jira Integration
+    ***
+
+    By default enabled for all projects [Y/n]?
+
     *** Jira connectivity
     ***