Move websession directory resolving into a provider
Change-Id: Ie69d42ea18deb325c1dbd81d3551b58460d24352
diff --git a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSession.java b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSession.java
index cb02265..475ff41 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSession.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSession.java
@@ -14,6 +14,7 @@
package com.googlesource.gerrit.plugins.websession.flatfile;
+import com.google.gerrit.extensions.annotations.RootRelative;
import com.google.gerrit.extensions.registration.DynamicItem;
import com.google.gerrit.httpd.CacheBasedWebSession;
import com.google.gerrit.httpd.WebSession;
@@ -21,12 +22,17 @@
import com.google.gerrit.server.AnonymousUser;
import com.google.gerrit.server.IdentifiedUser.RequestFactory;
import com.google.gerrit.server.config.AuthConfig;
+import com.google.gerrit.server.config.PluginConfigFactory;
+import com.google.gerrit.server.config.SitePaths;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Provider;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
import com.google.inject.servlet.RequestScoped;
import com.google.inject.servlet.ServletScopes;
-import com.google.gerrit.extensions.annotations.RootRelative;
+
+import java.io.File;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -41,6 +47,14 @@
DynamicItem.bind(binder(), WebSession.class)
.to(FlatFileWebSession.class).in(RequestScoped.class);
}
+
+ @Provides
+ @Singleton
+ @WebSessionDir
+ File getWebSessionDir(SitePaths site, PluginConfigFactory cfg) {
+ return new File(cfg.getFromGerritConfig("websession-flatfile").getString(
+ "directory", site.site_path + "/websessions"));
+ }
}
@Inject
diff --git a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCache.java b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCache.java
index 948a400..1114093 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCache.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCache.java
@@ -20,8 +20,6 @@
import com.google.gerrit.common.Nullable;
import com.google.gerrit.httpd.WebSessionManager;
import com.google.gerrit.httpd.WebSessionManager.Val;
-import com.google.gerrit.server.config.PluginConfigFactory;
-import com.google.gerrit.server.config.SitePaths;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -54,9 +52,8 @@
private final File dir;
@Inject
- public FlatFileWebSessionCache(SitePaths site, PluginConfigFactory cfg) {
- dir = new File(cfg.getFromGerritConfig("websession-flatfile")
- .getString("directory", site.site_path + "/websessions"));
+ public FlatFileWebSessionCache(@WebSessionDir File dir) {
+ this.dir = dir;
if (!dir.exists()) {
log.info(dir + " not found. Creating it.");
dir.mkdir();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/WebSessionDir.java b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/WebSessionDir.java
new file mode 100644
index 0000000..02288bf
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/WebSessionDir.java
@@ -0,0 +1,26 @@
+// Copyright (C) 2015 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.websession.flatfile;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import com.google.inject.BindingAnnotation;
+
+import java.lang.annotation.Retention;
+
+@Retention(RUNTIME)
+@BindingAnnotation
+@interface WebSessionDir {
+}