import groovy.lang.Binding;\r
import groovy.util.GroovyScriptEngine;\r
\r
-import java.io.BufferedReader;\r
-import java.io.BufferedWriter;\r
import java.io.File;\r
import java.io.IOException;\r
-import java.io.InputStreamReader;\r
-import java.io.OutputStreamWriter;\r
import java.text.MessageFormat;\r
import java.util.Collection;\r
import java.util.Enumeration;\r
.getName(), cmd.getResult(), cmd.getMessage()));\r
}\r
}\r
-\r
- // Experimental\r
- // runNativeScript(rp, "hooks/pre-receive", commands);\r
}\r
\r
/**\r
scripts.addAll(GitBlit.self().getPostReceiveScriptsInherited(repository));\r
scripts.addAll(repository.postReceiveScripts);\r
runGroovy(repository, user, commands, rp, scripts);\r
- \r
- // Experimental\r
- // runNativeScript(rp, "hooks/post-receive", commands);\r
}\r
\r
/**\r
}\r
}\r
}\r
-\r
- /**\r
- * Runs the native push hook script.\r
- * \r
- * http://book.git-scm.com/5_git_hooks.html\r
- * http://longair.net/blog/2011/04/09/missing-git-hooks-documentation/\r
- * \r
- * @param rp\r
- * @param script\r
- * @param commands\r
- */\r
- @SuppressWarnings("unused")\r
- protected void runNativeScript(ReceivePack rp, String script,\r
- Collection<ReceiveCommand> commands) {\r
-\r
- Repository repository = rp.getRepository();\r
- File scriptFile = new File(repository.getDirectory(), script);\r
-\r
- int resultCode = 0;\r
- if (scriptFile.exists()) {\r
- try {\r
- logger.debug("executing " + scriptFile);\r
- Process process = Runtime.getRuntime().exec(scriptFile.getAbsolutePath(), null,\r
- repository.getDirectory());\r
- BufferedReader reader = new BufferedReader(new InputStreamReader(\r
- process.getInputStream()));\r
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(\r
- process.getOutputStream()));\r
- for (ReceiveCommand command : commands) {\r
- switch (command.getType()) {\r
- case UPDATE:\r
- // updating a ref\r
- writer.append(MessageFormat.format("{0} {1} {2}\n", command.getOldId()\r
- .getName(), command.getNewId().getName(), command.getRefName()));\r
- break;\r
- case CREATE:\r
- // new ref\r
- // oldrev hard-coded to 40? weird.\r
- writer.append(MessageFormat.format("40 {0} {1}\n", command.getNewId()\r
- .getName(), command.getRefName()));\r
- break;\r
- }\r
- }\r
- resultCode = process.waitFor();\r
-\r
- // read and buffer stdin\r
- // this is supposed to be piped back to the git client.\r
- // not sure how to do that right now.\r
- StringBuilder sb = new StringBuilder();\r
- String line = null;\r
- while ((line = reader.readLine()) != null) {\r
- sb.append(line).append('\n');\r
- }\r
- logger.debug(sb.toString());\r
- } catch (Throwable e) {\r
- resultCode = -1;\r
- logger.error(\r
- MessageFormat.format("Failed to execute {0}",\r
- scriptFile.getAbsolutePath()), e);\r
- }\r
- }\r
-\r
- // reject push\r
- if (resultCode != 0) {\r
- for (ReceiveCommand command : commands) {\r
- command.setResult(Result.REJECTED_OTHER_REASON, MessageFormat.format(\r
- "Native script {0} rejected push or failed",\r
- scriptFile.getAbsolutePath()));\r
- }\r
- }\r
- }\r
}\r
}\r