summaryrefslogtreecommitdiffstats
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
parent79cad53bba094cffa1d25581edbf4972a5158cd4 (diff)
downloadgitblit-cacf8bff097fbb66a7be1bfe267b5da2605145f8.tar.gz
gitblit-cacf8bff097fbb66a7be1bfe267b5da2605145f8.zip
Use Dagger to inject managers into all filters and servlets
Change-Id: I9bb2cc0cbfac9841b13bed15a474fefb24355cd4
-rw-r--r--.classpath155
-rw-r--r--.gitignore2
-rw-r--r--build.moxie4
-rw-r--r--build.xml58
-rw-r--r--gitblit.iml45
-rw-r--r--src/main/.gitignore1
-rw-r--r--src/main/java/com/gitblit/AccessRestrictionFilter.java17
-rw-r--r--src/main/java/com/gitblit/AuthenticationFilter.java7
-rw-r--r--src/main/java/com/gitblit/BranchGraphServlet.java19
-rw-r--r--src/main/java/com/gitblit/DaggerModule.java136
-rw-r--r--src/main/java/com/gitblit/DownloadZipFilter.java15
-rw-r--r--src/main/java/com/gitblit/DownloadZipServlet.java17
-rw-r--r--src/main/java/com/gitblit/EnforceAuthenticationFilter.java19
-rw-r--r--src/main/java/com/gitblit/FederationServlet.java28
-rw-r--r--src/main/java/com/gitblit/GCExecutor.java10
-rw-r--r--src/main/java/com/gitblit/GitBlit.java19
-rw-r--r--src/main/java/com/gitblit/GitFilter.java21
-rw-r--r--src/main/java/com/gitblit/LogoServlet.java11
-rw-r--r--src/main/java/com/gitblit/LuceneExecutor.java10
-rw-r--r--src/main/java/com/gitblit/MirrorExecutor.java10
-rw-r--r--src/main/java/com/gitblit/PagesFilter.java14
-rw-r--r--src/main/java/com/gitblit/PagesServlet.java18
-rw-r--r--src/main/java/com/gitblit/RobotsTxtServlet.java10
-rw-r--r--src/main/java/com/gitblit/RpcFilter.java20
-rw-r--r--src/main/java/com/gitblit/RpcServlet.java38
-rw-r--r--src/main/java/com/gitblit/SparkleShareInviteServlet.java28
-rw-r--r--src/main/java/com/gitblit/SyndicationFilter.java24
-rw-r--r--src/main/java/com/gitblit/SyndicationServlet.java24
-rw-r--r--src/main/java/com/gitblit/dagger/DaggerContextListener.java80
-rw-r--r--src/main/java/com/gitblit/dagger/DaggerWicketFilter.java54
-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
-rw-r--r--src/main/java/com/gitblit/wicket/GitBlitWebApp.java69
-rw-r--r--src/main/java/com/gitblit/wicket/GitblitWicketFilter.java43
-rw-r--r--src/test/java/com/gitblit/tests/GitDaemonStopTest.java32
-rw-r--r--src/test/java/com/gitblit/tests/LuceneExecutorTest.java11
-rw-r--r--src/test/java/com/gitblit/tests/mock/MemorySettings.java9
41 files changed, 891 insertions, 352 deletions
diff --git a/.classpath b/.classpath
index d1b04dad..9d6a6d26 100644
--- a/.classpath
+++ b/.classpath
@@ -1,78 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" output="bin/test-classes" path="src/test/java"/>
- <classpathentry kind="src" path="src/main/resources"/>
- <classpathentry kind="lib" path="ext/jcommander-1.17.jar" sourcepath="ext/src/jcommander-1.17.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.6.6.jar" sourcepath="ext/src/slf4j-api-1.6.6.jar"/>
- <classpathentry kind="lib" path="ext/slf4j-log4j12-1.6.6.jar" sourcepath="ext/src/slf4j-log4j12-1.6.6.jar"/>
- <classpathentry kind="lib" path="ext/mail-1.4.3.jar" sourcepath="ext/src/mail-1.4.3.jar"/>
- <classpathentry kind="lib" path="ext/javax.servlet-api-3.0.1.jar" sourcepath="ext/src/javax.servlet-api-3.0.1.jar"/>
- <classpathentry kind="lib" path="ext/jetty-webapp-8.1.13.v20130916.jar" sourcepath="ext/src/jetty-webapp-8.1.13.v20130916.jar"/>
- <classpathentry kind="lib" path="ext/jetty-ajp-8.1.13.v20130916.jar" sourcepath="ext/src/jetty-ajp-8.1.13.v20130916.jar"/>
- <classpathentry kind="lib" path="ext/wicket-1.4.21.jar" sourcepath="ext/src/wicket-1.4.21.jar"/>
- <classpathentry kind="lib" path="ext/wicket-auth-roles-1.4.21.jar" sourcepath="ext/src/wicket-auth-roles-1.4.21.jar"/>
- <classpathentry kind="lib" path="ext/wicket-extensions-1.4.21.jar" sourcepath="ext/src/wicket-extensions-1.4.21.jar"/>
- <classpathentry kind="lib" path="ext/googlecharts-1.4.21.jar" sourcepath="ext/src/googlecharts-1.4.21.jar"/>
- <classpathentry kind="lib" path="ext/lucene-core-3.6.1.jar" sourcepath="ext/src/lucene-core-3.6.1.jar"/>
- <classpathentry kind="lib" path="ext/lucene-highlighter-3.6.1.jar" sourcepath="ext/src/lucene-highlighter-3.6.1.jar"/>
- <classpathentry kind="lib" path="ext/lucene-memory-3.6.1.jar" sourcepath="ext/src/lucene-memory-3.6.1.jar"/>
- <classpathentry kind="lib" path="ext/lucene-queries-3.6.1.jar" sourcepath="ext/src/lucene-queries-3.6.1.jar"/>
- <classpathentry kind="lib" path="ext/jakarta-regexp-1.4.jar"/>
- <classpathentry kind="lib" path="ext/pegdown-1.4.1.jar" sourcepath="ext/src/pegdown-1.4.1.jar"/>
- <classpathentry kind="lib" path="ext/parboiled-java-1.1.5.jar" sourcepath="ext/src/parboiled-java-1.1.5.jar"/>
- <classpathentry kind="lib" path="ext/parboiled-core-1.1.5.jar" sourcepath="ext/src/parboiled-core-1.1.5.jar"/>
- <classpathentry kind="lib" path="ext/asm-4.1.jar" sourcepath="ext/src/asm-4.1.jar"/>
- <classpathentry kind="lib" path="ext/asm-tree-4.1.jar" sourcepath="ext/src/asm-tree-4.1.jar"/>
- <classpathentry kind="lib" path="ext/asm-analysis-4.1.jar" sourcepath="ext/src/asm-analysis-4.1.jar"/>
- <classpathentry kind="lib" path="ext/asm-util-4.1.jar" sourcepath="ext/src/asm-util-4.1.jar"/>
- <classpathentry kind="lib" path="ext/wikitext-core-1.4.jar" sourcepath="ext/src/wikitext-core-1.4.jar"/>
- <classpathentry kind="lib" path="ext/twiki-core-1.4.jar" sourcepath="ext/src/twiki-core-1.4.jar"/>
- <classpathentry kind="lib" path="ext/textile-core-1.4.jar" sourcepath="ext/src/textile-core-1.4.jar"/>
- <classpathentry kind="lib" path="ext/tracwiki-core-1.4.jar" sourcepath="ext/src/tracwiki-core-1.4.jar"/>
- <classpathentry kind="lib" path="ext/mediawiki-core-1.4.jar" sourcepath="ext/src/mediawiki-core-1.4.jar"/>
- <classpathentry kind="lib" path="ext/confluence-core-1.4.jar" sourcepath="ext/src/confluence-core-1.4.jar"/>
- <classpathentry kind="lib" path="ext/org.eclipse.jgit-3.1.0.201310021548-r.jar" sourcepath="ext/src/org.eclipse.jgit-3.1.0.201310021548-r.jar"/>
- <classpathentry kind="lib" path="ext/jsch-0.1.46.jar" sourcepath="ext/src/jsch-0.1.46.jar"/>
- <classpathentry kind="lib" path="ext/JavaEWAH-0.5.6.jar" sourcepath="ext/src/JavaEWAH-0.5.6.jar"/>
- <classpathentry kind="lib" path="ext/org.eclipse.jgit.http.server-3.1.0.201310021548-r.jar" sourcepath="ext/src/org.eclipse.jgit.http.server-3.1.0.201310021548-r.jar"/>
- <classpathentry kind="lib" path="ext/bcprov-jdk15on-1.47.jar" sourcepath="ext/src/bcprov-jdk15on-1.47.jar"/>
- <classpathentry kind="lib" path="ext/bcmail-jdk15on-1.47.jar" sourcepath="ext/src/bcmail-jdk15on-1.47.jar"/>
- <classpathentry kind="lib" path="ext/bcpkix-jdk15on-1.47.jar" sourcepath="ext/src/bcpkix-jdk15on-1.47.jar"/>
- <classpathentry kind="lib" path="ext/rome-0.9.jar" sourcepath="ext/src/rome-0.9.jar"/>
- <classpathentry kind="lib" path="ext/jdom-1.0.jar" sourcepath="ext/src/jdom-1.0.jar"/>
- <classpathentry kind="lib" path="ext/gson-1.7.2.jar" sourcepath="ext/src/gson-1.7.2.jar"/>
- <classpathentry kind="lib" path="ext/groovy-all-1.8.8.jar" sourcepath="ext/src/groovy-all-1.8.8.jar"/>
- <classpathentry kind="lib" path="ext/unboundid-ldapsdk-2.3.0.jar" sourcepath="ext/src/unboundid-ldapsdk-2.3.0.jar"/>
- <classpathentry kind="lib" path="ext/ivy-2.2.0.jar" sourcepath="ext/src/ivy-2.2.0.jar"/>
- <classpathentry kind="lib" path="ext/jcalendar-1.3.2.jar"/>
- <classpathentry kind="lib" path="ext/commons-compress-1.4.1.jar" sourcepath="ext/src/commons-compress-1.4.1.jar"/>
- <classpathentry kind="lib" path="ext/xz-1.0.jar" sourcepath="ext/src/xz-1.0.jar"/>
- <classpathentry kind="lib" path="ext/commons-io-2.2.jar" sourcepath="ext/src/commons-io-2.2.jar"/>
- <classpathentry kind="lib" path="ext/force-partner-api-24.0.0.jar" sourcepath="ext/src/force-partner-api-24.0.0.jar"/>
- <classpathentry kind="lib" path="ext/force-wsc-24.0.0.jar" sourcepath="ext/src/force-wsc-24.0.0.jar"/>
- <classpathentry kind="lib" path="ext/js-1.7R2.jar" sourcepath="ext/src/js-1.7R2.jar"/>
- <classpathentry kind="lib" path="ext/freemarker-2.3.19.jar" sourcepath="ext/src/freemarker-2.3.19.jar"/>
- <classpathentry kind="lib" path="ext/waffle-jna-1.5.jar" sourcepath="ext/src/waffle-jna-1.5.jar"/>
- <classpathentry kind="lib" path="ext/platform-3.5.0.jar" sourcepath="ext/src/platform-3.5.0.jar"/>
- <classpathentry kind="lib" path="ext/jna-3.5.0.jar" sourcepath="ext/src/jna-3.5.0.jar"/>
- <classpathentry kind="lib" path="ext/guava-13.0.1.jar" sourcepath="ext/src/guava-13.0.1.jar"/>
- <classpathentry kind="lib" path="ext/libpam4j-1.7.jar" sourcepath="ext/src/libpam4j-1.7.jar"/>
- <classpathentry kind="lib" path="ext/commons-codec-1.7.jar" sourcepath="ext/src/commons-codec-1.7.jar"/>
- <classpathentry kind="lib" path="ext/junit-4.11.jar" sourcepath="ext/src/junit-4.11.jar"/>
- <classpathentry kind="lib" path="ext/hamcrest-core-1.3.jar" sourcepath="ext/src/hamcrest-core-1.3.jar"/>
- <classpathentry kind="lib" path="ext/selenium-java-2.28.0.jar" sourcepath="ext/src/selenium-java-2.28.0.jar"/>
- <classpathentry kind="lib" path="ext/selenium-support-2.28.0.jar" sourcepath="ext/src/selenium-support-2.28.0.jar"/>
- <classpathentry kind="lib" path="ext/selenium-firefox-driver-2.28.0.jar" sourcepath="ext/src/selenium-firefox-driver-2.28.0.jar"/>
- <classpathentry kind="lib" path="ext/selenium-remote-driver-2.28.0.jar" sourcepath="ext/src/selenium-remote-driver-2.28.0.jar"/>
- <classpathentry kind="lib" path="ext/cglib-nodep-2.1_3.jar" sourcepath="ext/src/cglib-nodep-2.1_3.jar"/>
- <classpathentry kind="lib" path="ext/json-20080701.jar" sourcepath="ext/src/json-20080701.jar"/>
- <classpathentry kind="lib" path="ext/selenium-api-2.28.0.jar" sourcepath="ext/src/selenium-api-2.28.0.jar"/>
- <classpathentry kind="lib" path="ext/httpclient-4.2.1.jar" sourcepath="ext/src/httpclient-4.2.1.jar"/>
- <classpathentry kind="lib" path="ext/httpcore-4.2.1.jar" sourcepath="ext/src/httpcore-4.2.1.jar"/>
- <classpathentry kind="lib" path="ext/commons-logging-1.1.1.jar" sourcepath="ext/src/commons-logging-1.1.1.jar"/>
- <classpathentry kind="lib" path="ext/commons-exec-1.1.jar" sourcepath="ext/src/commons-exec-1.1.jar"/>
+ <classpathentry kind="src" path="src/main/java" />
+ <classpathentry kind="src" path="src/test/java" output="bin/test-classes" />
+ <classpathentry kind="src" path="src/main/resources" />
+ <classpathentry kind="lib" path="ext/dagger-1.1.0.jar" sourcepath="ext/src/dagger-1.1.0.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.1.0.jar" sourcepath="ext/src/dagger-compiler-1.1.0.jar" />
+ <classpathentry kind="lib" path="ext/javawriter-2.1.1.jar" sourcepath="ext/src/javawriter-2.1.1.jar" />
+ <classpathentry kind="lib" path="ext/jcommander-1.17.jar" sourcepath="ext/src/jcommander-1.17.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.6.6.jar" sourcepath="ext/src/slf4j-api-1.6.6.jar" />
+ <classpathentry kind="lib" path="ext/slf4j-log4j12-1.6.6.jar" sourcepath="ext/src/slf4j-log4j12-1.6.6.jar" />
+ <classpathentry kind="lib" path="ext/mail-1.4.3.jar" sourcepath="ext/src/mail-1.4.3.jar" />
+ <classpathentry kind="lib" path="ext/javax.servlet-api-3.0.1.jar" sourcepath="ext/src/javax.servlet-api-3.0.1.jar" />
+ <classpathentry kind="lib" path="ext/jetty-webapp-8.1.13.v20130916.jar" sourcepath="ext/src/jetty-webapp-8.1.13.v20130916.jar" />
+ <classpathentry kind="lib" path="ext/jetty-ajp-8.1.13.v20130916.jar" sourcepath="ext/src/jetty-ajp-8.1.13.v20130916.jar" />
+ <classpathentry kind="lib" path="ext/wicket-1.4.21.jar" sourcepath="ext/src/wicket-1.4.21.jar" />
+ <classpathentry kind="lib" path="ext/wicket-auth-roles-1.4.21.jar" sourcepath="ext/src/wicket-auth-roles-1.4.21.jar" />
+ <classpathentry kind="lib" path="ext/wicket-extensions-1.4.21.jar" sourcepath="ext/src/wicket-extensions-1.4.21.jar" />
+ <classpathentry kind="lib" path="ext/googlecharts-1.4.21.jar" sourcepath="ext/src/googlecharts-1.4.21.jar" />
+ <classpathentry kind="lib" path="ext/lucene-core-3.6.1.jar" sourcepath="ext/src/lucene-core-3.6.1.jar" />
+ <classpathentry kind="lib" path="ext/lucene-highlighter-3.6.1.jar" sourcepath="ext/src/lucene-highlighter-3.6.1.jar" />
+ <classpathentry kind="lib" path="ext/lucene-memory-3.6.1.jar" sourcepath="ext/src/lucene-memory-3.6.1.jar" />
+ <classpathentry kind="lib" path="ext/lucene-queries-3.6.1.jar" sourcepath="ext/src/lucene-queries-3.6.1.jar" />
+ <classpathentry kind="lib" path="ext/jakarta-regexp-1.4.jar" />
+ <classpathentry kind="lib" path="ext/pegdown-1.4.1.jar" sourcepath="ext/src/pegdown-1.4.1.jar" />
+ <classpathentry kind="lib" path="ext/parboiled-java-1.1.5.jar" sourcepath="ext/src/parboiled-java-1.1.5.jar" />
+ <classpathentry kind="lib" path="ext/parboiled-core-1.1.5.jar" sourcepath="ext/src/parboiled-core-1.1.5.jar" />
+ <classpathentry kind="lib" path="ext/asm-4.1.jar" sourcepath="ext/src/asm-4.1.jar" />
+ <classpathentry kind="lib" path="ext/asm-tree-4.1.jar" sourcepath="ext/src/asm-tree-4.1.jar" />
+ <classpathentry kind="lib" path="ext/asm-analysis-4.1.jar" sourcepath="ext/src/asm-analysis-4.1.jar" />
+ <classpathentry kind="lib" path="ext/asm-util-4.1.jar" sourcepath="ext/src/asm-util-4.1.jar" />
+ <classpathentry kind="lib" path="ext/wikitext-core-1.4.jar" sourcepath="ext/src/wikitext-core-1.4.jar" />
+ <classpathentry kind="lib" path="ext/twiki-core-1.4.jar" sourcepath="ext/src/twiki-core-1.4.jar" />
+ <classpathentry kind="lib" path="ext/textile-core-1.4.jar" sourcepath="ext/src/textile-core-1.4.jar" />
+ <classpathentry kind="lib" path="ext/tracwiki-core-1.4.jar" sourcepath="ext/src/tracwiki-core-1.4.jar" />
+ <classpathentry kind="lib" path="ext/mediawiki-core-1.4.jar" sourcepath="ext/src/mediawiki-core-1.4.jar" />
+ <classpathentry kind="lib" path="ext/confluence-core-1.4.jar" sourcepath="ext/src/confluence-core-1.4.jar" />
+ <classpathentry kind="lib" path="ext/org.eclipse.jgit-3.1.0.201310021548-r.jar" sourcepath="ext/src/org.eclipse.jgit-3.1.0.201310021548-r.jar" />
+ <classpathentry kind="lib" path="ext/jsch-0.1.46.jar" sourcepath="ext/src/jsch-0.1.46.jar" />
+ <classpathentry kind="lib" path="ext/JavaEWAH-0.5.6.jar" sourcepath="ext/src/JavaEWAH-0.5.6.jar" />
+ <classpathentry kind="lib" path="ext/org.eclipse.jgit.http.server-3.1.0.201310021548-r.jar" sourcepath="ext/src/org.eclipse.jgit.http.server-3.1.0.201310021548-r.jar" />
+ <classpathentry kind="lib" path="ext/bcprov-jdk15on-1.47.jar" sourcepath="ext/src/bcprov-jdk15on-1.47.jar" />
+ <classpathentry kind="lib" path="ext/bcmail-jdk15on-1.47.jar" sourcepath="ext/src/bcmail-jdk15on-1.47.jar" />
+ <classpathentry kind="lib" path="ext/bcpkix-jdk15on-1.47.jar" sourcepath="ext/src/bcpkix-jdk15on-1.47.jar" />
+ <classpathentry kind="lib" path="ext/rome-0.9.jar" sourcepath="ext/src/rome-0.9.jar" />
+ <classpathentry kind="lib" path="ext/jdom-1.0.jar" sourcepath="ext/src/jdom-1.0.jar" />
+ <classpathentry kind="lib" path="ext/gson-1.7.2.jar" sourcepath="ext/src/gson-1.7.2.jar" />
+ <classpathentry kind="lib" path="ext/groovy-all-1.8.8.jar" sourcepath="ext/src/groovy-all-1.8.8.jar" />
+ <classpathentry kind="lib" path="ext/unboundid-ldapsdk-2.3.0.jar" sourcepath="ext/src/unboundid-ldapsdk-2.3.0.jar" />
+ <classpathentry kind="lib" path="ext/ivy-2.2.0.jar" sourcepath="ext/src/ivy-2.2.0.jar" />
+ <classpathentry kind="lib" path="ext/jcalendar-1.3.2.jar" />
+ <classpathentry kind="lib" path="ext/commons-compress-1.4.1.jar" sourcepath="ext/src/commons-compress-1.4.1.jar" />
+ <classpathentry kind="lib" path="ext/xz-1.0.jar" sourcepath="ext/src/xz-1.0.jar" />
+ <classpathentry kind="lib" path="ext/commons-io-2.2.jar" sourcepath="ext/src/commons-io-2.2.jar" />
+ <classpathentry kind="lib" path="ext/force-partner-api-24.0.0.jar" sourcepath="ext/src/force-partner-api-24.0.0.jar" />
+ <classpathentry kind="lib" path="ext/force-wsc-24.0.0.jar" sourcepath="ext/src/force-wsc-24.0.0.jar" />
+ <classpathentry kind="lib" path="ext/js-1.7R2.jar" sourcepath="ext/src/js-1.7R2.jar" />
+ <classpathentry kind="lib" path="ext/freemarker-2.3.19.jar" sourcepath="ext/src/freemarker-2.3.19.jar" />
+ <classpathentry kind="lib" path="ext/waffle-jna-1.5.jar" sourcepath="ext/src/waffle-jna-1.5.jar" />
+ <classpathentry kind="lib" path="ext/platform-3.5.0.jar" sourcepath="ext/src/platform-3.5.0.jar" />
+ <classpathentry kind="lib" path="ext/jna-3.5.0.jar" sourcepath="ext/src/jna-3.5.0.jar" />
+ <classpathentry kind="lib" path="ext/guava-13.0.1.jar" sourcepath="ext/src/guava-13.0.1.jar" />
+ <classpathentry kind="lib" path="ext/libpam4j-1.7.jar" sourcepath="ext/src/libpam4j-1.7.jar" />
+ <classpathentry kind="lib" path="ext/commons-codec-1.7.jar" sourcepath="ext/src/commons-codec-1.7.jar" />
+ <classpathentry kind="lib" path="ext/junit-4.11.jar" sourcepath="ext/src/junit-4.11.jar" />
+ <classpathentry kind="lib" path="ext/hamcrest-core-1.3.jar" sourcepath="ext/src/hamcrest-core-1.3.jar" />
+ <classpathentry kind="lib" path="ext/selenium-java-2.28.0.jar" sourcepath="ext/src/selenium-java-2.28.0.jar" />
+ <classpathentry kind="lib" path="ext/selenium-support-2.28.0.jar" sourcepath="ext/src/selenium-support-2.28.0.jar" />
+ <classpathentry kind="lib" path="ext/selenium-firefox-driver-2.28.0.jar" sourcepath="ext/src/selenium-firefox-driver-2.28.0.jar" />
+ <classpathentry kind="lib" path="ext/selenium-remote-driver-2.28.0.jar" sourcepath="ext/src/selenium-remote-driver-2.28.0.jar" />
+ <classpathentry kind="lib" path="ext/cglib-nodep-2.1_3.jar" sourcepath="ext/src/cglib-nodep-2.1_3.jar" />
+ <classpathentry kind="lib" path="ext/json-20080701.jar" sourcepath="ext/src/json-20080701.jar" />
+ <classpathentry kind="lib" path="ext/selenium-api-2.28.0.jar" sourcepath="ext/src/selenium-api-2.28.0.jar" />
+ <classpathentry kind="lib" path="ext/httpclient-4.2.1.jar" sourcepath="ext/src/httpclient-4.2.1.jar" />
+ <classpathentry kind="lib" path="ext/httpcore-4.2.1.jar" sourcepath="ext/src/httpcore-4.2.1.jar" />
+ <classpathentry kind="lib" path="ext/commons-logging-1.1.1.jar" sourcepath="ext/src/commons-logging-1.1.1.jar" />
+ <classpathentry kind="lib" path="ext/commons-exec-1.1.jar" sourcepath="ext/src/commons-exec-1.1.jar" />
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" />
+ <classpathentry kind="src" path="src/main/dagger">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ </attributes>
+ </classpathentry>
<classpathentry kind="output" path="bin/classes" />
</classpath>
diff --git a/.gitignore b/.gitignore
index f77b6ff2..078de7e0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,3 +22,5 @@
/build-next.xml
/*.ps1
/*.sh
+/*.factorypath
+/src/main/dagger
diff --git a/build.moxie b/build.moxie
index 7816c927..acc1afb1 100644
--- a/build.moxie
+++ b/build.moxie
@@ -57,6 +57,7 @@ mainclass: com.gitblit.GitBlitServer
# a scope to each directory.
sourceDirectories:
- compile 'src/main/java'
+- compile 'src/main/dagger' apt
- test 'src/test/java'
# Moxie supports one site-scoped directory for mx:doc
- site 'src/site'
@@ -120,6 +121,9 @@ properties: {
#
dependencies:
+# Dagger dependency injection library (annotation processor)
+- compile 'com.squareup.dagger:dagger:1.1.0' :war apt
+- compile 'com.squareup.dagger:dagger-compiler:1.1.0' :war optional apt
# Standard dependencies
- compile 'com.beust:jcommander:1.17' :fedclient :authority
- compile 'log4j:log4j:1.2.17' :war :fedclient :authority
diff --git a/build.xml b/build.xml
index 860eca90..ab6699bc 100644
--- a/build.xml
+++ b/build.xml
@@ -247,34 +247,7 @@
</mx:webxml>
<!-- Gitblit jar -->
- <mx:genjar destfile="${webinf}/lib/gitblit.jar" includeresources="false" excludeclasspathjars="true">
- <!-- Specify all web.xml servlets and filters -->
- <class name="com.gitblit.GitBlit" />
- <class name="com.gitblit.Keys" />
- <class name="com.gitblit.DownloadZipFilter" />
- <class name="com.gitblit.DownloadZipServlet" />
- <class name="com.gitblit.EnforceAuthenticationFilter" />
- <class name="com.gitblit.FederationServlet" />
- <class name="com.gitblit.GitFilter" />
- <class name="com.gitblit.git.GitServlet" />
- <class name="com.gitblit.LogoServlet" />
- <class name="com.gitblit.PagesFilter" />
- <class name="com.gitblit.PagesServlet" />
- <class name="com.gitblit.RobotsTxtServlet" />
- <class name="com.gitblit.RpcFilter" />
- <class name="com.gitblit.RpcServlet" />
- <class name="com.gitblit.SyndicationFilter" />
- <class name="com.gitblit.SyndicationServlet" />
- <class name="com.gitblit.SparkleShareInviteServlet" />
- <class name="com.gitblit.wicket.GitblitWicketFilter" />
- <class name="com.gitblit.wicket.GitBlitWebApp" />
- <!-- Manually include alternative User Services -->
- <class name="com.gitblit.LdapUserService" />
- <class name="com.gitblit.RedmineUserService" />
- <class name="com.gitblit.SalesforceUserService" />
- <class name="com.gitblit.WindowsUserService" />
- <class name="com.gitblit.PAMUserService" />
- </mx:genjar>
+ <mx:jar destfile="${webinf}/lib/gitblit.jar" includeresources="false" />
<!-- Build the WAR file -->
<mx:zip basedir="${war.dir}" destfile="${project.targetDirectory}/${distribution.warfile}" compress="true" >
@@ -368,34 +341,7 @@
</mx:webxml>
<!-- Gitblit classes -->
- <mx:genjar destfile="${webinf}/lib/gitblit.jar" includeresources="false" excludeclasspathjars="true">
- <!-- Specify all web.xml servlets and filters -->
- <class name="com.gitblit.GitBlit" />
- <class name="com.gitblit.Keys" />
- <class name="com.gitblit.DownloadZipFilter" />
- <class name="com.gitblit.DownloadZipServlet" />
- <class name="com.gitblit.EnforceAuthenticationFilter" />
- <class name="com.gitblit.FederationServlet" />
- <class name="com.gitblit.GitFilter" />
- <class name="com.gitblit.git.GitServlet" />
- <class name="com.gitblit.LogoServlet" />
- <class name="com.gitblit.PagesFilter" />
- <class name="com.gitblit.PagesServlet" />
- <class name="com.gitblit.RobotsTxtServlet" />
- <class name="com.gitblit.RpcFilter" />
- <class name="com.gitblit.RpcServlet" />
- <class name="com.gitblit.SyndicationFilter" />
- <class name="com.gitblit.SyndicationServlet" />
- <class name="com.gitblit.SparkleShareInviteServlet" />
- <class name="com.gitblit.wicket.GitblitWicketFilter" />
- <class name="com.gitblit.wicket.GitBlitWebApp" />
- <!-- Manually include alternative User Services -->
- <class name="com.gitblit.LdapUserService" />
- <class name="com.gitblit.RedmineUserService" />
- <class name="com.gitblit.SalesforceUserService" />
- <class name="com.gitblit.WindowsUserService" />
- <class name="com.gitblit.PAMUserService" />
- </mx:genjar>
+ <mx:jar destfile="${webinf}/lib/gitblit.jar" includeresources="false" />
<!-- Build Express Zip file -->
<mx:zip basedir="${express.dir}" destfile="${project.targetDirectory}/${express.zipfile}">
diff --git a/gitblit.iml b/gitblit.iml
index 67638df6..74b1e85a 100644
--- a/gitblit.iml
+++ b/gitblit.iml
@@ -6,11 +6,56 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/dagger" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
+ <library name="dagger-1.1.0.jar">
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/ext/dagger-1.1.0.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES>
+ <root url="jar://$MODULE_DIR$/ext/src/dagger-1.1.0.jar!/" />
+ </SOURCES>
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library name="javax.inject-1.jar">
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/ext/javax.inject-1.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES>
+ <root url="jar://$MODULE_DIR$/ext/src/javax.inject-1.jar!/" />
+ </SOURCES>
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library name="dagger-compiler-1.1.0.jar">
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/ext/dagger-compiler-1.1.0.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES>
+ <root url="jar://$MODULE_DIR$/ext/src/dagger-compiler-1.1.0.jar!/" />
+ </SOURCES>
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library name="javawriter-2.1.1.jar">
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/ext/javawriter-2.1.1.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES>
+ <root url="jar://$MODULE_DIR$/ext/src/javawriter-2.1.1.jar!/" />
+ </SOURCES>
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
<library name="jcommander-1.17.jar">
<CLASSES>
<root url="jar://$MODULE_DIR$/ext/jcommander-1.17.jar!/" />
diff --git a/src/main/.gitignore b/src/main/.gitignore
new file mode 100644
index 00000000..01c48ab2
--- /dev/null
+++ b/src/main/.gitignore
@@ -0,0 +1 @@
+/dagger
diff --git a/src/main/java/com/gitblit/AccessRestrictionFilter.java b/src/main/java/com/gitblit/AccessRestrictionFilter.java
index ac97ba2e..5f0baed2 100644
--- a/src/main/java/com/gitblit/AccessRestrictionFilter.java
+++ b/src/main/java/com/gitblit/AccessRestrictionFilter.java
@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletResponse;
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.ISessionManager;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.StringUtils;
@@ -47,6 +48,19 @@ import com.gitblit.utils.StringUtils;
*/
public abstract class AccessRestrictionFilter extends AuthenticationFilter {
+ protected final IRuntimeManager runtimeManager;
+
+ protected final IRepositoryManager repositoryManager;
+
+ protected AccessRestrictionFilter(
+ IRuntimeManager runtimeManager,
+ ISessionManager sessionManager,
+ IRepositoryManager repositoryManager) {
+ super(sessionManager);
+ this.runtimeManager = runtimeManager;
+ this.repositoryManager = repositoryManager;
+ }
+
/**
* Extract the repository name from the url.
*
@@ -128,9 +142,6 @@ public abstract class AccessRestrictionFilter extends AuthenticationFilter {
String fullUrl = getFullUrl(httpRequest);
String repository = extractRepositoryName(fullUrl);
- IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
-
if (repositoryManager.isCollectingGarbage(repository)) {
logger.info(MessageFormat.format("ARF: Rejecting request for {0}, busy collecting garbage!", repository));
httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
diff --git a/src/main/java/com/gitblit/AuthenticationFilter.java b/src/main/java/com/gitblit/AuthenticationFilter.java
index 9aeb89f7..96d880f4 100644
--- a/src/main/java/com/gitblit/AuthenticationFilter.java
+++ b/src/main/java/com/gitblit/AuthenticationFilter.java
@@ -57,6 +57,12 @@ public abstract class AuthenticationFilter implements Filter {
protected transient Logger logger = LoggerFactory.getLogger(getClass());
+ protected final ISessionManager sessionManager;
+
+ protected AuthenticationFilter(ISessionManager sessionManager) {
+ this.sessionManager = sessionManager;
+ }
+
/**
* doFilter does the actual work of preprocessing the request to ensure that
* the user may proceed.
@@ -101,7 +107,6 @@ public abstract class AuthenticationFilter implements Filter {
* @return user
*/
protected UserModel getUser(HttpServletRequest httpRequest) {
- ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);
UserModel user = sessionManager.authenticate(httpRequest, requiresClientCertificate());
return user;
}
diff --git a/src/main/java/com/gitblit/BranchGraphServlet.java b/src/main/java/com/gitblit/BranchGraphServlet.java
index 986560c6..58a57781 100644
--- a/src/main/java/com/gitblit/BranchGraphServlet.java
+++ b/src/main/java/com/gitblit/BranchGraphServlet.java
@@ -36,6 +36,8 @@ import java.util.Set;
import java.util.TreeSet;
import javax.imageio.ImageIO;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -61,6 +63,7 @@ import com.gitblit.utils.StringUtils;
* @author James Moger
*
*/
+@Singleton
public class BranchGraphServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@@ -74,8 +77,18 @@ public class BranchGraphServlet extends HttpServlet {
private final Stroke[] strokeCache;
- public BranchGraphServlet() {
+ private final IStoredSettings settings;
+
+ private final IRepositoryManager repositoryManager;
+
+ @Inject
+ public BranchGraphServlet(
+ IRuntimeManager runtimeManager,
+ IRepositoryManager repositoryManager) {
+
super();
+ this.settings = runtimeManager.getSettings();
+ this.repositoryManager = repositoryManager;
strokeCache = new Stroke[4];
for (int i = 1; i < strokeCache.length; i++)
@@ -104,7 +117,6 @@ public class BranchGraphServlet extends HttpServlet {
protected long getLastModified(HttpServletRequest req) {
String repository = req.getParameter("r");
String objectId = req.getParameter("h");
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
Repository r = null;
try {
r = repositoryManager.getRepository(repository);
@@ -131,9 +143,6 @@ public class BranchGraphServlet extends HttpServlet {
String objectId = request.getParameter("h");
String length = request.getParameter("l");
- IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
-
r = repositoryManager.getRepository(repository);
rw = new PlotWalk(r);
diff --git a/src/main/java/com/gitblit/DaggerModule.java b/src/main/java/com/gitblit/DaggerModule.java
new file mode 100644
index 00000000..7ee8ecd6
--- /dev/null
+++ b/src/main/java/com/gitblit/DaggerModule.java
@@ -0,0 +1,136 @@
+/*
+ * 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;
+
+import javax.inject.Singleton;
+
+import org.apache.wicket.protocol.http.WebApplication;
+
+import com.gitblit.git.GitServlet;
+import com.gitblit.manager.IFederationManager;
+import com.gitblit.manager.IGitblitManager;
+import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IProjectManager;
+import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.ISessionManager;
+import com.gitblit.manager.IUserManager;
+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 = {
+ // core managers
+ IRuntimeManager.class,
+ INotificationManager.class,
+ IUserManager.class,
+ ISessionManager.class,
+ IRepositoryManager.class,
+ IProjectManager.class,
+ IGitblitManager.class,
+ IFederationManager.class,
+
+ // filters & servlets
+ GitServlet.class,
+ GitFilter.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,
+ EnforceAuthenticationFilter.class,
+ GitblitWicketFilter.class
+ }
+)
+public class DaggerModule {
+
+ final GitBlit gitblit;
+
+ // HACK but necessary for now
+ public DaggerModule(GitBlit gitblit) {
+ this.gitblit = gitblit;
+ }
+
+ @Provides @Singleton IRuntimeManager provideRuntimeManager() {
+ return gitblit;
+ }
+
+ @Provides @Singleton INotificationManager provideNotificationManager() {
+ return gitblit;
+ }
+
+ @Provides @Singleton IUserManager provideUserManager() {
+ return gitblit;
+ }
+
+ @Provides @Singleton ISessionManager provideSessionManager() {
+ return gitblit;
+ }
+
+ @Provides @Singleton IRepositoryManager provideRepositoryManager() {
+ return gitblit;
+ }
+
+ @Provides @Singleton IProjectManager provideProjectManager() {
+ return gitblit;
+ }
+
+ @Provides @Singleton IGitblitManager provideGitblitManager() {
+ return gitblit;
+ }
+
+ @Provides @Singleton IFederationManager provideFederationManager() {
+ return gitblit;
+ }
+
+ @Provides @Singleton WebApplication provideWebApplication(
+ IRuntimeManager runtimeManager,
+ INotificationManager notificationManager,
+ IUserManager userManager,
+ ISessionManager sessionManager,
+ IRepositoryManager repositoryManager,
+ IProjectManager projectManager,
+ IGitblitManager gitblitManager,
+ IFederationManager federationManager) {
+
+ return new GitBlitWebApp(
+ runtimeManager,
+ notificationManager,
+ userManager,
+ sessionManager,
+ repositoryManager,
+ projectManager,
+ gitblitManager,
+ federationManager);
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/gitblit/DownloadZipFilter.java b/src/main/java/com/gitblit/DownloadZipFilter.java
index e52d9d79..914d89e5 100644
--- a/src/main/java/com/gitblit/DownloadZipFilter.java
+++ b/src/main/java/com/gitblit/DownloadZipFilter.java
@@ -15,7 +15,13 @@
*/
package com.gitblit;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
import com.gitblit.Constants.AccessRestrictionType;
+import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.ISessionManager;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
@@ -27,9 +33,16 @@ import com.gitblit.models.UserModel;
* @author James Moger
*
*/
+@Singleton
public class DownloadZipFilter extends AccessRestrictionFilter {
- public DownloadZipFilter() {
+ @Inject
+ public DownloadZipFilter(
+ IRuntimeManager runtimeManager,
+ ISessionManager sessionManager,
+ IRepositoryManager repositoryManager) {
+
+ super(runtimeManager, sessionManager, repositoryManager);
}
/**
diff --git a/src/main/java/com/gitblit/DownloadZipServlet.java b/src/main/java/com/gitblit/DownloadZipServlet.java
index 82846dac..d629dcfc 100644
--- a/src/main/java/com/gitblit/DownloadZipServlet.java
+++ b/src/main/java/com/gitblit/DownloadZipServlet.java
@@ -20,6 +20,8 @@ import java.text.MessageFormat;
import java.text.ParseException;
import java.util.Date;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
@@ -43,12 +45,17 @@ import com.gitblit.utils.StringUtils;
* @author James Moger
*
*/
+@Singleton
public class DownloadZipServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private transient Logger logger = LoggerFactory.getLogger(DownloadZipServlet.class);
+ private final IStoredSettings settings;
+
+ private final IRepositoryManager repositoryManager;
+
public static enum Format {
zip(".zip"), tar(".tar"), gz(".tar.gz"), xz(".tar.xz"), bzip2(".tar.bzip2");
@@ -68,8 +75,14 @@ public class DownloadZipServlet extends HttpServlet {
}
}
- public DownloadZipServlet() {
+ @Inject
+ public DownloadZipServlet(
+ IRuntimeManager runtimeManager,
+ IRepositoryManager repositoryManager) {
+
super();
+ this.settings = runtimeManager.getSettings();
+ this.repositoryManager = repositoryManager;
}
/**
@@ -103,7 +116,6 @@ public class DownloadZipServlet extends HttpServlet {
private void processRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,
java.io.IOException {
- IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
if (!settings.getBoolean(Keys.web.allowZipDownloads, true)) {
logger.warn("Zip downloads are disabled");
response.sendError(HttpServletResponse.SC_FORBIDDEN);
@@ -133,7 +145,6 @@ public class DownloadZipServlet extends HttpServlet {
name += "-" + objectId;
}
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
Repository r = repositoryManager.getRepository(repository);
if (r == null) {
if (repositoryManager.isCollectingGarbage(repository)) {
diff --git a/src/main/java/com/gitblit/EnforceAuthenticationFilter.java b/src/main/java/com/gitblit/EnforceAuthenticationFilter.java
index 12b07595..48fc0057 100644
--- a/src/main/java/com/gitblit/EnforceAuthenticationFilter.java
+++ b/src/main/java/com/gitblit/EnforceAuthenticationFilter.java
@@ -18,6 +18,8 @@
import java.io.IOException;
import java.text.MessageFormat;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -42,11 +44,23 @@ import com.gitblit.models.UserModel;
* @author Laurens Vrijnsen
*
*/
+@Singleton
public class EnforceAuthenticationFilter implements Filter {
protected transient Logger logger = LoggerFactory.getLogger(getClass());
- public EnforceAuthenticationFilter() {
+ private final IStoredSettings settings;
+
+ private final ISessionManager sessionManager;
+
+ @Inject
+ public EnforceAuthenticationFilter(
+ IRuntimeManager runtimeManager,
+ ISessionManager sessionManager) {
+
+ super();
+ this.settings = runtimeManager.getSettings();
+ this.sessionManager = sessionManager;
}
/*
@@ -56,7 +70,6 @@ public class EnforceAuthenticationFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {
}
-
/*
* This does the actual filtering: is the user authenticated? If not, enforce HTTP authentication (401)
*
@@ -65,8 +78,6 @@ public class EnforceAuthenticationFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
- IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
- ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);
Boolean mustForceAuth = settings.getBoolean(Keys.web.authenticateViewPages, false)
&& settings.getBoolean(Keys.web.enforceHttpBasicAuthentication, false);
diff --git a/src/main/java/com/gitblit/FederationServlet.java b/src/main/java/com/gitblit/FederationServlet.java
index 0d83b4f4..31e3c0e1 100644
--- a/src/main/java/com/gitblit/FederationServlet.java
+++ b/src/main/java/com/gitblit/FederationServlet.java
@@ -25,6 +25,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.http.HttpServletResponse;
import com.gitblit.Constants.FederationRequest;
@@ -48,12 +50,31 @@ import com.gitblit.utils.TimeUtils;
* @author James Moger
*
*/
+@Singleton
public class FederationServlet extends JsonServlet {
private static final long serialVersionUID = 1L;
- public FederationServlet() {
+ private final IStoredSettings settings;
+
+ private final IUserManager userManager;
+
+ private final IRepositoryManager repositoryManager;
+
+ private final IFederationManager federationManager;
+
+ @Inject
+ public FederationServlet(
+ IRuntimeManager runtimeManager,
+ IUserManager userManager,
+ IRepositoryManager repositoryManager,
+ IFederationManager federationManager) {
+
super();
+ this.settings = runtimeManager.getSettings();
+ this.userManager = userManager;
+ this.repositoryManager = repositoryManager;
+ this.federationManager = federationManager;
}
/**
@@ -70,11 +91,6 @@ public class FederationServlet extends JsonServlet {
javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,
java.io.IOException {
- IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
- IUserManager userManager = GitBlit.getManager(IUserManager.class);
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
- IFederationManager federationManager = GitBlit.getManager(IFederationManager.class);
-
FederationRequest reqType = FederationRequest.fromName(request.getParameter("req"));
logger.info(MessageFormat.format("Federation {0} request from {1}", reqType,
request.getRemoteAddr()));
diff --git a/src/main/java/com/gitblit/GCExecutor.java b/src/main/java/com/gitblit/GCExecutor.java
index 837741f2..3ab98956 100644
--- a/src/main/java/com/gitblit/GCExecutor.java
+++ b/src/main/java/com/gitblit/GCExecutor.java
@@ -54,14 +54,20 @@ public class GCExecutor implements Runnable {
private final IStoredSettings settings;
+ private final IRepositoryManager repositoryManager;
+
private AtomicBoolean running = new AtomicBoolean(false);
private AtomicBoolean forceClose = new AtomicBoolean(false);
private final Map<String, GCStatus> gcCache = new ConcurrentHashMap<String, GCStatus>();
- public GCExecutor(IStoredSettings settings) {
+ public GCExecutor(
+ IStoredSettings settings,
+ IRepositoryManager repositoryManager) {
+
this.settings = settings;
+ this.repositoryManager = repositoryManager;
}
/**
@@ -132,8 +138,6 @@ public class GCExecutor implements Runnable {
running.set(true);
Date now = new Date();
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
-
for (String repositoryName : repositoryManager.getRepositoryList()) {
if (forceClose.get()) {
break;
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java
index 31dedf13..8be50fb6 100644
--- a/src/main/java/com/gitblit/GitBlit.java
+++ b/src/main/java/com/gitblit/GitBlit.java
@@ -65,7 +65,6 @@ import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
@@ -95,6 +94,7 @@ import com.gitblit.Constants.FederationStrategy;
import com.gitblit.Constants.FederationToken;
import com.gitblit.Constants.PermissionType;
import com.gitblit.Constants.RegistrantType;
+import com.gitblit.dagger.DaggerContextListener;
import com.gitblit.fanout.FanoutNioService;
import com.gitblit.fanout.FanoutService;
import com.gitblit.fanout.FanoutSocketService;
@@ -164,7 +164,7 @@ import com.google.gson.reflect.TypeToken;
*
*/
@WebListener
-public class GitBlit extends InjectionContextListener
+public class GitBlit extends DaggerContextListener
implements IRuntimeManager,
INotificationManager,
IUserManager,
@@ -3479,9 +3479,9 @@ public class GitBlit extends InjectionContextListener
// prepare service executors
mailExecutor = new MailExecutor(settings);
- luceneExecutor = new LuceneExecutor(settings, repositoriesFolder);
- gcExecutor = new GCExecutor(settings);
- mirrorExecutor = new MirrorExecutor(settings);
+ luceneExecutor = new LuceneExecutor(settings, getManager(IRepositoryManager.class));
+ gcExecutor = new GCExecutor(settings, getManager(IRepositoryManager.class));
+ mirrorExecutor = new MirrorExecutor(settings, getManager(IRepositoryManager.class));
// initialize utilities
String prefix = settings.getString(Keys.git.userRepositoryPrefix, "~");
@@ -3641,7 +3641,7 @@ public class GitBlit extends InjectionContextListener
String bindInterface = settings.getString(Keys.git.daemonBindInterface, "localhost");
if (port > 0) {
try {
- gitDaemon = new GitDaemon(bindInterface, port, getRepositoriesFolder());
+ gitDaemon = new GitDaemon(this, this, this, this);
gitDaemon.start();
} catch (IOException e) {
gitDaemon = null;
@@ -3854,7 +3854,7 @@ public class GitBlit extends InjectionContextListener
* shutting down or because the servlet container is re-deploying Gitblit.
*/
@Override
- public void contextDestroyed(ServletContextEvent contextEvent) {
+ protected void destroyContext(ServletContext context) {
logger.info("Gitblit context destroyed by servlet container.");
scheduledExecutor.shutdownNow();
luceneExecutor.close();
@@ -4052,6 +4052,11 @@ public class GitBlit extends InjectionContextListener
userService.logout(user);
}
+ @Override
+ protected Object [] getModules() {
+ return new Object [] { new DaggerModule(this) };
+ }
+
/**
* Instantiate and inject all filters and servlets into the container using
* the servlet 3 specification.
diff --git a/src/main/java/com/gitblit/GitFilter.java b/src/main/java/com/gitblit/GitFilter.java
index a06c7e52..ba8443d0 100644
--- a/src/main/java/com/gitblit/GitFilter.java
+++ b/src/main/java/com/gitblit/GitFilter.java
@@ -17,10 +17,14 @@ package com.gitblit;
import java.text.MessageFormat;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.Constants.AuthorizationControl;
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.ISessionManager;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.StringUtils;
@@ -33,6 +37,7 @@ import com.gitblit.utils.StringUtils;
* @author James Moger
*
*/
+@Singleton
public class GitFilter extends AccessRestrictionFilter {
protected static final String gitReceivePack = "/git-receive-pack";
@@ -42,7 +47,16 @@ public class GitFilter extends AccessRestrictionFilter {
protected static final String[] suffixes = { gitReceivePack, gitUploadPack, "/info/refs", "/HEAD",
"/objects" };
- public GitFilter() {
+ private final IStoredSettings settings;
+
+ @Inject
+ public GitFilter(
+ IRuntimeManager runtimeManager,
+ ISessionManager sessionManager,
+ IRepositoryManager repositoryManager) {
+
+ super(runtimeManager, sessionManager, repositoryManager);
+ this.settings = runtimeManager.getSettings();
}
/**
@@ -105,7 +119,6 @@ public class GitFilter extends AccessRestrictionFilter {
*/
@Override
protected boolean isCreationAllowed() {
- IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
return settings.getBoolean(Keys.git.allowCreateOnPush, true);
}
@@ -125,7 +138,6 @@ public class GitFilter extends AccessRestrictionFilter {
@Override
protected boolean requiresClientCertificate() {
- IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
return settings.getBoolean(Keys.git.requiresClientCertificate, false);
}
@@ -159,7 +171,6 @@ public class GitFilter extends AccessRestrictionFilter {
*/
@Override
protected boolean canAccess(RepositoryModel repository, UserModel user, String action) {
- IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
if (!settings.getBoolean(Keys.git.enableGitServlet, true)) {
// Git Servlet disabled
return false;
@@ -231,14 +242,12 @@ public class GitFilter extends AccessRestrictionFilter {
model.accessRestriction = AccessRestrictionType.VIEW;
} else {
// common repository, user default server settings
- IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
model.authorizationControl = AuthorizationControl.fromName(settings.getString(Keys.git.defaultAuthorizationControl, ""));
model.accessRestriction = AccessRestrictionType.fromName(settings.getString(Keys.git.defaultAccessRestriction, "PUSH"));
}
// create the repository
try {
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
repositoryManager.updateRepositoryModel(model.name, model, true);
logger.info(MessageFormat.format("{0} created {1} ON-PUSH", user.username, model.name));
return repositoryManager.getRepositoryModel(model.name);
diff --git a/src/main/java/com/gitblit/LogoServlet.java b/src/main/java/com/gitblit/LogoServlet.java
index 4222f8ff..17b05cfd 100644
--- a/src/main/java/com/gitblit/LogoServlet.java
+++ b/src/main/java/com/gitblit/LogoServlet.java
@@ -21,6 +21,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -35,19 +37,23 @@ import com.gitblit.manager.IRuntimeManager;
* @author James Moger
*
*/
+@Singleton
public class LogoServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final long lastModified = System.currentTimeMillis();
- public LogoServlet() {
+ private final IRuntimeManager runtimeManager;
+
+ @Inject
+ public LogoServlet(IRuntimeManager runtimeManager) {
super();
+ this.runtimeManager = runtimeManager;
}
@Override
protected long getLastModified(HttpServletRequest req) {
- IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);
File file = runtimeManager.getFileOrFolder(Keys.web.headerLogo, "${baseFolder}/logo.png");
if (file.exists()) {
return Math.max(lastModified, file.lastModified());
@@ -62,7 +68,6 @@ public class LogoServlet extends HttpServlet {
InputStream is = null;
try {
String contentType = null;
- IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);
File file = runtimeManager.getFileOrFolder(Keys.web.headerLogo, "${baseFolder}/logo.png");
if (file.exists()) {
// custom logo
diff --git a/src/main/java/com/gitblit/LuceneExecutor.java b/src/main/java/com/gitblit/LuceneExecutor.java
index 19395b3b..b7b71c5e 100644
--- a/src/main/java/com/gitblit/LuceneExecutor.java
+++ b/src/main/java/com/gitblit/LuceneExecutor.java
@@ -128,6 +128,7 @@ public class LuceneExecutor implements Runnable {
private final Logger logger = LoggerFactory.getLogger(LuceneExecutor.class);
private final IStoredSettings storedSettings;
+ private final IRepositoryManager repositoryManager;
private final File repositoriesFolder;
private final Map<String, IndexSearcher> searchers = new ConcurrentHashMap<String, IndexSearcher>();
@@ -136,9 +137,13 @@ public class LuceneExecutor implements Runnable {
private final String luceneIgnoreExtensions = "7z arc arj bin bmp dll doc docx exe gif gz jar jpg lib lzh odg odf odt pdf ppt png so swf xcf xls xlsx zip";
private Set<String> excludedExtensions;
- public LuceneExecutor(IStoredSettings settings, File repositoriesFolder) {
+ public LuceneExecutor(
+ IStoredSettings settings,
+ IRepositoryManager repositoryManager) {
+
this.storedSettings = settings;
- this.repositoriesFolder = repositoriesFolder;
+ this.repositoryManager = repositoryManager;
+ this.repositoriesFolder = repositoryManager.getRepositoriesFolder();
String exts = luceneIgnoreExtensions;
if (settings != null) {
exts = settings.getString(Keys.web.luceneIgnoreExtensions, exts);
@@ -161,7 +166,6 @@ public class LuceneExecutor implements Runnable {
String exts = storedSettings.getString(Keys.web.luceneIgnoreExtensions, luceneIgnoreExtensions);
excludedExtensions = new TreeSet<String>(StringUtils.getStringsFromValue(exts));
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
if (repositoryManager.isCollectingGarbage()) {
// busy collecting garbage, try again later
return;
diff --git a/src/main/java/com/gitblit/MirrorExecutor.java b/src/main/java/com/gitblit/MirrorExecutor.java
index a96c955f..6c951b94 100644
--- a/src/main/java/com/gitblit/MirrorExecutor.java
+++ b/src/main/java/com/gitblit/MirrorExecutor.java
@@ -52,14 +52,20 @@ public class MirrorExecutor implements Runnable {
private final IStoredSettings settings;
+ private final IRepositoryManager repositoryManager;
+
private AtomicBoolean running = new AtomicBoolean(false);
private AtomicBoolean forceClose = new AtomicBoolean(false);
private final UserModel gitblitUser;
- public MirrorExecutor(IStoredSettings settings) {
+ public MirrorExecutor(
+ IStoredSettings settings,
+ IRepositoryManager repositoryManager) {
+
this.settings = settings;
+ this.repositoryManager = repositoryManager;
this.gitblitUser = new UserModel("gitblit");
this.gitblitUser.displayName = "Gitblit";
}
@@ -84,8 +90,6 @@ public class MirrorExecutor implements Runnable {
running.set(true);
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
-
for (String repositoryName : repositoryManager.getRepositoryList()) {
if (forceClose.get()) {
break;
diff --git a/src/main/java/com/gitblit/PagesFilter.java b/src/main/java/com/gitblit/PagesFilter.java
index 4c9568dc..a322af2f 100644
--- a/src/main/java/com/gitblit/PagesFilter.java
+++ b/src/main/java/com/gitblit/PagesFilter.java
@@ -15,10 +15,15 @@
*/
package com.gitblit;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
import org.eclipse.jgit.lib.Repository;
import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.ISessionManager;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
@@ -29,9 +34,15 @@ import com.gitblit.models.UserModel;
* @author James Moger
*
*/
+@Singleton
public class PagesFilter extends AccessRestrictionFilter {
- public PagesFilter() {
+ @Inject
+ public PagesFilter(IRuntimeManager runtimeManager,
+ ISessionManager sessionManager,
+ IRepositoryManager repositoryManager) {
+
+ super(runtimeManager, sessionManager, repositoryManager);
}
/**
@@ -53,7 +64,6 @@ public class PagesFilter extends AccessRestrictionFilter {
} else {
repository = url.substring(0, slash);
}
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
r = repositoryManager.getRepository(repository, false);
if (r == null) {
// try again
diff --git a/src/main/java/com/gitblit/PagesServlet.java b/src/main/java/com/gitblit/PagesServlet.java
index 5569ab39..ba919e07 100644
--- a/src/main/java/com/gitblit/PagesServlet.java
+++ b/src/main/java/com/gitblit/PagesServlet.java
@@ -23,6 +23,8 @@ import java.util.List;
import java.util.Set;
import java.util.TreeSet;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -53,14 +55,25 @@ import com.gitblit.wicket.MarkupProcessor.MarkupDocument;
* @author James Moger
*
*/
+@Singleton
public class PagesServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private transient Logger logger = LoggerFactory.getLogger(PagesServlet.class);
- public PagesServlet() {
+ private final IStoredSettings settings;
+
+ private final IRepositoryManager repositoryManager;
+
+ @Inject
+ public PagesServlet(
+ IRuntimeManager runtimeManager,
+ IRepositoryManager repositoryManager) {
+
super();
+ this.settings = runtimeManager.getSettings();
+ this.repositoryManager = repositoryManager;
}
/**
@@ -101,9 +114,6 @@ public class PagesServlet extends HttpServlet {
path = path.substring(1);
}
- IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
-
// determine repository and resource from url
String repository = "";
String resource = "";
diff --git a/src/main/java/com/gitblit/RobotsTxtServlet.java b/src/main/java/com/gitblit/RobotsTxtServlet.java
index 6a7c02d3..c07aa1d0 100644
--- a/src/main/java/com/gitblit/RobotsTxtServlet.java
+++ b/src/main/java/com/gitblit/RobotsTxtServlet.java
@@ -18,6 +18,8 @@ package com.gitblit;
import java.io.File;
import java.io.IOException;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -32,12 +34,17 @@ import com.gitblit.utils.FileUtils;
* @author James Moger
*
*/
+@Singleton
public class RobotsTxtServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
- public RobotsTxtServlet() {
+ private final IRuntimeManager runtimeManager;
+
+ @Inject
+ public RobotsTxtServlet(IRuntimeManager runtimeManager) {
super();
+ this.runtimeManager = runtimeManager;
}
@Override
@@ -55,7 +62,6 @@ public class RobotsTxtServlet extends HttpServlet {
protected void processRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,
java.io.IOException {
- IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);
File file = runtimeManager.getFileOrFolder(Keys.web.robots.txt, null);
String content = "";
if (file.exists()) {
diff --git a/src/main/java/com/gitblit/RpcFilter.java b/src/main/java/com/gitblit/RpcFilter.java
index b1384ad3..c4b6451c 100644
--- a/src/main/java/com/gitblit/RpcFilter.java
+++ b/src/main/java/com/gitblit/RpcFilter.java
@@ -18,6 +18,8 @@ package com.gitblit;
import java.io.IOException;
import java.text.MessageFormat;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
@@ -27,6 +29,7 @@ import javax.servlet.http.HttpServletResponse;
import com.gitblit.Constants.RpcRequest;
import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.ISessionManager;
import com.gitblit.models.UserModel;
/**
@@ -42,9 +45,21 @@ import com.gitblit.models.UserModel;
* @author James Moger
*
*/
+@Singleton
public class RpcFilter extends AuthenticationFilter {
- public RpcFilter() {
+ private final IStoredSettings settings;
+
+ private final IRuntimeManager runtimeManager;
+
+ @Inject
+ public RpcFilter(
+ IRuntimeManager runtimeManager,
+ ISessionManager sessionManager) {
+
+ super(sessionManager);
+ this.settings = runtimeManager.getSettings();
+ this.runtimeManager = runtimeManager;
}
/**
@@ -68,9 +83,6 @@ public class RpcFilter extends AuthenticationFilter {
return;
}
- IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);
- IStoredSettings settings = runtimeManager.getSettings();
-
boolean adminRequest = requestType.exceeds(RpcRequest.LIST_SETTINGS);
// conditionally reject all rpc requests
diff --git a/src/main/java/com/gitblit/RpcServlet.java b/src/main/java/com/gitblit/RpcServlet.java
index a8fa6f83..a3629b9c 100644
--- a/src/main/java/com/gitblit/RpcServlet.java
+++ b/src/main/java/com/gitblit/RpcServlet.java
@@ -23,6 +23,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -53,14 +55,41 @@ import com.gitblit.utils.StringUtils;
* @author James Moger
*
*/
+@Singleton
public class RpcServlet extends JsonServlet {
private static final long serialVersionUID = 1L;
public static final int PROTOCOL_VERSION = 6;
- public RpcServlet() {
+ private final IStoredSettings settings;
+
+ private final IRuntimeManager runtimeManager;
+
+ private final IUserManager userManager;
+
+ private final IRepositoryManager repositoryManager;
+
+ private final IFederationManager federationManager;
+
+ private final IGitblitManager gitblitManager;
+
+ @Inject
+ public RpcServlet(
+ IRuntimeManager runtimeManager,
+ IUserManager userManager,
+ IRepositoryManager repositoryManager,
+ IFederationManager federationManager,
+ IGitblitManager gitblitManager) {
+
super();
+
+ this.settings = runtimeManager.getSettings();
+ this.runtimeManager = runtimeManager;
+ this.userManager = userManager;
+ this.repositoryManager = repositoryManager;
+ this.federationManager = federationManager;
+ this.gitblitManager = gitblitManager;
}
/**
@@ -79,13 +108,6 @@ public class RpcServlet extends JsonServlet {
logger.info(MessageFormat.format("Rpc {0} request from {1}", reqType,
request.getRemoteAddr()));
- IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);
- IUserManager userManager = GitBlit.getManager(IUserManager.class);
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
- IGitblitManager gitblitManager = GitBlit.getManager(IGitblitManager.class);
- IFederationManager federationManager = GitBlit.getManager(IFederationManager.class);
- IStoredSettings settings = runtimeManager.getSettings();
-
UserModel user = (UserModel) request.getUserPrincipal();
boolean allowManagement = user != null && user.canAdmin()
diff --git a/src/main/java/com/gitblit/SparkleShareInviteServlet.java b/src/main/java/com/gitblit/SparkleShareInviteServlet.java
index 9f6618b2..1cd997d3 100644
--- a/src/main/java/com/gitblit/SparkleShareInviteServlet.java
+++ b/src/main/java/com/gitblit/SparkleShareInviteServlet.java
@@ -18,6 +18,8 @@ package com.gitblit;
import java.io.IOException;
import java.text.MessageFormat;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -37,12 +39,31 @@ import com.gitblit.utils.StringUtils;
* @author James Moger
*
*/
+@Singleton
public class SparkleShareInviteServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
- public SparkleShareInviteServlet() {
+ private final IStoredSettings settings;
+
+ private final IUserManager userManager;
+
+ private final ISessionManager sessionManager;
+
+ private final IRepositoryManager repositoryManager;
+
+ @Inject
+ public SparkleShareInviteServlet(
+ IRuntimeManager runtimeManager,
+ IUserManager userManager,
+ ISessionManager sessionManager,
+ IRepositoryManager repositoryManager) {
+
super();
+ this.settings = runtimeManager.getSettings();
+ this.userManager = userManager;
+ this.sessionManager = sessionManager;
+ this.repositoryManager = repositoryManager;
}
@Override
@@ -61,11 +82,6 @@ public class SparkleShareInviteServlet extends HttpServlet {
javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,
java.io.IOException {
- IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
- IUserManager userManager = GitBlit.getManager(IUserManager.class);
- ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
-
// extract repo name from request
String repoUrl = request.getPathInfo().substring(1);
diff --git a/src/main/java/com/gitblit/SyndicationFilter.java b/src/main/java/com/gitblit/SyndicationFilter.java
index ad908fa8..10b88102 100644
--- a/src/main/java/com/gitblit/SyndicationFilter.java
+++ b/src/main/java/com/gitblit/SyndicationFilter.java
@@ -18,6 +18,8 @@ package com.gitblit;
import java.io.IOException;
import java.text.MessageFormat;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
@@ -29,6 +31,7 @@ import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.manager.IProjectManager;
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.ISessionManager;
import com.gitblit.models.ProjectModel;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
@@ -41,9 +44,24 @@ import com.gitblit.models.UserModel;
* @author James Moger
*
*/
+@Singleton
public class SyndicationFilter extends AuthenticationFilter {
- public SyndicationFilter() {
+ private final IRuntimeManager runtimeManager;
+ private final IRepositoryManager repositoryManager;
+ private final IProjectManager projectManager;
+
+ @Inject
+ public SyndicationFilter(
+ IRuntimeManager runtimeManager,
+ ISessionManager sessionManager,
+ IRepositoryManager repositoryManager,
+ IProjectManager projectManager) {
+
+ super(sessionManager);
+ this.runtimeManager = runtimeManager;
+ this.repositoryManager = repositoryManager;
+ this.projectManager = projectManager;
}
/**
@@ -76,10 +94,6 @@ public class SyndicationFilter extends AuthenticationFilter {
String fullUrl = getFullUrl(httpRequest);
String name = extractRequestedName(fullUrl);
- IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
- IProjectManager projectManager = GitBlit.getManager(IProjectManager.class);
-
ProjectModel project = projectManager.getProjectModel(name);
RepositoryModel model = null;
diff --git a/src/main/java/com/gitblit/SyndicationServlet.java b/src/main/java/com/gitblit/SyndicationServlet.java
index 11089ee1..397545fa 100644
--- a/src/main/java/com/gitblit/SyndicationServlet.java
+++ b/src/main/java/com/gitblit/SyndicationServlet.java
@@ -22,6 +22,8 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.http.HttpServlet;
import org.eclipse.jgit.lib.ObjectId;
@@ -53,13 +55,29 @@ import com.gitblit.utils.SyndicationUtils;
* @author James Moger
*
*/
+@Singleton
public class SyndicationServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private transient Logger logger = LoggerFactory.getLogger(SyndicationServlet.class);
- public SyndicationServlet() {
+ private final IStoredSettings settings;
+
+ private final IRepositoryManager repositoryManager;
+
+ private final IProjectManager projectManager;
+
+ @Inject
+ public SyndicationServlet(
+ IRuntimeManager runtimeManager,
+ IRepositoryManager repositoryManager,
+ IProjectManager projectManager) {
+
+ super();
+ this.settings = runtimeManager.getSettings();
+ this.repositoryManager = repositoryManager;
+ this.projectManager = projectManager;
}
/**
@@ -133,10 +151,6 @@ public class SyndicationServlet extends HttpServlet {
javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,
java.io.IOException {
- IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
- IProjectManager projectManager = GitBlit.getManager(IProjectManager.class);
-
String servletUrl = request.getContextPath() + request.getServletPath();
String url = request.getRequestURI().substring(servletUrl.length());
if (url.charAt(0) == '/' && url.length() > 1) {
diff --git a/src/main/java/com/gitblit/dagger/DaggerContextListener.java b/src/main/java/com/gitblit/dagger/DaggerContextListener.java
new file mode 100644
index 00000000..3c268860
--- /dev/null
+++ b/src/main/java/com/gitblit/dagger/DaggerContextListener.java
@@ -0,0 +1,80 @@
+/*
+ * 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.ServletContextEvent;
+
+import com.gitblit.InjectionContextListener;
+
+import dagger.ObjectGraph;
+
+/**
+ * Dagger servlet context listener is a context listener that uses Dagger to
+ * instantiate and inject servlets, filters, and anything else you might want.
+ *
+ * @author James Moger
+ *
+ */
+public abstract class DaggerContextListener extends InjectionContextListener {
+
+ protected static final String INJECTOR_NAME = ObjectGraph.class.getName();
+
+ protected abstract Object [] getModules();
+
+ protected abstract void destroyContext(ServletContext context);
+
+ protected ObjectGraph 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");
+ try {
+ o = ObjectGraph.create(modules);
+ logger.debug("setting Dagger injector into {} attribute", INJECTOR_NAME);
+ context.setAttribute(INJECTOR_NAME, o);
+ } catch (Throwable t) {
+ logger.error("an error occurred creating the Dagger injector", t);
+ }
+ }
+ return (ObjectGraph) o;
+ }
+
+ /**
+ * Instantiates an object.
+ *
+ * @param clazz
+ * @return the object
+ */
+ @Override
+ protected <X> X instantiate(ServletContext context, Class<X> clazz) {
+ try {
+ ObjectGraph injector = getInjector(context);
+ return injector.get(clazz);
+ } catch (Throwable t) {
+ logger.error(null, t);
+ }
+ return null;
+ }
+
+ @Override
+ public final void contextDestroyed(ServletContextEvent contextEvent) {
+ ServletContext context = contextEvent.getServletContext();
+ context.setAttribute(INJECTOR_NAME, null);
+ destroyContext(context);
+ }
+}
diff --git a/src/main/java/com/gitblit/dagger/DaggerWicketFilter.java b/src/main/java/com/gitblit/dagger/DaggerWicketFilter.java
new file mode 100644
index 00000000..b778f1f6
--- /dev/null
+++ b/src/main/java/com/gitblit/dagger/DaggerWicketFilter.java
@@ -0,0 +1,54 @@
+/*
+ * 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 groovy.lang.Singleton;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.apache.wicket.protocol.http.IWebApplicationFactory;
+import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.protocol.http.WicketFilter;
+
+/**
+ *
+ * A Wicket filter that supports Dagger injection.
+ *
+ * @author James Moger
+ *
+ */
+@Singleton
+public class DaggerWicketFilter extends WicketFilter {
+
+ @Inject
+ Provider<WebApplication> webApplicationProvider;
+
+ @Inject
+ public DaggerWicketFilter() {
+ super();
+ }
+
+ @Override
+ protected IWebApplicationFactory getApplicationFactory() {
+ return new IWebApplicationFactory() {
+ @Override
+ public WebApplication createApplication(WicketFilter filter) {
+ return webApplicationProvider.get();
+ }
+ };
+ }
+}
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;
diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java
index 46a3b067..ad13a042 100644
--- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java
+++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java
@@ -28,7 +28,6 @@ import org.apache.wicket.Session;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.protocol.http.WebApplication;
-import com.gitblit.GitBlit;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.manager.IFederationManager;
@@ -82,14 +81,50 @@ public class GitBlitWebApp extends WebApplication {
private final Map<String, CacheControl> cacheablePages = new HashMap<String, CacheControl>();
- private IStoredSettings settings;
+ private final IStoredSettings settings;
+
+ private final IRuntimeManager runtimeManager;
+
+ private final INotificationManager notificationManager;
+
+ private final IUserManager userManager;
+
+ private final ISessionManager sessionManager;
+
+ private final IRepositoryManager repositoryManager;
+
+ private final IProjectManager projectManager;
+
+ private final IGitblitManager gitblitManager;
+
+ private final IFederationManager federationManager;
+
+ public GitBlitWebApp(
+ IRuntimeManager runtimeManager,
+ INotificationManager notificationManager,
+ IUserManager userManager,
+ ISessionManager sessionManager,
+ IRepositoryManager repositoryManager,
+ IProjectManager projectManager,
+ IGitblitManager gitblitManager,
+ IFederationManager federationManager) {
+
+ super();
+ this.settings = runtimeManager.getSettings();
+ this.runtimeManager = runtimeManager;
+ this.notificationManager = notificationManager;
+ this.userManager = userManager;
+ this.sessionManager = sessionManager;
+ this.repositoryManager = repositoryManager;
+ this.projectManager = projectManager;
+ this.gitblitManager = gitblitManager;
+ this.federationManager = federationManager;
+ }
@Override
public void init() {
super.init();
- settings = runtime().getSettings();
-
// Setup page authorization mechanism
boolean useAuthentication = settings.getBoolean(Keys.web.authenticateViewPages, false)
|| settings.getBoolean(Keys.web.authenticateAdminPages, false);
@@ -205,7 +240,7 @@ public class GitBlitWebApp extends WebApplication {
* @return true if Gitblit is running in debug mode
*/
public boolean isDebugMode() {
- return runtime().isDebugMode();
+ return runtimeManager.isDebugMode();
}
/*
@@ -213,52 +248,52 @@ public class GitBlitWebApp extends WebApplication {
* step towards modularization across multiple commits.
*/
public Date getBootDate() {
- return runtime().getBootDate();
+ return runtimeManager.getBootDate();
}
public Date getLastActivityDate() {
- return repositories().getLastActivityDate();
+ return repositoryManager.getLastActivityDate();
}
public IRuntimeManager runtime() {
- return GitBlit.getManager(IRuntimeManager.class);
+ return runtimeManager;
}
public INotificationManager notifier() {
- return GitBlit.getManager(INotificationManager.class);
+ return notificationManager;
}
public IUserManager users() {
- return GitBlit.getManager(IUserManager.class);
+ return userManager;
}
public ISessionManager session() {
- return GitBlit.getManager(ISessionManager.class);
+ return sessionManager;
}
public IRepositoryManager repositories() {
- return GitBlit.getManager(IRepositoryManager.class);
+ return repositoryManager;
}
public IProjectManager projects() {
- return GitBlit.getManager(IProjectManager.class);
+ return projectManager;
}
public IFederationManager federation() {
- return GitBlit.getManager(IFederationManager.class);
+ return federationManager;
}
public IGitblitManager gitblit() {
- return GitBlit.getManager(IGitblitManager.class);
+ return gitblitManager;
}
public TimeZone getTimezone() {
- return runtime().getTimezone();
+ return runtimeManager.getTimezone();
}
@Override
public final String getConfigurationType() {
- if (isDebugMode()) {
+ if (runtimeManager.isDebugMode()) {
return Application.DEVELOPMENT;
}
return Application.DEPLOYMENT;
diff --git a/src/main/java/com/gitblit/wicket/GitblitWicketFilter.java b/src/main/java/com/gitblit/wicket/GitblitWicketFilter.java
index bc65d77d..87b0a08f 100644
--- a/src/main/java/com/gitblit/wicket/GitblitWicketFilter.java
+++ b/src/main/java/com/gitblit/wicket/GitblitWicketFilter.java
@@ -17,18 +17,17 @@ package com.gitblit.wicket;
import java.util.Date;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest;
-import org.apache.wicket.protocol.http.IWebApplicationFactory;
-import org.apache.wicket.protocol.http.WebApplication;
-import org.apache.wicket.protocol.http.WicketFilter;
import org.apache.wicket.util.string.Strings;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
-import com.gitblit.GitBlit;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
+import com.gitblit.dagger.DaggerWicketFilter;
import com.gitblit.manager.IProjectManager;
import com.gitblit.manager.IRepositoryManager;
import com.gitblit.manager.IRuntimeManager;
@@ -45,19 +44,28 @@ import com.gitblit.utils.StringUtils;
* @author James Moger
*
*/
-public class GitblitWicketFilter extends WicketFilter {
+@Singleton
+public class GitblitWicketFilter extends DaggerWicketFilter {
- public GitblitWicketFilter() {
- }
+ private final IStoredSettings settings;
- @Override
- protected IWebApplicationFactory getApplicationFactory() {
- return new IWebApplicationFactory() {
- @Override
- public WebApplication createApplication(WicketFilter filter) {
- return new GitBlitWebApp();
- }
- };
+ private final IRuntimeManager runtimeManager;
+
+ private final IRepositoryManager repositoryManager;
+
+ private final IProjectManager projectManager;
+
+ @Inject
+ public GitblitWicketFilter(
+ IRuntimeManager runtimeManager,
+ IRepositoryManager repositoryManager,
+ IProjectManager projectManager) {
+
+ super();
+ this.settings = runtimeManager.getSettings();
+ this.runtimeManager = runtimeManager;
+ this.repositoryManager = repositoryManager;
+ this.projectManager = projectManager;
}
/**
@@ -97,11 +105,6 @@ public class GitblitWicketFilter extends WicketFilter {
commitId = servletRequest.getParameter("h");
}
- IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);
- IStoredSettings settings = runtimeManager.getSettings();
- IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
- IProjectManager projectManager = GitBlit.getManager(IProjectManager.class);
-
repo = repo.replace("%2f", "/").replace("%2F", "/").replace(settings.getChar(Keys.web.forwardSlashCharacter, '/'), '/');
GitBlitWebApp app = (GitBlitWebApp) getWebApplication();
diff --git a/src/test/java/com/gitblit/tests/GitDaemonStopTest.java b/src/test/java/com/gitblit/tests/GitDaemonStopTest.java
deleted file mode 100644
index 6e940cbe..00000000
--- a/src/test/java/com/gitblit/tests/GitDaemonStopTest.java
+++ /dev/null
@@ -1,32 +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.tests;
-
-import org.junit.Test;
-
-import com.gitblit.git.GitDaemon;
-
-public class GitDaemonStopTest extends GitblitUnitTest {
-
- @Test
- public void testGitDaemonStop() throws Exception {
- GitDaemon daemon = new GitDaemon("localhost", GitDaemon.DEFAULT_PORT + 1, GitBlitSuite.REPOSITORIES);
- daemon.setTimeout(5);
- daemon.start();
- Thread.sleep(5000);
- daemon.stop();
- }
-}
diff --git a/src/test/java/com/gitblit/tests/LuceneExecutorTest.java b/src/test/java/com/gitblit/tests/LuceneExecutorTest.java
index 0f7e55ca..0e1aee1e 100644
--- a/src/test/java/com/gitblit/tests/LuceneExecutorTest.java
+++ b/src/test/java/com/gitblit/tests/LuceneExecutorTest.java
@@ -16,15 +16,15 @@
package com.gitblit.tests;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import org.eclipse.jgit.lib.Repository;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import com.gitblit.GitBlit;
+import com.gitblit.Keys;
import com.gitblit.LuceneExecutor;
import com.gitblit.models.RefModel;
import com.gitblit.models.RepositoryModel;
@@ -44,9 +44,10 @@ public class LuceneExecutorTest extends GitblitUnitTest {
LuceneExecutor lucene;
private LuceneExecutor newLuceneExecutor() {
- Map<String, Object> map = new HashMap<String, Object>();
- MemorySettings settings = new MemorySettings(map);
- return new LuceneExecutor(settings, GitBlitSuite.REPOSITORIES);
+ MemorySettings settings = new MemorySettings();
+ settings.put(Keys.git.repositoriesFolder, GitBlitSuite.REPOSITORIES);
+ GitBlit gitblit = new GitBlit(settings, GitBlitSuite.REPOSITORIES);
+ return new LuceneExecutor(settings, gitblit);
}
private RepositoryModel newRepositoryModel(Repository repository) {
diff --git a/src/test/java/com/gitblit/tests/mock/MemorySettings.java b/src/test/java/com/gitblit/tests/mock/MemorySettings.java
index 5b8e60a9..e3f971f0 100644
--- a/src/test/java/com/gitblit/tests/mock/MemorySettings.java
+++ b/src/test/java/com/gitblit/tests/mock/MemorySettings.java
@@ -16,6 +16,7 @@
*/
package com.gitblit.tests.mock;
+import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -25,6 +26,10 @@ public class MemorySettings extends IStoredSettings {
private Map<String, Object> backingMap;
+ public MemorySettings() {
+ this(new HashMap<String, Object>());
+ }
+
public MemorySettings(Map<String, Object> backingMap) {
super(MemorySettings.class);
this.backingMap = backingMap;
@@ -38,8 +43,8 @@ public class MemorySettings extends IStoredSettings {
return props;
}
- public void put(Object key, Object value) {
- backingMap.put(key.toString(), value);
+ public void put(String key, Object value) {
+ backingMap.put(key, value);
}
@Override