Do not inject into Module constructor.

No functionality is changed.
This is required to work with Google Gerrit servers.

Change-Id: I93dc4f2a539590234756cd49acb151df7bf0b416
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
index f5972d6..80fa81d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
@@ -15,6 +15,7 @@
 package com.googlesource.gerrit.plugins.findowners;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.restapi.BadRequestException;
 import com.google.gerrit.extensions.restapi.Response;
 import com.google.gerrit.extensions.restapi.RestReadView;
@@ -28,6 +29,7 @@
 import com.google.gerrit.server.account.AccountCache;
 import com.google.gerrit.server.change.ChangeResource;
 import com.google.gerrit.server.change.RevisionResource;
+import com.google.gerrit.server.config.PluginConfigFactory;
 import com.google.gerrit.server.git.GitRepositoryManager;
 import com.google.gerrit.server.query.change.ChangeData;
 import com.google.gwtorm.server.OrmException;
@@ -64,6 +66,8 @@
 
   @Inject
   Action(
+      @PluginName String pluginName,
+      PluginConfigFactory configFactory,
       Provider<CurrentUser> userProvider,
       SchemaFactory<ReviewDb> reviewDbProvider,
       ChangeData.Factory changeDataFactory,
@@ -74,6 +78,8 @@
     this.changeDataFactory = changeDataFactory;
     this.accountCache = accountCache;
     this.repoManager = repoManager;
+    Config.setVariables(pluginName, configFactory);
+    Cache.getInstance(); // Create a single Cache.
   }
 
   @VisibleForTesting
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/Config.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/Config.java
index 66c394c..8eb0f84 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Config.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Config.java
@@ -46,10 +46,14 @@
 
   private static final Logger log = LoggerFactory.getLogger(Config.class);
 
-  static void setVariables(
-      PluginConfigFactory conf, PluginConfig gc, org.eclipse.jgit.lib.Config pc) {
-    // Get config variables from pc, or from gc.
+  static void setVariables(String pluginName, PluginConfigFactory conf) {
+    if (conf == null) { // When called from integration tests.
+      return;
+    }
     config = conf;
+    PluginConfig gc = config.getFromGerritConfig(pluginName, true);
+    org.eclipse.jgit.lib.Config pc = config.getGlobalPluginConfig(pluginName);
+    // Get config variables from pc, or from gc.
     addDebugMsg =
         pc.getBoolean(SECTION, null, ADD_DEBUG_MSG, gc.getBoolean(Config.ADD_DEBUG_MSG, false));
     reportSyntaxError =
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/GetOwners.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/GetOwners.java
index bbf5619..d4e45ef 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/GetOwners.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/GetOwners.java
@@ -14,6 +14,7 @@
 
 package com.googlesource.gerrit.plugins.findowners;
 
+import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.restapi.BadRequestException;
 import com.google.gerrit.extensions.restapi.Response;
 import com.google.gerrit.extensions.restapi.RestReadView;
@@ -21,6 +22,7 @@
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.account.AccountCache;
 import com.google.gerrit.server.change.ChangeResource;
+import com.google.gerrit.server.config.PluginConfigFactory;
 import com.google.gerrit.server.git.GitRepositoryManager;
 import com.google.gerrit.server.query.change.ChangeData;
 import com.google.gwtorm.server.OrmException;
@@ -36,7 +38,7 @@
 public class GetOwners implements RestReadView<ChangeResource> {
   private static final Logger log = LoggerFactory.getLogger(GetOwners.class);
 
-  private Action action;
+  private final Action action;
 
   // "debug" could be true/yes/1 or false/no/0,
   // when not specified configuration variable "addDebugMsg" is used.
@@ -48,13 +50,22 @@
 
   @Inject
   GetOwners(
+      @PluginName String pluginName,
+      PluginConfigFactory configFactory,
       Provider<CurrentUser> userProvider,
       SchemaFactory<ReviewDb> reviewDbProvider,
       ChangeData.Factory dataFactory,
       AccountCache accountCache,
       GitRepositoryManager repoManager) {
     this.action =
-        new Action(userProvider, reviewDbProvider, dataFactory, accountCache, repoManager);
+        new Action(
+            pluginName,
+            configFactory,
+            userProvider,
+            reviewDbProvider,
+            dataFactory,
+            accountCache,
+            repoManager);
   }
 
   @Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/Module.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/Module.java
index 13a3b5d..9fc2709 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Module.java
@@ -32,21 +32,19 @@
 public class Module extends AbstractModule {
   /** Prolog Predicate Provider. */
   static class FindOwnersProvider implements PredicateProvider {
+
+    @Inject
+    public FindOwnersProvider(@PluginName String pluginName, PluginConfigFactory configFactory) {
+      Config.setVariables(pluginName, configFactory);
+      Cache.getInstance(); // Create a single Cache.
+    }
+
     @Override
     public ImmutableSet<String> getPackages() {
       return ImmutableSet.of(Config.PROLOG_NAMESPACE);
     }
   }
 
-  @Inject
-  public Module(@PluginName String pluginName, PluginConfigFactory config) {
-    Config.setVariables(
-        config,
-        config.getFromGerritConfig(pluginName, true),
-        config.getGlobalPluginConfig(pluginName));
-    Cache.getInstance(); // Create a single Cache.
-  }
-
   @Override
   protected void configure() {
     install(
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwnersIT.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwnersIT.java
index 75e1e16..1501b3e 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwnersIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwnersIT.java
@@ -178,7 +178,8 @@
     ChangeInfo changeInfo = newChangeInfo("test Action.apply");
     ChangeResource cr = parseChangeResource(changeInfo.changeId);
     Action.Parameters param = new Action.Parameters();
-    Action action = new Action(null, null, changeDataFactory, accountCache, repoManager);
+    Action action =
+        new Action("find-owners", null, null, null, changeDataFactory, accountCache, repoManager);
     Response<RestResult> response = action.apply(db, cr, param);
     RestResult result = response.value();
     verifyRestResult(result, 1, 1, changeInfo._number, false);