From: James Moger Date: Tue, 30 Sep 2014 11:51:31 +0000 (-0400) Subject: Support GITBLIT_HOME as a system property and environment variable X-Git-Tag: v1.6.1~21^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Ftickets%2F93%2F193%2F1;p=gitblit.git Support GITBLIT_HOME as a system property and environment variable --- diff --git a/src/main/java/com/gitblit/GitBlitServer.java b/src/main/java/com/gitblit/GitBlitServer.java index b40e21f8..c79b1720 100644 --- a/src/main/java/com/gitblit/GitBlitServer.java +++ b/src/main/java/com/gitblit/GitBlitServer.java @@ -148,6 +148,15 @@ public class GitBlitServer { System.exit(0); } + protected File getBaseFolder(Params params) { + String path = System.getProperty("GITBLIT_HOME", Params.baseFolder); + if (!StringUtils.isEmpty(System.getenv("GITBLIT_HOME"))) { + path = System.getenv("GITBLIT_HOME"); + } + + return new File(path).getAbsoluteFile(); + } + /** * Stop Gitblt GO. */ @@ -170,7 +179,7 @@ public class GitBlitServer { * Start Gitblit GO. */ protected final void start(Params params) { - final File baseFolder = new File(Params.baseFolder).getAbsoluteFile(); + final File baseFolder = getBaseFolder(params); FileSettings settings = params.FILESETTINGS; if (!StringUtils.isEmpty(params.settingsfile)) { if (new File(params.settingsfile).exists()) { diff --git a/src/main/java/com/gitblit/servlet/GitblitContext.java b/src/main/java/com/gitblit/servlet/GitblitContext.java index 64d68e77..e5c59bd0 100644 --- a/src/main/java/com/gitblit/servlet/GitblitContext.java +++ b/src/main/java/com/gitblit/servlet/GitblitContext.java @@ -153,7 +153,7 @@ public class GitblitContext extends DaggerContext { // 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); @@ -218,6 +218,24 @@ public class GitblitContext extends DaggerContext { 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 loadManager(ObjectGraph injector, Class clazz) { X x = injector.get(clazz); return x; @@ -305,9 +323,9 @@ public class GitblitContext extends DaggerContext { logger.debug("configuring Gitblit WAR"); logger.info("WAR contextFolder is " + ((contextFolder != null) ? contextFolder.getAbsolutePath() : "")); - 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}\"!", @@ -317,18 +335,15 @@ public class GitblitContext extends DaggerContext { 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 @@ -340,7 +355,7 @@ public class GitblitContext extends DaggerContext { // the target file for runtimeSettings is set to "localSettings". runtimeSettings.merge(fileSettings); - return base; + return baseFolder; } /**