]> source.dussan.org Git - gitblit.git/commitdiff
WAR/Express builds now copy bundled push scripts to configured scripts folder
authorJames Moger <james.moger@gitblit.com>
Fri, 6 Jan 2012 22:20:59 +0000 (17:20 -0500)
committerJames Moger <james.moger@gitblit.com>
Fri, 6 Jan 2012 22:20:59 +0000 (17:20 -0500)
build.xml
src/com/gitblit/GitBlit.java
src/com/gitblit/utils/FileUtils.java

index c7040463c5803f052b8ad4a7178d4dde9c0e98a7..0d906ed657c2e1ac03af6b96f1a8cc2ff4e3ca1e 100644 (file)
--- a/build.xml
+++ b/build.xml
                <copy tofile="${deployments.root}/WEB-INF/reference.properties" \r
                        file="${basedir}/distrib/gitblit.properties"/>\r
 \r
+               <!-- Copy the supported Groovy hook scripts -->\r
+               <mkdir dir="${deployments.root}/WEB-INF/groovy" />\r
+               <copy todir="${deployments.root}/WEB-INF/groovy">\r
+                       <fileset dir="${basedir}/groovy">\r
+                               <include name="sendmail.groovy" />\r
+                               <include name="jenkins.groovy" />\r
+                       </fileset>\r
+               </copy>\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
index d7120569701703a897768c36709f70a137aebe8b..ce3e16d6d68f8af29e8a2c4dcc1861656e3534d7 100644 (file)
@@ -452,7 +452,7 @@ public class GitBlit implements ServletContextListener {
                List<String> names = new ArrayList<String>(userService.getAllUsernames());\r
                return names;\r
        }\r
-       \r
+\r
        /**\r
         * Returns the list of all users available to the login service.\r
         * \r
@@ -546,7 +546,7 @@ public class GitBlit implements ServletContextListener {
                List<String> teams = new ArrayList<String>(userService.getAllTeamNames());\r
                return teams;\r
        }\r
-       \r
+\r
        /**\r
         * Returns the list of available teams that a user or repository may be\r
         * assigned to.\r
@@ -1788,6 +1788,21 @@ public class GitBlit implements ServletContextListener {
                                webxmlSettings.applyOverrides(overrideFile);\r
                        }\r
                        configureContext(webxmlSettings, true);\r
+\r
+                       // Copy the included scripts to the configured groovy folder\r
+                       File localScripts = getFileOrFolder(Keys.groovy.scriptsFolder, "groovy");\r
+                       if (!localScripts.exists()) {\r
+                               File includedScripts = new File(context.getRealPath("/WEB-INF/groovy"));\r
+                               if (!includedScripts.equals(localScripts)) {\r
+                                       try {\r
+                                               com.gitblit.utils.FileUtils.copy(localScripts, includedScripts.listFiles());\r
+                                       } catch (IOException e) {\r
+                                               logger.error(MessageFormat.format(\r
+                                                               "Failed to copy included Groovy scripts from {0} to {1}",\r
+                                                               includedScripts, localScripts));\r
+                                       }\r
+                               }\r
+                       }\r
                }\r
 \r
                serverStatus.servletContainer = servletContext.getServerInfo();\r
index 73bef34f70c1e472acaf67d1fa2e6ac5d3d12a53..29c9d0fe64bfc782a0fd6e3b034f2b9f153ee956 100644 (file)
  */\r
 package com.gitblit.utils;\r
 \r
+import java.io.BufferedInputStream;\r
 import java.io.BufferedReader;\r
 import java.io.BufferedWriter;\r
 import java.io.File;\r
 import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
 import java.io.FileOutputStream;\r
+import java.io.IOException;\r
 import java.io.InputStreamReader;\r
 import java.io.OutputStreamWriter;\r
 import java.nio.charset.Charset;\r
@@ -103,4 +106,47 @@ public class FileUtils {
                }\r
                return length;\r
        }\r
+\r
+       /**\r
+        * Copies a file or folder (recursively) to a destination folder.\r
+        * \r
+        * @param destinationFolder\r
+        * @param filesOrFolders\r
+        * @return\r
+        * @throws FileNotFoundException\r
+        * @throws IOException\r
+        */\r
+       public static void copy(File destinationFolder, File... filesOrFolders)\r
+                       throws FileNotFoundException, IOException {\r
+               destinationFolder.mkdirs();\r
+               for (File file : filesOrFolders) {\r
+                       if (file.isDirectory()) {\r
+                               copy(new File(destinationFolder, file.getName()), file.listFiles());\r
+                       } else {\r
+                               File dFile = new File(destinationFolder, file.getName());\r
+                               BufferedInputStream bufin = null;\r
+                               FileOutputStream fos = null;\r
+                               try {\r
+                                       bufin = new BufferedInputStream(new FileInputStream(file));\r
+                                       fos = new FileOutputStream(dFile);\r
+                                       int len = 8196;\r
+                                       byte[] buff = new byte[len];\r
+                                       int n = 0;\r
+                                       while ((n = bufin.read(buff, 0, len)) != -1) {\r
+                                               fos.write(buff, 0, n);\r
+                                       }\r
+                               } finally {\r
+                                       try {\r
+                                               bufin.close();\r
+                                       } catch (Throwable t) {\r
+                                       }\r
+                                       try {\r
+                                               fos.close();\r
+                                       } catch (Throwable t) {\r
+                                       }\r
+                               }\r
+                               dFile.setLastModified(file.lastModified());\r
+                       }\r
+               }\r
+       }\r
 }\r