Extract the submit rules into a separate module

And bind this module to BatchModule!

This way, the submit rules provided by this plugin can be used in the
offline reindexing task.

Change-Id: Ib0221df4acdcad149c132d9c7d8eb370e66ddc31
diff --git a/BUILD b/BUILD
index b4c70b6..273cf24 100644
--- a/BUILD
+++ b/BUILD
@@ -6,7 +6,8 @@
     srcs = glob(["src/main/java/**/*.java"]),
     manifest_entries = [
         "Gerrit-PluginName: simple-submit-rules",
-        "Gerrit-Module: com.googlesource.gerrit.plugins.simplesubmitrules.SimpleSubmitRulesModule",
+        "Gerrit-Module: com.googlesource.gerrit.plugins.simplesubmitrules.Module",
+        "Gerrit-BatchModule: com.googlesource.gerrit.plugins.simplesubmitrules.BatchModule",
     ],
     resources = glob(["src/main/resources/**/*"]),
 )
diff --git a/src/main/java/com/googlesource/gerrit/plugins/simplesubmitrules/SimpleSubmitRulesModule.java b/src/main/java/com/googlesource/gerrit/plugins/simplesubmitrules/BatchModule.java
similarity index 66%
copy from src/main/java/com/googlesource/gerrit/plugins/simplesubmitrules/SimpleSubmitRulesModule.java
copy to src/main/java/com/googlesource/gerrit/plugins/simplesubmitrules/BatchModule.java
index 874f6d5..3e9d696 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/simplesubmitrules/SimpleSubmitRulesModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/simplesubmitrules/BatchModule.java
@@ -15,32 +15,17 @@
 package com.googlesource.gerrit.plugins.simplesubmitrules;
 
 import com.google.gerrit.extensions.registration.DynamicSet;
-import com.google.gerrit.extensions.restapi.RestApiModule;
-import com.google.gerrit.server.project.ProjectResource;
 import com.google.gerrit.server.rules.SubmitRule;
 import com.google.inject.AbstractModule;
-import com.googlesource.gerrit.plugins.simplesubmitrules.config.ConfigServlet;
 import com.googlesource.gerrit.plugins.simplesubmitrules.config.ConfigTranslator;
 import com.googlesource.gerrit.plugins.simplesubmitrules.rules.NoUnresolvedCommentsRule;
 import com.googlesource.gerrit.plugins.simplesubmitrules.rules.RequireNonAuthorApprovalRule;
 
-/** Bootstraps the Simple Submit Rules plugin */
-public class SimpleSubmitRulesModule extends AbstractModule {
-  private static final String API_ENDPOINT = "simple-submit-rules";
-
+/** Rules for the batch programs (offline reindexer) */
+public class BatchModule extends AbstractModule {
   @Override
   protected void configure() {
     bind(ConfigTranslator.class);
-
-    install(
-        new RestApiModule() {
-          @Override
-          protected void configure() {
-            get(ProjectResource.PROJECT_KIND, API_ENDPOINT).to(ConfigServlet.class);
-            put(ProjectResource.PROJECT_KIND, API_ENDPOINT).to(ConfigServlet.class);
-          }
-        });
-
     DynamicSet.bind(binder(), SubmitRule.class).to(RequireNonAuthorApprovalRule.class);
     DynamicSet.bind(binder(), SubmitRule.class).to(NoUnresolvedCommentsRule.class);
   }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/simplesubmitrules/SimpleSubmitRulesModule.java b/src/main/java/com/googlesource/gerrit/plugins/simplesubmitrules/Module.java
similarity index 67%
rename from src/main/java/com/googlesource/gerrit/plugins/simplesubmitrules/SimpleSubmitRulesModule.java
rename to src/main/java/com/googlesource/gerrit/plugins/simplesubmitrules/Module.java
index 874f6d5..5aa4cb0 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/simplesubmitrules/SimpleSubmitRulesModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/simplesubmitrules/Module.java
@@ -14,24 +14,17 @@
 
 package com.googlesource.gerrit.plugins.simplesubmitrules;
 
-import com.google.gerrit.extensions.registration.DynamicSet;
 import com.google.gerrit.extensions.restapi.RestApiModule;
 import com.google.gerrit.server.project.ProjectResource;
-import com.google.gerrit.server.rules.SubmitRule;
 import com.google.inject.AbstractModule;
 import com.googlesource.gerrit.plugins.simplesubmitrules.config.ConfigServlet;
-import com.googlesource.gerrit.plugins.simplesubmitrules.config.ConfigTranslator;
-import com.googlesource.gerrit.plugins.simplesubmitrules.rules.NoUnresolvedCommentsRule;
-import com.googlesource.gerrit.plugins.simplesubmitrules.rules.RequireNonAuthorApprovalRule;
 
 /** Bootstraps the Simple Submit Rules plugin */
-public class SimpleSubmitRulesModule extends AbstractModule {
+public class Module extends AbstractModule {
   private static final String API_ENDPOINT = "simple-submit-rules";
 
   @Override
   protected void configure() {
-    bind(ConfigTranslator.class);
-
     install(
         new RestApiModule() {
           @Override
@@ -40,8 +33,6 @@
             put(ProjectResource.PROJECT_KIND, API_ENDPOINT).to(ConfigServlet.class);
           }
         });
-
-    DynamicSet.bind(binder(), SubmitRule.class).to(RequireNonAuthorApprovalRule.class);
-    DynamicSet.bind(binder(), SubmitRule.class).to(NoUnresolvedCommentsRule.class);
+    install(new BatchModule());
   }
 }