Merge "Load additional plugin-specific rule base"
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/its/InitIts.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/its/InitIts.java
index 47c23ae..4c59b5c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/its/InitIts.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/its/InitIts.java
@@ -61,7 +61,7 @@
@Override
public void postRun() throws IOException, ConfigInvalidException {
- Config cfg = allProjectsConfig.load();
+ Config cfg = allProjectsConfig.load().getConfig();
ui.message("\n");
ui.header(itsDisplayName + " Integration");
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/its/ItsFacade.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/its/ItsFacade.java
index 2ee72a3..b4f9cd6 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/its/ItsFacade.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/its/ItsFacade.java
@@ -27,8 +27,6 @@
ACCESS
}
- public String name();
-
public String healthCheck(Check check)
throws IOException;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/its/NoopItsFacade.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/its/NoopItsFacade.java
index 49d2e03..b7bfe44 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/its/NoopItsFacade.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/its/NoopItsFacade.java
@@ -75,9 +75,4 @@
}
return "";
}
-
- @Override
- public String name() {
- return "not configured";
- }
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/validation/ItsValidateComment.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/validation/ItsValidateComment.java
index f47889e..bd8ed2c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/validation/ItsValidateComment.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/validation/ItsValidateComment.java
@@ -101,7 +101,7 @@
sb.append(commit.getId().getName());
sb.append(",\n");
sb.append("but do not exist in ");
- sb.append(client.name());
+ sb.append(pluginName);
sb.append(" Issue-Tracker");
details = sb.toString();
@@ -121,7 +121,7 @@
sb.append(issueExtractor.getPattern().pattern());
sb.append("\n");
sb.append(" and are pointing to existing tickets on ");
- sb.append(client.name());
+ sb.append(pluginName);
sb.append(" Issue-Tracker");
details = sb.toString();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddComment.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddComment.java
index ac19c2e..123f119 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddComment.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddComment.java
@@ -19,6 +19,7 @@
import org.eclipse.jgit.lib.Config;
import com.google.common.base.Strings;
+import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.server.config.AnonymousCowardName;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.data.AccountAttribute;
@@ -30,6 +31,7 @@
import com.google.gerrit.server.events.ChangeRestoredEvent;
import com.google.gerrit.server.events.CommentAddedEvent;
import com.google.inject.Inject;
+
import com.googlesource.gerrit.plugins.hooks.its.ItsFacade;
import com.googlesource.gerrit.plugins.hooks.util.IssueExtractor;
@@ -48,9 +50,12 @@
@Inject
private IssueExtractor issueExtractor;
+ @Inject @PluginName
+ private String pluginName;
+
@Override
public void doFilter(CommentAddedEvent hook) throws IOException {
- if (!(gerritConfig.getBoolean(its.name(), null, "commentOnCommentAdded",
+ if (!(gerritConfig.getBoolean(pluginName, null, "commentOnCommentAdded",
true))) {
return;
}
@@ -61,7 +66,7 @@
@Override
public void doFilter(ChangeMergedEvent hook) throws IOException {
- if (!(gerritConfig.getBoolean(its.name(), null, "commentOnChangeMerged",
+ if (!(gerritConfig.getBoolean(pluginName, null, "commentOnChangeMerged",
true))) {
return;
}
@@ -72,7 +77,7 @@
@Override
public void doFilter(ChangeAbandonedEvent hook) throws IOException {
- if (!(gerritConfig.getBoolean(its.name(), null, "commentOnChangeAbandoned",
+ if (!(gerritConfig.getBoolean(pluginName, null, "commentOnChangeAbandoned",
true))) {
return;
}
@@ -82,7 +87,7 @@
@Override
public void doFilter(ChangeRestoredEvent hook) throws IOException {
- if (!(gerritConfig.getBoolean(its.name(), null, "commentOnChangeRestored",
+ if (!(gerritConfig.getBoolean(pluginName, null, "commentOnChangeRestored",
true))) {
return;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToChangeId.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToChangeId.java
index 3a8314b..8d6b4ca 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToChangeId.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToChangeId.java
@@ -24,6 +24,7 @@
import org.slf4j.LoggerFactory;
import com.google.common.collect.Lists;
+import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb;
@@ -32,6 +33,7 @@
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.ResultSet;
import com.google.inject.Inject;
+
import com.googlesource.gerrit.plugins.hooks.its.ItsFacade;
import com.googlesource.gerrit.plugins.hooks.util.IssueExtractor;
@@ -54,6 +56,10 @@
@Inject
private ReviewDb db;
+ @Inject @PluginName
+ private String pluginName;
+
+
/**
* Filter issues to those that occur for the first time in a change
*
@@ -97,14 +103,14 @@
@Override
public void doFilter(PatchSetCreatedEvent patchsetCreated)
throws IOException, OrmException {
- boolean addPatchSetComment = gerritConfig.getBoolean(its.name(), null,
+ boolean addPatchSetComment = gerritConfig.getBoolean(pluginName, null,
"commentOnPatchSetCreated", true);
boolean addChangeComment = "1".equals(patchsetCreated.patchSet.number) &&
- gerritConfig.getBoolean(its.name(), null, "commentOnChangeCreated",
+ gerritConfig.getBoolean(pluginName, null, "commentOnChangeCreated",
false);
- boolean addFirstLinkedPatchSetComment = gerritConfig.getBoolean(its.name(),
+ boolean addFirstLinkedPatchSetComment = gerritConfig.getBoolean(pluginName,
null, "commentOnFirstLinkedPatchSetCreated", false);
if (addPatchSetComment || addFirstLinkedPatchSetComment || addChangeComment) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToGitWeb.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToGitWeb.java
index da582f8..cee6d79 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToGitWeb.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToGitWeb.java
@@ -28,10 +28,12 @@
import com.google.gerrit.common.data.GitWebType;
import com.google.gerrit.common.data.ParameterizedString;
+import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.httpd.GitWebConfig;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.events.RefUpdatedEvent;
import com.google.inject.Inject;
+
import com.googlesource.gerrit.plugins.hooks.its.ItsFacade;
import com.googlesource.gerrit.plugins.hooks.util.IssueExtractor;
@@ -53,9 +55,12 @@
@Inject
private IssueExtractor issueExtractor;
+ @Inject @PluginName
+ private String pluginName;
+
@Override
public void doFilter(RefUpdatedEvent hook) throws IOException {
- if (!(gerritConfig.getBoolean(its.name(), null, "commentOnRefUpdatedGitWeb",
+ if (!(gerritConfig.getBoolean(pluginName, null, "commentOnRefUpdatedGitWeb",
true))) {
return;
}
diff --git a/src/main/resources/Documentation/config-common.md b/src/main/resources/Documentation/config-common.md
index 6609d8f..4ad3c97 100644
--- a/src/main/resources/Documentation/config-common.md
+++ b/src/main/resources/Documentation/config-common.md
@@ -113,12 +113,36 @@
‘John Doe’ voted ‘+2’ for ‘Code-Review’ on a change”) should trigger
which action on the ITS (e.g.: “Set issue's status to ‘Resolved’”) is
configured through a [rule base][rule-base] in
-`etc/its/action.config`.
+`etc/its/actions.config`.
[rule-base]: config-rulebase-common.html
+[multiple-its]: #multiple-its
+<a name="mutiple-its">Multiple ITS</a>
+--------------------------------------
+
+Although not a common setup the @PLUGIN@ plugin supports connecting
+Gerrit to multiple issue tracking systems.
+
+For example users may want to reference issues from two independent
+issue tracking systems (i.e. a Bugzilla and a Jira instance). In
+this configuration you can simply install both its plugins and
+configure them as described.
+
+In situations where users want to reference issues from multiple
+instances of the same issue tracking system (i.e. two independent
+Bugzilla instances) they can simply create two its-bugzilla plugin
+files with different names (i.e. its-bugzilla-external.jar and
+its-bugzilla-internal.jar). Gerrit will give each plugin the same
+name as the file name (minus the extension). You can view the names
+by going to the Gerrit UI under menu Plugins -> Installed. Now you
+just need to use the appropriate name to configure each plugin.
+
+
+
+
[legacy-configuration]: #legacy-configuration
<a name="legacy-configuration">Legacy configuration</a>
-------------------------------------------------------
@@ -181,4 +205,4 @@
[Back to @PLUGIN@ documentation index][index]
-[index]: index.html
\ No newline at end of file
+[index]: index.html
diff --git a/src/main/resources/Documentation/config-rulebase-common.md b/src/main/resources/Documentation/config-rulebase-common.md
index 250e18e..1e79fa5 100644
--- a/src/main/resources/Documentation/config-rulebase-common.md
+++ b/src/main/resources/Documentation/config-rulebase-common.md
@@ -47,7 +47,7 @@
Goodness! Someone gave a negative code review in Gerrit on an
associated change.” to each such issue.
-The order of rules in `etc/its/action.config` need not be
+The order of rules in `etc/its/actions.config` need not be
respected. So in the above example, do not rely on `rule1` being
evaluated before `rule2`.
@@ -594,4 +594,4 @@
[Back to @PLUGIN@ documentation index][index]
-[index]: index.html
\ No newline at end of file
+[index]: index.html
diff --git a/src/test/java/com/googlesource/gerrit/plugins/hooks/util/PropertyExtractorTest.java b/src/test/java/com/googlesource/gerrit/plugins/hooks/util/PropertyExtractorTest.java
index dda4173..bb3f7df 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/hooks/util/PropertyExtractorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/hooks/util/PropertyExtractorTest.java
@@ -22,6 +22,7 @@
import com.google.common.collect.Sets;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
+import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.config.FactoryModule;
import com.google.gerrit.server.data.AccountAttribute;
import com.google.gerrit.server.data.ApprovalAttribute;
@@ -38,6 +39,7 @@
import com.google.gerrit.server.events.RefUpdatedEvent;
import com.google.inject.Guice;
import com.google.inject.Injector;
+
import com.googlesource.gerrit.plugins.hooks.testutil.LoggingMockingTestCase;
import com.googlesource.gerrit.plugins.hooks.util.IssueExtractor;
import com.googlesource.gerrit.plugins.hooks.util.PropertyExtractor;
@@ -465,5 +467,20 @@
}
private class DummyChangeEvent extends ChangeEvent {
+ public String getType() {
+ return null;
+ }
+
+ public Project.NameKey getProjectNameKey() {
+ return null;
+ }
+
+ public Change.Key getChangeKey() {
+ return null;
+ }
+
+ public String getRefName() {
+ return null;
+ }
}
}
\ No newline at end of file
diff --git a/src/test/java/com/googlesource/gerrit/plugins/hooks/validation/ItsValidateCommentTest.java b/src/test/java/com/googlesource/gerrit/plugins/hooks/validation/ItsValidateCommentTest.java
index f3fbb12..7c65938 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/hooks/validation/ItsValidateCommentTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/hooks/validation/ItsValidateCommentTest.java
@@ -86,7 +86,6 @@
expect(commit.getName()).andReturn("TestCommit").anyTimes();
expect(issueExtractor.getIssueIds("TestMessage")).andReturn(
new String[] {}).atLeastOnce();
- expect(itsFacade.name()).andReturn("TestFacade").anyTimes();
replayMocks();
@@ -112,7 +111,6 @@
expect(commit.getName()).andReturn("TestCommit").anyTimes();
expect(issueExtractor.getIssueIds("TestMessage")).andReturn(
new String[] {}).atLeastOnce();
- expect(itsFacade.name()).andReturn("TestFacade").anyTimes();
replayMocks();
@@ -142,7 +140,6 @@
expect(commit.getName()).andReturn("TestCommit").anyTimes();
expect(issueExtractor.getIssueIds("bug#4711")).andReturn(
new String[] {"4711"}).atLeastOnce();
- expect(itsFacade.name()).andReturn("TestFacade").anyTimes();
expect(itsFacade.exists("4711")).andReturn(true).atLeastOnce();
replayMocks();
@@ -168,7 +165,6 @@
expect(commit.getName()).andReturn("TestCommit").anyTimes();
expect(issueExtractor.getIssueIds("bug#4711")).andReturn(
new String[] {"4711"}).atLeastOnce();
- expect(itsFacade.name()).andReturn("TestFacade").anyTimes();
expect(itsFacade.exists("4711")).andReturn(true).atLeastOnce();
replayMocks();
@@ -194,7 +190,6 @@
expect(commit.getName()).andReturn("TestCommit").anyTimes();
expect(issueExtractor.getIssueIds("bug#4711")).andReturn(
new String[] {"4711"}).atLeastOnce();
- expect(itsFacade.name()).andReturn("TestFacade").anyTimes();
expect(itsFacade.exists("4711")).andReturn(false).atLeastOnce();
replayMocks();
@@ -224,7 +219,6 @@
expect(commit.getName()).andReturn("TestCommit").anyTimes();
expect(issueExtractor.getIssueIds("bug#4711")).andReturn(
new String[] {"4711"}).atLeastOnce();
- expect(itsFacade.name()).andReturn("TestFacade").anyTimes();
expect(itsFacade.exists("4711")).andReturn(false).atLeastOnce();
replayMocks();
@@ -255,7 +249,6 @@
expect(commit.getName()).andReturn("TestCommit").anyTimes();
expect(issueExtractor.getIssueIds("bug#4711, bug#42")).andReturn(
new String[] {"4711", "42"}).atLeastOnce();
- expect(itsFacade.name()).andReturn("TestFacade").anyTimes();
expect(itsFacade.exists("4711")).andReturn(true).atLeastOnce();
expect(itsFacade.exists("42")).andReturn(true).atLeastOnce();
@@ -283,7 +276,6 @@
expect(commit.getName()).andReturn("TestCommit").anyTimes();
expect(issueExtractor.getIssueIds("bug#4711, bug#42")).andReturn(
new String[] {"4711", "42"}).atLeastOnce();
- expect(itsFacade.name()).andReturn("TestFacade").anyTimes();
expect(itsFacade.exists("4711")).andReturn(true).atLeastOnce();
expect(itsFacade.exists("42")).andReturn(true).atLeastOnce();
@@ -311,7 +303,6 @@
expect(commit.getName()).andReturn("TestCommit").anyTimes();
expect(issueExtractor.getIssueIds("bug#4711, bug#42")).andReturn(
new String[] {"4711", "42"}).atLeastOnce();
- expect(itsFacade.name()).andReturn("TestFacade").anyTimes();
expect(itsFacade.exists("4711")).andReturn(false).atLeastOnce();
expect(itsFacade.exists("42")).andReturn(true).atLeastOnce();
@@ -345,7 +336,6 @@
expect(commit.getName()).andReturn("TestCommit").anyTimes();
expect(issueExtractor.getIssueIds("bug#4711, bug#42")).andReturn(
new String[] {"4711", "42"}).atLeastOnce();
- expect(itsFacade.name()).andReturn("TestFacade").anyTimes();
expect(itsFacade.exists("4711")).andReturn(false).atLeastOnce();
expect(itsFacade.exists("42")).andReturn(true).atLeastOnce();
@@ -377,7 +367,6 @@
expect(commit.getName()).andReturn("TestCommit").anyTimes();
expect(issueExtractor.getIssueIds("bug#4711, bug#42")).andReturn(
new String[] {"4711", "42"}).atLeastOnce();
- expect(itsFacade.name()).andReturn("TestFacade").anyTimes();
expect(itsFacade.exists("4711")).andReturn(false).atLeastOnce();
expect(itsFacade.exists("42")).andReturn(false).atLeastOnce();
@@ -411,7 +400,6 @@
expect(commit.getName()).andReturn("TestCommit").anyTimes();
expect(issueExtractor.getIssueIds("bug#4711, bug#42")).andReturn(
new String[] {"4711", "42"}).atLeastOnce();
- expect(itsFacade.name()).andReturn("TestFacade").anyTimes();
expect(itsFacade.exists("4711")).andReturn(false).atLeastOnce();
expect(itsFacade.exists("42")).andReturn(false).atLeastOnce();
@@ -443,7 +431,6 @@
expect(commit.getName()).andReturn("TestCommit").anyTimes();
expect(issueExtractor.getIssueIds("bug#4711, bug#42"))
.andReturn(new String[] {"4711", "42"}).atLeastOnce();
- expect(itsFacade.name()).andReturn("TestFacade").anyTimes();
expect(itsFacade.exists("4711")).andThrow(new IOException("InjectedEx1"))
.atLeastOnce();
expect(itsFacade.exists("42")).andReturn(false).atLeastOnce();