Define PluginName and use it instead of ITS_NAME_JIRA

Change-Id: Ia0c6eb35dcfaf73c2bc69d614c8be38d4ad87d16
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/pom.xml b/pom.xml
index 0fe62b4..7b04c60 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,6 +28,7 @@
   <properties>
     <Gerrit-ApiType>plugin</Gerrit-ApiType>
     <Gerrit-ReloadMode>reload</Gerrit-ReloadMode>
+    <Gerrit-PluginName>jira</Gerrit-PluginName>
     <Gerrit-InitStep>com.googlesource.gerrit.plugins.hooks.jira.InitJira</Gerrit-InitStep>
     <Gerrit-Module>com.googlesource.gerrit.plugins.hooks.jira.JiraModule</Gerrit-Module>
   </properties>
@@ -112,6 +113,7 @@
                 <Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType>
                 <Gerrit-ApiVersion>${project.version}</Gerrit-ApiVersion>
                 <Gerrit-ReloadMode>${Gerrit-ReloadMode}</Gerrit-ReloadMode>
+                <Gerrit-PluginName>${Gerrit-PluginName}</Gerrit-PluginName>
                 <Gerrit-InitStep>${Gerrit-InitStep}</Gerrit-InitStep>
                 <Gerrit-Module>${Gerrit-Module}</Gerrit-Module>
               </manifestEntries>
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 1b2a8e4..c17a5fd 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
@@ -16,6 +16,7 @@
 
 import java.rmi.RemoteException;
 
+import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.pgm.init.InitStep;
 import com.google.gerrit.pgm.init.Section;
 import com.google.gerrit.pgm.init.Section.Factory;
@@ -23,14 +24,15 @@
 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;
 
 /** Initialize the GitRepositoryManager configuration section. */
 @Singleton
 class InitJira extends InitIts implements InitStep {
-  private static final String JIRA_SECTION = "jira";
   private static final String COMMENT_LINK_SECTION = "commentLink";
+  private final String pluginName;
   private final ConsoleUI ui;
   private final Factory sections;
   private Section jira;
@@ -40,14 +42,16 @@
   private String jiraPassword;
 
   @Inject
-  InitJira(final ConsoleUI ui, final Injector injector, final Section.Factory sections) {
+  InitJira(final @PluginName String pluginName, final ConsoleUI ui,
+      final Injector injector, final Section.Factory sections) {
+    this.pluginName = pluginName;
     this.sections = sections;
     this.ui = ui;
   }
 
   public void run() {
-    this.jira = sections.get(JIRA_SECTION, null);
-    this.jiraComment = sections.get(COMMENT_LINK_SECTION, JIRA_SECTION);
+    this.jira = sections.get(pluginName, null);
+    this.jiraComment = sections.get(COMMENT_LINK_SECTION, pluginName);
 
     ui.message("\n");
     ui.header("Jira connectivity");
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/jira/JiraItsFacade.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/jira/JiraItsFacade.java
index 029591f..17385b6 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/jira/JiraItsFacade.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/jira/JiraItsFacade.java
@@ -28,15 +28,16 @@
 import com.atlassian.jira.rpc.soap.client.RemoteComment;
 import com.atlassian.jira.rpc.soap.client.RemoteNamedObject;
 import com.atlassian.jira.rpc.soap.client.RemoteServerInfo;
+
+import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.server.config.GerritServerConfig;
 import com.google.inject.Inject;
+
 import com.googlesource.gerrit.plugins.hooks.its.InvalidTransitionException;
 import com.googlesource.gerrit.plugins.hooks.its.ItsFacade;
 
 public class JiraItsFacade implements ItsFacade {
 
-  public static final String ITS_NAME_JIRA = "jira";
-
   private static final String GERRIT_CONFIG_USERNAME = "username";
   private static final String GERRIT_CONFIG_PASSWORD = "password";
   private static final String GERRIT_CONFIG_URL = "url";
@@ -45,13 +46,16 @@
 
   private Logger log = LoggerFactory.getLogger(JiraItsFacade.class);
 
+  private final String pluginName;
   private Config gerritConfig;
 
   private JiraClient client;
   private JiraSession token;
 
   @Inject
-  public JiraItsFacade(@GerritServerConfig Config cfg) {
+  public JiraItsFacade(@PluginName String pluginName,
+      @GerritServerConfig Config cfg) {
+    this.pluginName = pluginName;
     try {
       this.gerritConfig = cfg;
       RemoteServerInfo info = client().getServerInfo(token);
@@ -241,21 +245,21 @@
 
   private String getPassword() {
     final String pass =
-        gerritConfig.getString(ITS_NAME_JIRA, null,
+        gerritConfig.getString(pluginName, null,
             GERRIT_CONFIG_PASSWORD);
     return pass;
   }
 
   private String getUsername() {
     final String user =
-        gerritConfig.getString(ITS_NAME_JIRA, null,
+        gerritConfig.getString(pluginName, null,
             GERRIT_CONFIG_USERNAME);
     return user;
   }
 
   private String getUrl() {
     final String url =
-        gerritConfig.getString(ITS_NAME_JIRA, null, GERRIT_CONFIG_URL);
+        gerritConfig.getString(pluginName, null, GERRIT_CONFIG_URL);
     return url;
   }
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/jira/JiraModule.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/jira/JiraModule.java
index 469e293..8448ac3 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/jira/JiraModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/jira/JiraModule.java
@@ -18,9 +18,11 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.server.config.GerritServerConfig;
 import com.google.inject.AbstractModule;
 import com.google.inject.Inject;
+
 import com.googlesource.gerrit.plugins.hooks.ItsHookModule;
 import com.googlesource.gerrit.plugins.hooks.its.ItsFacade;
 
@@ -28,20 +30,23 @@
 
   private static final Logger LOG = LoggerFactory.getLogger(JiraModule.class);
 
+  private final String pluginName;
   private final Config gerritConfig;
 
   @Inject
-  public JiraModule(@GerritServerConfig final Config config) {
+  public JiraModule(@PluginName final String pluginName,
+      @GerritServerConfig final Config config) {
+    this.pluginName = pluginName;
     this.gerritConfig = config;
   }
 
   @Override
   protected void configure() {
-    if (gerritConfig.getString(JiraItsFacade.ITS_NAME_JIRA, null, "url") != null) {
+    if (gerritConfig.getString(pluginName, null, "url") != null) {
       LOG.info("JIRA is configured as ITS");
-      bind(ItsFacade.class).toInstance(new JiraItsFacade(gerritConfig));
+      bind(ItsFacade.class).toInstance(new JiraItsFacade(pluginName, gerritConfig));
 
-      install(new ItsHookModule(JiraItsFacade.ITS_NAME_JIRA));
+      install(new ItsHookModule());
     }
   }
 }