summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/git
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-11-18 22:31:37 -0500
committerJames Moger <james.moger@gitblit.com>2013-11-29 11:05:46 -0500
commitcacf8bff097fbb66a7be1bfe267b5da2605145f8 (patch)
tree7096df41b5944c569b1db24203eae8dcfa26ba04 /src/main/java/com/gitblit/git
parent79cad53bba094cffa1d25581edbf4972a5158cd4 (diff)
downloadgitblit-cacf8bff097fbb66a7be1bfe267b5da2605145f8.tar.gz
gitblit-cacf8bff097fbb66a7be1bfe267b5da2605145f8.zip
Use Dagger to inject managers into all filters and servlets
Change-Id: I9bb2cc0cbfac9841b13bed15a474fefb24355cd4
Diffstat (limited to 'src/main/java/com/gitblit/git')
-rw-r--r--src/main/java/com/gitblit/git/GitDaemon.java58
-rw-r--r--src/main/java/com/gitblit/git/GitServlet.java34
-rw-r--r--src/main/java/com/gitblit/git/GitblitReceivePack.java20
-rw-r--r--src/main/java/com/gitblit/git/GitblitReceivePackFactory.java28
-rw-r--r--src/main/java/com/gitblit/git/GitblitUploadPackFactory.java8
-rw-r--r--src/main/java/com/gitblit/git/RepositoryResolver.java17
6 files changed, 102 insertions, 63 deletions
diff --git a/src/main/java/com/gitblit/git/GitDaemon.java b/src/main/java/com/gitblit/git/GitDaemon.java
index bb578efc..40cbe704 100644
--- a/src/main/java/com/gitblit/git/GitDaemon.java
+++ b/src/main/java/com/gitblit/git/GitDaemon.java
@@ -43,7 +43,6 @@
*/
package com.gitblit.git;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
@@ -68,6 +67,12 @@ import org.eclipse.jgit.transport.resolver.UploadPackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.gitblit.IStoredSettings;
+import com.gitblit.Keys;
+import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.ISessionManager;
+import com.gitblit.manager.IUserManager;
import com.gitblit.utils.StringUtils;
/**
@@ -106,45 +111,28 @@ public class GitDaemon {
private ReceivePackFactory<GitDaemonClient> receivePackFactory;
- /** Configure a daemon to listen on any available network port. */
- public GitDaemon() {
- this(null);
- }
+ public GitDaemon(
+ IRuntimeManager runtimeManager,
+ IUserManager userManager,
+ ISessionManager sessionManager,
+ IRepositoryManager repositoryManager) {
- /**
- * Construct the Gitblit Git daemon.
- *
- * @param bindInterface
- * the ip address of the interface to bind
- * @param port
- * the port to serve on
- * @param folder
- * the folder to serve from
- */
- public GitDaemon(String bindInterface, int port, File folder) {
- this(StringUtils.isEmpty(bindInterface) ? new InetSocketAddress(port)
- : new InetSocketAddress(bindInterface, port));
+ IStoredSettings settings = runtimeManager.getSettings();
+ int port = settings.getInteger(Keys.git.daemonPort, 0);
+ String bindInterface = settings.getString(Keys.git.daemonBindInterface, "localhost");
- // set the repository resolver and pack factories
- repositoryResolver = new RepositoryResolver<GitDaemonClient>(folder);
- }
+ if (StringUtils.isEmpty(bindInterface)) {
+ myAddress = new InetSocketAddress(port);
+ } else {
+ myAddress = new InetSocketAddress(bindInterface, port);
+ }
- /**
- * Configure a new daemon for the specified network address.
- *
- * @param addr
- * address to listen for connections on. If null, any available
- * port will be chosen on all network interfaces.
- */
- public GitDaemon(final InetSocketAddress addr) {
- myAddress = addr;
- processors = new ThreadGroup("Git-Daemon");
+ repositoryResolver = new RepositoryResolver<GitDaemonClient>(sessionManager, repositoryManager);
+ uploadPackFactory = new GitblitUploadPackFactory<GitDaemonClient>(sessionManager);
+ receivePackFactory = new GitblitReceivePackFactory<GitDaemonClient>(runtimeManager, userManager, repositoryManager);
run = new AtomicBoolean(false);
- repositoryResolver = null;
- uploadPackFactory = new GitblitUploadPackFactory<GitDaemonClient>();
- receivePackFactory = new GitblitReceivePackFactory<GitDaemonClient>();
-
+ processors = new ThreadGroup("Git-Daemon");
services = new GitDaemonService[] { new GitDaemonService("upload-pack", "uploadpack") {
{
setEnabled(true);
diff --git a/src/main/java/com/gitblit/git/GitServlet.java b/src/main/java/com/gitblit/git/GitServlet.java
index 23ea3434..e4719d9b 100644
--- a/src/main/java/com/gitblit/git/GitServlet.java
+++ b/src/main/java/com/gitblit/git/GitServlet.java
@@ -15,12 +15,16 @@
*/
package com.gitblit.git;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
-import com.gitblit.GitBlit;
import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.ISessionManager;
+import com.gitblit.manager.IUserManager;
/**
* The GitServlet provides http/https access to Git repositories.
@@ -29,19 +33,37 @@ import com.gitblit.manager.IRepositoryManager;
* @author James Moger
*
*/
+@Singleton
public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
private static final long serialVersionUID = 1L;
- public GitServlet() {
+ private final IRuntimeManager runtimeManager;
+
+ private final IUserManager userManager;
+
+ private final ISessionManager sessionManager;
+
+ private final IRepositoryManager repositoryManager;
+
+ @Inject
+ public GitServlet(
+ IRuntimeManager runtimeManager,
+ IUserManager userManager,
+ ISessionManager sessionManager,
+ IRepositoryManager repositoryManager) {
+ super();
+ this.runtimeManager = runtimeManager;
+ this.userManager = userManager;
+ this.sessionManager = sessionManager;
+ this.repositoryManager = repositoryManager;
}
@Override
public void init(ServletConfig config) throws ServletException {
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
- setRepositoryResolver(new RepositoryResolver<HttpServletRequest>(repositoryManager.getRepositoriesFolder()));
- setUploadPackFactory(new GitblitUploadPackFactory<HttpServletRequest>());
- setReceivePackFactory(new GitblitReceivePackFactory<HttpServletRequest>());
+ setRepositoryResolver(new RepositoryResolver<HttpServletRequest>(sessionManager, repositoryManager));
+ setUploadPackFactory(new GitblitUploadPackFactory<HttpServletRequest>(sessionManager));
+ setReceivePackFactory(new GitblitReceivePackFactory<HttpServletRequest>(runtimeManager, userManager, repositoryManager));
super.init(config);
}
}
diff --git a/src/main/java/com/gitblit/git/GitblitReceivePack.java b/src/main/java/com/gitblit/git/GitblitReceivePack.java
index 8da603ac..44e2bef5 100644
--- a/src/main/java/com/gitblit/git/GitblitReceivePack.java
+++ b/src/main/java/com/gitblit/git/GitblitReceivePack.java
@@ -91,11 +91,20 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
protected GroovyScriptEngine gse;
- public GitblitReceivePack(Repository db, RepositoryModel repository, UserModel user) {
- super(db);
+ private final IStoredSettings settings;
+
+ private final IRepositoryManager repositoryManager;
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
+ public GitblitReceivePack(
+ IRuntimeManager runtimeManager,
+ IRepositoryManager repositoryManager,
+ Repository db,
+ RepositoryModel repository,
+ UserModel user) {
+ super(db);
+ this.settings = runtimeManager.getSettings();
+ this.repositoryManager = repositoryManager;
this.repository = repository;
this.user = user == null ? UserModel.ANONYMOUS : user;
this.groovyDir = repositoryManager.getHooksFolder();
@@ -239,7 +248,6 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
}
}
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
Set<String> scripts = new LinkedHashSet<String>();
scripts.addAll(repositoryManager.getPreReceiveScriptsInherited(repository));
if (!ArrayUtils.isEmpty(repository.preReceiveScripts)) {
@@ -266,8 +274,6 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
return;
}
- IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
-
// log ref changes
for (ReceiveCommand cmd : commands) {
@@ -336,8 +342,6 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
LOGGER.error(MessageFormat.format("Failed to update {0} pushlog", repository.name), e);
}
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
-
// run Groovy hook scripts
Set<String> scripts = new LinkedHashSet<String>();
scripts.addAll(repositoryManager.getPostReceiveScriptsInherited(repository));
diff --git a/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java b/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java
index a90c36b1..2cdb9856 100644
--- a/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java
+++ b/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java
@@ -26,7 +26,6 @@ import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.gitblit.GitBlit;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.manager.IRepositoryManager;
@@ -48,14 +47,31 @@ public class GitblitReceivePackFactory<X> implements ReceivePackFactory<X> {
protected final Logger logger = LoggerFactory.getLogger(GitblitReceivePackFactory.class);
+ private final IStoredSettings settings;
+
+ private final IRuntimeManager runtimeManager;
+
+ private final IUserManager userManager;
+
+ private final IRepositoryManager repositoryManager;
+
+ public GitblitReceivePackFactory(
+ IRuntimeManager runtimeManager,
+ IUserManager userManager,
+ IRepositoryManager repositoryManager) {
+
+ super();
+ this.settings = runtimeManager.getSettings();
+ this.runtimeManager = runtimeManager;
+ this.userManager = userManager;
+ this.repositoryManager = repositoryManager;
+
+ }
+
@Override
public ReceivePack create(X req, Repository db)
throws ServiceNotEnabledException, ServiceNotAuthorizedException {
- IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
- IUserManager userManager = GitBlit.getManager(IUserManager.class);
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
-
UserModel user = UserModel.ANONYMOUS;
String repositoryName = "";
String origin = "";
@@ -97,7 +113,7 @@ public class GitblitReceivePackFactory<X> implements ReceivePackFactory<X> {
final RepositoryModel repository = repositoryManager.getRepositoryModel(repositoryName);
- final GitblitReceivePack rp = new GitblitReceivePack(db, repository, user);
+ final GitblitReceivePack rp = new GitblitReceivePack(runtimeManager, repositoryManager, db, repository, user);
rp.setGitblitUrl(gitblitUrl);
rp.setRepositoryUrl(repositoryUrl);
rp.setRefLogIdent(new PersonIdent(user.username, user.username + "@" + origin));
diff --git a/src/main/java/com/gitblit/git/GitblitUploadPackFactory.java b/src/main/java/com/gitblit/git/GitblitUploadPackFactory.java
index 180e8b55..2afdde1d 100644
--- a/src/main/java/com/gitblit/git/GitblitUploadPackFactory.java
+++ b/src/main/java/com/gitblit/git/GitblitUploadPackFactory.java
@@ -23,7 +23,6 @@ import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
import org.eclipse.jgit.transport.resolver.UploadPackFactory;
-import com.gitblit.GitBlit;
import com.gitblit.manager.ISessionManager;
import com.gitblit.models.UserModel;
@@ -37,11 +36,16 @@ import com.gitblit.models.UserModel;
*/
public class GitblitUploadPackFactory<X> implements UploadPackFactory<X> {
+ private final ISessionManager sessionManager;
+
+ public GitblitUploadPackFactory(ISessionManager sessionManager) {
+ this.sessionManager = sessionManager;
+ }
+
@Override
public UploadPack create(X req, Repository db)
throws ServiceNotEnabledException, ServiceNotAuthorizedException {
- ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);
UserModel user = UserModel.ANONYMOUS;
int timeout = 0;
diff --git a/src/main/java/com/gitblit/git/RepositoryResolver.java b/src/main/java/com/gitblit/git/RepositoryResolver.java
index 5441596d..87795c07 100644
--- a/src/main/java/com/gitblit/git/RepositoryResolver.java
+++ b/src/main/java/com/gitblit/git/RepositoryResolver.java
@@ -15,7 +15,6 @@
*/
package com.gitblit.git;
-import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
@@ -28,7 +27,6 @@ import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.gitblit.GitBlit;
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.ISessionManager;
import com.gitblit.models.RepositoryModel;
@@ -44,8 +42,17 @@ public class RepositoryResolver<X> extends FileResolver<X> {
private final Logger logger = LoggerFactory.getLogger(RepositoryResolver.class);
- public RepositoryResolver(File repositoriesFolder) {
- super(repositoriesFolder, true);
+ private final ISessionManager sessionManager;
+
+ private final IRepositoryManager repositoryManager;
+
+ public RepositoryResolver(
+ ISessionManager sessionManager,
+ IRepositoryManager repositoryManager) {
+
+ super(repositoryManager.getRepositoriesFolder(), true);
+ this.sessionManager = sessionManager;
+ this.repositoryManager = repositoryManager;
}
/**
@@ -76,8 +83,6 @@ public class RepositoryResolver<X> extends FileResolver<X> {
*/
@Override
protected boolean isExportOk(X req, String repositoryName, Repository db) throws IOException {
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
- ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);
RepositoryModel model = repositoryManager.getRepositoryModel(repositoryName);
String scheme = null;