]> source.dussan.org Git - gitblit.git/commitdiff
Use Dagger to inject managers into all filters and servlets
authorJames Moger <james.moger@gitblit.com>
Tue, 19 Nov 2013 03:31:37 +0000 (22:31 -0500)
committerJames Moger <james.moger@gitblit.com>
Fri, 29 Nov 2013 16:05:46 +0000 (11:05 -0500)
Change-Id: I9bb2cc0cbfac9841b13bed15a474fefb24355cd4

41 files changed:
.classpath
.gitignore
build.moxie
build.xml
gitblit.iml
src/main/.gitignore [new file with mode: 0644]
src/main/java/com/gitblit/AccessRestrictionFilter.java
src/main/java/com/gitblit/AuthenticationFilter.java
src/main/java/com/gitblit/BranchGraphServlet.java
src/main/java/com/gitblit/DaggerModule.java [new file with mode: 0644]
src/main/java/com/gitblit/DownloadZipFilter.java
src/main/java/com/gitblit/DownloadZipServlet.java
src/main/java/com/gitblit/EnforceAuthenticationFilter.java
src/main/java/com/gitblit/FederationServlet.java
src/main/java/com/gitblit/GCExecutor.java
src/main/java/com/gitblit/GitBlit.java
src/main/java/com/gitblit/GitFilter.java
src/main/java/com/gitblit/LogoServlet.java
src/main/java/com/gitblit/LuceneExecutor.java
src/main/java/com/gitblit/MirrorExecutor.java
src/main/java/com/gitblit/PagesFilter.java
src/main/java/com/gitblit/PagesServlet.java
src/main/java/com/gitblit/RobotsTxtServlet.java
src/main/java/com/gitblit/RpcFilter.java
src/main/java/com/gitblit/RpcServlet.java
src/main/java/com/gitblit/SparkleShareInviteServlet.java
src/main/java/com/gitblit/SyndicationFilter.java
src/main/java/com/gitblit/SyndicationServlet.java
src/main/java/com/gitblit/dagger/DaggerContextListener.java [new file with mode: 0644]
src/main/java/com/gitblit/dagger/DaggerWicketFilter.java [new file with mode: 0644]
src/main/java/com/gitblit/git/GitDaemon.java
src/main/java/com/gitblit/git/GitServlet.java
src/main/java/com/gitblit/git/GitblitReceivePack.java
src/main/java/com/gitblit/git/GitblitReceivePackFactory.java
src/main/java/com/gitblit/git/GitblitUploadPackFactory.java
src/main/java/com/gitblit/git/RepositoryResolver.java
src/main/java/com/gitblit/wicket/GitBlitWebApp.java
src/main/java/com/gitblit/wicket/GitblitWicketFilter.java
src/test/java/com/gitblit/tests/GitDaemonStopTest.java [deleted file]
src/test/java/com/gitblit/tests/LuceneExecutorTest.java
src/test/java/com/gitblit/tests/mock/MemorySettings.java

index d1b04dad85715fbeb59c604bbfdabd9adf9cc147..9d6a6d2640c1fb41bb472c7371a8f6d7f5b9efd5 100644 (file)
@@ -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>
index f77b6ff240da09e0d434160433ef63d46e30863c..078de7e0474c5ba220cdf91113042f45405fc60d 100644 (file)
@@ -22,3 +22,5 @@
 /build-next.xml
 /*.ps1
 /*.sh
+/*.factorypath
+/src/main/dagger
index 7816c927801592bc209d26e0b9346d49857f9ecf..acc1afb11d92ef7c3fd0227eaa7d35334b512bb3 100644 (file)
@@ -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
index 860eca90ed55a8b71bde0fbebada4057b028d114..ab6699bc1dafd8805a16e263faeaf937fccbd3d1 100644 (file)
--- a/build.xml
+++ b/build.xml
                </mx:webxml>\r
 \r
                <!-- Gitblit jar -->\r
-               <mx:genjar destfile="${webinf}/lib/gitblit.jar" includeresources="false" excludeclasspathjars="true">\r
-                       <!-- Specify all web.xml servlets and filters -->\r
-                       <class name="com.gitblit.GitBlit" />\r
-                       <class name="com.gitblit.Keys" />\r
-                       <class name="com.gitblit.DownloadZipFilter" />\r
-                       <class name="com.gitblit.DownloadZipServlet" />\r
-                       <class name="com.gitblit.EnforceAuthenticationFilter" />\r
-                       <class name="com.gitblit.FederationServlet" />\r
-                       <class name="com.gitblit.GitFilter" />\r
-                       <class name="com.gitblit.git.GitServlet" />\r
-                       <class name="com.gitblit.LogoServlet" />\r
-                       <class name="com.gitblit.PagesFilter" />\r
-                       <class name="com.gitblit.PagesServlet" />\r
-                       <class name="com.gitblit.RobotsTxtServlet" />\r
-                       <class name="com.gitblit.RpcFilter" />\r
-                       <class name="com.gitblit.RpcServlet" />\r
-                       <class name="com.gitblit.SyndicationFilter" />\r
-                       <class name="com.gitblit.SyndicationServlet" />\r
-                       <class name="com.gitblit.SparkleShareInviteServlet" />\r
-                       <class name="com.gitblit.wicket.GitblitWicketFilter" />\r
-                       <class name="com.gitblit.wicket.GitBlitWebApp" />\r
-                       <!-- Manually include alternative User Services -->\r
-                       <class name="com.gitblit.LdapUserService" />\r
-                       <class name="com.gitblit.RedmineUserService" />\r
-                       <class name="com.gitblit.SalesforceUserService" />\r
-                       <class name="com.gitblit.WindowsUserService" />\r
-                       <class name="com.gitblit.PAMUserService" />\r
-               </mx:genjar>\r
+               <mx:jar destfile="${webinf}/lib/gitblit.jar" includeresources="false" />\r
 \r
                <!-- Build the WAR file -->\r
                <mx:zip basedir="${war.dir}" destfile="${project.targetDirectory}/${distribution.warfile}" compress="true" >\r
                </mx:webxml>\r
 \r
                <!-- Gitblit classes -->\r
-               <mx:genjar destfile="${webinf}/lib/gitblit.jar" includeresources="false" excludeclasspathjars="true">\r
-                       <!-- Specify all web.xml servlets and filters -->\r
-                       <class name="com.gitblit.GitBlit" />\r
-                       <class name="com.gitblit.Keys" />\r
-                       <class name="com.gitblit.DownloadZipFilter" />\r
-                       <class name="com.gitblit.DownloadZipServlet" />\r
-                       <class name="com.gitblit.EnforceAuthenticationFilter" />\r
-                       <class name="com.gitblit.FederationServlet" />\r
-                       <class name="com.gitblit.GitFilter" />\r
-                       <class name="com.gitblit.git.GitServlet" />\r
-                       <class name="com.gitblit.LogoServlet" />\r
-                       <class name="com.gitblit.PagesFilter" />\r
-                       <class name="com.gitblit.PagesServlet" />\r
-                       <class name="com.gitblit.RobotsTxtServlet" />\r
-                       <class name="com.gitblit.RpcFilter" />\r
-                       <class name="com.gitblit.RpcServlet" />\r
-                       <class name="com.gitblit.SyndicationFilter" />\r
-                       <class name="com.gitblit.SyndicationServlet" />\r
-                       <class name="com.gitblit.SparkleShareInviteServlet" />\r
-                       <class name="com.gitblit.wicket.GitblitWicketFilter" />\r
-                       <class name="com.gitblit.wicket.GitBlitWebApp" />\r
-                       <!-- Manually include alternative User Services -->\r
-                       <class name="com.gitblit.LdapUserService" />\r
-                       <class name="com.gitblit.RedmineUserService" />\r
-                       <class name="com.gitblit.SalesforceUserService" />\r
-                       <class name="com.gitblit.WindowsUserService" />\r
-                       <class name="com.gitblit.PAMUserService" />\r
-               </mx:genjar>\r
+               <mx:jar destfile="${webinf}/lib/gitblit.jar" includeresources="false" />\r
 \r
                <!-- Build Express Zip file -->\r
                <mx:zip basedir="${express.dir}" destfile="${project.targetDirectory}/${express.zipfile}">\r
index 67638df666e83b5de9ca12714c01dd02d0b2d677..74b1e85ae0ffaee6fcad550a45f08085572e0342 100644 (file)
@@ -6,10 +6,55 @@
     <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>
diff --git a/src/main/.gitignore b/src/main/.gitignore
new file mode 100644 (file)
index 0000000..01c48ab
--- /dev/null
@@ -0,0 +1 @@
+/dagger
index ac97ba2e5be7071402c7a0bc8d37606e6c73a798..5f0baed2f2aed0a7e30aa99b81891c78c2788c76 100644 (file)
@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletResponse;
 \r
 import com.gitblit.manager.IRepositoryManager;\r
 import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.ISessionManager;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.StringUtils;\r
@@ -47,6 +48,19 @@ import com.gitblit.utils.StringUtils;
  */\r
 public abstract class AccessRestrictionFilter extends AuthenticationFilter {\r
 \r
+       protected final IRuntimeManager runtimeManager;\r
+\r
+       protected final IRepositoryManager repositoryManager;\r
+\r
+       protected AccessRestrictionFilter(\r
+                       IRuntimeManager runtimeManager,\r
+                       ISessionManager sessionManager,\r
+                       IRepositoryManager repositoryManager) {\r
+               super(sessionManager);\r
+               this.runtimeManager = runtimeManager;\r
+               this.repositoryManager = repositoryManager;\r
+       }\r
+\r
        /**\r
         * Extract the repository name from the url.\r
         *\r
@@ -128,9 +142,6 @@ public abstract class AccessRestrictionFilter extends AuthenticationFilter {
                String fullUrl = getFullUrl(httpRequest);\r
                String repository = extractRepositoryName(fullUrl);\r
 \r
-               IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
-\r
                if (repositoryManager.isCollectingGarbage(repository)) {\r
                        logger.info(MessageFormat.format("ARF: Rejecting request for {0}, busy collecting garbage!", repository));\r
                        httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);\r
index 9aeb89f7e6f9706e4b6cf3ef48b03f1fa754fbd2..96d880f4a5e46a922b63b5cfe2ab2c711de7c761 100644 (file)
@@ -57,6 +57,12 @@ public abstract class AuthenticationFilter implements Filter {
 \r
        protected transient Logger logger = LoggerFactory.getLogger(getClass());\r
 \r
+       protected final ISessionManager sessionManager;\r
+\r
+       protected AuthenticationFilter(ISessionManager sessionManager) {\r
+               this.sessionManager = sessionManager;\r
+       }\r
+\r
        /**\r
         * doFilter does the actual work of preprocessing the request to ensure that\r
         * the user may proceed.\r
@@ -101,7 +107,6 @@ public abstract class AuthenticationFilter implements Filter {
         * @return user\r
         */\r
        protected UserModel getUser(HttpServletRequest httpRequest) {\r
-               ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);\r
                UserModel user = sessionManager.authenticate(httpRequest, requiresClientCertificate());\r
                return user;\r
        }\r
index 986560c6bb8a122e27b96e6fa26b177f4c0def1a..58a5778161d17ae51d8dadb2111525486183fa3a 100644 (file)
@@ -36,6 +36,8 @@ import java.util.Set;
 import java.util.TreeSet;\r
 \r
 import javax.imageio.ImageIO;\r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
 import javax.servlet.ServletException;\r
 import javax.servlet.http.HttpServlet;\r
 import javax.servlet.http.HttpServletRequest;\r
@@ -61,6 +63,7 @@ import com.gitblit.utils.StringUtils;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class BranchGraphServlet extends HttpServlet {\r
 \r
        private static final long serialVersionUID = 1L;\r
@@ -74,8 +77,18 @@ public class BranchGraphServlet extends HttpServlet {
 \r
        private final Stroke[] strokeCache;\r
 \r
-       public BranchGraphServlet() {\r
+       private final IStoredSettings settings;\r
+\r
+       private final IRepositoryManager repositoryManager;\r
+\r
+       @Inject\r
+       public BranchGraphServlet(\r
+                       IRuntimeManager runtimeManager,\r
+                       IRepositoryManager repositoryManager) {\r
+\r
                super();\r
+               this.settings = runtimeManager.getSettings();\r
+               this.repositoryManager = repositoryManager;\r
 \r
                strokeCache = new Stroke[4];\r
                for (int i = 1; i < strokeCache.length; i++)\r
@@ -104,7 +117,6 @@ public class BranchGraphServlet extends HttpServlet {
        protected long getLastModified(HttpServletRequest req) {\r
                String repository = req.getParameter("r");\r
                String objectId = req.getParameter("h");\r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
                Repository r = null;\r
                try {\r
                        r = repositoryManager.getRepository(repository);\r
@@ -131,9 +143,6 @@ public class BranchGraphServlet extends HttpServlet {
                        String objectId = request.getParameter("h");\r
                        String length = request.getParameter("l");\r
 \r
-                       IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
-                       IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
-\r
                        r = repositoryManager.getRepository(repository);\r
 \r
                        rw = new PlotWalk(r);\r
diff --git a/src/main/java/com/gitblit/DaggerModule.java b/src/main/java/com/gitblit/DaggerModule.java
new file mode 100644 (file)
index 0000000..7ee8ecd
--- /dev/null
@@ -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
index e52d9d790ca3a0d5dc778982751cb4f7d362cebd..914d89e5561c12b4e159927535a98c238025f57a 100644 (file)
  */\r
 package com.gitblit;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
+\r
 import com.gitblit.Constants.AccessRestrictionType;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.ISessionManager;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 \r
@@ -27,9 +33,16 @@ import com.gitblit.models.UserModel;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class DownloadZipFilter extends AccessRestrictionFilter {\r
 \r
-       public DownloadZipFilter() {\r
+       @Inject\r
+       public DownloadZipFilter(\r
+                       IRuntimeManager runtimeManager,\r
+                       ISessionManager sessionManager,\r
+                       IRepositoryManager repositoryManager) {\r
+\r
+               super(runtimeManager, sessionManager, repositoryManager);\r
        }\r
 \r
        /**\r
index 82846dac0dda24c44e7c5ea6e3b9afc472aaa73d..d629dcfc18597f159299273d1687b984114d51e6 100644 (file)
@@ -20,6 +20,8 @@ import java.text.MessageFormat;
 import java.text.ParseException;\r
 import java.util.Date;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
 import javax.servlet.ServletException;\r
 import javax.servlet.http.HttpServlet;\r
 import javax.servlet.http.HttpServletResponse;\r
@@ -43,12 +45,17 @@ import com.gitblit.utils.StringUtils;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class DownloadZipServlet extends HttpServlet {\r
 \r
        private static final long serialVersionUID = 1L;\r
 \r
        private transient Logger logger = LoggerFactory.getLogger(DownloadZipServlet.class);\r
 \r
+       private final IStoredSettings settings;\r
+\r
+       private final IRepositoryManager repositoryManager;\r
+\r
        public static enum Format {\r
                zip(".zip"), tar(".tar"), gz(".tar.gz"), xz(".tar.xz"), bzip2(".tar.bzip2");\r
 \r
@@ -68,8 +75,14 @@ public class DownloadZipServlet extends HttpServlet {
                }\r
        }\r
 \r
-       public DownloadZipServlet() {\r
+       @Inject\r
+       public DownloadZipServlet(\r
+                       IRuntimeManager runtimeManager,\r
+                       IRepositoryManager repositoryManager) {\r
+\r
                super();\r
+               this.settings = runtimeManager.getSettings();\r
+               this.repositoryManager = repositoryManager;\r
        }\r
 \r
        /**\r
@@ -103,7 +116,6 @@ public class DownloadZipServlet extends HttpServlet {
        private void processRequest(javax.servlet.http.HttpServletRequest request,\r
                        javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,\r
                        java.io.IOException {\r
-               IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
                if (!settings.getBoolean(Keys.web.allowZipDownloads, true)) {\r
                        logger.warn("Zip downloads are disabled");\r
                        response.sendError(HttpServletResponse.SC_FORBIDDEN);\r
@@ -133,7 +145,6 @@ public class DownloadZipServlet extends HttpServlet {
                                name += "-" + objectId;\r
                        }\r
 \r
-                       IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
                        Repository r = repositoryManager.getRepository(repository);\r
                        if (r == null) {\r
                                if (repositoryManager.isCollectingGarbage(repository)) {\r
index 12b0759539c1bc783e1d84e7af0c101ade3fde5f..48fc0057b29bae28596d60068eacacb6a26d5c07 100644 (file)
@@ -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);
 
index 0d83b4f445078bc54b74d556b8fc6032a084a595..31e3c0e1f9763942cd753c8186b3eb5d97df9e0a 100644 (file)
@@ -25,6 +25,8 @@ import java.util.List;
 import java.util.Map;\r
 import java.util.Set;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
 import javax.servlet.http.HttpServletResponse;\r
 \r
 import com.gitblit.Constants.FederationRequest;\r
@@ -48,12 +50,31 @@ import com.gitblit.utils.TimeUtils;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class FederationServlet extends JsonServlet {\r
 \r
        private static final long serialVersionUID = 1L;\r
 \r
-       public FederationServlet() {\r
+       private final IStoredSettings settings;\r
+\r
+       private final IUserManager userManager;\r
+\r
+       private final IRepositoryManager repositoryManager;\r
+\r
+       private final IFederationManager federationManager;\r
+\r
+       @Inject\r
+       public FederationServlet(\r
+                       IRuntimeManager runtimeManager,\r
+                       IUserManager userManager,\r
+                       IRepositoryManager repositoryManager,\r
+                       IFederationManager federationManager) {\r
+\r
                super();\r
+               this.settings = runtimeManager.getSettings();\r
+               this.userManager = userManager;\r
+               this.repositoryManager = repositoryManager;\r
+               this.federationManager = federationManager;\r
        }\r
 \r
        /**\r
@@ -70,11 +91,6 @@ public class FederationServlet extends JsonServlet {
                        javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,\r
                        java.io.IOException {\r
 \r
-               IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
-               IUserManager userManager = GitBlit.getManager(IUserManager.class);\r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
-               IFederationManager federationManager = GitBlit.getManager(IFederationManager.class);\r
-\r
                FederationRequest reqType = FederationRequest.fromName(request.getParameter("req"));\r
                logger.info(MessageFormat.format("Federation {0} request from {1}", reqType,\r
                                request.getRemoteAddr()));\r
index 837741f2095bb1914af0b4a3b02f61196c805529..3ab989565a38f2bb751d7403a5f75106aa128d03 100644 (file)
@@ -54,14 +54,20 @@ public class GCExecutor implements Runnable {
 \r
        private final IStoredSettings settings;\r
 \r
+       private final IRepositoryManager repositoryManager;\r
+\r
        private AtomicBoolean running = new AtomicBoolean(false);\r
 \r
        private AtomicBoolean forceClose = new AtomicBoolean(false);\r
 \r
        private final Map<String, GCStatus> gcCache = new ConcurrentHashMap<String, GCStatus>();\r
 \r
-       public GCExecutor(IStoredSettings settings) {\r
+       public GCExecutor(\r
+                       IStoredSettings settings,\r
+                       IRepositoryManager repositoryManager) {\r
+\r
                this.settings = settings;\r
+               this.repositoryManager = repositoryManager;\r
        }\r
 \r
        /**\r
@@ -132,8 +138,6 @@ public class GCExecutor implements Runnable {
                running.set(true);\r
                Date now = new Date();\r
 \r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
-\r
                for (String repositoryName : repositoryManager.getRepositoryList()) {\r
                        if (forceClose.get()) {\r
                                break;\r
index 31dedf1355e8963b83dcb2569d6aa006722a08a5..8be50fb6aae93946b38e0ea79d2d70061d77cba7 100644 (file)
@@ -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.
index a06c7e52ce94f827cdaa8cd4a1cb032e7bf64513..ba8443d0d40da15be076d1d60cbd132b463719d8 100644 (file)
@@ -17,10 +17,14 @@ package com.gitblit;
 \r
 import java.text.MessageFormat;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
+\r
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.Constants.AuthorizationControl;\r
 import com.gitblit.manager.IRepositoryManager;\r
 import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.ISessionManager;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.StringUtils;\r
@@ -33,6 +37,7 @@ import com.gitblit.utils.StringUtils;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class GitFilter extends AccessRestrictionFilter {\r
 \r
        protected static final String gitReceivePack = "/git-receive-pack";\r
@@ -42,7 +47,16 @@ public class GitFilter extends AccessRestrictionFilter {
        protected static final String[] suffixes = { gitReceivePack, gitUploadPack, "/info/refs", "/HEAD",\r
                        "/objects" };\r
 \r
-       public GitFilter() {\r
+       private final IStoredSettings settings;\r
+\r
+       @Inject\r
+       public GitFilter(\r
+                       IRuntimeManager runtimeManager,\r
+                       ISessionManager sessionManager,\r
+                       IRepositoryManager repositoryManager) {\r
+\r
+               super(runtimeManager, sessionManager, repositoryManager);\r
+               this.settings = runtimeManager.getSettings();\r
        }\r
 \r
        /**\r
@@ -105,7 +119,6 @@ public class GitFilter extends AccessRestrictionFilter {
         */\r
        @Override\r
        protected boolean isCreationAllowed() {\r
-               IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
                return settings.getBoolean(Keys.git.allowCreateOnPush, true);\r
        }\r
 \r
@@ -125,7 +138,6 @@ public class GitFilter extends AccessRestrictionFilter {
 \r
        @Override\r
        protected boolean requiresClientCertificate() {\r
-               IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
                return settings.getBoolean(Keys.git.requiresClientCertificate, false);\r
        }\r
 \r
@@ -159,7 +171,6 @@ public class GitFilter extends AccessRestrictionFilter {
         */\r
        @Override\r
        protected boolean canAccess(RepositoryModel repository, UserModel user, String action) {\r
-               IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
                if (!settings.getBoolean(Keys.git.enableGitServlet, true)) {\r
                        // Git Servlet disabled\r
                        return false;\r
@@ -231,14 +242,12 @@ public class GitFilter extends AccessRestrictionFilter {
                                        model.accessRestriction = AccessRestrictionType.VIEW;\r
                                } else {\r
                                        // common repository, user default server settings\r
-                                       IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
                                        model.authorizationControl = AuthorizationControl.fromName(settings.getString(Keys.git.defaultAuthorizationControl, ""));\r
                                        model.accessRestriction = AccessRestrictionType.fromName(settings.getString(Keys.git.defaultAccessRestriction, "PUSH"));\r
                                }\r
 \r
                                // create the repository\r
                                try {\r
-                                       IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
                                        repositoryManager.updateRepositoryModel(model.name, model, true);\r
                                        logger.info(MessageFormat.format("{0} created {1} ON-PUSH", user.username, model.name));\r
                                        return repositoryManager.getRepositoryModel(model.name);\r
index 4222f8ff327356e07189d9eb8e89e884d2fce4ea..17b05cfd3bd4ae405bdfa716e5f820a27c3ac39b 100644 (file)
@@ -21,6 +21,8 @@ import java.io.IOException;
 import java.io.InputStream;\r
 import java.io.OutputStream;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
 import javax.servlet.ServletContext;\r
 import javax.servlet.ServletException;\r
 import javax.servlet.http.HttpServlet;\r
@@ -35,19 +37,23 @@ import com.gitblit.manager.IRuntimeManager;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class LogoServlet extends HttpServlet {\r
 \r
        private static final long serialVersionUID = 1L;\r
 \r
        private static final long lastModified = System.currentTimeMillis();\r
 \r
-       public LogoServlet() {\r
+       private final IRuntimeManager runtimeManager;\r
+\r
+       @Inject\r
+       public LogoServlet(IRuntimeManager runtimeManager) {\r
                super();\r
+               this.runtimeManager = runtimeManager;\r
        }\r
 \r
        @Override\r
        protected long getLastModified(HttpServletRequest req) {\r
-               IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
                File file = runtimeManager.getFileOrFolder(Keys.web.headerLogo, "${baseFolder}/logo.png");\r
                if (file.exists()) {\r
                        return Math.max(lastModified, file.lastModified());\r
@@ -62,7 +68,6 @@ public class LogoServlet extends HttpServlet {
                InputStream is = null;\r
                try {\r
                        String contentType = null;\r
-                       IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
                        File file = runtimeManager.getFileOrFolder(Keys.web.headerLogo, "${baseFolder}/logo.png");\r
                        if (file.exists()) {\r
                                // custom logo\r
index 19395b3bb82675590a03fa043f361a553772cab1..b7b71c5ec8d9f93d056724ee5285211b10326ab3 100644 (file)
@@ -128,6 +128,7 @@ public class LuceneExecutor implements Runnable {
        private final Logger logger = LoggerFactory.getLogger(LuceneExecutor.class);\r
 \r
        private final IStoredSettings storedSettings;\r
+       private final IRepositoryManager repositoryManager;\r
        private final File repositoriesFolder;\r
 \r
        private final Map<String, IndexSearcher> searchers = new ConcurrentHashMap<String, IndexSearcher>();\r
@@ -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";\r
        private Set<String> excludedExtensions;\r
 \r
-       public LuceneExecutor(IStoredSettings settings, File repositoriesFolder) {\r
+       public LuceneExecutor(\r
+                       IStoredSettings settings,\r
+                       IRepositoryManager repositoryManager) {\r
+\r
                this.storedSettings = settings;\r
-               this.repositoriesFolder = repositoriesFolder;\r
+               this.repositoryManager = repositoryManager;\r
+               this.repositoriesFolder = repositoryManager.getRepositoriesFolder();\r
                String exts = luceneIgnoreExtensions;\r
                if (settings != null) {\r
                        exts = settings.getString(Keys.web.luceneIgnoreExtensions, exts);\r
@@ -161,7 +166,6 @@ public class LuceneExecutor implements Runnable {
                String exts = storedSettings.getString(Keys.web.luceneIgnoreExtensions, luceneIgnoreExtensions);\r
                excludedExtensions = new TreeSet<String>(StringUtils.getStringsFromValue(exts));\r
 \r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
                if (repositoryManager.isCollectingGarbage()) {\r
                        // busy collecting garbage, try again later\r
                        return;\r
index a96c955f1bc1c93ce4c24726fa82c0066c50ab55..6c951b945150cb7e30771fa944b2f1d91676a5c7 100644 (file)
@@ -52,14 +52,20 @@ public class MirrorExecutor implements Runnable {
 \r
        private final IStoredSettings settings;\r
 \r
+       private final IRepositoryManager repositoryManager;\r
+\r
        private AtomicBoolean running = new AtomicBoolean(false);\r
 \r
        private AtomicBoolean forceClose = new AtomicBoolean(false);\r
 \r
        private final UserModel gitblitUser;\r
 \r
-       public MirrorExecutor(IStoredSettings settings) {\r
+       public MirrorExecutor(\r
+                       IStoredSettings settings,\r
+                       IRepositoryManager repositoryManager) {\r
+\r
                this.settings = settings;\r
+               this.repositoryManager = repositoryManager;\r
                this.gitblitUser = new UserModel("gitblit");\r
                this.gitblitUser.displayName = "Gitblit";\r
        }\r
@@ -84,8 +90,6 @@ public class MirrorExecutor implements Runnable {
 \r
                running.set(true);\r
 \r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
-\r
                for (String repositoryName : repositoryManager.getRepositoryList()) {\r
                        if (forceClose.get()) {\r
                                break;\r
index 4c9568dcb0de3ec2ce514026f1c018b958fe3d19..a322af2f93e97c9cfa369983579344d84d57271e 100644 (file)
  */\r
 package com.gitblit;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
+\r
 import org.eclipse.jgit.lib.Repository;\r
 \r
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.ISessionManager;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 \r
@@ -29,9 +34,15 @@ import com.gitblit.models.UserModel;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class PagesFilter extends AccessRestrictionFilter {\r
 \r
-       public PagesFilter() {\r
+       @Inject\r
+       public PagesFilter(IRuntimeManager runtimeManager,\r
+                       ISessionManager sessionManager,\r
+                       IRepositoryManager repositoryManager) {\r
+\r
+               super(runtimeManager, sessionManager, repositoryManager);\r
        }\r
 \r
        /**\r
@@ -53,7 +64,6 @@ public class PagesFilter extends AccessRestrictionFilter {
                        } else {\r
                                repository = url.substring(0, slash);\r
                        }\r
-                       IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
                        r = repositoryManager.getRepository(repository, false);\r
                        if (r == null) {\r
                                // try again\r
index 5569ab3949c405c1f35fde9805c7100fdc525f94..ba919e0710800dfd0fbcf3d65b91dd6bc6cf464d 100644 (file)
@@ -23,6 +23,8 @@ import java.util.List;
 import java.util.Set;\r
 import java.util.TreeSet;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
 import javax.servlet.ServletContext;\r
 import javax.servlet.ServletException;\r
 import javax.servlet.http.HttpServlet;\r
@@ -53,14 +55,25 @@ import com.gitblit.wicket.MarkupProcessor.MarkupDocument;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class PagesServlet extends HttpServlet {\r
 \r
        private static final long serialVersionUID = 1L;\r
 \r
        private transient Logger logger = LoggerFactory.getLogger(PagesServlet.class);\r
 \r
-       public PagesServlet() {\r
+       private final IStoredSettings settings;\r
+\r
+       private final IRepositoryManager repositoryManager;\r
+\r
+       @Inject\r
+       public PagesServlet(\r
+                       IRuntimeManager runtimeManager,\r
+                       IRepositoryManager repositoryManager) {\r
+\r
                super();\r
+               this.settings = runtimeManager.getSettings();\r
+               this.repositoryManager = repositoryManager;\r
        }\r
 \r
        /**\r
@@ -101,9 +114,6 @@ public class PagesServlet extends HttpServlet {
                        path = path.substring(1);\r
                }\r
 \r
-               IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
-\r
                // determine repository and resource from url\r
                String repository = "";\r
                String resource = "";\r
index 6a7c02d30eb1729333f5bf4a3feae22493b8e140..c07aa1d0d5e7c6781219e90295ce2c84d1fd7f02 100644 (file)
@@ -18,6 +18,8 @@ package com.gitblit;
 import java.io.File;\r
 import java.io.IOException;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
 import javax.servlet.ServletException;\r
 import javax.servlet.http.HttpServlet;\r
 import javax.servlet.http.HttpServletRequest;\r
@@ -32,12 +34,17 @@ import com.gitblit.utils.FileUtils;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class RobotsTxtServlet extends HttpServlet {\r
 \r
        private static final long serialVersionUID = 1L;\r
 \r
-       public RobotsTxtServlet() {\r
+       private final IRuntimeManager runtimeManager;\r
+\r
+       @Inject\r
+       public RobotsTxtServlet(IRuntimeManager runtimeManager) {\r
                super();\r
+               this.runtimeManager = runtimeManager;\r
        }\r
 \r
        @Override\r
@@ -55,7 +62,6 @@ public class RobotsTxtServlet extends HttpServlet {
        protected void processRequest(javax.servlet.http.HttpServletRequest request,\r
                        javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,\r
                        java.io.IOException {\r
-               IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
                File file = runtimeManager.getFileOrFolder(Keys.web.robots.txt, null);\r
                String content = "";\r
                if (file.exists()) {\r
index b1384ad39d9568bfe2f94c9d37815e636a0d60cf..c4b6451cb9115f8a26d7c9267ced68952365f6eb 100644 (file)
@@ -18,6 +18,8 @@ package com.gitblit;
 import java.io.IOException;\r
 import java.text.MessageFormat;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
 import javax.servlet.FilterChain;\r
 import javax.servlet.ServletException;\r
 import javax.servlet.ServletRequest;\r
@@ -27,6 +29,7 @@ import javax.servlet.http.HttpServletResponse;
 \r
 import com.gitblit.Constants.RpcRequest;\r
 import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.ISessionManager;\r
 import com.gitblit.models.UserModel;\r
 \r
 /**\r
@@ -42,9 +45,21 @@ import com.gitblit.models.UserModel;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class RpcFilter extends AuthenticationFilter {\r
 \r
-       public RpcFilter() {\r
+       private final IStoredSettings settings;\r
+\r
+       private final IRuntimeManager runtimeManager;\r
+\r
+       @Inject\r
+       public RpcFilter(\r
+                       IRuntimeManager runtimeManager,\r
+                       ISessionManager sessionManager) {\r
+\r
+               super(sessionManager);\r
+               this.settings = runtimeManager.getSettings();\r
+               this.runtimeManager = runtimeManager;\r
        }\r
 \r
        /**\r
@@ -68,9 +83,6 @@ public class RpcFilter extends AuthenticationFilter {
                        return;\r
                }\r
 \r
-               IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
-               IStoredSettings settings = runtimeManager.getSettings();\r
-\r
                boolean adminRequest = requestType.exceeds(RpcRequest.LIST_SETTINGS);\r
 \r
                // conditionally reject all rpc requests\r
index a8fa6f8393c018a22e4537b1aced789676248d08..a3629b9c7a946ea8509dbacf167514501e733757 100644 (file)
@@ -23,6 +23,8 @@ import java.util.HashMap;
 import java.util.List;\r
 import java.util.Map;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
 import javax.servlet.ServletException;\r
 import javax.servlet.http.HttpServletRequest;\r
 import javax.servlet.http.HttpServletResponse;\r
@@ -53,14 +55,41 @@ import com.gitblit.utils.StringUtils;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class RpcServlet extends JsonServlet {\r
 \r
        private static final long serialVersionUID = 1L;\r
 \r
        public static final int PROTOCOL_VERSION = 6;\r
 \r
-       public RpcServlet() {\r
+       private final IStoredSettings settings;\r
+\r
+       private final IRuntimeManager runtimeManager;\r
+\r
+       private final IUserManager userManager;\r
+\r
+       private final IRepositoryManager repositoryManager;\r
+\r
+       private final IFederationManager federationManager;\r
+\r
+       private final IGitblitManager gitblitManager;\r
+\r
+       @Inject\r
+       public RpcServlet(\r
+                       IRuntimeManager runtimeManager,\r
+                       IUserManager userManager,\r
+                       IRepositoryManager repositoryManager,\r
+                       IFederationManager federationManager,\r
+                       IGitblitManager gitblitManager) {\r
+\r
                super();\r
+\r
+               this.settings = runtimeManager.getSettings();\r
+               this.runtimeManager = runtimeManager;\r
+               this.userManager = userManager;\r
+               this.repositoryManager = repositoryManager;\r
+               this.federationManager = federationManager;\r
+               this.gitblitManager = gitblitManager;\r
        }\r
 \r
        /**\r
@@ -79,13 +108,6 @@ public class RpcServlet extends JsonServlet {
                logger.info(MessageFormat.format("Rpc {0} request from {1}", reqType,\r
                                request.getRemoteAddr()));\r
 \r
-               IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
-               IUserManager userManager = GitBlit.getManager(IUserManager.class);\r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
-               IGitblitManager gitblitManager = GitBlit.getManager(IGitblitManager.class);\r
-               IFederationManager federationManager = GitBlit.getManager(IFederationManager.class);\r
-               IStoredSettings settings = runtimeManager.getSettings();\r
-\r
                UserModel user = (UserModel) request.getUserPrincipal();\r
 \r
                boolean allowManagement = user != null && user.canAdmin()\r
index 9f6618b229268735f3e16eb902e907de15c7524f..1cd997d313993e25cc4b41a69187982691b072ed 100644 (file)
@@ -18,6 +18,8 @@ package com.gitblit;
 import java.io.IOException;\r
 import java.text.MessageFormat;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
 import javax.servlet.ServletException;\r
 import javax.servlet.http.HttpServlet;\r
 import javax.servlet.http.HttpServletRequest;\r
@@ -37,12 +39,31 @@ import com.gitblit.utils.StringUtils;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class SparkleShareInviteServlet extends HttpServlet {\r
 \r
        private static final long serialVersionUID = 1L;\r
 \r
-       public SparkleShareInviteServlet() {\r
+       private final IStoredSettings settings;\r
+\r
+       private final IUserManager userManager;\r
+\r
+       private final ISessionManager sessionManager;\r
+\r
+       private final IRepositoryManager repositoryManager;\r
+\r
+       @Inject\r
+       public SparkleShareInviteServlet(\r
+                       IRuntimeManager runtimeManager,\r
+                       IUserManager userManager,\r
+                       ISessionManager sessionManager,\r
+                       IRepositoryManager repositoryManager) {\r
+\r
                super();\r
+               this.settings = runtimeManager.getSettings();\r
+               this.userManager = userManager;\r
+               this.sessionManager = sessionManager;\r
+               this.repositoryManager = repositoryManager;\r
        }\r
 \r
        @Override\r
@@ -61,11 +82,6 @@ public class SparkleShareInviteServlet extends HttpServlet {
                        javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,\r
                        java.io.IOException {\r
 \r
-               IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
-               IUserManager userManager = GitBlit.getManager(IUserManager.class);\r
-               ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);\r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
-\r
                // extract repo name from request\r
                String repoUrl = request.getPathInfo().substring(1);\r
 \r
index ad908fa8853e091515eaf6c08aa7de20a55d8395..10b88102dd3c2f38de9441bd77b2907165f47107 100644 (file)
@@ -18,6 +18,8 @@ package com.gitblit;
 import java.io.IOException;\r
 import java.text.MessageFormat;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
 import javax.servlet.FilterChain;\r
 import javax.servlet.ServletException;\r
 import javax.servlet.ServletRequest;\r
@@ -29,6 +31,7 @@ import com.gitblit.Constants.AccessRestrictionType;
 import com.gitblit.manager.IProjectManager;\r
 import com.gitblit.manager.IRepositoryManager;\r
 import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.ISessionManager;\r
 import com.gitblit.models.ProjectModel;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
@@ -41,9 +44,24 @@ import com.gitblit.models.UserModel;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class SyndicationFilter extends AuthenticationFilter {\r
 \r
-       public SyndicationFilter() {\r
+       private final IRuntimeManager runtimeManager;\r
+       private final IRepositoryManager repositoryManager;\r
+       private final IProjectManager projectManager;\r
+\r
+       @Inject\r
+       public SyndicationFilter(\r
+                       IRuntimeManager runtimeManager,\r
+                       ISessionManager sessionManager,\r
+                       IRepositoryManager repositoryManager,\r
+                       IProjectManager projectManager) {\r
+\r
+               super(sessionManager);\r
+               this.runtimeManager = runtimeManager;\r
+               this.repositoryManager = repositoryManager;\r
+               this.projectManager = projectManager;\r
        }\r
 \r
        /**\r
@@ -76,10 +94,6 @@ public class SyndicationFilter extends AuthenticationFilter {
                String fullUrl = getFullUrl(httpRequest);\r
                String name = extractRequestedName(fullUrl);\r
 \r
-               IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
-               IProjectManager projectManager = GitBlit.getManager(IProjectManager.class);\r
-\r
                ProjectModel project = projectManager.getProjectModel(name);\r
                RepositoryModel model = null;\r
 \r
index 11089ee1f5619c2b473774ed3eec4e501c7171d8..397545fafbaac57ffd8248f4d9ac30432ab7550b 100644 (file)
@@ -22,6 +22,8 @@ import java.util.Collections;
 import java.util.List;\r
 import java.util.Map;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
 import javax.servlet.http.HttpServlet;\r
 \r
 import org.eclipse.jgit.lib.ObjectId;\r
@@ -53,13 +55,29 @@ import com.gitblit.utils.SyndicationUtils;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class SyndicationServlet extends HttpServlet {\r
 \r
        private static final long serialVersionUID = 1L;\r
 \r
        private transient Logger logger = LoggerFactory.getLogger(SyndicationServlet.class);\r
 \r
-       public SyndicationServlet() {\r
+       private final IStoredSettings settings;\r
+\r
+       private final IRepositoryManager repositoryManager;\r
+\r
+       private final IProjectManager projectManager;\r
+\r
+       @Inject\r
+       public SyndicationServlet(\r
+                       IRuntimeManager runtimeManager,\r
+                       IRepositoryManager repositoryManager,\r
+                       IProjectManager projectManager) {\r
+\r
+               super();\r
+               this.settings = runtimeManager.getSettings();\r
+               this.repositoryManager = repositoryManager;\r
+               this.projectManager = projectManager;\r
        }\r
 \r
        /**\r
@@ -133,10 +151,6 @@ public class SyndicationServlet extends HttpServlet {
                        javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,\r
                        java.io.IOException {\r
 \r
-               IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
-               IProjectManager projectManager = GitBlit.getManager(IProjectManager.class);\r
-\r
                String servletUrl = request.getContextPath() + request.getServletPath();\r
                String url = request.getRequestURI().substring(servletUrl.length());\r
                if (url.charAt(0) == '/' && url.length() > 1) {\r
diff --git a/src/main/java/com/gitblit/dagger/DaggerContextListener.java b/src/main/java/com/gitblit/dagger/DaggerContextListener.java
new file mode 100644 (file)
index 0000000..3c26886
--- /dev/null
@@ -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 (file)
index 0000000..b778f1f
--- /dev/null
@@ -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();
+                       }
+               };
+       }
+}
index bb578efccf55e45fa99285f391b7c70a231adae4..40cbe7040731f77bc0a537639728c6a1a385ce7c 100644 (file)
@@ -43,7 +43,6 @@
  */\r
 package com.gitblit.git;\r
 \r
-import java.io.File;\r
 import java.io.IOException;\r
 import java.io.InputStream;\r
 import java.io.InterruptedIOException;\r
@@ -68,6 +67,12 @@ import org.eclipse.jgit.transport.resolver.UploadPackFactory;
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
+import com.gitblit.IStoredSettings;\r
+import com.gitblit.Keys;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.ISessionManager;\r
+import com.gitblit.manager.IUserManager;\r
 import com.gitblit.utils.StringUtils;\r
 \r
 /**\r
@@ -106,45 +111,28 @@ public class GitDaemon {
 \r
        private ReceivePackFactory<GitDaemonClient> receivePackFactory;\r
 \r
-       /** Configure a daemon to listen on any available network port. */\r
-       public GitDaemon() {\r
-               this(null);\r
-       }\r
+       public GitDaemon(\r
+                       IRuntimeManager runtimeManager,\r
+                       IUserManager userManager,\r
+                       ISessionManager sessionManager,\r
+                       IRepositoryManager repositoryManager) {\r
 \r
-       /**\r
-        * Construct the Gitblit Git daemon.\r
-        *\r
-        * @param bindInterface\r
-        *            the ip address of the interface to bind\r
-        * @param port\r
-        *            the port to serve on\r
-        * @param folder\r
-        *            the folder to serve from\r
-        */\r
-       public GitDaemon(String bindInterface, int port, File folder) {\r
-               this(StringUtils.isEmpty(bindInterface) ? new InetSocketAddress(port)\r
-                               : new InetSocketAddress(bindInterface, port));\r
+               IStoredSettings settings = runtimeManager.getSettings();\r
+               int port = settings.getInteger(Keys.git.daemonPort, 0);\r
+               String bindInterface = settings.getString(Keys.git.daemonBindInterface, "localhost");\r
 \r
-               // set the repository resolver and pack factories\r
-               repositoryResolver = new RepositoryResolver<GitDaemonClient>(folder);\r
-       }\r
+               if (StringUtils.isEmpty(bindInterface)) {\r
+                       myAddress = new InetSocketAddress(port);\r
+               } else {\r
+                       myAddress = new InetSocketAddress(bindInterface, port);\r
+               }\r
 \r
-       /**\r
-        * Configure a new daemon for the specified network address.\r
-        *\r
-        * @param addr\r
-        *            address to listen for connections on. If null, any available\r
-        *            port will be chosen on all network interfaces.\r
-        */\r
-       public GitDaemon(final InetSocketAddress addr) {\r
-               myAddress = addr;\r
-               processors = new ThreadGroup("Git-Daemon");\r
+               repositoryResolver = new RepositoryResolver<GitDaemonClient>(sessionManager, repositoryManager);\r
+               uploadPackFactory = new GitblitUploadPackFactory<GitDaemonClient>(sessionManager);\r
+               receivePackFactory = new GitblitReceivePackFactory<GitDaemonClient>(runtimeManager, userManager, repositoryManager);\r
 \r
                run = new AtomicBoolean(false);\r
-               repositoryResolver = null;\r
-               uploadPackFactory = new GitblitUploadPackFactory<GitDaemonClient>();\r
-               receivePackFactory = new GitblitReceivePackFactory<GitDaemonClient>();\r
-\r
+               processors = new ThreadGroup("Git-Daemon");\r
                services = new GitDaemonService[] { new GitDaemonService("upload-pack", "uploadpack") {\r
                                        {\r
                                                setEnabled(true);\r
index 23ea3434e752980bb15bc78aeff3b84e580f06bd..e4719d9bf59efab4e826b951fad977fc202bea77 100644 (file)
  */\r
 package com.gitblit.git;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
 import javax.servlet.ServletConfig;\r
 import javax.servlet.ServletException;\r
 import javax.servlet.http.HttpServletRequest;\r
 \r
-import com.gitblit.GitBlit;\r
 import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.ISessionManager;\r
+import com.gitblit.manager.IUserManager;\r
 \r
 /**\r
  * The GitServlet provides http/https access to Git repositories.\r
@@ -29,19 +33,37 @@ import com.gitblit.manager.IRepositoryManager;
  * @author James Moger\r
  *\r
  */\r
+@Singleton\r
 public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {\r
 \r
        private static final long serialVersionUID = 1L;\r
 \r
-       public GitServlet() {\r
+       private final IRuntimeManager runtimeManager;\r
+\r
+       private final IUserManager userManager;\r
+\r
+       private final ISessionManager sessionManager;\r
+\r
+       private final IRepositoryManager repositoryManager;\r
+\r
+       @Inject\r
+       public GitServlet(\r
+                       IRuntimeManager runtimeManager,\r
+                       IUserManager userManager,\r
+                       ISessionManager sessionManager,\r
+                       IRepositoryManager repositoryManager) {\r
+               super();\r
+               this.runtimeManager = runtimeManager;\r
+               this.userManager = userManager;\r
+               this.sessionManager = sessionManager;\r
+               this.repositoryManager = repositoryManager;\r
        }\r
 \r
        @Override\r
        public void init(ServletConfig config) throws ServletException {\r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
-               setRepositoryResolver(new RepositoryResolver<HttpServletRequest>(repositoryManager.getRepositoriesFolder()));\r
-               setUploadPackFactory(new GitblitUploadPackFactory<HttpServletRequest>());\r
-               setReceivePackFactory(new GitblitReceivePackFactory<HttpServletRequest>());\r
+               setRepositoryResolver(new RepositoryResolver<HttpServletRequest>(sessionManager, repositoryManager));\r
+               setUploadPackFactory(new GitblitUploadPackFactory<HttpServletRequest>(sessionManager));\r
+               setReceivePackFactory(new GitblitReceivePackFactory<HttpServletRequest>(runtimeManager, userManager, repositoryManager));\r
                super.init(config);\r
        }\r
 }\r
index 8da603ac04dda8d8197bcf0c2ae9b4e75153c267..44e2bef54b284e8af346b2dc4c5ca2e62de60824 100644 (file)
@@ -91,11 +91,20 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
 \r
        protected GroovyScriptEngine gse;\r
 \r
-       public GitblitReceivePack(Repository db, RepositoryModel repository, UserModel user) {\r
-               super(db);\r
+       private final IStoredSettings settings;\r
+\r
+       private final IRepositoryManager repositoryManager;\r
 \r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+       public GitblitReceivePack(\r
+                       IRuntimeManager runtimeManager,\r
+                       IRepositoryManager repositoryManager,\r
+                       Repository db,\r
+                       RepositoryModel repository,\r
+                       UserModel user) {\r
 \r
+               super(db);\r
+               this.settings = runtimeManager.getSettings();\r
+               this.repositoryManager = repositoryManager;\r
                this.repository = repository;\r
                this.user = user == null ? UserModel.ANONYMOUS : user;\r
                this.groovyDir = repositoryManager.getHooksFolder();\r
@@ -239,7 +248,6 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
                        }\r
                }\r
 \r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
                Set<String> scripts = new LinkedHashSet<String>();\r
                scripts.addAll(repositoryManager.getPreReceiveScriptsInherited(repository));\r
                if (!ArrayUtils.isEmpty(repository.preReceiveScripts)) {\r
@@ -266,8 +274,6 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
                        return;\r
                }\r
 \r
-               IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
-\r
                // log ref changes\r
                for (ReceiveCommand cmd : commands) {\r
 \r
@@ -336,8 +342,6 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
                        LOGGER.error(MessageFormat.format("Failed to update {0} pushlog", repository.name), e);\r
                }\r
 \r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
-\r
                // run Groovy hook scripts\r
                Set<String> scripts = new LinkedHashSet<String>();\r
                scripts.addAll(repositoryManager.getPostReceiveScriptsInherited(repository));\r
index a90c36b1df865c722370bd2dd60d4d99f492b004..2cdb9856ddb257b435efd21c070ad70be489457f 100644 (file)
@@ -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));
index 180e8b55d2d80e0835d0f6a8a9fe2cdf5b02bc2c..2afdde1d3c859e97cc91cd6cd28f2f08e009b876 100644 (file)
@@ -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;
 
index 5441596db223804cab0900f0d24921a911da0fd5..87795c0730feb7f751ec90312f34d653c0d79788 100644 (file)
@@ -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;
index 46a3b067a921488a039e8f8385a0b775d1265451..ad13a04253da96301402ee8ba375cedb381e3b0f 100644 (file)
@@ -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;
index bc65d77da111bd4dea98ecf0d02a3dd365e11912..87b0a08f06142488e0bef105c3964d66ea0bdc0b 100644 (file)
@@ -17,18 +17,17 @@ package com.gitblit.wicket;
 \r
 import java.util.Date;\r
 \r
+import javax.inject.Inject;\r
+import javax.inject.Singleton;\r
 import javax.servlet.http.HttpServletRequest;\r
 \r
-import org.apache.wicket.protocol.http.IWebApplicationFactory;\r
-import org.apache.wicket.protocol.http.WebApplication;\r
-import org.apache.wicket.protocol.http.WicketFilter;\r
 import org.apache.wicket.util.string.Strings;\r
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
-import com.gitblit.GitBlit;\r
 import com.gitblit.IStoredSettings;\r
 import com.gitblit.Keys;\r
+import com.gitblit.dagger.DaggerWicketFilter;\r
 import com.gitblit.manager.IProjectManager;\r
 import com.gitblit.manager.IRepositoryManager;\r
 import com.gitblit.manager.IRuntimeManager;\r
@@ -45,19 +44,28 @@ import com.gitblit.utils.StringUtils;
  * @author James Moger\r
  *\r
  */\r
-public class GitblitWicketFilter extends WicketFilter {\r
+@Singleton\r
+public class GitblitWicketFilter extends DaggerWicketFilter {\r
 \r
-       public GitblitWicketFilter() {\r
-       }\r
+       private final IStoredSettings settings;\r
 \r
-       @Override\r
-       protected IWebApplicationFactory getApplicationFactory() {\r
-               return new IWebApplicationFactory() {\r
-                       @Override\r
-                       public WebApplication createApplication(WicketFilter filter) {\r
-                               return new GitBlitWebApp();\r
-                       }\r
-               };\r
+       private final IRuntimeManager runtimeManager;\r
+\r
+       private final IRepositoryManager repositoryManager;\r
+\r
+       private final IProjectManager projectManager;\r
+\r
+       @Inject\r
+       public GitblitWicketFilter(\r
+                       IRuntimeManager runtimeManager,\r
+                       IRepositoryManager repositoryManager,\r
+                       IProjectManager projectManager) {\r
+\r
+               super();\r
+               this.settings = runtimeManager.getSettings();\r
+               this.runtimeManager = runtimeManager;\r
+               this.repositoryManager = repositoryManager;\r
+               this.projectManager = projectManager;\r
        }\r
 \r
        /**\r
@@ -97,11 +105,6 @@ public class GitblitWicketFilter extends WicketFilter {
                        commitId = servletRequest.getParameter("h");\r
                }\r
 \r
-               IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
-               IStoredSettings settings = runtimeManager.getSettings();\r
-               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
-               IProjectManager projectManager = GitBlit.getManager(IProjectManager.class);\r
-\r
                repo = repo.replace("%2f", "/").replace("%2F", "/").replace(settings.getChar(Keys.web.forwardSlashCharacter, '/'), '/');\r
 \r
                GitBlitWebApp app = (GitBlitWebApp) getWebApplication();\r
diff --git a/src/test/java/com/gitblit/tests/GitDaemonStopTest.java b/src/test/java/com/gitblit/tests/GitDaemonStopTest.java
deleted file mode 100644 (file)
index 6e940cb..0000000
+++ /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();
-       }
-}
index 0f7e55ca701ad2061ee88bc6df12c0a9679ce0bd..0e1aee1ed1e23a90579cca3ed4ef78d42ab780e0 100644 (file)
 package com.gitblit.tests;\r
 \r
 import java.util.ArrayList;\r
-import java.util.HashMap;\r
 import java.util.List;\r
-import java.util.Map;\r
 \r
 import org.eclipse.jgit.lib.Repository;\r
 import org.junit.After;\r
 import org.junit.Before;\r
 import org.junit.Test;\r
 \r
+import com.gitblit.GitBlit;\r
+import com.gitblit.Keys;\r
 import com.gitblit.LuceneExecutor;\r
 import com.gitblit.models.RefModel;\r
 import com.gitblit.models.RepositoryModel;\r
@@ -44,9 +44,10 @@ public class LuceneExecutorTest extends GitblitUnitTest {
        LuceneExecutor lucene;\r
 \r
        private LuceneExecutor newLuceneExecutor() {\r
-               Map<String, Object> map = new HashMap<String, Object>();\r
-               MemorySettings settings = new MemorySettings(map);\r
-               return new LuceneExecutor(settings, GitBlitSuite.REPOSITORIES);\r
+               MemorySettings settings = new MemorySettings();\r
+               settings.put(Keys.git.repositoriesFolder, GitBlitSuite.REPOSITORIES);\r
+               GitBlit gitblit = new GitBlit(settings, GitBlitSuite.REPOSITORIES);\r
+               return new LuceneExecutor(settings, gitblit);\r
        }\r
 \r
        private RepositoryModel newRepositoryModel(Repository repository) {\r
index 5b8e60a97daf65ca4d1dbaf1c7be0c0e61f56e23..e3f971f003eff0bab7d0c6493e985fa8f1d0084c 100644 (file)
@@ -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