Extract audit configuration into a separate class
Make the configuration a 1st class citizen by having a dedicated
AuditConfig where more logic can be put in the right place.
Change-Id: I06a8ff691bb64253689d77077224f0a5bc05064c
Change-Id: Id229740f0e2f5d1f303d6608253b09270fad6a37
diff --git a/src/main/java/com/googlesource/gerrit/plugins/auditsl4j/AuditConfig.java b/src/main/java/com/googlesource/gerrit/plugins/auditsl4j/AuditConfig.java
new file mode 100644
index 0000000..ce7a09a
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/auditsl4j/AuditConfig.java
@@ -0,0 +1,33 @@
+// 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.auditsl4j;
+
+import com.google.gerrit.extensions.annotations.PluginName;
+import com.google.gerrit.server.config.PluginConfig;
+import com.google.gerrit.server.config.PluginConfigFactory;
+import com.google.inject.Inject;
+
+public class AuditConfig {
+ private final PluginConfig config;
+
+ @Inject
+ public AuditConfig(@PluginName String pluginName, PluginConfigFactory configFactory) {
+ config = configFactory.getFromGerritConfig(pluginName);
+ }
+
+ public AuditFormatTypes getFormat() {
+ return config.getEnum("format", AuditFormatTypes.CSV);
+ }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/auditsl4j/Module.java b/src/main/java/com/googlesource/gerrit/plugins/auditsl4j/Module.java
index 436ee37..664ce4d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/auditsl4j/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/auditsl4j/Module.java
@@ -15,26 +15,23 @@
package com.googlesource.gerrit.plugins.auditsl4j;
import com.google.gerrit.audit.AuditListener;
-import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.registration.DynamicSet;
-import com.google.gerrit.server.config.PluginConfig;
-import com.google.gerrit.server.config.PluginConfigFactory;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
public class Module extends AbstractModule {
- private final PluginConfig config;
+ private final AuditConfig config;
@Inject
- public Module(@PluginName String pluginName, PluginConfigFactory configFactory) {
- config = configFactory.getFromGerritConfig(pluginName);
+ public Module(AuditConfig config) {
+ this.config = config;
}
@Override
protected void configure() {
DynamicSet.bind(binder(), AuditListener.class).to(LoggerAudit.class);
- AuditFormatTypes rendererType = config.getEnum("format", AuditFormatTypes.CSV);
+ AuditFormatTypes rendererType = config.getFormat();
switch (rendererType) {
case CSV:
bind(AuditFormatRenderer.class).to(AuditRendererToCsv.class);