From 0e44acbb2fec928a1606dc60f427a148fff405c9 Mon Sep 17 00:00:00 2001
From: Mohamed Ragab <moragab@gmail.com>
Date: Wed, 02 May 2012 11:15:01 -0400
Subject: [PATCH] Added a script to facilitate setting the proxy host and port and no proxy hosts, and then it concatenates all the java system properties for setting the java proxy configurations and puts the resulting string in an environment variable JAVA_PROXY_CONFIG, modified the scirpts gitblit, gitblit-ubuntu, and gitblit-centos to source the java-proxy-config.sh script and then include the resulting java proxy configuration in the java command
---
src/com/gitblit/GitServlet.java | 93 ++++++++++++++++++++++++++++++++++------------
1 files changed, 69 insertions(+), 24 deletions(-)
diff --git a/src/com/gitblit/GitServlet.java b/src/com/gitblit/GitServlet.java
index b2ee1c7..94042c7 100644
--- a/src/com/gitblit/GitServlet.java
+++ b/src/com/gitblit/GitServlet.java
@@ -26,9 +26,12 @@
import java.io.OutputStreamWriter;
import java.text.MessageFormat;
import java.util.Collection;
-import java.util.List;
+import java.util.Enumeration;
+import java.util.LinkedHashSet;
+import java.util.Set;
import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -47,6 +50,8 @@
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;
@@ -68,24 +73,13 @@
private GroovyScriptEngine gse;
- /**
- * Configure the servlet from Gitblit's configuration.
- */
- @Override
- public String getInitParameter(String name) {
- if (name.equals("base-path")) {
- return GitBlit.getRepositoriesFolder().getAbsolutePath();
- } else if (name.equals("export-all")) {
- return "1";
- }
- return super.getInitParameter(name);
- }
+ private File groovyDir;
@Override
public void init(ServletConfig config) throws ServletException {
- String groovyRoot = GitBlit.getString(Keys.groovy.scriptsFolder, "groovy");
+ groovyDir = GitBlit.getGroovyScriptsFolder();
try {
- gse = new GroovyScriptEngine(groovyRoot);
+ gse = new GroovyScriptEngine(groovyDir.getAbsolutePath());
} catch (IOException e) {
throw new ServletException("Failed to instantiate Groovy Script Engine!", e);
}
@@ -103,7 +97,48 @@
return rp;
}
});
- super.init(config);
+ super.init(new GitblitServletConfig(config));
+ }
+
+ /**
+ * Transitional wrapper class to configure the JGit 1.2 GitFilter. This
+ * GitServlet will probably be replaced by a GitFilter so that Gitblit can
+ * serve Git repositories on the root URL and not a /git sub-url.
+ *
+ * @author James Moger
+ *
+ */
+ private class GitblitServletConfig implements ServletConfig {
+ final ServletConfig config;
+
+ GitblitServletConfig(ServletConfig config) {
+ this.config = config;
+ }
+
+ @Override
+ public String getServletName() {
+ return config.getServletName();
+ }
+
+ @Override
+ public ServletContext getServletContext() {
+ return config.getServletContext();
+ }
+
+ @Override
+ public String getInitParameter(String name) {
+ if (name.equals("base-path")) {
+ return GitBlit.getRepositoriesFolder().getAbsolutePath();
+ } else if (name.equals("export-all")) {
+ return "1";
+ }
+ return config.getInitParameter(name);
+ }
+
+ @Override
+ public Enumeration<String> getInitParameterNames() {
+ return config.getInitParameterNames();
+ }
}
/**
@@ -127,11 +162,12 @@
*/
@Override
public void onPreReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {
- List<String> scripts = GitBlit.getStrings(Keys.groovy.preReceiveScripts);
RepositoryModel repository = getRepositoryModel(rp);
+ Set<String> scripts = new LinkedHashSet<String>();
+ 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()
@@ -154,11 +190,12 @@
logger.info("skipping post-receive hooks, no refs created, updated, or removed");
return;
}
- List<String> scripts = GitBlit.getStrings(Keys.groovy.postReceiveScripts);
RepositoryModel repository = getRepositoryModel(rp);
+ Set<String> scripts = new LinkedHashSet<String>();
+ 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);
@@ -172,9 +209,7 @@
*/
protected RepositoryModel getRepositoryModel(ReceivePack rp) {
Repository repository = rp.getRepository();
- String rootPath = GitBlit.getRepositoriesFolder().getAbsolutePath();
- String repositoryName = repository.getDirectory().getAbsolutePath();
- repositoryName = repositoryName.substring(rootPath.length() + 1);
+ String repositoryName = FileUtils.getRelativePath(GitBlit.getRepositoriesFolder(), repository.getDirectory());
RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
return model;
}
@@ -204,7 +239,7 @@
* @param scripts
*/
protected void runGroovy(RepositoryModel repository, UserModel user,
- Collection<ReceiveCommand> commands, List<String> scripts) {
+ Collection<ReceiveCommand> commands, ReceivePack rp, Set<String> scripts) {
if (scripts == null || scripts.size() == 0) {
// no Groovy scripts to execute
return;
@@ -217,10 +252,20 @@
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;
}
+ // allow script to be specified without .groovy extension
+ // this is easier to read in the settings
+ File file = new File(groovyDir, script);
+ if (!file.exists() && !script.toLowerCase().endsWith(".groovy")) {
+ file = new File(groovyDir, script + ".groovy");
+ if (file.exists()) {
+ script = file.getName();
+ }
+ }
try {
Object result = gse.run(script, binding);
if (result instanceof Boolean) {
--
Gitblit v1.9.1