]> source.dussan.org Git - gitblit.git/commitdiff
Support GITBLIT_HOME as a system property and environment variable 93/193/1
authorJames Moger <james.moger@gitblit.com>
Tue, 30 Sep 2014 11:51:31 +0000 (07:51 -0400)
committerJames Moger <james.moger@gitblit.com>
Tue, 30 Sep 2014 11:51:31 +0000 (07:51 -0400)
src/main/java/com/gitblit/GitBlitServer.java
src/main/java/com/gitblit/servlet/GitblitContext.java

index b40e21f821889914acf15176d1667dbf0b95ddfc..c79b17205aa9e359ce302808a4c3fd5994d1e4b9 100644 (file)
@@ -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()) {
index 64d68e773facf96ff94de6149d6629ed22129868..e5c59bd0a3007e4b90410c4916a0d0f7317e80d2 100644 (file)
@@ -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 extends IManager> X loadManager(ObjectGraph injector, Class<X> 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() : "<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}\"!",
@@ -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;
        }
 
        /**