summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.classpath7
-rw-r--r--build.moxie5
-rw-r--r--gitblit.iml29
-rw-r--r--src/main/java/com/gitblit/GitBlit.java140
-rw-r--r--src/main/java/com/gitblit/dagger/DaggerFilter.java47
-rw-r--r--src/main/java/com/gitblit/dagger/DaggerModule.java189
-rw-r--r--src/main/java/com/gitblit/dagger/DaggerServlet.java44
-rw-r--r--src/main/java/com/gitblit/guice/GuiceContext.java (renamed from src/main/java/com/gitblit/dagger/DaggerContext.java)37
-rw-r--r--src/main/java/com/gitblit/guice/GuiceModule.java100
-rw-r--r--src/main/java/com/gitblit/servlet/GitblitContext.java30
-rw-r--r--src/main/java/com/gitblit/tickets/BranchTicketService.java5
-rw-r--r--src/main/java/com/gitblit/tickets/FileTicketService.java5
-rw-r--r--src/main/java/com/gitblit/tickets/NullTicketService.java5
-rw-r--r--src/main/java/com/gitblit/tickets/RedisTicketService.java5
14 files changed, 192 insertions, 456 deletions
diff --git a/.classpath b/.classpath
index 6d6011c4..ec9495fb 100644
--- a/.classpath
+++ b/.classpath
@@ -5,11 +5,10 @@
<classpathentry kind="src" path="src/test/java" output="bin/test-classes" />
<classpathentry kind="src" path="src/test/bugtraq" output="bin/test-classes" />
<classpathentry kind="src" path="src/main/resources" />
- <classpathentry kind="lib" path="ext/dagger-1.2.1.jar" sourcepath="ext/src/dagger-1.2.1.jar" />
+ <classpathentry kind="lib" path="ext/guice-4.0-beta4.jar" sourcepath="ext/src/guice-4.0-beta4.jar" />
<classpathentry kind="lib" path="ext/javax.inject-1.jar" sourcepath="ext/src/javax.inject-1.jar" />
- <classpathentry kind="lib" path="ext/dagger-compiler-1.2.1.jar" sourcepath="ext/src/dagger-compiler-1.2.1.jar" />
- <classpathentry kind="lib" path="ext/javawriter-2.3.0.jar" sourcepath="ext/src/javawriter-2.3.0.jar" />
- <classpathentry kind="lib" path="ext/guava-15.0.jar" sourcepath="ext/src/guava-15.0.jar" />
+ <classpathentry kind="lib" path="ext/aopalliance-1.0.jar" sourcepath="ext/src/aopalliance-1.0.jar" />
+ <classpathentry kind="lib" path="ext/guava-16.0.1.jar" sourcepath="ext/src/guava-16.0.1.jar" />
<classpathentry kind="lib" path="ext/annotations-12.0.jar" sourcepath="ext/src/annotations-12.0.jar" />
<classpathentry kind="lib" path="ext/log4j-1.2.17.jar" sourcepath="ext/src/log4j-1.2.17.jar" />
<classpathentry kind="lib" path="ext/slf4j-api-1.7.7.jar" sourcepath="ext/src/slf4j-api-1.7.7.jar" />
diff --git a/build.moxie b/build.moxie
index c5ad4423..0501b779 100644
--- a/build.moxie
+++ b/build.moxie
@@ -127,9 +127,8 @@ properties: {
dependencies:
# Dagger dependency injection library (annotation processor)
-- compile 'com.squareup.dagger:dagger:1.2.1' :war apt
-- compile 'com.squareup.dagger:dagger-compiler:1.2.1' :war optional apt
-- compile 'com.google.guava:guava:15.0' :war
+- compile 'com.google.inject:guice:4.0-beta4' :war
+- compile 'com.google.guava:guava:16.0.1' :war
# Standard dependencies
- compile 'com.intellij:annotations:12.0' :war
- compile 'log4j:log4j:1.2.17' :war :fedclient :authority
diff --git a/gitblit.iml b/gitblit.iml
index cd6e14a2..9a689dab 100644
--- a/gitblit.iml
+++ b/gitblit.iml
@@ -14,13 +14,13 @@
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
- <library name="dagger-1.2.1.jar">
+ <library name="guice-4.0-beta4.jar">
<CLASSES>
- <root url="jar://$MODULE_DIR$/ext/dagger-1.2.1.jar!/" />
+ <root url="jar://$MODULE_DIR$/ext/guice-4.0-beta4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
- <root url="jar://$MODULE_DIR$/ext/src/dagger-1.2.1.jar!/" />
+ <root url="jar://$MODULE_DIR$/ext/src/guice-4.0-beta4.jar!/" />
</SOURCES>
</library>
</orderEntry>
@@ -36,35 +36,24 @@
</library>
</orderEntry>
<orderEntry type="module-library">
- <library name="dagger-compiler-1.2.1.jar">
+ <library name="aopalliance-1.0.jar">
<CLASSES>
- <root url="jar://$MODULE_DIR$/ext/dagger-compiler-1.2.1.jar!/" />
+ <root url="jar://$MODULE_DIR$/ext/aopalliance-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
- <root url="jar://$MODULE_DIR$/ext/src/dagger-compiler-1.2.1.jar!/" />
+ <root url="jar://$MODULE_DIR$/ext/src/aopalliance-1.0.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
- <library name="javawriter-2.3.0.jar">
+ <library name="guava-16.0.1.jar">
<CLASSES>
- <root url="jar://$MODULE_DIR$/ext/javawriter-2.3.0.jar!/" />
+ <root url="jar://$MODULE_DIR$/ext/guava-16.0.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
- <root url="jar://$MODULE_DIR$/ext/src/javawriter-2.3.0.jar!/" />
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library name="guava-15.0.jar">
- <CLASSES>
- <root url="jar://$MODULE_DIR$/ext/guava-15.0.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root url="jar://$MODULE_DIR$/ext/src/guava-15.0.jar!/" />
+ <root url="jar://$MODULE_DIR$/ext/src/guava-16.0.1.jar!/" />
</SOURCES>
</library>
</orderEntry>
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java
index 8bfa043a..df2f502e 100644
--- a/src/main/java/com/gitblit/GitBlit.java
+++ b/src/main/java/com/gitblit/GitBlit.java
@@ -25,7 +25,6 @@ import java.util.List;
import java.util.Set;
import javax.inject.Inject;
-import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest;
import com.gitblit.Constants.AccessPermission;
@@ -44,17 +43,13 @@ import com.gitblit.manager.ServicesManager;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.RepositoryUrl;
import com.gitblit.models.UserModel;
-import com.gitblit.tickets.BranchTicketService;
-import com.gitblit.tickets.FileTicketService;
import com.gitblit.tickets.ITicketService;
import com.gitblit.tickets.NullTicketService;
-import com.gitblit.tickets.RedisTicketService;
import com.gitblit.transport.ssh.IPublicKeyManager;
import com.gitblit.utils.StringUtils;
-
-import dagger.Module;
-import dagger.ObjectGraph;
-import dagger.Provides;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
/**
* GitBlit is the aggregate manager for the Gitblit webapp. It provides all
@@ -65,7 +60,7 @@ import dagger.Provides;
*/
public class GitBlit extends GitblitManager {
- private final ObjectGraph injector;
+ private final Injector injector;
private final ServicesManager servicesManager;
@@ -93,7 +88,7 @@ public class GitBlit extends GitblitManager {
projectManager,
federationManager);
- this.injector = ObjectGraph.create(getModules());
+ this.injector = Guice.createInjector(getModules());
this.servicesManager = new ServicesManager(this);
}
@@ -135,8 +130,8 @@ public class GitBlit extends GitblitManager {
return servicesManager.isServingSSH();
}
- protected Object [] getModules() {
- return new Object [] { new GitBlitModule()};
+ protected AbstractModule [] getModules() {
+ return new AbstractModule [] { new GitBlitModule()};
}
protected boolean acceptPush(Transport byTransport) {
@@ -360,7 +355,7 @@ public class GitBlit extends GitblitManager {
}
try {
Class<? extends ITicketService> serviceClass = (Class<? extends ITicketService>) Class.forName(clazz);
- ticketService = injector.get(serviceClass).start();
+ ticketService = injector.getInstance(serviceClass).start();
if (ticketService instanceof NullTicketService) {
logger.warn("No ticket service configured.");
} else if (ticketService.isReady()) {
@@ -370,118 +365,31 @@ public class GitBlit extends GitblitManager {
}
} catch (Exception e) {
logger.error("failed to create ticket service " + clazz, e);
- ticketService = injector.get(NullTicketService.class).start();
+ ticketService = injector.getInstance(NullTicketService.class).start();
}
}
/**
- * A nested Dagger graph is used for constructor dependency injection of
+ * A nested Guice Module is used for constructor dependency injection of
* complex classes.
*
* @author James Moger
*
*/
- @Module(
- library = true,
- injects = {
- IStoredSettings.class,
-
- // core managers
- IRuntimeManager.class,
- IPluginManager.class,
- INotificationManager.class,
- IUserManager.class,
- IAuthenticationManager.class,
- IRepositoryManager.class,
- IProjectManager.class,
- IFederationManager.class,
-
- // the monolithic manager
- IGitblit.class,
-
- // ticket services
- NullTicketService.class,
- FileTicketService.class,
- BranchTicketService.class,
- RedisTicketService.class
- }
- )
- class GitBlitModule {
-
- @Provides @Singleton IStoredSettings provideSettings() {
- return settings;
- }
-
- @Provides @Singleton IRuntimeManager provideRuntimeManager() {
- return runtimeManager;
- }
-
- @Provides @Singleton IPluginManager providePluginManager() {
- return pluginManager;
- }
-
- @Provides @Singleton INotificationManager provideNotificationManager() {
- return notificationManager;
- }
-
- @Provides @Singleton IUserManager provideUserManager() {
- return userManager;
- }
-
- @Provides @Singleton IAuthenticationManager provideAuthenticationManager() {
- return authenticationManager;
- }
-
- @Provides @Singleton IRepositoryManager provideRepositoryManager() {
- return repositoryManager;
- }
-
- @Provides @Singleton IProjectManager provideProjectManager() {
- return projectManager;
- }
-
- @Provides @Singleton IFederationManager provideFederationManager() {
- return federationManager;
- }
-
- @Provides @Singleton IGitblit provideGitblit() {
- return GitBlit.this;
- }
-
- @Provides @Singleton NullTicketService provideNullTicketService() {
- return new NullTicketService(
- runtimeManager,
- pluginManager,
- notificationManager,
- userManager,
- repositoryManager);
- }
-
- @Provides @Singleton FileTicketService provideFileTicketService() {
- return new FileTicketService(
- runtimeManager,
- pluginManager,
- notificationManager,
- userManager,
- repositoryManager);
- }
-
- @Provides @Singleton BranchTicketService provideBranchTicketService() {
- return new BranchTicketService(
- runtimeManager,
- pluginManager,
- notificationManager,
- userManager,
- repositoryManager);
- }
-
- @Provides @Singleton RedisTicketService provideRedisTicketService() {
- return new RedisTicketService(
- runtimeManager,
- pluginManager,
- notificationManager,
- userManager,
- repositoryManager);
+ class GitBlitModule extends AbstractModule {
+
+ @Override
+ protected void configure() {
+ bind(IStoredSettings.class).toInstance(settings);
+ bind(IRuntimeManager.class).toInstance(runtimeManager);
+ bind(IPluginManager.class).toInstance(pluginManager);
+ bind(INotificationManager.class).toInstance(notificationManager);
+ bind(IUserManager.class).toInstance(userManager);
+ bind(IAuthenticationManager.class).toInstance(authenticationManager);
+ bind(IRepositoryManager.class).toInstance(repositoryManager);
+ bind(IProjectManager.class).toInstance(projectManager);
+ bind(IFederationManager.class).toInstance(federationManager);
+ bind(IGitblit.class).toInstance(GitBlit.this);
}
}
}
diff --git a/src/main/java/com/gitblit/dagger/DaggerFilter.java b/src/main/java/com/gitblit/dagger/DaggerFilter.java
deleted file mode 100644
index 01c07a4a..00000000
--- a/src/main/java/com/gitblit/dagger/DaggerFilter.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2013 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.dagger;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-
-import dagger.ObjectGraph;
-
-/**
- * Uses Dagger to manually inject dependencies into a servlet filter.
- * This class is useful for servlet containers that offer CDI and are
- * confused by Dagger.
- *
- * @author James Moger
- *
- */
-public abstract class DaggerFilter implements Filter {
-
- @Override
- public final void init(FilterConfig filterConfig) throws ServletException {
- ServletContext context = filterConfig.getServletContext();
- ObjectGraph objectGraph = (ObjectGraph) context.getAttribute(DaggerContext.INJECTOR_NAME);
- inject(objectGraph, filterConfig);
- }
-
- protected abstract void inject(ObjectGraph dagger, FilterConfig filterConfig) throws ServletException;
-
- @Override
- public void destroy() {
- }
-}
diff --git a/src/main/java/com/gitblit/dagger/DaggerModule.java b/src/main/java/com/gitblit/dagger/DaggerModule.java
deleted file mode 100644
index 9f001fa7..00000000
--- a/src/main/java/com/gitblit/dagger/DaggerModule.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright 2013 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.dagger;
-
-import javax.inject.Singleton;
-
-import com.gitblit.FileSettings;
-import com.gitblit.GitBlit;
-import com.gitblit.IStoredSettings;
-import com.gitblit.Keys;
-import com.gitblit.manager.AuthenticationManager;
-import com.gitblit.manager.FederationManager;
-import com.gitblit.manager.IAuthenticationManager;
-import com.gitblit.manager.IFederationManager;
-import com.gitblit.manager.IGitblit;
-import com.gitblit.manager.INotificationManager;
-import com.gitblit.manager.IPluginManager;
-import com.gitblit.manager.IProjectManager;
-import com.gitblit.manager.IRepositoryManager;
-import com.gitblit.manager.IRuntimeManager;
-import com.gitblit.manager.IUserManager;
-import com.gitblit.manager.NotificationManager;
-import com.gitblit.manager.PluginManager;
-import com.gitblit.manager.ProjectManager;
-import com.gitblit.manager.RepositoryManager;
-import com.gitblit.manager.RuntimeManager;
-import com.gitblit.manager.UserManager;
-import com.gitblit.servlet.BranchGraphServlet;
-import com.gitblit.servlet.DownloadZipFilter;
-import com.gitblit.servlet.DownloadZipServlet;
-import com.gitblit.servlet.EnforceAuthenticationFilter;
-import com.gitblit.servlet.FederationServlet;
-import com.gitblit.servlet.GitFilter;
-import com.gitblit.servlet.GitServlet;
-import com.gitblit.servlet.LogoServlet;
-import com.gitblit.servlet.PagesFilter;
-import com.gitblit.servlet.PagesServlet;
-import com.gitblit.servlet.ProxyFilter;
-import com.gitblit.servlet.PtServlet;
-import com.gitblit.servlet.RawFilter;
-import com.gitblit.servlet.RawServlet;
-import com.gitblit.servlet.RobotsTxtServlet;
-import com.gitblit.servlet.RpcFilter;
-import com.gitblit.servlet.RpcServlet;
-import com.gitblit.servlet.SparkleShareInviteServlet;
-import com.gitblit.servlet.SyndicationFilter;
-import com.gitblit.servlet.SyndicationServlet;
-import com.gitblit.transport.ssh.FileKeyManager;
-import com.gitblit.transport.ssh.IPublicKeyManager;
-import com.gitblit.transport.ssh.MemoryKeyManager;
-import com.gitblit.transport.ssh.NullKeyManager;
-import com.gitblit.utils.StringUtils;
-import com.gitblit.wicket.GitBlitWebApp;
-import com.gitblit.wicket.GitblitWicketFilter;
-
-import dagger.Module;
-import dagger.Provides;
-
-/**
- * DaggerModule references all injectable objects.
- *
- * @author James Moger
- *
- */
-@Module(
- injects = {
- IStoredSettings.class,
-
- // core managers
- IRuntimeManager.class,
- IPluginManager.class,
- INotificationManager.class,
- IUserManager.class,
- IAuthenticationManager.class,
- IPublicKeyManager.class,
- IRepositoryManager.class,
- IProjectManager.class,
- IFederationManager.class,
-
- // the monolithic manager
- IGitblit.class,
-
- // the Gitblit Wicket app
- GitBlitWebApp.class,
-
- // filters & servlets
- GitServlet.class,
- GitFilter.class,
- RawServlet.class,
- RawFilter.class,
- PagesServlet.class,
- PagesFilter.class,
- RpcServlet.class,
- RpcFilter.class,
- DownloadZipServlet.class,
- DownloadZipFilter.class,
- SyndicationServlet.class,
- SyndicationFilter.class,
- FederationServlet.class,
- SparkleShareInviteServlet.class,
- BranchGraphServlet.class,
- RobotsTxtServlet.class,
- LogoServlet.class,
- PtServlet.class,
- ProxyFilter.class,
- EnforceAuthenticationFilter.class,
- GitblitWicketFilter.class
- }
-)
-public class DaggerModule {
-
- @Provides @Singleton IStoredSettings provideSettings() {
- return new FileSettings();
- }
-
- @Provides @Singleton IRuntimeManager provideRuntimeManager(RuntimeManager manager) {
- return manager;
- }
-
- @Provides @Singleton IPluginManager providePluginManager(PluginManager manager) {
- return manager;
- }
-
- @Provides @Singleton INotificationManager provideNotificationManager(NotificationManager manager) {
- return manager;
- }
-
- @Provides @Singleton IUserManager provideUserManager(UserManager manager) {
- return manager;
- }
-
- @Provides @Singleton IAuthenticationManager provideAuthenticationManager(AuthenticationManager manager) {
- return manager;
- }
-
- @Provides @Singleton IPublicKeyManager providePublicKeyManager(
- IStoredSettings settings,
- IRuntimeManager runtimeManager) {
-
- String clazz = settings.getString(Keys.git.sshKeysManager, FileKeyManager.class.getName());
- if (StringUtils.isEmpty(clazz)) {
- clazz = FileKeyManager.class.getName();
- }
- if (FileKeyManager.class.getName().equals(clazz)) {
- return new FileKeyManager(runtimeManager);
- } else if (NullKeyManager.class.getName().equals(clazz)) {
- return new NullKeyManager();
- } else if (MemoryKeyManager.class.getName().equals(clazz)) {
- return new MemoryKeyManager();
- } else {
- try {
- Class<?> mgrClass = Class.forName(clazz);
- return (IPublicKeyManager) mgrClass.newInstance();
- } catch (Exception e) {
-
- }
- return null;
- }
- }
-
- @Provides @Singleton IRepositoryManager provideRepositoryManager(RepositoryManager manager) {
- return manager;
- }
-
- @Provides @Singleton IProjectManager provideProjectManager(ProjectManager manager) {
- return manager;
- }
-
- @Provides @Singleton IFederationManager provideFederationManager(FederationManager manager) {
- return manager;
- }
-
- @Provides @Singleton IGitblit provideGitblit(GitBlit gitblit) {
- return gitblit;
- }
-} \ No newline at end of file
diff --git a/src/main/java/com/gitblit/dagger/DaggerServlet.java b/src/main/java/com/gitblit/dagger/DaggerServlet.java
deleted file mode 100644
index 88331a43..00000000
--- a/src/main/java/com/gitblit/dagger/DaggerServlet.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2013 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.dagger;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-
-import dagger.ObjectGraph;
-
-/**
- * Uses Dagger to manually inject dependencies into a servlet.
- * This class is useful for servlet containers that offer CDI and are
- * confused by Dagger.
- *
- * @author James Moger
- *
- */
-public abstract class DaggerServlet extends HttpServlet {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public final void init() throws ServletException {
- ServletContext context = getServletContext();
- ObjectGraph objectGraph = (ObjectGraph) context.getAttribute(DaggerContext.INJECTOR_NAME);
- inject(objectGraph);
- }
-
- protected abstract void inject(ObjectGraph dagger);
-}
diff --git a/src/main/java/com/gitblit/dagger/DaggerContext.java b/src/main/java/com/gitblit/guice/GuiceContext.java
index ef570804..4361b7bd 100644
--- a/src/main/java/com/gitblit/dagger/DaggerContext.java
+++ b/src/main/java/com/gitblit/guice/GuiceContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 gitblit.com.
+ * Copyright 2014 gitblit.com.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.gitblit.dagger;
+package com.gitblit.guice;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
@@ -22,41 +22,42 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.gitblit.servlet.InjectionContextListener;
-
-import dagger.ObjectGraph;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
/**
- * Dagger servlet context listener is a context listener that uses Dagger to
+ * Guice servlet context listener is a context listener that uses Guice to
* instantiate and inject servlets, filters, and anything else you might want.
*
* @author James Moger
*
*/
-public abstract class DaggerContext extends InjectionContextListener {
+public abstract class GuiceContext extends InjectionContextListener {
- public static final String INJECTOR_NAME = ObjectGraph.class.getName();
+ public static final String INJECTOR_NAME = Injector.class.getName();
protected final Logger logger = LoggerFactory.getLogger(getClass());
- protected abstract Object [] getModules();
+ protected abstract AbstractModule [] getModules();
protected abstract void destroyContext(ServletContext context);
- protected ObjectGraph getInjector(ServletContext context) {
+ protected Injector getInjector(ServletContext context) {
Object o = context.getAttribute(INJECTOR_NAME);
if (o == null) {
- logger.debug("instantiating Dagger modules");
- Object [] modules = getModules();
- logger.debug("getting Dagger injector");
+ logger.debug("instantiating Guice modules");
+ AbstractModule [] modules = getModules();
+ logger.debug("getting Guice injector");
try {
- o = ObjectGraph.create(modules);
- logger.debug("setting Dagger injector into {} attribute", INJECTOR_NAME);
+ o = Guice.createInjector(modules);
+ logger.debug("setting Guice injector into {} attribute", INJECTOR_NAME);
context.setAttribute(INJECTOR_NAME, o);
} catch (Throwable t) {
- logger.error("an error occurred creating the Dagger injector", t);
+ logger.error("an error occurred creating the Guice injector", t);
}
}
- return (ObjectGraph) o;
+ return (Injector) o;
}
/**
@@ -68,8 +69,8 @@ public abstract class DaggerContext extends InjectionContextListener {
@Override
protected <X> X instantiate(ServletContext context, Class<X> clazz) {
try {
- ObjectGraph injector = getInjector(context);
- return injector.get(clazz);
+ Injector injector = getInjector(context);
+ return injector.getInstance(clazz);
} catch (Throwable t) {
logger.error(null, t);
}
diff --git a/src/main/java/com/gitblit/guice/GuiceModule.java b/src/main/java/com/gitblit/guice/GuiceModule.java
new file mode 100644
index 00000000..254e0680
--- /dev/null
+++ b/src/main/java/com/gitblit/guice/GuiceModule.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.guice;
+
+import javax.inject.Singleton;
+
+import com.gitblit.FileSettings;
+import com.gitblit.GitBlit;
+import com.gitblit.IStoredSettings;
+import com.gitblit.Keys;
+import com.gitblit.manager.AuthenticationManager;
+import com.gitblit.manager.FederationManager;
+import com.gitblit.manager.IAuthenticationManager;
+import com.gitblit.manager.IFederationManager;
+import com.gitblit.manager.IGitblit;
+import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IPluginManager;
+import com.gitblit.manager.IProjectManager;
+import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.IUserManager;
+import com.gitblit.manager.NotificationManager;
+import com.gitblit.manager.PluginManager;
+import com.gitblit.manager.ProjectManager;
+import com.gitblit.manager.RepositoryManager;
+import com.gitblit.manager.RuntimeManager;
+import com.gitblit.manager.UserManager;
+import com.gitblit.transport.ssh.FileKeyManager;
+import com.gitblit.transport.ssh.IPublicKeyManager;
+import com.gitblit.transport.ssh.MemoryKeyManager;
+import com.gitblit.transport.ssh.NullKeyManager;
+import com.gitblit.utils.StringUtils;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+
+/**
+ * GuiceModule references all injectable objects.
+ *
+ * @author James Moger
+ *
+ */
+public class GuiceModule extends AbstractModule {
+
+ @Override
+ protected void configure() {
+
+ bind(IStoredSettings.class).toInstance(new FileSettings());
+
+ // core managers
+ bind(IRuntimeManager.class).to(RuntimeManager.class).in(Singleton.class);
+ bind(IPluginManager.class).to(PluginManager.class).in(Singleton.class);
+ bind(INotificationManager.class).to(NotificationManager.class).in(Singleton.class);
+ bind(IUserManager.class).to(UserManager.class).in(Singleton.class);
+ bind(IAuthenticationManager.class).to(AuthenticationManager.class).in(Singleton.class);
+ bind(IRepositoryManager.class).to(RepositoryManager.class).in(Singleton.class);
+ bind(IProjectManager.class).to(ProjectManager.class).in(Singleton.class);
+ bind(IFederationManager.class).to(FederationManager.class).in(Singleton.class);
+
+ // the monolithic manager
+ bind(IGitblit.class).to(GitBlit.class).in(Singleton.class);
+ }
+
+ @Provides
+ @Singleton
+ IPublicKeyManager providePublicKeyManager(IStoredSettings settings, IRuntimeManager runtimeManager) {
+
+ String clazz = settings.getString(Keys.git.sshKeysManager, FileKeyManager.class.getName());
+ if (StringUtils.isEmpty(clazz)) {
+ clazz = FileKeyManager.class.getName();
+ }
+ if (FileKeyManager.class.getName().equals(clazz)) {
+ return new FileKeyManager(runtimeManager);
+ } else if (NullKeyManager.class.getName().equals(clazz)) {
+ return new NullKeyManager();
+ } else if (MemoryKeyManager.class.getName().equals(clazz)) {
+ return new MemoryKeyManager();
+ } else {
+ try {
+ Class<?> mgrClass = Class.forName(clazz);
+ return (IPublicKeyManager) mgrClass.newInstance();
+ } catch (Exception e) {
+
+ }
+ return null;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/gitblit/servlet/GitblitContext.java b/src/main/java/com/gitblit/servlet/GitblitContext.java
index c3a1fadd..fb16d32d 100644
--- a/src/main/java/com/gitblit/servlet/GitblitContext.java
+++ b/src/main/java/com/gitblit/servlet/GitblitContext.java
@@ -38,9 +38,9 @@ import com.gitblit.FileSettings;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.WebXmlSettings;
-import com.gitblit.dagger.DaggerContext;
-import com.gitblit.dagger.DaggerModule;
import com.gitblit.extensions.LifeCycleListener;
+import com.gitblit.guice.GuiceContext;
+import com.gitblit.guice.GuiceModule;
import com.gitblit.manager.IAuthenticationManager;
import com.gitblit.manager.IFederationManager;
import com.gitblit.manager.IGitblit;
@@ -55,8 +55,8 @@ import com.gitblit.transport.ssh.IPublicKeyManager;
import com.gitblit.utils.ContainerUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.GitblitWicketFilter;
-
-import dagger.ObjectGraph;
+import com.google.inject.AbstractModule;
+import com.google.inject.Injector;
/**
* This class is the main entry point for the entire webapp. It is a singleton
@@ -70,7 +70,7 @@ import dagger.ObjectGraph;
*
*/
@WebListener
-public class GitblitContext extends DaggerContext {
+public class GitblitContext extends GuiceContext {
private static GitblitContext gitblit;
@@ -116,11 +116,11 @@ public class GitblitContext extends DaggerContext {
}
/**
- * Returns Gitblit's Dagger injection modules.
+ * Returns Gitblit's Guice injection modules.
*/
@Override
- protected Object [] getModules() {
- return new Object [] { new DaggerModule() };
+ protected AbstractModule [] getModules() {
+ return new AbstractModule [] { new GuiceModule() };
}
/**
@@ -128,10 +128,10 @@ public class GitblitContext extends DaggerContext {
*/
@Override
protected void beforeServletInjection(ServletContext context) {
- ObjectGraph injector = getInjector(context);
+ Injector injector = getInjector(context);
// create the runtime settings object
- IStoredSettings runtimeSettings = injector.get(IStoredSettings.class);
+ IStoredSettings runtimeSettings = injector.getInstance(IStoredSettings.class);
final File baseFolder;
if (goSettings != null) {
@@ -161,7 +161,7 @@ public class GitblitContext extends DaggerContext {
// Manually configure IRuntimeManager
logManager(IRuntimeManager.class);
- IRuntimeManager runtime = injector.get(IRuntimeManager.class);
+ IRuntimeManager runtime = injector.getInstance(IRuntimeManager.class);
runtime.setBaseFolder(baseFolder);
runtime.getStatus().isGO = goSettings != null;
runtime.getStatus().servletContainer = context.getServerInfo();
@@ -189,7 +189,7 @@ public class GitblitContext extends DaggerContext {
logger.info("All managers started.");
logger.info("");
- IPluginManager pluginManager = injector.get(IPluginManager.class);
+ IPluginManager pluginManager = injector.getInstance(IPluginManager.class);
for (LifeCycleListener listener : pluginManager.getExtensions(LifeCycleListener.class)) {
try {
listener.onStartup();
@@ -211,12 +211,12 @@ public class GitblitContext extends DaggerContext {
return null;
}
- protected <X extends IManager> X loadManager(ObjectGraph injector, Class<X> clazz) {
- X x = injector.get(clazz);
+ protected <X extends IManager> X loadManager(Injector injector, Class<X> clazz) {
+ X x = injector.getInstance(clazz);
return x;
}
- protected <X extends IManager> X startManager(ObjectGraph injector, Class<X> clazz) {
+ protected <X extends IManager> X startManager(Injector injector, Class<X> clazz) {
X x = loadManager(injector, clazz);
logManager(clazz);
x.start();
diff --git a/src/main/java/com/gitblit/tickets/BranchTicketService.java b/src/main/java/com/gitblit/tickets/BranchTicketService.java
index 8c000550..a555ece3 100644
--- a/src/main/java/com/gitblit/tickets/BranchTicketService.java
+++ b/src/main/java/com/gitblit/tickets/BranchTicketService.java
@@ -30,6 +30,9 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.dircache.DirCache;
@@ -81,6 +84,7 @@ import com.gitblit.utils.StringUtils;
* @author James Moger
*
*/
+@Singleton
public class BranchTicketService extends ITicketService implements RefsChangedListener {
public static final String BRANCH = "refs/meta/gitblit/tickets";
@@ -91,6 +95,7 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi
private final Map<String, AtomicLong> lastAssignedId;
+ @Inject
public BranchTicketService(
IRuntimeManager runtimeManager,
IPluginManager pluginManager,
diff --git a/src/main/java/com/gitblit/tickets/FileTicketService.java b/src/main/java/com/gitblit/tickets/FileTicketService.java
index b3d8838e..c10d7855 100644
--- a/src/main/java/com/gitblit/tickets/FileTicketService.java
+++ b/src/main/java/com/gitblit/tickets/FileTicketService.java
@@ -27,6 +27,9 @@ import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
import org.eclipse.jgit.lib.Repository;
import com.gitblit.Constants;
@@ -51,6 +54,7 @@ import com.gitblit.utils.StringUtils;
* @author James Moger
*
*/
+@Singleton
public class FileTicketService extends ITicketService {
private static final String JOURNAL = "journal.json";
@@ -59,6 +63,7 @@ public class FileTicketService extends ITicketService {
private final Map<String, AtomicLong> lastAssignedId;
+ @Inject
public FileTicketService(
IRuntimeManager runtimeManager,
IPluginManager pluginManager,
diff --git a/src/main/java/com/gitblit/tickets/NullTicketService.java b/src/main/java/com/gitblit/tickets/NullTicketService.java
index d410cdd0..b8882788 100644
--- a/src/main/java/com/gitblit/tickets/NullTicketService.java
+++ b/src/main/java/com/gitblit/tickets/NullTicketService.java
@@ -19,6 +19,9 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
import com.gitblit.manager.INotificationManager;
import com.gitblit.manager.IPluginManager;
import com.gitblit.manager.IRepositoryManager;
@@ -35,8 +38,10 @@ import com.gitblit.models.TicketModel.Change;
* @author James Moger
*
*/
+@Singleton
public class NullTicketService extends ITicketService {
+ @Inject
public NullTicketService(
IRuntimeManager runtimeManager,
IPluginManager pluginManager,
diff --git a/src/main/java/com/gitblit/tickets/RedisTicketService.java b/src/main/java/com/gitblit/tickets/RedisTicketService.java
index d773b0bd..6b8817b6 100644
--- a/src/main/java/com/gitblit/tickets/RedisTicketService.java
+++ b/src/main/java/com/gitblit/tickets/RedisTicketService.java
@@ -22,6 +22,9 @@ import java.util.List;
import java.util.Set;
import java.util.TreeSet;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.Client;
@@ -53,6 +56,7 @@ import com.gitblit.utils.StringUtils;
* @author James Moger
*
*/
+@Singleton
public class RedisTicketService extends ITicketService {
private final JedisPool pool;
@@ -61,6 +65,7 @@ public class RedisTicketService extends ITicketService {
journal, ticket, counter
}
+ @Inject
public RedisTicketService(
IRuntimeManager runtimeManager,
IPluginManager pluginManager,