RuleBase: Extract name of config files to providers

Facilitate reusing the name of the rules configuration files besides its
use in RuleBase. This refactoring is needed in order to add capability
of reading project-specific rules, which is done in a follow-up change.

Change-Id: Ibe2d5af442b048ee35448ee3fa0ad18a512484aa
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/GlobalRulesFileName.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/GlobalRulesFileName.java
new file mode 100644
index 0000000..4d33168
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/GlobalRulesFileName.java
@@ -0,0 +1,24 @@
+// Copyright (C) 2018 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.googlesource.gerrit.plugins.its.base;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import com.google.inject.BindingAnnotation;
+import java.lang.annotation.Retention;
+
+@Retention(RUNTIME)
+@BindingAnnotation
+public @interface GlobalRulesFileName {}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/ItsHookModule.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/ItsHookModule.java
index 691a037..a85a4e9 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/ItsHookModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/ItsHookModule.java
@@ -41,6 +41,9 @@
 
 public class ItsHookModule extends FactoryModule {
 
+  /** Rules configuration filename pattern */
+  private static final String CONFIG_FILE_NAME = "actions%s.config";
+
   /** Folder where rules configuration files are located */
   private static final String ITS_FOLDER = "its";
 
@@ -76,4 +79,16 @@
   Path itsPath(SitePaths sitePaths) {
     return sitePaths.etc_dir.normalize().resolve(ITS_FOLDER);
   }
+
+  @Provides
+  @GlobalRulesFileName
+  String globalRulesFileName() {
+    return String.format(CONFIG_FILE_NAME, "");
+  }
+
+  @Provides
+  @PluginRulesFileName
+  String pluginRulesFileName() {
+    return String.format(CONFIG_FILE_NAME, "-" + pluginName);
+  }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/PluginRulesFileName.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/PluginRulesFileName.java
new file mode 100644
index 0000000..e53b44b
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/PluginRulesFileName.java
@@ -0,0 +1,24 @@
+// Copyright (C) 2018 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.googlesource.gerrit.plugins.its.base;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import com.google.inject.BindingAnnotation;
+import java.lang.annotation.Retention;
+
+@Retention(RUNTIME)
+@BindingAnnotation
+public @interface PluginRulesFileName {}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBase.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBase.java
index e1f6220..a6afa08 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBase.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBase.java
@@ -15,9 +15,10 @@
 package com.googlesource.gerrit.plugins.its.base.workflow;
 
 import com.google.common.collect.Lists;
-import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.inject.Inject;
+import com.googlesource.gerrit.plugins.its.base.GlobalRulesFileName;
 import com.googlesource.gerrit.plugins.its.base.ItsPath;
+import com.googlesource.gerrit.plugins.its.base.PluginRulesFileName;
 import java.io.File;
 import java.io.IOException;
 import java.nio.file.Path;
@@ -32,9 +33,6 @@
 public class RuleBase {
   private static final Logger log = LoggerFactory.getLogger(RuleBase.class);
 
-  /** Rules configuration filename pattern */
-  private static final String CONFIG_FILE_NAME = "actions%s.config";
-
   /** The section for rules within rulebases */
   private static final String RULE_SECTION = "rule";
 
@@ -45,7 +43,8 @@
   private final Rule.Factory ruleFactory;
   private final Condition.Factory conditionFactory;
   private final ActionRequest.Factory actionRequestFactory;
-  private final String pluginName;
+  private final String globalRulesFileName;
+  private final String pluginRulesFileName;
 
   private Collection<Rule> rules;
 
@@ -59,12 +58,14 @@
       Rule.Factory ruleFactory,
       Condition.Factory conditionFactory,
       ActionRequest.Factory actionRequestFactory,
-      @PluginName String pluginName) {
+      @GlobalRulesFileName String globalRulesFileName,
+      @PluginRulesFileName String pluginRulesFileName) {
     this.itsPath = itsPath;
     this.ruleFactory = ruleFactory;
     this.conditionFactory = conditionFactory;
     this.actionRequestFactory = actionRequestFactory;
-    this.pluginName = pluginName;
+    this.globalRulesFileName = globalRulesFileName;
+    this.pluginRulesFileName = pluginRulesFileName;
     reloadRules();
   }
 
@@ -117,12 +118,11 @@
     rules = Lists.newArrayList();
 
     // Add global rules
-    File globalRuleFile = itsPath.resolve(String.format(CONFIG_FILE_NAME, "")).toFile();
+    File globalRuleFile = itsPath.resolve(globalRulesFileName).toFile();
     addRulesFromFile(globalRuleFile);
 
     // Add its-specific rules
-    File itsSpecificRuleFile =
-        itsPath.resolve(String.format(CONFIG_FILE_NAME, "-" + pluginName)).toFile();
+    File itsSpecificRuleFile = itsPath.resolve(pluginRulesFileName).toFile();
     addRulesFromFile(itsSpecificRuleFile);
 
     if (!globalRuleFile.exists() && !itsSpecificRuleFile.exists()) {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBaseTest.java b/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBaseTest.java
index 2ba4d4a..d7c66b2 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBaseTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBaseTest.java
@@ -20,7 +20,9 @@
 import com.google.gerrit.extensions.config.FactoryModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
+import com.googlesource.gerrit.plugins.its.base.GlobalRulesFileName;
 import com.googlesource.gerrit.plugins.its.base.ItsPath;
+import com.googlesource.gerrit.plugins.its.base.PluginRulesFileName;
 import com.googlesource.gerrit.plugins.its.base.testutil.LoggingMockingTestCase;
 import java.io.IOException;
 import java.nio.file.Files;
@@ -332,6 +334,14 @@
 
       bind(Path.class).annotatedWith(ItsPath.class).toInstance(itsPath);
 
+      bind(String.class)
+          .annotatedWith(GlobalRulesFileName.class)
+          .toInstance(RuleBaseKind.GLOBAL.fileName);
+
+      bind(String.class)
+          .annotatedWith(PluginRulesFileName.class)
+          .toInstance(RuleBaseKind.ITS.fileName);
+
       ruleFactory = createMock(Rule.Factory.class);
       bind(Rule.Factory.class).toInstance(ruleFactory);