]> source.dussan.org Git - gitblit.git/commitdiff
Preliminary changes for running on RedHat OpenShift. Still in-progress.
authorJames Moger <james.moger@gitblit.com>
Fri, 2 Dec 2011 20:31:38 +0000 (15:31 -0500)
committerJames Moger <james.moger@gitblit.com>
Fri, 2 Dec 2011 20:31:38 +0000 (15:31 -0500)
.gitignore
build.xml
distrib/openshift.mkd [new file with mode: 0644]
docs/00_index.mkd
docs/04_releases.mkd
src/com/gitblit/GitBlit.java
src/com/gitblit/GitServlet.java
src/com/gitblit/WebXmlSettings.java

index 9074474fac995fb46461e0d92148f0bbce93995f..66dc8d673527a6e0c172041cd4111269406aa0b0 100644 (file)
@@ -21,3 +21,5 @@
 /bin/\r
 /.settings/\r
 /javadoc
+/express
+/build-demo.xml
index 4d5ce6ec900ffad4fbf3695f90852815d1b52586..e2d9e4bbfc0d68c1138d6e4dba6af8cbe26f45b7 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -16,6 +16,7 @@
        <property name="project.war.dir" value="${basedir}/war" />\r
        <property name="project.site.dir" value="${basedir}/site" />\r
        <property name="project.resources.dir" value="${basedir}/resources" />  \r
+       <property name="project.express.dir" value="${basedir}/express" />\r
        <available property="hasBuildProps" file="${basedir}/build.properties"/>\r
 \r
        <!--\r
@@ -87,6 +88,7 @@
                <property name="fedclient.zipfile" value="fedclient-${gb.version}.zip" />\r
                <property name="manager.zipfile" value="manager-${gb.version}.zip" />\r
                <property name="gbapi.zipfile" value="gbapi-${gb.version}.zip" />\r
+               <property name="express.zipfile" value="express-${gb.version}.zip" />\r
        </target>\r
        \r
        \r
                        <fileset dir="${basedir}/distrib">\r
                                <include name="**/*" />\r
                                <exclude name="federation.properties" />\r
+                               <exclude name="openshift.mkd" />\r
                        </fileset>\r
                        <fileset dir="${basedir}">\r
                                <include name="LICENSE" />\r
                                <arg value="--substitute" />\r
                                <arg value="%API%=${gbapi.zipfile}" />\r
 \r
+                               <arg value="--substitute" />\r
+                               <arg value="%EXPRESS%=${express.zipfile}" />\r
+\r
                                <arg value="--substitute" />\r
                                <arg value="%BUILDDATE%=${gb.versionDate}" />\r
 \r
                \r
                <echo>Building Gitblit WAR ${gb.version}</echo>\r
                \r
-               <delete dir="${project.war.dir}" />             \r
+               <delete dir="${project.war.dir}" />\r
 \r
                <!-- Copy web.xml and users.properties to WEB-INF -->\r
                <copy todir="${project.war.dir}/WEB-INF">\r
                <mkdir dir="${project.war.dir}/WEB-INF/classes"/>\r
                <copy todir="${project.war.dir}/WEB-INF/classes">\r
                        <fileset dir="${project.build.dir}">\r
-                               <exclude name="WEB-INF/web.xml" />\r
+                               <exclude name="WEB-INF/" />\r
                                <exclude name="com/gitblit/tests/" />\r
                                <exclude name="com/gitblit/build/**" />\r
                                <exclude name="com/gitblit/client/**" />\r
        </target>\r
 \r
 \r
+       <!-- \r
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+               Build a Gitblit filesystem for deployment to RedHat OpenShif Expresst\r
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+       -->\r
+       <target name="buildOpenShift" depends="compile" description="Build exploded WAR file suitable for deployment to OpenShift Express">\r
+               <echo>Building Gitblit Express for RedHat OpenShift ${gb.version}</echo>\r
+               \r
+               <delete dir="${project.express.dir}" />\r
+               \r
+               <!-- Create the OpenShift filesystem -->\r
+               <property name="deployments.root" value="${project.express.dir}/deployments/ROOT.war"/>\r
+               <mkdir dir="${deployments.root}" />\r
+               <touch file="${project.express.dir}/deployments/ROOT.war.dodeploy" />\r
+\r
+               <!-- Copy the Gitblit OpenShift readme file -->\r
+               <copy tofile="${project.express.dir}/README.gitblit" \r
+                       file="${basedir}/distrib/openshift.mkd"/>\r
+\r
+               <!-- Copy LICENSE and NOTICE to WEB-INF -->\r
+               <copy todir="${deployments.root}/WEB-INF">\r
+                       <fileset dir="${basedir}">\r
+                               <include name="LICENSE" />\r
+                               <include name="NOTICE" />\r
+                       </fileset>\r
+               </copy>\r
+\r
+               <!-- Copy gitblit.properties as reference.properties -->\r
+               <copy tofile="${deployments.root}/WEB-INF/reference.properties" \r
+                       file="${basedir}/distrib/gitblit.properties"/>\r
+\r
+               <!-- Build the WAR web.xml from the prototype web.xml and gitblit.properties -->\r
+               <!-- THIS FILE IS NOT OVERRIDDEN ONCE IT IS BUILT!!! -->\r
+               <java classpath="${project.build.dir}" classname="com.gitblit.build.BuildWebXml">\r
+                       <classpath refid="master-classpath" />\r
+\r
+                       <arg value="--sourceFile" />\r
+                       <arg value="${basedir}/src/WEB-INF/web.xml" />\r
+\r
+                       <arg value="--destinationFile" />\r
+                       <arg value="${deployments.root}/WEB-INF/web.xml" />\r
+\r
+                       <arg value="--propertiesFile" />\r
+                       <arg value="${basedir}/distrib/gitblit.properties" />\r
+               </java>\r
+\r
+               <!-- Gitblit resources -->\r
+               <copy todir="${deployments.root}">\r
+                       <fileset dir="${project.resources.dir}">\r
+                               <exclude name="thumbs.db" />\r
+                       </fileset>\r
+               </copy>\r
+\r
+               <!-- Gitblit library dependencies -->\r
+               <mkdir dir="${deployments.root}/WEB-INF/lib"/>\r
+               <copy todir="${deployments.root}/WEB-INF/lib">\r
+                       <fileset dir="${basedir}/ext">\r
+                               <exclude name="*-sources.jar" />\r
+                               <exclude name="*-javadoc.jar" />\r
+                               <exclude name="jcommander*.jar" />\r
+                               <exclude name="jetty*.jar" />\r
+                               <exclude name="junit*.jar" />\r
+                               <exclude name="servlet*.jar" />\r
+                       </fileset>\r
+               </copy>\r
+\r
+               <!-- Gitblit classes -->\r
+               <mkdir dir="${deployments.root}/WEB-INF/classes"/>\r
+               <copy todir="${deployments.root}/WEB-INF/classes">\r
+                       <fileset dir="${project.build.dir}">\r
+                               <exclude name="WEB-INF/" />\r
+                               <exclude name="com/gitblit/tests/" />\r
+                               <exclude name="com/gitblit/build/**" />\r
+                               <exclude name="com/gitblit/client/**" />\r
+                               <exclude name="com/gitblit/GitBlitServer*.class" />\r
+                               <exclude name="com/gitblit/Launcher*.class" />\r
+                               <exclude name="com/gitblit/MakeCertificate*.class" />\r
+                       </fileset>\r
+               </copy>\r
+\r
+               <!-- Build Express Zip file -->\r
+               <zip destfile="${express.zipfile}">\r
+                       <fileset dir="${project.express.dir}" />\r
+               </zip>\r
+\r
+       </target>\r
+\r
+\r
        <!-- \r
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
                Build the stand-alone, Gitblit Manager\r
        -->\r
        <target name="buildManager" depends="compile" description="Builds the stand-alone Gitblit Manager">\r
                <echo>Building Gitblit Manager ${gb.version}</echo>\r
-       \r
+\r
                <genjar jarfile="manager-${gb.version}.jar">\r
                        <resource file="${basedir}/src/com/gitblit/client/splash.png" />\r
                        <resource file="${basedir}/resources/gitblt-favicon.png" />\r
                        <resource file="${basedir}/resources/commit_merge_16x16.png" />\r
                        <resource file="${basedir}/resources/blank.png" />\r
                        <resource file="${basedir}/src/com/gitblit/wicket/GitBlitWebApp.properties" />\r
-                               \r
+\r
                        <class name="com.gitblit.client.GitblitManagerLauncher" />\r
                        <classfilter>\r
                                <exclude name="org.apache." />\r
                                <attribute name="Release-Date" value="${gb.versionDate}" />\r
                        </manifest>\r
                </genjar>\r
-               \r
+\r
                <!-- Build Manager Zip file -->\r
                <zip destfile="${manager.zipfile}">\r
                        <fileset dir="${basedir}">\r
                        <arg value="--substitute" />\r
                        <arg value="%API%=${gbapi.zipfile}" />\r
 \r
+                       <arg value="--substitute" />\r
+                       <arg value="%EXPRESS%=${express.zipfile}" />\r
+\r
                        <arg value="--substitute" />\r
                        <arg value="%BUILDDATE%=${gb.versionDate}" />\r
 \r
 \r
                </java> \r
        </target>\r
-               \r
+\r
 \r
        <!--\r
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \r
                Compile from source, publish binaries, and build & deploy site\r
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
        -->\r
-       <target name="buildAll" depends="buildGO,buildWAR,buildFederationClient,buildManager,buildApiLibrary,buildSite">                \r
+       <target name="buildAll" depends="buildGO,buildWAR,buildOpenShift,buildFederationClient,buildManager,buildApiLibrary,buildSite">         \r
                <!-- Cleanup -->\r
                <delete dir="${project.build.dir}" />\r
                <delete dir="${project.war.dir}" />\r
                <delete dir="${project.deploy.dir}" />\r
+               <delete dir="${project.express.dir}" />\r
        </target>\r
-                               \r
-       \r
+\r
+\r
        <!-- \r
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
                Publish binaries to Google Code\r
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
        -->\r
-       <target name="publishBinaries" depends="buildGO,buildWAR,buildFederationClient,buildManager" description="Publish the Gitblit binaries to Google Code">\r
-               \r
+       <target name="publishBinaries" depends="buildGO,buildWAR,buildOpenShift,buildFederationClient,buildManager" description="Publish the Gitblit binaries to Google Code">\r
+\r
                <echo>Uploading Gitblit ${gb.version} binaries</echo>\r
-               \r
+\r
                <!-- Upload Gitblit GO ZIP file -->\r
                <gcupload \r
                         username="${googlecode.user}" \r
                         targetfilename="gitblit-${gb.version}.zip"\r
                         summary="Gitblit GO v${gb.version} (standalone, integrated Gitblit server)"\r
                         labels="Featured, Type-Package, OpSys-All" />\r
-                       \r
+\r
                <!-- Upload Gitblit WAR file -->\r
                <gcupload \r
                     username="${googlecode.user}" \r
                     targetfilename="gitblit-${gb.version}.war"\r
                     summary="Gitblit WAR v${gb.version} (standard WAR webapp for servlet containers)"\r
                     labels="Featured, Type-Package, OpSys-All" />\r
-               \r
+\r
                <!-- Upload Gitblit FedClient -->\r
                <gcupload \r
                        username="${googlecode.user}" \r
                        targetfilename="manager-${gb.version}.zip"\r
                        summary="Gitblit Manager v${gb.version} (Swing tool to remotely administer a Gitblit server)"\r
                        labels="Featured, Type-Package, OpSys-All" />\r
-               \r
+\r
                <!-- Upload Gitblit API Library -->\r
                <gcupload \r
                        username="${googlecode.user}" \r
                        targetfilename="gbapi-${gb.version}.zip"\r
                        summary="Gitblit API Library v${gb.version} (JSON RPC library to integrate with your software)"\r
                        labels="Featured, Type-Package, OpSys-All" />\r
+\r
+               <!-- Upload Gitblit Express for RedHat OpenShift -->\r
+               <gcupload \r
+                       username="${googlecode.user}" \r
+                       password="${googlecode.password}" \r
+                       projectname="gitblit" \r
+                       filename="${express.zipfile}" \r
+                       targetfilename="express-${gb.version}.zip"\r
+                       summary="Gitblit Express v${gb.version} (run Gitblit on RedHat's OpenShift cloud)"\r
+                       labels="Featured, Type-Package, OpSys-All" />\r
+\r
        </target>\r
 \r
-       \r
+\r
        <!--\r
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \r
-               Publish site to hosting service\r
+               Publish site to site hosting service\r
                You must add ext/commons-net-1.4.0.jar to your ANT classpath.\r
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
        -->\r
        <target name="publishSite" depends="buildSite" description="Publish the Gitblit site to a webserver (requires ext/commons-net-1.4.0.jar)" >\r
-               \r
+\r
                <echo>Uploading Gitblit ${gb.version} website</echo>\r
-               \r
+\r
                <ftp server="${ftp.server}"\r
                        userid="${ftp.user}"\r
                        password="${ftp.password}"\r
                </ftp>\r
        </target>\r
 \r
-       \r
+\r
        <!--\r
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \r
                Compile from source, publish binaries, and build & deploy site\r
diff --git a/distrib/openshift.mkd b/distrib/openshift.mkd
new file mode 100644 (file)
index 0000000..5d144bd
--- /dev/null
@@ -0,0 +1,35 @@
+## Gitblit on RedHat's OpenShift Cloud Service\r
+\r
+The Gitblit Express distribution can be copied to the root of your RedHat OpenShift\r
+application repository.  Gitblit Express is an exploded WAR file with all appropriate\r
+dependencies bundled.\r
+\r
+You should delete the `pom.xml` file and the `src` folder from your application repository\r
+as this Gitblit Express is not a source distribution to be built with Maven on OpenShift.\r
+\r
+Gitblit automatically adjusts itself to running on OpenShift.  Repositories, users,\r
+federation proposals, and setting overrides are stored in *OPENSHIFT_DATA_DIR*.\r
+\r
+It is recommended to enable all RPC settings in the `web.xml` file to allow remote\r
+administration and, more importantly, configuration of your Gitblit Express\r
+installation using the Gitblit Manager.\r
+\r
+Please do not change the following settings unless you know exactly what you are\r
+doing:\r
+\r
+- *git.repositoriesFolder*\r
+- *federation.proposalsFolder*\r
+- *realm.userService* (for standard users.properties)\r
\r
+Additionally, it is recommended to force your Gitblit installation to cleanup up\r
+older versions on your OpenShift filesystem to maximize available space for your\r
+repositories.\r
+\r
+Append the following command to your ./openshift/action_hooks/build file:\r
+\r
+    rm -fr $OPENSHIFT_APP_DIR/jbossas-7.0/standalone/tmp/vfs/*\r
+\r
+For more detailed instructions on how to setup and deploy an OpenShift application\r
+please see this excellent turorial:\r
+\r
+https://github.com/opensas/play-demo/wiki/Step-12.5---deploy-to-openshift\r
index fadde6410b6e7c9efba3071308c6797f278819a3..91e617f8fb3b3df0104a81ebbe2721806e32cce7 100644 (file)
@@ -1,15 +1,16 @@
 ## What is Gitblit?\r
 <div class="well" style="margin-left:5px;float:right;width:275px;padding: 10px 10px;">\r
 <b>Current Release %VERSION% (%BUILDDATE%)</b> <a href="releases.html">changelog</a>\r
-<div style="padding:5px;"><a style="text-decoration:none;" class="btn success" href="http://code.google.com/p/gitblit/downloads/detail?name=%GO%">Download Gitblit GO</a></div>\r
-<div style="padding:5px;"><a style="text-decoration:none;" class="btn danger" href="http://code.google.com/p/gitblit/downloads/detail?name=%WAR%">Download Gitblit WAR</a></div>\r
-<div style="padding:5px;"><a style="text-decoration:none;" class="btn primary" href="http://code.google.com/p/gitblit/downloads/detail?name=%MANAGER%">Download Gitblit Manager</a></div>\r
-       <div style="text-align:center;">\r
+<div style="padding:5px;"><a style="width:150px;text-decoration:none;" class="btn success" href="http://code.google.com/p/gitblit/downloads/detail?name=%GO%">Download Gitblit GO</a></div>\r
+<div style="padding:5px;"><a style="width:150px;text-decoration:none;" class="btn danger" href="http://code.google.com/p/gitblit/downloads/detail?name=%WAR%">Download Gitblit WAR</a></div>\r
+<div style="padding:5px;"><a style="width:150px;text-decoration:none;" class="btn info" href="http://code.google.com/p/gitblit/downloads/detail?name=%EXPRESS%">Download Gitblit Express</a></div>\r
+<div style="padding:5px;"><a style="width:150px;text-decoration:none;" class="btn primary" href="http://code.google.com/p/gitblit/downloads/detail?name=%MANAGER%">Download Gitblit Manager</a></div>\r
+       <div style="text-align:center">\r
                <a href="http://code.google.com/p/gitblit/downloads/detail?name=%API%">Gitblit API</a> | <a href="http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%">Gitblit Federation Client</a>\r
                <br/>\r
                <a href="screenshots.html" title="Screenshots"><img style="margin-top:5px;border:1px solid #ccc;" src="thumbs/00.png" alt="Screenshots" /></a>\r
        </div>\r
-       \r
+\r
        <div style="padding-top:5px;">\r
        <table class="condensed-table">\r
                <tbody>\r
@@ -19,9 +20,9 @@
                <tr><th>Discussion</th><td><a href="http://groups.google.com/group/gitblit">Gitblit Group</a></td></tr>\r
                <tr><th>Google+</th><td><a href="https://plus.google.com/114464678392593421684">Gitblit+</a></td></tr>\r
                </tbody>\r
-               </table>                \r
+               </table>\r
        </div>\r
-       \r
+\r
        <a target="_top" href="http://www.ohloh.net/p/gitblit">\r
                <img style="padding-top:5px;" border="0" width="100" height="16" src="http://www.ohloh.net/p/gitblit/widgets/project_thin_badge.gif" alt="Ohloh project report for Gitblit" />\r
        </a>\r
 Gitblit is an open-source, pure Java stack for managing, viewing, and serving [Git][git] repositories.  \r
 It's designed primarily as a tool for small workgroups who want to host centralized repositories.\r
 \r
+You can browse a live demo [here](http://demo-gitblit.rhcloud.com) hosted on [RedHat's OpenShift][rhcloud] cloud service.\r
+\r
 ### GO: Single-Stack Solution\r
 \r
 *Gitblit GO* is an integrated, single-stack solution based on Jetty.\r
-  \r
+\r
 You do not need Apache httpd, Perl, Git, or Gitweb.  Should you want to use some or all of those, you still can; Gitblit plays nice with the other kids on the block.\r
 \r
 This is what you should download if you want to go from zero to Git in less than 5 mins.\r
-   \r
+\r
 All dependencies are downloaded on first execution.\r
 \r
 ### WAR: For Your Servlet Container\r
 *Gitblit WAR* is what you should download if you already have a servlet container available that you wish to use.  Jetty 6/7/8 and Tomcat 6/7 are known to work.  Generally, any Servlet 2.5 or Servlet 3.0 container should work.\r
-    \r
+\r
+All dependencies are bundled.\r
+\r
+### Express: For the Cloud\r
+*Gitblit Express* is a prepared distribution for [RedHat's OpenShift][rhcloud] cloud service.\r
+\r
 All dependencies are bundled.\r
 \r
 ### You decide how to use Gitblit\r
@@ -72,4 +80,5 @@ Gitblit includes a backup mechanism (*federation*) which can be used to backup r
 Gitblit requires a Java 6 Runtime Environment (JRE) or a Java 6 Development Kit (JDK).\r
 \r
 [jgit]: http://eclipse.org/jgit "Eclipse JGit Site"\r
-[git]: http://git-scm.com "Official Git Site"
\ No newline at end of file
+[git]: http://git-scm.com "Official Git Site"\r
+[rhcloud]: https://openshift.redhat.com/app "RedHat OpenShift"
\ No newline at end of file
index 22ecce7824c5ad12c81dbff0e7165eaff390dddd..a4a2c4c4a4f8c04166f08de7d90010e4b89b849c 100644 (file)
@@ -1,11 +1,12 @@
 ## Release History\r
 \r
 ### Current Release\r
-**%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%) | [war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%) | [fedclient](http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%) | [manager](http://code.google.com/p/gitblit/downloads/detail?name=%MANAGER%) | [api](http://code.google.com/p/gitblit/downloads/detail?name=%API%)) based on [%JGIT%][jgit] &nbsp; *released %BUILDDATE%*\r
+**%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%) | [war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%) | [express](http://code.google.com/p/gitblit/downloads/detail?name=%EXPRESS%) | [fedclient](http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%) | [manager](http://code.google.com/p/gitblit/downloads/detail?name=%MANAGER%) | [api](http://code.google.com/p/gitblit/downloads/detail?name=%API%)) based on [%JGIT%][jgit] &nbsp; *released %BUILDDATE%*\r
 \r
+- added: Gitblit Express bundle for running Gitblit on RedHat's OpenShift cloud\r
 - added: optional Gravatar integration  \r
     **New:** *web.allowGravatar = true*   \r
-- added: multi-repository activity page.  this is a timeline of commit activity over the last N days for one or more repositories.\r
+- added: multi-repository activity page.  this is a timeline of commit activity over the last N days for one or more repositories.  \r
    **New:** *web.activityDuration = 14*  \r
    **New:** *web.timeFormat = HH:mm*  \r
    **New:** *web.datestampLongFormat = EEEE, MMMM d, yyyy*  \r
index bc356676202a7b85218657b13da2ddc681a54d15..80550f497b828f26770c33813a64c087ea5264fd 100644 (file)
@@ -246,6 +246,54 @@ public class GitBlit implements ServletContextListener {
                return self().settings.getBoolean(Keys.web.debugMode, false);\r
        }\r
 \r
+       /**\r
+        * Returns the file object for the specified configuration key.\r
+        * \r
+        * @return the file\r
+        */\r
+       public static File getFileOrFolder(String key, String defaultFileOrFolder) {\r
+               String fileOrFolder = GitBlit.getString(key, defaultFileOrFolder);\r
+               return getFileOrFolder(fileOrFolder);\r
+       }\r
+\r
+       /**\r
+        * Returns the file object which may have it's base-path determined by\r
+        * environment variables for running on a cloud hosting service. All Gitblit\r
+        * file or folder retrievals are (at least initially) funneled through this\r
+        * method so it is the correct point to globally override/alter filesystem\r
+        * access based on environment or some other indicator.\r
+        * \r
+        * @return the file\r
+        */\r
+       public static File getFileOrFolder(String fileOrFolder) {\r
+               String openShift = System.getenv("OPENSHIFT_DATA_DIR");\r
+               if (!StringUtils.isEmpty(openShift)) {\r
+                       // running on RedHat OpenShift\r
+                       return new File(openShift, fileOrFolder);\r
+               }\r
+               return new File(fileOrFolder);\r
+       }\r
+\r
+       /**\r
+        * Returns the path of the repositories folder. This method checks to see if\r
+        * Gitblit is running on a cloud service and may return an adjusted path.\r
+        * \r
+        * @return the repositories folder path\r
+        */\r
+       public static File getRepositoriesFolder() {\r
+               return getFileOrFolder(Keys.git.repositoriesFolder, "git");\r
+       }\r
+\r
+       /**\r
+        * Returns the path of the proposals folder. This method checks to see if\r
+        * Gitblit is running on a cloud service and may return an adjusted path.\r
+        * \r
+        * @return the proposals folder path\r
+        */\r
+       public static File getProposalsFolder() {\r
+               return getFileOrFolder(Keys.federation.proposalsFolder, "proposals");\r
+       }\r
+\r
        /**\r
         * Updates the list of server settings.\r
         * \r
@@ -1120,8 +1168,7 @@ public class GitBlit implements ServletContextListener {
 \r
                try {\r
                        // make the proposals folder\r
-                       File proposalsFolder = new File(getString(Keys.federation.proposalsFolder, "proposals")\r
-                                       .trim());\r
+                       File proposalsFolder = getProposalsFolder();\r
                        proposalsFolder.mkdirs();\r
 \r
                        // cache json to a file\r
@@ -1153,7 +1200,7 @@ public class GitBlit implements ServletContextListener {
         */\r
        public List<FederationProposal> getPendingFederationProposals() {\r
                List<FederationProposal> list = new ArrayList<FederationProposal>();\r
-               File folder = new File(getString(Keys.federation.proposalsFolder, "proposals").trim());\r
+               File folder = getProposalsFolder();\r
                if (folder.exists()) {\r
                        File[] files = folder.listFiles(new FileFilter() {\r
                                @Override\r
@@ -1276,7 +1323,7 @@ public class GitBlit implements ServletContextListener {
         * @return true if the proposal was deleted\r
         */\r
        public boolean deletePendingFederationProposal(FederationProposal proposal) {\r
-               File folder = new File(getString(Keys.federation.proposalsFolder, "proposals").trim());\r
+               File folder = getProposalsFolder();\r
                File file = new File(folder, proposal.token + Constants.PROPOSAL_EXT);\r
                return file.delete();\r
        }\r
@@ -1391,7 +1438,7 @@ public class GitBlit implements ServletContextListener {
        public void configureContext(IStoredSettings settings, boolean startFederation) {\r
                logger.info("Reading configuration from " + settings.toString());\r
                this.settings = settings;\r
-               repositoriesFolder = new File(settings.getString(Keys.git.repositoriesFolder, "git"));\r
+               repositoriesFolder = getRepositoriesFolder();\r
                logger.info("Git repositories folder " + repositoriesFolder.getAbsolutePath());\r
                repositoryResolver = new FileResolver<Void>(repositoriesFolder, exportAll);\r
                serverStatus = new ServerStatus(isGO());\r
@@ -1406,16 +1453,26 @@ public class GitBlit implements ServletContextListener {
                } catch (Throwable t) {\r
                        // not a login service class or class could not be instantiated.\r
                        // try to use default file login service\r
-                       File realmFile = new File(realm);\r
-                       if (!realmFile.exists()) {\r
+                       File realmFile = getFileOrFolder(Keys.realm.userService, "users.properties");\r
+                       if (realmFile.exists()) {\r
+                               // load the existing realm file\r
+                               loginService = new FileUserService(realmFile);\r
+                       } else {\r
+                               // create a new realm file and add the default admin account.\r
+                               // this is necessary for bootstrapping a dynamic environment\r
+                               // like running on a cloud service.\r
                                try {\r
                                        realmFile.createNewFile();\r
+                                       loginService = new FileUserService(realmFile);\r
+                                       UserModel admin = new UserModel("admin");\r
+                                       admin.password = "admin";\r
+                                       admin.canAdmin = true;\r
+                                       loginService.updateUserModel(admin);\r
                                } catch (IOException x) {\r
                                        logger.error(\r
                                                        MessageFormat.format("COULD NOT CREATE REALM FILE {0}!", realmFile), x);\r
                                }\r
                        }\r
-                       loginService = new FileUserService(realmFile);\r
                }\r
                setUserService(loginService);\r
                mailExecutor = new MailExecutor(settings);\r
@@ -1441,7 +1498,21 @@ public class GitBlit implements ServletContextListener {
                settingsModel = loadSettingModels();\r
                if (settings == null) {\r
                        // Gitblit WAR is running in a servlet container\r
-                       WebXmlSettings webxmlSettings = new WebXmlSettings(contextEvent.getServletContext());\r
+                       ServletContext context = contextEvent.getServletContext();\r
+                       WebXmlSettings webxmlSettings = new WebXmlSettings(context);\r
+\r
+                       // 0.7.0 web.properties in the deployed war folder\r
+                       File overrideFile = new File(context.getRealPath("/WEB-INF/web.properties"));\r
+                       if (overrideFile.exists()) {\r
+                               webxmlSettings.applyOverrides(overrideFile);\r
+                       }\r
+\r
+                       // 0.8.0 gitblit.properties file located outside the deployed war\r
+                       // folder lie, for example, on RedHat OpenShift.\r
+                       overrideFile = getFileOrFolder("gitblit.properties");\r
+                       if (!overrideFile.getPath().equals("gitblit.properties")) {\r
+                               webxmlSettings.applyOverrides(overrideFile);\r
+                       }\r
                        configureContext(webxmlSettings, true);\r
                }\r
 \r
index 34d1257d141c21f817eec3da5a6504908e97db95..b928d83606f0a990339ac225f2aaedcae5412647 100644 (file)
@@ -35,7 +35,7 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
        @Override\r
        public String getInitParameter(String name) {\r
                if (name.equals("base-path")) {\r
-                       return GitBlit.getString(Keys.git.repositoriesFolder, "git");\r
+                       return GitBlit.getRepositoriesFolder().getAbsolutePath();\r
                } else if (name.equals("export-all")) {\r
                        return "1";\r
                }\r
index 055c7d35762f36538d94eb4b9fdd74b9f88b5307..7c8120b7b2422c0eed7ee7c6c631a7c7f73f355a 100644 (file)
@@ -20,6 +20,7 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;\r
 import java.io.InputStream;\r
 import java.io.OutputStream;\r
+import java.text.MessageFormat;\r
 import java.util.Enumeration;\r
 import java.util.Map;\r
 import java.util.Properties;\r
@@ -38,11 +39,10 @@ public class WebXmlSettings extends IStoredSettings {
 \r
        private final Properties properties = new Properties();\r
 \r
-       private final ServletContext context;\r
+       private File overrideFile;\r
 \r
        public WebXmlSettings(ServletContext context) {\r
                super(WebXmlSettings.class);\r
-               this.context = context;\r
                Enumeration<?> keys = context.getInitParameterNames();\r
                while (keys.hasMoreElements()) {\r
                        String key = keys.nextElement().toString();\r
@@ -50,15 +50,21 @@ public class WebXmlSettings extends IStoredSettings {
                        properties.put(key, decodeValue(value));\r
                        logger.debug(key + "=" + properties.getProperty(key));\r
                }\r
+       }\r
+\r
+       public void applyOverrides(File overrideFile) {\r
+               this.overrideFile = overrideFile;\r
+               \r
                // apply any web-configured overrides\r
-               File file = new File(context.getRealPath("/WEB-INF/web.properties"));\r
-               if (file.exists()) {\r
+               if (overrideFile.exists()) {\r
                        try {\r
-                               InputStream is = new FileInputStream(file);\r
+                               InputStream is = new FileInputStream(overrideFile);\r
                                properties.load(is);\r
                                is.close();\r
                        } catch (Throwable t) {\r
-                               logger.error("Failed to load web.properties setting overrides", t);\r
+                               logger.error(\r
+                                               MessageFormat.format("Failed to apply {0} setting overrides",\r
+                                                               overrideFile.getAbsolutePath()), t);\r
                        }\r
                }\r
        }\r
@@ -78,19 +84,18 @@ public class WebXmlSettings extends IStoredSettings {
                try {\r
                        Properties props = new Properties();\r
                        // load pre-existing web-configuration\r
-                       File file = new File(context.getRealPath("/WEB-INF/web.properties"));\r
-                       if (file.exists()) {\r
-                               InputStream is = new FileInputStream(file);\r
+                       if (overrideFile.exists()) {\r
+                               InputStream is = new FileInputStream(overrideFile);\r
                                props.load(is);\r
                                is.close();\r
                        }\r
-                       \r
+\r
                        // put all new settings and persist\r
                        props.putAll(settings);\r
-                       OutputStream os = new FileOutputStream(file);\r
+                       OutputStream os = new FileOutputStream(overrideFile);\r
                        props.store(os, null);\r
                        os.close();\r
-                       \r
+\r
                        // override current runtime settings\r
                        properties.putAll(settings);\r
                        return true;\r