summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/servlet/GitblitContext.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-09-30 08:07:59 -0400
committerJames Moger <james.moger@gitblit.com>2014-09-30 08:07:59 -0400
commit794034351714877b71838aec5c51dc015b55d848 (patch)
tree3b8c437bec1b1b3b2569fadfc1183c3fc2b4930c /src/main/java/com/gitblit/servlet/GitblitContext.java
parentafbcba32133f1c85ef50a6515fabad2aa745b614 (diff)
parent43ddbf959829a732f5aefcccf72d2812a41fdbfd (diff)
downloadgitblit-794034351714877b71838aec5c51dc015b55d848.tar.gz
gitblit-794034351714877b71838aec5c51dc015b55d848.zip
Merge branch 'ticket/193' into develop
Diffstat (limited to 'src/main/java/com/gitblit/servlet/GitblitContext.java')
-rw-r--r--src/main/java/com/gitblit/servlet/GitblitContext.java39
1 files changed, 27 insertions, 12 deletions
diff --git a/src/main/java/com/gitblit/servlet/GitblitContext.java b/src/main/java/com/gitblit/servlet/GitblitContext.java
index a18a1431..04a7d92e 100644
--- a/src/main/java/com/gitblit/servlet/GitblitContext.java
+++ b/src/main/java/com/gitblit/servlet/GitblitContext.java
@@ -168,7 +168,7 @@ public class GitblitContext extends GuiceServletContextListener {
// if the base folder dosen't match the default assume they don't want to use express,
// this allows for other containers to customise the basefolder per context.
String defaultBase = Constants.contextFolder$ + "/WEB-INF/data";
- String base = System.getProperty("GITBLIT_HOME",lookupBaseFolderFromJndi());
+ String base = getBaseFolderPath(defaultBase);
if (!StringUtils.isEmpty(System.getenv("OPENSHIFT_DATA_DIR")) && defaultBase.equals(base)) {
// RedHat OpenShift
baseFolder = configureExpress(context, webxmlSettings, contextFolder, runtimeSettings);
@@ -235,6 +235,24 @@ public class GitblitContext extends GuiceServletContextListener {
return null;
}
+ protected String getBaseFolderPath(String defaultBaseFolder) {
+ // try a system property or a JNDI property
+ String specifiedBaseFolder = System.getProperty("GITBLIT_HOME", lookupBaseFolderFromJndi());
+
+ if (!StringUtils.isEmpty(System.getenv("GITBLIT_HOME"))) {
+ // try an environment variable
+ specifiedBaseFolder = System.getenv("GITBLIT_HOME");
+ }
+
+ if (!StringUtils.isEmpty(specifiedBaseFolder)) {
+ // use specified base folder path
+ return specifiedBaseFolder;
+ }
+
+ // use default base folder path
+ return defaultBaseFolder;
+ }
+
protected <X extends IManager> X loadManager(Injector injector, Class<X> clazz) {
X x = injector.getInstance(clazz);
return x;
@@ -328,9 +346,9 @@ public class GitblitContext extends GuiceServletContextListener {
logger.debug("configuring Gitblit WAR");
logger.info("WAR contextFolder is " + ((contextFolder != null) ? contextFolder.getAbsolutePath() : "<empty>"));
- String path = webxmlSettings.getString(Constants.baseFolder, Constants.contextFolder$ + "/WEB-INF/data");
+ String webXmlPath = webxmlSettings.getString(Constants.baseFolder, Constants.contextFolder$ + "/WEB-INF/data");
- if (path.contains(Constants.contextFolder$) && contextFolder == null) {
+ if (webXmlPath.contains(Constants.contextFolder$) && contextFolder == null) {
// warn about null contextFolder (issue-199)
logger.error("");
logger.error(MessageFormat.format("\"{0}\" depends on \"{1}\" but \"{2}\" is returning NULL for \"{1}\"!",
@@ -340,18 +358,15 @@ public class GitblitContext extends GuiceServletContextListener {
logger.error("");
}
- String externalBase = System.getProperty("GITBLIT_HOME", lookupBaseFolderFromJndi());
- if (!StringUtils.isEmpty(externalBase)) {
- path = externalBase;
- }
+ String baseFolderPath = getBaseFolderPath(webXmlPath);
- File base = com.gitblit.utils.FileUtils.resolveParameter(Constants.contextFolder$, contextFolder, path);
- base.mkdirs();
+ File baseFolder = com.gitblit.utils.FileUtils.resolveParameter(Constants.contextFolder$, contextFolder, baseFolderPath);
+ baseFolder.mkdirs();
// try to extract the data folder resource to the baseFolder
- File localSettings = new File(base, "gitblit.properties");
+ File localSettings = new File(baseFolder, "gitblit.properties");
if (!localSettings.exists()) {
- extractResources(context, "/WEB-INF/data/", base);
+ extractResources(context, "/WEB-INF/data/", baseFolder);
}
// delegate all config to baseFolder/gitblit.properties file
@@ -363,7 +378,7 @@ public class GitblitContext extends GuiceServletContextListener {
// the target file for runtimeSettings is set to "localSettings".
runtimeSettings.merge(fileSettings);
- return base;
+ return baseFolder;
}
/**