Define PluginName and use it instead of ITS_NAME_BUGZILLA
Change-Id: I9688304fffdd72b607ef54f699b36c5b397a63cb
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/pom.xml b/pom.xml
index ce42cad..59ae40b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,6 +29,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<Gerrit-ApiType>plugin</Gerrit-ApiType>
<Gerrit-ReloadMode>reload</Gerrit-ReloadMode>
+ <Gerrit-PluginName>its-bugzilla</Gerrit-PluginName>
<Gerrit-InitStep>com.googlesource.gerrit.plugins.hooks.bz.InitBugzilla</Gerrit-InitStep>
<Gerrit-Module>com.googlesource.gerrit.plugins.hooks.bz.BugzillaModule</Gerrit-Module>
<easymockVersion>3.0</easymockVersion>
@@ -74,6 +75,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/bz/BugzillaItsFacade.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/bz/BugzillaItsFacade.java
index 0a473a8..b6ff5b8 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/bz/BugzillaItsFacade.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/bz/BugzillaItsFacade.java
@@ -22,15 +22,15 @@
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.Inject;
+
import com.googlesource.gerrit.plugins.hooks.its.ItsFacade;
import com.j2bugzilla.base.BugzillaException;
import com.j2bugzilla.base.ConnectionException;
public class BugzillaItsFacade implements ItsFacade {
- public static final String ITS_NAME_BUGZILLA = "bugzilla";
-
private static final String GERRIT_CONFIG_USERNAME = "username";
private static final String GERRIT_CONFIG_PASSWORD = "password";
private static final String GERRIT_CONFIG_URL = "url";
@@ -39,12 +39,15 @@
private Logger log = LoggerFactory.getLogger(BugzillaItsFacade.class);
+ private final String pluginName;
private Config gerritConfig;
private BugzillaClient client;
@Inject
- public BugzillaItsFacade(@GerritServerConfig Config cfg) {
+ public BugzillaItsFacade(@PluginName String pluginName,
+ @GerritServerConfig Config cfg) {
+ this.pluginName = pluginName;
try {
this.gerritConfig = cfg;
log.info("Connected to Bugzilla at " + client().getXmlRpcUrl()
@@ -197,21 +200,21 @@
private String getPassword() {
final String pass =
- gerritConfig.getString(ITS_NAME_BUGZILLA, null,
+ gerritConfig.getString(pluginName, null,
GERRIT_CONFIG_PASSWORD);
return pass;
}
private String getUsername() {
final String user =
- gerritConfig.getString(ITS_NAME_BUGZILLA, null,
+ gerritConfig.getString(pluginName, null,
GERRIT_CONFIG_USERNAME);
return user;
}
private String getUrl() {
final String url =
- gerritConfig.getString(ITS_NAME_BUGZILLA, null, GERRIT_CONFIG_URL);
+ gerritConfig.getString(pluginName, null, GERRIT_CONFIG_URL);
return url;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/bz/BugzillaModule.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/bz/BugzillaModule.java
index f55a3e6..b9030d2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/bz/BugzillaModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/bz/BugzillaModule.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(BugzillaModule.class);
+ private final String pluginName;
private final Config gerritConfig;
@Inject
- public BugzillaModule(@GerritServerConfig final Config config) {
+ public BugzillaModule(@PluginName final String pluginName,
+ @GerritServerConfig final Config config) {
+ this.pluginName = pluginName;
this.gerritConfig = config;
}
@Override
protected void configure() {
- if (gerritConfig.getString(BugzillaItsFacade.ITS_NAME_BUGZILLA, null, "url") != null) {
+ if (gerritConfig.getString(pluginName, null, "url") != null) {
log.info("Bugzilla is configured as ITS");
- bind(ItsFacade.class).toInstance(new BugzillaItsFacade(gerritConfig));
+ bind(ItsFacade.class).toInstance(new BugzillaItsFacade(pluginName, gerritConfig));
- install(new ItsHookModule(BugzillaItsFacade.ITS_NAME_BUGZILLA));
+ install(new ItsHookModule());
}
}
}
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 3774701..f2b1dc4 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
@@ -14,6 +14,7 @@
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.Section;
import com.google.gerrit.pgm.init.Section.Factory;
@@ -21,6 +22,7 @@
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 com.j2bugzilla.base.BugzillaException;
@@ -29,7 +31,7 @@
/** Initialize the GitRepositoryManager configuration section. */
@Singleton
class InitBugzilla extends InitIts implements InitStep {
- private static final String BUGZILLA_SECTION = "bugzilla";
+ private final String pluginName;
private final ConsoleUI ui;
private final Factory sections;
private Section bugzilla;
@@ -39,14 +41,16 @@
private String bugzillaPassword;
@Inject
- InitBugzilla(final ConsoleUI ui, final Injector injector, final Section.Factory sections) {
+ InitBugzilla(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.bugzilla = sections.get(BUGZILLA_SECTION, null);
- this.bugzillaComment = sections.get(COMMENT_LINK_SECTION, BUGZILLA_SECTION);
+ this.bugzilla = sections.get(pluginName, null);
+ this.bugzillaComment = sections.get(COMMENT_LINK_SECTION, pluginName);
ui.message("\n");
ui.header("Bugzilla connectivity");
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index 5a8756b..ecde689 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -29,7 +29,7 @@
Example:
- [commentLink "bugzilla"]
+ [commentLink "its-bugzilla"]
match = \\([Bb][Uu][Gg][ ]*([1-9][0-9]*)\\)
html = "<a href=\"http://mybugzilla.org/show_bug.cgi?id=$1\">(bug $1)</a>"
association = SUGGESTED
@@ -41,18 +41,18 @@
Note that the plugin relies on $1 holding the numeric id, so we cannot
have match group 1 spanning over the whole “(Bug 4711)”.
-Be sure to label the commentLink “bugzilla” with lowercase “b” to
+Be sure to label the commentLink “its-bugzilla” with all lowercase to
match the config section's name below.
Bugzilla connectivity
---------------------
In order for Gerrit to connect to Bugzilla/XML-RPC url and credentials
-are required in your gerrit.config / secure.config under the [bugzilla] section.
+are required in your gerrit.config / secure.config under the [its-bugzilla] section.
Example:
- [bugzilla]
+ [its-bugzilla]
url=http://mybugzilla.org
username=bzuser
password=bzpass
@@ -108,7 +108,7 @@
To turn off the legacy event handling of older 'its-*' plugins and
stop unwanted legacy comments, add the following settings to the
-'bugzilla' section of 'etc/gerrit.config':
+'its-bugzilla' section of 'etc/gerrit.config':
----
commentOnChangeAbandoned = false
diff --git a/src/test/java/com/googlesource/gerrit/plugins/hooks/bz/BugzillaItsFacadeTest.java b/src/test/java/com/googlesource/gerrit/plugins/hooks/bz/BugzillaItsFacadeTest.java
index 46f7c79..5c43601 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/hooks/bz/BugzillaItsFacadeTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/hooks/bz/BugzillaItsFacadeTest.java
@@ -17,6 +17,7 @@
import org.eclipse.jgit.lib.Config;
+import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.server.config.FactoryModule;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.inject.Guice;
@@ -77,11 +78,11 @@
}
private void mockUnconnectableBugzilla() {
- expect(serverConfig.getString("bugzilla", null, "url"))
+ expect(serverConfig.getString("its-bugzilla", null, "url"))
.andReturn("<no-url>").anyTimes();
- expect(serverConfig.getString("bugzilla", null, "username"))
+ expect(serverConfig.getString("its-bugzilla", null, "username"))
.andReturn("none").anyTimes();
- expect(serverConfig.getString("bugzilla", null, "password"))
+ expect(serverConfig.getString("its-bugzilla", null, "password"))
.andReturn("none").anyTimes();
}
@@ -104,6 +105,8 @@
serverConfig = createMock(Config.class);
bind(Config.class).annotatedWith(GerritServerConfig.class)
.toInstance(serverConfig);
+ bind(String.class).annotatedWith(PluginName.class)
+ .toInstance("its-bugzilla");
}
}
}
\ No newline at end of file