| | |
| | |
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.ClientLogger;
|
| | | import com.gitblit.utils.FileUtils;
|
| | | import com.gitblit.utils.HttpUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | |
|
| | |
| | | public void init(ServletConfig config) throws ServletException {
|
| | | groovyDir = GitBlit.getGroovyScriptsFolder();
|
| | | try {
|
| | | gse = new GroovyScriptEngine(groovyDir.getAbsolutePath());
|
| | | // set Grape root
|
| | | File grapeRoot = new File(GitBlit.getString(Keys.groovy.grapeFolder, "groovy/grape")).getAbsoluteFile();
|
| | | grapeRoot.mkdirs();
|
| | | System.setProperty("grape.root", grapeRoot.getAbsolutePath());
|
| | | |
| | | gse = new GroovyScriptEngine(groovyDir.getAbsolutePath()); |
| | | } catch (IOException e) {
|
| | | throw new ServletException("Failed to instantiate Groovy Script Engine!", e);
|
| | | }
|
| | |
| | | scripts.addAll(GitBlit.self().getPreReceiveScriptsInherited(repository));
|
| | | scripts.addAll(repository.preReceiveScripts);
|
| | | UserModel user = getUserModel(rp);
|
| | | runGroovy(repository, user, commands, scripts);
|
| | | runGroovy(repository, user, commands, rp, scripts);
|
| | | for (ReceiveCommand cmd : commands) {
|
| | | if (!Result.NOT_ATTEMPTED.equals(cmd.getResult())) {
|
| | | logger.warn(MessageFormat.format("{0} {1} because \"{2}\"", cmd.getNewId()
|
| | |
| | | scripts.addAll(GitBlit.self().getPostReceiveScriptsInherited(repository));
|
| | | scripts.addAll(repository.postReceiveScripts);
|
| | | UserModel user = getUserModel(rp);
|
| | | runGroovy(repository, user, commands, scripts);
|
| | | runGroovy(repository, user, commands, rp, scripts);
|
| | |
|
| | | // Experimental
|
| | | // runNativeScript(rp, "hooks/post-receive", commands);
|
| | |
| | | */
|
| | | protected RepositoryModel getRepositoryModel(ReceivePack rp) {
|
| | | Repository repository = rp.getRepository();
|
| | | String rootPath = GitBlit.getRepositoriesFolder().getAbsolutePath();
|
| | | String repositoryName = StringUtils.getRelativePath(rootPath, repository.getDirectory()
|
| | | .getAbsolutePath());
|
| | | String repositoryName = FileUtils.getRelativePath(GitBlit.getRepositoriesFolder(), repository.getDirectory());
|
| | | RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
|
| | | return model;
|
| | | }
|
| | |
| | | * @param scripts
|
| | | */
|
| | | protected void runGroovy(RepositoryModel repository, UserModel user,
|
| | | Collection<ReceiveCommand> commands, Set<String> scripts) {
|
| | | Collection<ReceiveCommand> commands, ReceivePack rp, Set<String> scripts) {
|
| | | if (scripts == null || scripts.size() == 0) {
|
| | | // no Groovy scripts to execute
|
| | | return;
|
| | |
| | | binding.setVariable("commands", commands);
|
| | | binding.setVariable("url", gitblitUrl);
|
| | | binding.setVariable("logger", logger);
|
| | | binding.setVariable("clientLogger", new ClientLogger(rp));
|
| | | for (String script : scripts) {
|
| | | if (StringUtils.isEmpty(script)) {
|
| | | continue;
|