]> source.dussan.org Git - gitblit.git/commitdiff
Define manager interfaces and update all of Gitblit to use managers
authorJames Moger <james.moger@gitblit.com>
Sun, 17 Nov 2013 21:15:24 +0000 (16:15 -0500)
committerJames Moger <james.moger@gitblit.com>
Tue, 26 Nov 2013 21:07:04 +0000 (16:07 -0500)
These manager interfaces define how the GitBlit singleton will
eventually be split into smaller component managers.  The Wicket app and
all servlets have been updated to request the needed managers.  There
are _very_ few method signature changes - although there are a handful.

This is a surgical sharding of responsibility based on a proof of
concept refactor.  Instead of random references to  GittBlit.self()
there are now precise references to the manager interface required to
accomplish some task.  Some tasks may require references to multiple
managers.

The code is now littered with calls to GitBlit.getManager(class) and
those familiar with the code-base will no doubt notice the duplication
of methods from IUserService in IUserManager and the addition of
implementation methods in the GitBlit context class.  When the
GitBlit class is broken apart and the existing external authentication
user service classes are refactored to AuthenticationService classes,
this will again simplify and flatten.  But in order to safely and
cleanly modularize the stable code-base we will have to live with a
little duplication for a short while.

Change-Id: I7314ec8acaab2dcc6092785ed4434cc09fdbbe16

97 files changed:
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/DownloadZipServlet.java
src/main/java/com/gitblit/EnforceAuthenticationFilter.java
src/main/java/com/gitblit/FederationClient.java
src/main/java/com/gitblit/FederationPullExecutor.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/GitBlitServer.java
src/main/java/com/gitblit/GitFilter.java
src/main/java/com/gitblit/GitblitUserService.java
src/main/java/com/gitblit/HtpasswdUserService.java
src/main/java/com/gitblit/IStoredSettings.java
src/main/java/com/gitblit/LdapUserService.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/PAMUserService.java
src/main/java/com/gitblit/PagesFilter.java
src/main/java/com/gitblit/PagesServlet.java
src/main/java/com/gitblit/RedmineUserService.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/SalesforceUserService.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/WindowsUserService.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/manager/IFederationManager.java [new file with mode: 0644]
src/main/java/com/gitblit/manager/IGitblitManager.java [new file with mode: 0644]
src/main/java/com/gitblit/manager/INotificationManager.java [new file with mode: 0644]
src/main/java/com/gitblit/manager/IProjectManager.java [new file with mode: 0644]
src/main/java/com/gitblit/manager/IRepositoryManager.java [new file with mode: 0644]
src/main/java/com/gitblit/manager/IRuntimeManager.java [new file with mode: 0644]
src/main/java/com/gitblit/manager/ISessionManager.java [new file with mode: 0644]
src/main/java/com/gitblit/manager/IUserManager.java [new file with mode: 0644]
src/main/java/com/gitblit/utils/ActivityUtils.java
src/main/java/com/gitblit/wicket/GitBlitWebApp.java
src/main/java/com/gitblit/wicket/GitblitWicketFilter.java
src/main/java/com/gitblit/wicket/pages/ActivityPage.java
src/main/java/com/gitblit/wicket/pages/ChangePasswordPage.java
src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java
src/main/java/com/gitblit/wicket/pages/EditTeamPage.java
src/main/java/com/gitblit/wicket/pages/EditUserPage.java
src/main/java/com/gitblit/wicket/pages/EmptyRepositoryPage.java
src/main/java/com/gitblit/wicket/pages/LogoutPage.java
src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
src/main/java/com/gitblit/wicket/pages/RootPage.java
src/main/java/com/gitblit/wicket/pages/SessionPage.java
src/test/java/com/gitblit/tests/ActivityTest.java
src/test/java/com/gitblit/tests/ArrayUtilsTest.java
src/test/java/com/gitblit/tests/Base64Test.java
src/test/java/com/gitblit/tests/ByteFormatTest.java
src/test/java/com/gitblit/tests/DiffUtilsTest.java
src/test/java/com/gitblit/tests/FanoutServiceTest.java
src/test/java/com/gitblit/tests/FederationTests.java
src/test/java/com/gitblit/tests/FileUtilsTest.java
src/test/java/com/gitblit/tests/GitBlitSuite.java
src/test/java/com/gitblit/tests/GitBlitTest.java
src/test/java/com/gitblit/tests/GitDaemonStopTest.java
src/test/java/com/gitblit/tests/GitDaemonTest.java
src/test/java/com/gitblit/tests/GitServletTest.java
src/test/java/com/gitblit/tests/GitblitUnitTest.java [new file with mode: 0644]
src/test/java/com/gitblit/tests/GroovyScriptTest.java
src/test/java/com/gitblit/tests/HtpasswdUserServiceTest.java
src/test/java/com/gitblit/tests/Issue0259Test.java
src/test/java/com/gitblit/tests/Issue0271Test.java
src/test/java/com/gitblit/tests/JGitUtilsTest.java
src/test/java/com/gitblit/tests/JnaUtilsTest.java
src/test/java/com/gitblit/tests/JsonUtilsTest.java
src/test/java/com/gitblit/tests/LdapUserServiceTest.java
src/test/java/com/gitblit/tests/LuceneExecutorTest.java
src/test/java/com/gitblit/tests/MailTest.java
src/test/java/com/gitblit/tests/MarkdownUtilsTest.java
src/test/java/com/gitblit/tests/MetricUtilsTest.java
src/test/java/com/gitblit/tests/ModelUtilsTest.java
src/test/java/com/gitblit/tests/ObjectCacheTest.java
src/test/java/com/gitblit/tests/PermissionsTest.java
src/test/java/com/gitblit/tests/PushLogTest.java
src/test/java/com/gitblit/tests/RedmineUserServiceTest.java
src/test/java/com/gitblit/tests/RepositoryModelTest.java
src/test/java/com/gitblit/tests/RpcTests.java
src/test/java/com/gitblit/tests/StringUtilsTest.java
src/test/java/com/gitblit/tests/SyndicationUtilsTest.java
src/test/java/com/gitblit/tests/TimeUtilsTest.java
src/test/java/com/gitblit/tests/UserServiceTest.java
src/test/java/com/gitblit/tests/X509UtilsTest.java
src/test/java/de/akquinet/devops/GitBlit4UITests.java
src/test/java/de/akquinet/devops/GitBlitServer4UITests.java

index cadf91550e6ce60555cf2efc4d1508c31cd2b985..ac97ba2e5be7071402c7a0bc8d37606e6c73a798 100644 (file)
@@ -25,6 +25,8 @@ import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;\r
 import javax.servlet.http.HttpServletResponse;\r
 \r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.StringUtils;\r
@@ -126,7 +128,10 @@ public abstract class AccessRestrictionFilter extends AuthenticationFilter {
                String fullUrl = getFullUrl(httpRequest);\r
                String repository = extractRepositoryName(fullUrl);\r
 \r
-               if (GitBlit.self().isCollectingGarbage(repository)) {\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
                        return;\r
@@ -139,12 +144,12 @@ public abstract class AccessRestrictionFilter extends AuthenticationFilter {
                UserModel user = getUser(httpRequest);\r
 \r
                // Load the repository model\r
-               RepositoryModel model = GitBlit.self().getRepositoryModel(repository);\r
+               RepositoryModel model = repositoryManager.getRepositoryModel(repository);\r
                if (model == null) {\r
                        if (isCreationAllowed()) {\r
                                if (user == null) {\r
                                        // challenge client to provide credentials for creation. send 401.\r
-                                       if (GitBlit.isDebugMode()) {\r
+                                       if (runtimeManager.isDebugMode()) {\r
                                                logger.info(MessageFormat.format("ARF: CREATE CHALLENGE {0}", fullUrl));\r
                                        }\r
                                        httpResponse.setHeader("WWW-Authenticate", CHALLENGE);\r
@@ -191,7 +196,7 @@ public abstract class AccessRestrictionFilter extends AuthenticationFilter {
                if (!StringUtils.isEmpty(urlRequestType) && requiresAuthentication(model, urlRequestType)) {\r
                        if (user == null) {\r
                                // challenge client to provide credentials. send 401.\r
-                               if (GitBlit.isDebugMode()) {\r
+                               if (runtimeManager.isDebugMode()) {\r
                                        logger.info(MessageFormat.format("ARF: CHALLENGE {0}", fullUrl));\r
                                }\r
                                httpResponse.setHeader("WWW-Authenticate", CHALLENGE);\r
@@ -209,7 +214,7 @@ public abstract class AccessRestrictionFilter extends AuthenticationFilter {
                                        return;\r
                                }\r
                                // valid user, but not for requested access. send 403.\r
-                               if (GitBlit.isDebugMode()) {\r
+                               if (runtimeManager.isDebugMode()) {\r
                                        logger.info(MessageFormat.format("ARF: {0} forbidden to access {1}",\r
                                                        user.username, fullUrl));\r
                                }\r
@@ -218,7 +223,7 @@ public abstract class AccessRestrictionFilter extends AuthenticationFilter {
                        }\r
                }\r
 \r
-               if (GitBlit.isDebugMode()) {\r
+               if (runtimeManager.isDebugMode()) {\r
                        logger.info(MessageFormat.format("ARF: {0} ({1}) unauthenticated", fullUrl,\r
                                        HttpServletResponse.SC_CONTINUE));\r
                }\r
index 640bf17655ae85e8642890f178f95cb53518a84a..9aeb89f7e6f9706e4b6cf3ef48b03f1fa754fbd2 100644 (file)
@@ -35,6 +35,7 @@ import javax.servlet.http.HttpSession;
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
+import com.gitblit.manager.ISessionManager;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.DeepCopier;\r
 import com.gitblit.utils.StringUtils;\r
@@ -100,7 +101,8 @@ public abstract class AuthenticationFilter implements Filter {
         * @return user\r
         */\r
        protected UserModel getUser(HttpServletRequest httpRequest) {\r
-               UserModel user = GitBlit.self().authenticate(httpRequest, requiresClientCertificate());\r
+               ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);\r
+               UserModel user = sessionManager.authenticate(httpRequest, requiresClientCertificate());\r
                return user;\r
        }\r
 \r
index 293a2919a75f7734fcb47fce68e94eae386c0496..986560c6bb8a122e27b96e6fa26b177f4c0def1a 100644 (file)
@@ -50,6 +50,8 @@ import org.eclipse.jgit.revplot.PlotLane;
 import org.eclipse.jgit.revplot.PlotWalk;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.utils.StringUtils;\r
 \r
@@ -102,9 +104,10 @@ 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 = GitBlit.self().getRepository(repository);\r
+                       r = repositoryManager.getRepository(repository);\r
                        if (StringUtils.isEmpty(objectId)) {\r
                                objectId = JGitUtils.getHEADRef(r);\r
                        }\r
@@ -128,7 +131,10 @@ public class BranchGraphServlet extends HttpServlet {
                        String objectId = request.getParameter("h");\r
                        String length = request.getParameter("l");\r
 \r
-                       r = GitBlit.self().getRepository(repository);\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
                        if (StringUtils.isEmpty(objectId)) {\r
@@ -138,7 +144,7 @@ public class BranchGraphServlet extends HttpServlet {
                        rw.markStart(rw.lookupCommit(r.resolve(objectId)));\r
 \r
                        // default to the items-per-page setting, unless specified\r
-                       int maxCommits = GitBlit.getInteger(Keys.web.itemsPerPage, 50);\r
+                       int maxCommits = settings.getInteger(Keys.web.itemsPerPage, 50);\r
                        int requestedCommits = maxCommits;\r
                        if (!StringUtils.isEmpty(length)) {\r
                                int l = Integer.parseInt(length);\r
index c8da267de1f70ca7dc05cab19456ca314a620b83..82846dac0dda24c44e7c5ea6e3b9afc472aaa73d 100644 (file)
@@ -29,6 +29,8 @@ import org.eclipse.jgit.revwalk.RevCommit;
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.utils.CompressionUtils;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.utils.MarkdownUtils;\r
@@ -101,7 +103,8 @@ 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
-               if (!GitBlit.getBoolean(Keys.web.allowZipDownloads, true)) {\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
                        return;\r
@@ -130,9 +133,10 @@ public class DownloadZipServlet extends HttpServlet {
                                name += "-" + objectId;\r
                        }\r
 \r
-                       Repository r = GitBlit.self().getRepository(repository);\r
+                       IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+                       Repository r = repositoryManager.getRepository(repository);\r
                        if (r == null) {\r
-                               if (GitBlit.self().isCollectingGarbage(repository)) {\r
+                               if (repositoryManager.isCollectingGarbage(repository)) {\r
                                        error(response, MessageFormat.format("# Error\nGitblit is busy collecting garbage in {0}", repository));\r
                                        return;\r
                                } else {\r
index ae91c322d237e78764239ba160c4423c753cbcba..93057b452ca6b87324b6599799883236395716f8 100644 (file)
@@ -30,6 +30,8 @@ import javax.servlet.http.HttpServletResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.ISessionManager;
 import com.gitblit.models.UserModel;
 
 /**
@@ -49,9 +51,7 @@ public class EnforceAuthenticationFilter implements Filter {
         */
        @Override
        public void init(FilterConfig filterConfig) throws ServletException {
-               // nothing to be done
-
-       } //init
+       }
 
 
        /*
@@ -62,32 +62,28 @@ public class EnforceAuthenticationFilter implements Filter {
        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
 
-               /*
-                * Determine whether to enforce the BASIC authentication:
-                */
-               @SuppressWarnings("static-access")
-               Boolean mustForceAuth = GitBlit.self().getBoolean(Keys.web.authenticateViewPages, false)
-                                                               && GitBlit.self().getBoolean(Keys.web.enforceHttpBasicAuthentication, false);
+               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);
 
-               HttpServletRequest  HttpRequest  = (HttpServletRequest)request;
-               HttpServletResponse HttpResponse = (HttpServletResponse)response;
-               UserModel user = GitBlit.self().authenticate(HttpRequest);
+               HttpServletRequest  httpRequest  = (HttpServletRequest) request;
+               HttpServletResponse httpResponse = (HttpServletResponse) response;
+               UserModel user = sessionManager.authenticate(httpRequest);
 
                if (mustForceAuth && (user == null)) {
                        // not authenticated, enforce now:
                        logger.debug(MessageFormat.format("EnforceAuthFilter: user not authenticated for URL {0}!", request.toString()));
-                       @SuppressWarnings("static-access")
-                       String CHALLENGE = MessageFormat.format("Basic realm=\"{0}\"", GitBlit.self().getString("web.siteName",""));
-                       HttpResponse.setHeader("WWW-Authenticate", CHALLENGE);
-                       HttpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+                       String challenge = MessageFormat.format("Basic realm=\"{0}\"", settings.getString(Keys.web.siteName, ""));
+                       httpResponse.setHeader("WWW-Authenticate", challenge);
+                       httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                        return;
 
                } else {
                        // user is authenticated, or don't care, continue handling
-                       chain.doFilter( request, response );
-
-               } // authenticated
-       } // doFilter
+                       chain.doFilter(request, response);
+               }
+       }
 
 
        /*
@@ -95,8 +91,5 @@ public class EnforceAuthenticationFilter implements Filter {
         */
        @Override
        public void destroy() {
-               // Nothing to be done
-
-       } // destroy
-
+       }
 }
index 6b2161c67189cdf21d1f19abe21034b3be1c5f9e..eae6b94f087af973f456538de29ea150f2a088a8 100644 (file)
@@ -83,7 +83,8 @@ public class FederationClient {
                }\r
 \r
                // configure the Gitblit singleton for minimal, non-server operation\r
-               GitBlit.self().configureContext(settings, baseFolder, false);\r
+               GitBlit gitblit = new GitBlit(settings, baseFolder);\r
+               gitblit.configureContext(settings, baseFolder, false);\r
                FederationPullExecutor executor = new FederationPullExecutor(registrations, params.isDaemon);\r
                executor.run();\r
                if (!params.isDaemon) {\r
index 831c7a5e8e9a9ba0e886057335b7d984e41a6f79..e9a604da7f719e1a154553870305bd0d062beb61 100644 (file)
@@ -46,6 +46,11 @@ import com.gitblit.Constants.AccessPermission;
 import com.gitblit.Constants.FederationPullStatus;\r
 import com.gitblit.Constants.FederationStrategy;\r
 import com.gitblit.GitBlitException.ForbiddenException;\r
+import com.gitblit.manager.IGitblitManager;\r
+import com.gitblit.manager.INotificationManager;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.IUserManager;\r
 import com.gitblit.models.FederationModel;\r
 import com.gitblit.models.RefModel;\r
 import com.gitblit.models.RepositoryModel;\r
@@ -116,7 +121,8 @@ public class FederationPullExecutor implements Runnable {
                                        if (registration.notifyOnError) {\r
                                                String message = "Federation pull of " + registration.name + " @ "\r
                                                                + registration.url + " is now at " + is.name();\r
-                                               GitBlit.self()\r
+                                               INotificationManager mailManager = GitBlit.getManager(INotificationManager.class);\r
+                                               mailManager\r
                                                                .sendMailToAdministrators(\r
                                                                                "Pull Status of " + registration.name + " is " + is.name(),\r
                                                                                message);\r
@@ -153,7 +159,8 @@ public class FederationPullExecutor implements Runnable {
                                                        c, registrationFolder, registration.name));\r
                        return;\r
                }\r
-               File repositoriesFolder = GitBlit.getRepositoriesFolder();\r
+               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+               File repositoriesFolder = repositoryManager.getRepositoriesFolder();\r
                File registrationFolderFile = new File(repositoriesFolder, registrationFolder);\r
                registrationFolderFile.mkdirs();\r
 \r
@@ -193,9 +200,9 @@ public class FederationPullExecutor implements Runnable {
                        // confirm that the origin of any pre-existing repository matches\r
                        // the clone url\r
                        String fetchHead = null;\r
-                       Repository existingRepository = GitBlit.self().getRepository(repositoryName);\r
+                       Repository existingRepository = repositoryManager.getRepository(repositoryName);\r
 \r
-                       if (existingRepository == null && GitBlit.self().isCollectingGarbage(repositoryName)) {\r
+                       if (existingRepository == null && repositoryManager.isCollectingGarbage(repositoryName)) {\r
                                logger.warn(MessageFormat.format("Skipping local repository {0}, busy collecting garbage", repositoryName));\r
                                continue;\r
                        }\r
@@ -227,8 +234,8 @@ public class FederationPullExecutor implements Runnable {
 \r
                        CloneResult result = JGitUtils.cloneRepository(registrationFolderFile, repository.name,\r
                                        cloneUrl, registration.bare, credentials);\r
-                       Repository r = GitBlit.self().getRepository(repositoryName);\r
-                       RepositoryModel rm = GitBlit.self().getRepositoryModel(repositoryName);\r
+                       Repository r = repositoryManager.getRepository(repositoryName);\r
+                       RepositoryModel rm = repositoryManager.getRepositoryModel(repositoryName);\r
                        repository.isFrozen = registration.mirror;\r
                        if (result.createdRepository) {\r
                                // default local settings\r
@@ -316,10 +323,12 @@ public class FederationPullExecutor implements Runnable {
                        // "federated" repositories.\r
                        repository.isFederated = cloneUrl.startsWith(registration.url);\r
 \r
-                       GitBlit.self().updateConfiguration(r, repository);\r
+                       repositoryManager.updateConfiguration(r, repository);\r
                        r.close();\r
                }\r
 \r
+               IUserManager userManager = GitBlit.getManager(IUserManager.class);\r
+               IGitblitManager gitblitManager = GitBlit.getManager(IGitblitManager.class);\r
                IUserService userService = null;\r
 \r
                try {\r
@@ -359,10 +368,10 @@ public class FederationPullExecutor implements Runnable {
                                                }\r
 \r
                                                // insert new user or update local user\r
-                                               UserModel localUser = GitBlit.self().getUserModel(user.username);\r
+                                               UserModel localUser = userManager.getUserModel(user.username);\r
                                                if (localUser == null) {\r
                                                        // create new local user\r
-                                                       GitBlit.self().updateUserModel(user.username, user, true);\r
+                                                       gitblitManager.updateUserModel(user.username, user, true);\r
                                                } else {\r
                                                        // update repository permissions of local user\r
                                                        if (user.permissions != null) {\r
@@ -379,19 +388,19 @@ public class FederationPullExecutor implements Runnable {
                                                        }\r
                                                        localUser.password = user.password;\r
                                                        localUser.canAdmin = user.canAdmin;\r
-                                                       GitBlit.self().updateUserModel(localUser.username, localUser, false);\r
+                                                       gitblitManager.updateUserModel(localUser.username, localUser, false);\r
                                                }\r
 \r
-                                               for (String teamname : GitBlit.self().getAllTeamnames()) {\r
-                                                       TeamModel team = GitBlit.self().getTeamModel(teamname);\r
+                                               for (String teamname : userManager.getAllTeamNames()) {\r
+                                                       TeamModel team = userManager.getTeamModel(teamname);\r
                                                        if (user.isTeamMember(teamname) && !team.hasUser(user.username)) {\r
                                                                // new team member\r
                                                                team.addUser(user.username);\r
-                                                               GitBlit.self().updateTeamModel(teamname, team, false);\r
+                                                               userManager.updateTeamModel(teamname, team);\r
                                                        } else if (!user.isTeamMember(teamname) && team.hasUser(user.username)) {\r
                                                                // remove team member\r
                                                                team.removeUser(user.username);\r
-                                                               GitBlit.self().updateTeamModel(teamname, team, false);\r
+                                                               userManager.updateTeamModel(teamname, team);\r
                                                        }\r
 \r
                                                        // update team repositories\r
@@ -402,11 +411,11 @@ public class FederationPullExecutor implements Runnable {
                                                                        for (Map.Entry<String, AccessPermission> entry : remoteTeam.permissions.entrySet()){\r
                                                                                team.setRepositoryPermission(entry.getKey(), entry.getValue());\r
                                                                        }\r
-                                                                       GitBlit.self().updateTeamModel(teamname, team, false);\r
+                                                                       userManager.updateTeamModel(teamname, team);\r
                                                                } else if(!ArrayUtils.isEmpty(remoteTeam.repositories)) {\r
                                                                        // pulling from <= 1.1\r
                                                                        team.addRepositoryPermissions(remoteTeam.repositories);\r
-                                                                       GitBlit.self().updateTeamModel(teamname, team, false);\r
+                                                                       userManager.updateTeamModel(teamname, team);\r
                                                                }\r
                                                        }\r
                                                }\r
@@ -497,7 +506,8 @@ public class FederationPullExecutor implements Runnable {
                        return;\r
                }\r
                InetAddress addr = InetAddress.getLocalHost();\r
-               String federationName = GitBlit.getString(Keys.federation.name, null);\r
+               IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+               String federationName = settings.getString(Keys.federation.name, null);\r
                if (StringUtils.isEmpty(federationName)) {\r
                        federationName = addr.getHostName();\r
                }\r
index 5db9645083072b3b46d3038f68b8b0ebb0ac8bf7..0d83b4f445078bc54b74d556b8fc6032a084a595 100644 (file)
@@ -28,6 +28,10 @@ import java.util.Set;
 import javax.servlet.http.HttpServletResponse;\r
 \r
 import com.gitblit.Constants.FederationRequest;\r
+import com.gitblit.manager.IFederationManager;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.IUserManager;\r
 import com.gitblit.models.FederationModel;\r
 import com.gitblit.models.FederationProposal;\r
 import com.gitblit.models.TeamModel;\r
@@ -65,6 +69,12 @@ public class FederationServlet extends JsonServlet {
        protected void processRequest(javax.servlet.http.HttpServletRequest request,\r
                        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
@@ -75,13 +85,13 @@ public class FederationServlet extends JsonServlet {
                        return;\r
                }\r
 \r
-               if (!GitBlit.getBoolean(Keys.git.enableGitServlet, true)) {\r
+               if (!settings.getBoolean(Keys.git.enableGitServlet, true)) {\r
                        logger.warn(Keys.git.enableGitServlet + " must be set TRUE for federation requests.");\r
                        response.sendError(HttpServletResponse.SC_FORBIDDEN);\r
                        return;\r
                }\r
 \r
-               String uuid = GitBlit.getString(Keys.federation.passphrase, "");\r
+               String uuid = settings.getString(Keys.federation.passphrase, "");\r
                if (StringUtils.isEmpty(uuid)) {\r
                        logger.warn(Keys.federation.passphrase\r
                                        + " is not properly set!  Federation request denied.");\r
@@ -97,7 +107,7 @@ public class FederationServlet extends JsonServlet {
                        }\r
 \r
                        // reject proposal, if not receipt prohibited\r
-                       if (!GitBlit.getBoolean(Keys.federation.allowProposals, false)) {\r
+                       if (!settings.getBoolean(Keys.federation.allowProposals, false)) {\r
                                logger.error(MessageFormat.format("Rejected {0} federation proposal from {1}",\r
                                                proposal.tokenType.name(), proposal.url));\r
                                response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);\r
@@ -119,7 +129,7 @@ public class FederationServlet extends JsonServlet {
                        }\r
 \r
                        String url = HttpUtils.getGitblitURL(request);\r
-                       GitBlit.self().submitFederationProposal(proposal, url);\r
+                       federationManager.submitFederationProposal(proposal, url);\r
                        logger.info(MessageFormat.format(\r
                                        "Submitted {0} federation proposal to pull {1} repositories from {2}",\r
                                        proposal.tokenType.name(), proposal.repositories.size(), proposal.url));\r
@@ -145,7 +155,7 @@ public class FederationServlet extends JsonServlet {
                        results.nextPull = new Date(System.currentTimeMillis() + (mins * 60 * 1000L));\r
 \r
                        // acknowledge the receipt of status\r
-                       GitBlit.self().acknowledgeFederationStatus(identification, results);\r
+                       federationManager.acknowledgeFederationStatus(identification, results);\r
                        logger.info(MessageFormat.format(\r
                                        "Received status of {0} federated repositories from {1}", results\r
                                                        .getStatusList().size(), identification));\r
@@ -155,7 +165,7 @@ public class FederationServlet extends JsonServlet {
 \r
                // Determine the federation tokens for this gitblit instance\r
                String token = request.getParameter("token");\r
-               List<String> tokens = GitBlit.self().getFederationTokens();\r
+               List<String> tokens = federationManager.getFederationTokens();\r
                if (!tokens.contains(token)) {\r
                        logger.warn(MessageFormat.format(\r
                                        "Received Federation token ''{0}'' does not match the server tokens", token));\r
@@ -166,11 +176,11 @@ public class FederationServlet extends JsonServlet {
                Object result = null;\r
                if (FederationRequest.PULL_REPOSITORIES.equals(reqType)) {\r
                        String gitblitUrl = HttpUtils.getGitblitURL(request);\r
-                       result = GitBlit.self().getRepositories(gitblitUrl, token);\r
+                       result = federationManager.getRepositories(gitblitUrl, token);\r
                } else {\r
                        if (FederationRequest.PULL_SETTINGS.equals(reqType)) {\r
                                // pull settings\r
-                               if (!GitBlit.self().validateFederationRequest(reqType, token)) {\r
+                               if (!federationManager.validateFederationRequest(reqType, token)) {\r
                                        // invalid token to pull users or settings\r
                                        logger.warn(MessageFormat.format(\r
                                                        "Federation token from {0} not authorized to pull SETTINGS",\r
@@ -178,15 +188,15 @@ public class FederationServlet extends JsonServlet {
                                        response.sendError(HttpServletResponse.SC_FORBIDDEN);\r
                                        return;\r
                                }\r
-                               Map<String, String> settings = new HashMap<String, String>();\r
-                               List<String> keys = GitBlit.getAllKeys(null);\r
+                               Map<String, String> map = new HashMap<String, String>();\r
+                               List<String> keys = settings.getAllKeys(null);\r
                                for (String key : keys) {\r
-                                       settings.put(key, GitBlit.getString(key, ""));\r
+                                       map.put(key, settings.getString(key, ""));\r
                                }\r
-                               result = settings;\r
+                               result = map;\r
                        } else if (FederationRequest.PULL_USERS.equals(reqType)) {\r
                                // pull users\r
-                               if (!GitBlit.self().validateFederationRequest(reqType, token)) {\r
+                               if (!federationManager.validateFederationRequest(reqType, token)) {\r
                                        // invalid token to pull users or settings\r
                                        logger.warn(MessageFormat.format(\r
                                                        "Federation token from {0} not authorized to pull USERS",\r
@@ -194,10 +204,10 @@ public class FederationServlet extends JsonServlet {
                                        response.sendError(HttpServletResponse.SC_FORBIDDEN);\r
                                        return;\r
                                }\r
-                               List<String> usernames = GitBlit.self().getAllUsernames();\r
+                               List<String> usernames = userManager.getAllUsernames();\r
                                List<UserModel> users = new ArrayList<UserModel>();\r
                                for (String username : usernames) {\r
-                                       UserModel user = GitBlit.self().getUserModel(username);\r
+                                       UserModel user = userManager.getUserModel(username);\r
                                        if (!user.excludeFromFederation) {\r
                                                users.add(user);\r
                                        }\r
@@ -205,7 +215,7 @@ public class FederationServlet extends JsonServlet {
                                result = users;\r
                        } else if (FederationRequest.PULL_TEAMS.equals(reqType)) {\r
                                // pull teams\r
-                               if (!GitBlit.self().validateFederationRequest(reqType, token)) {\r
+                               if (!federationManager.validateFederationRequest(reqType, token)) {\r
                                        // invalid token to pull teams\r
                                        logger.warn(MessageFormat.format(\r
                                                        "Federation token from {0} not authorized to pull TEAMS",\r
@@ -213,16 +223,16 @@ public class FederationServlet extends JsonServlet {
                                        response.sendError(HttpServletResponse.SC_FORBIDDEN);\r
                                        return;\r
                                }\r
-                               List<String> teamnames = GitBlit.self().getAllTeamnames();\r
+                               List<String> teamnames = userManager.getAllTeamNames();\r
                                List<TeamModel> teams = new ArrayList<TeamModel>();\r
                                for (String teamname : teamnames) {\r
-                                       TeamModel user = GitBlit.self().getTeamModel(teamname);\r
+                                       TeamModel user = userManager.getTeamModel(teamname);\r
                                        teams.add(user);\r
                                }\r
                                result = teams;\r
                        } else if (FederationRequest.PULL_SCRIPTS.equals(reqType)) {\r
                                // pull scripts\r
-                               if (!GitBlit.self().validateFederationRequest(reqType, token)) {\r
+                               if (!federationManager.validateFederationRequest(reqType, token)) {\r
                                        // invalid token to pull script\r
                                        logger.warn(MessageFormat.format(\r
                                                        "Federation token from {0} not authorized to pull SCRIPTS",\r
@@ -233,13 +243,13 @@ public class FederationServlet extends JsonServlet {
                                Map<String, String> scripts = new HashMap<String, String>();\r
 \r
                                Set<String> names = new HashSet<String>();\r
-                               names.addAll(GitBlit.getStrings(Keys.groovy.preReceiveScripts));\r
-                               names.addAll(GitBlit.getStrings(Keys.groovy.postReceiveScripts));\r
-                               for (TeamModel team :  GitBlit.self().getAllTeams()) {\r
+                               names.addAll(settings.getStrings(Keys.groovy.preReceiveScripts));\r
+                               names.addAll(settings.getStrings(Keys.groovy.postReceiveScripts));\r
+                               for (TeamModel team :  userManager.getAllTeams()) {\r
                                        names.addAll(team.preReceiveScripts);\r
                                        names.addAll(team.postReceiveScripts);\r
                                }\r
-                               File scriptsFolder = GitBlit.getFileOrFolder(Keys.groovy.scriptsFolder, "groovy");\r
+                               File scriptsFolder = repositoryManager.getHooksFolder();\r
                                for (String name : names) {\r
                                        File file = new File(scriptsFolder, name);\r
                                        if (!file.exists() && !file.getName().endsWith(".groovy")) {\r
index 681065be9608aeec6729f8ed14af629bc860a1b4..837741f2095bb1914af0b4a3b02f61196c805529 100644 (file)
@@ -31,6 +31,7 @@ import org.eclipse.jgit.lib.Repository;
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
+import com.gitblit.manager.IRepositoryManager;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.utils.FileUtils;\r
 \r
@@ -131,7 +132,9 @@ public class GCExecutor implements Runnable {
                running.set(true);\r
                Date now = new Date();\r
 \r
-               for (String repositoryName : GitBlit.self().getRepositoryList()) {\r
+               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+\r
+               for (String repositoryName : repositoryManager.getRepositoryList()) {\r
                        if (forceClose.get()) {\r
                                break;\r
                        }\r
@@ -143,8 +146,8 @@ public class GCExecutor implements Runnable {
                        RepositoryModel model = null;\r
                        Repository repository = null;\r
                        try {\r
-                               model = GitBlit.self().getRepositoryModel(repositoryName);\r
-                               repository = GitBlit.self().getRepository(repositoryName);\r
+                               model = repositoryManager.getRepositoryModel(repositoryName);\r
+                               repository = repositoryManager.getRepository(repositoryName);\r
                                if (repository == null) {\r
                                        logger.warn(MessageFormat.format("GCExecutor is missing repository {0}?!?", repositoryName));\r
                                        continue;\r
@@ -204,7 +207,7 @@ public class GCExecutor implements Runnable {
                                        if (garbageCollected) {\r
                                                // update the last GC date\r
                                                model.lastGC = new Date();\r
-                                               GitBlit.self().updateConfiguration(repository, model);\r
+                                               repositoryManager.updateConfiguration(repository, model);\r
                                        }\r
 \r
                                        repository.close();\r
index 6d52e763dff8ef901b49aa904097dacce7c2c457..5fbc876b115334e92c2182a16dc4e13b461a0bd0 100644 (file)
@@ -69,9 +69,9 @@ import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.apache.wicket.RequestCycle;
-import org.apache.wicket.protocol.http.WebResponse;
 import org.apache.wicket.resource.ContextRelativeResource;
 import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
 import org.eclipse.jgit.lib.Repository;
@@ -100,6 +100,14 @@ import com.gitblit.fanout.FanoutNioService;
 import com.gitblit.fanout.FanoutService;
 import com.gitblit.fanout.FanoutSocketService;
 import com.gitblit.git.GitDaemon;
+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.models.FederationModel;
 import com.gitblit.models.FederationProposal;
 import com.gitblit.models.FederationSet;
@@ -158,10 +166,20 @@ import com.google.gson.reflect.TypeToken;
  * @author James Moger
  *
  */
-public class GitBlit implements ServletContextListener {
+public class GitBlit implements ServletContextListener,
+                                                               IRuntimeManager,
+                                                               INotificationManager,
+                                                               IUserManager,
+                                                               ISessionManager,
+                                                               IRepositoryManager,
+                                                               IProjectManager,
+                                                               IFederationManager,
+                                                               IGitblitManager {
 
        private static GitBlit gitblit;
 
+       private final IStoredSettings goSettings;
+
        private final Logger logger = LoggerFactory.getLogger(GitBlit.class);
 
        private final ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(10);
@@ -218,36 +236,56 @@ public class GitBlit implements ServletContextListener {
        private GitDaemon gitDaemon;
 
        public GitBlit() {
-               if (gitblit == null) {
-                       // set the static singleton reference
-                       gitblit = this;
-               }
+               this.goSettings = null;
        }
 
-       public GitBlit(final IUserService userService) {
+       protected GitBlit(final IUserService userService) {
+               this.goSettings = null;
                this.userService = userService;
                gitblit = this;
        }
 
+       public GitBlit(IStoredSettings settings, File baseFolder) {
+               this.goSettings = settings;
+               this.baseFolder = baseFolder;
+               gitblit = this;
+       }
+
        /**
         * Returns the Gitblit singleton.
         *
         * @return gitblit singleton
         */
        public static GitBlit self() {
-               if (gitblit == null) {
-                       new GitBlit();
-               }
                return gitblit;
        }
 
+       @SuppressWarnings("unchecked")
+       public static <X> X getManager(Class<X> managerClass) {
+               if (managerClass.isAssignableFrom(GitBlit.class)) {
+                       return (X) gitblit;
+               }
+               return null;
+       }
+
+       @Override
+       public File getBaseFolder() {
+               return baseFolder;
+       }
+
+       @Override
+       public void setBaseFolder(File folder) {
+               this.baseFolder = folder;
+       }
+
        /**
         * Returns the boot date of the Gitblit server.
         *
         * @return the boot date of Gitblit
         */
-       public static Date getBootDate() {
-               return self().serverStatus.bootDate;
+       @Override
+       public Date getBootDate() {
+               return serverStatus.bootDate;
        }
 
        /**
@@ -255,10 +293,11 @@ public class GitBlit implements ServletContextListener {
         *
         * @return a date
         */
-       public static Date getLastActivityDate() {
+       @Override
+       public Date getLastActivityDate() {
                Date date = null;
-               for (String name : self().getRepositoryList()) {
-                       Repository r = self().getRepository(name);
+               for (String name : getRepositoryList()) {
+                       Repository r = getRepository(name);
                        Date lastChange = JGitUtils.getLastChange(r).when;
                        r.close();
                        if (lastChange != null && (date == null || lastChange.after(date))) {
@@ -268,33 +307,15 @@ public class GitBlit implements ServletContextListener {
                return date;
        }
 
-       /**
-        * Determine if this is the GO variant of Gitblit.
-        *
-        * @return true if this is the GO variant of Gitblit.
-        */
-       public static boolean isGO() {
-               return self().settings instanceof FileSettings;
-       }
-
-       /**
-        * Determine if this Gitblit instance is actively serving git repositories
-        * or if it is merely a repository viewer.
-        *
-        * @return true if Gitblit is serving repositories
-        */
-       public static boolean isServingRepositories() {
-               return getBoolean(Keys.git.enableGitServlet, true) || (getInteger(Keys.git.daemonPort, 0) > 0);
-       }
-
        /**
         * Determine if this Gitblit instance is actively serving git repositories
         * or if it is merely a repository viewer.
         *
         * @return true if Gitblit is serving repositories
         */
-       public static boolean isSendingMail() {
-               return self().mailExecutor.isReady();
+       @Override
+       public boolean isServingRepositories() {
+               return settings.getBoolean(Keys.git.enableGitServlet, true) || (settings.getInteger(Keys.git.daemonPort, 0) > 0);
        }
 
        /**
@@ -302,167 +323,17 @@ public class GitBlit implements ServletContextListener {
         *
         * @return a timezone
         */
-       public static TimeZone getTimezone() {
-               if (self().timezone == null) {
-                       String tzid = getString("web.timezone", null);
+       @Override
+       public TimeZone getTimezone() {
+               if (timezone == null) {
+                       String tzid = settings.getString("web.timezone", null);
                        if (StringUtils.isEmpty(tzid)) {
-                               self().timezone = TimeZone.getDefault();
-                               return self().timezone;
+                               timezone = TimeZone.getDefault();
+                               return timezone;
                        }
-                       self().timezone = TimeZone.getTimeZone(tzid);
+                       timezone = TimeZone.getTimeZone(tzid);
                }
-               return self().timezone;
-       }
-
-       /**
-        * Returns the active settings.
-        *
-        * @return the active settings
-        */
-       public static IStoredSettings getSettings() {
-               return self().settings;
-       }
-
-       /**
-        * Returns the user-defined blob encodings.
-        *
-        * @return an array of encodings, may be empty
-        */
-       public static String [] getEncodings() {
-               return getStrings(Keys.web.blobEncodings).toArray(new String[0]);
-       }
-
-
-       /**
-        * Returns the boolean value for the specified key. If the key does not
-        * exist or the value for the key can not be interpreted as a boolean, the
-        * defaultValue is returned.
-        *
-        * @see IStoredSettings.getBoolean(String, boolean)
-        * @param key
-        * @param defaultValue
-        * @return key value or defaultValue
-        */
-       public static boolean getBoolean(String key, boolean defaultValue) {
-               return self().settings.getBoolean(key, defaultValue);
-       }
-
-       /**
-        * Returns the integer value for the specified key. If the key does not
-        * exist or the value for the key can not be interpreted as an integer, the
-        * defaultValue is returned.
-        *
-        * @see IStoredSettings.getInteger(String key, int defaultValue)
-        * @param key
-        * @param defaultValue
-        * @return key value or defaultValue
-        */
-       public static int getInteger(String key, int defaultValue) {
-               return self().settings.getInteger(key, defaultValue);
-       }
-
-       /**
-        * Returns the integer list for the specified key. If the key does not
-        * exist or the value for the key can not be interpreted as an integer, an
-        * empty list is returned.
-        *
-        * @see IStoredSettings.getIntegers(String key)
-        * @param key
-        * @return key value or defaultValue
-        */
-       public static List<Integer> getIntegers(String key) {
-               return self().settings.getIntegers(key);
-       }
-
-       /**
-        * Returns the value in bytes for the specified key. If the key does not
-        * exist or the value for the key can not be interpreted as an integer, the
-        * defaultValue is returned.
-        *
-        * @see IStoredSettings.getFilesize(String key, int defaultValue)
-        * @param key
-        * @param defaultValue
-        * @return key value or defaultValue
-        */
-       public static int getFilesize(String key, int defaultValue) {
-               return self().settings.getFilesize(key, defaultValue);
-       }
-
-       /**
-        * Returns the value in bytes for the specified key. If the key does not
-        * exist or the value for the key can not be interpreted as a long, the
-        * defaultValue is returned.
-        *
-        * @see IStoredSettings.getFilesize(String key, long defaultValue)
-        * @param key
-        * @param defaultValue
-        * @return key value or defaultValue
-        */
-       public static long getFilesize(String key, long defaultValue) {
-               return self().settings.getFilesize(key, defaultValue);
-       }
-
-       /**
-        * Returns the char value for the specified key. If the key does not exist
-        * or the value for the key can not be interpreted as a character, the
-        * defaultValue is returned.
-        *
-        * @see IStoredSettings.getChar(String key, char defaultValue)
-        * @param key
-        * @param defaultValue
-        * @return key value or defaultValue
-        */
-       public static char getChar(String key, char defaultValue) {
-               return self().settings.getChar(key, defaultValue);
-       }
-
-       /**
-        * Returns the string value for the specified key. If the key does not exist
-        * or the value for the key can not be interpreted as a string, the
-        * defaultValue is returned.
-        *
-        * @see IStoredSettings.getString(String key, String defaultValue)
-        * @param key
-        * @param defaultValue
-        * @return key value or defaultValue
-        */
-       public static String getString(String key, String defaultValue) {
-               return self().settings.getString(key, defaultValue);
-       }
-
-       /**
-        * Returns a list of space-separated strings from the specified key.
-        *
-        * @see IStoredSettings.getStrings(String key)
-        * @param n
-        * @return list of strings
-        */
-       public static List<String> getStrings(String key) {
-               return self().settings.getStrings(key);
-       }
-
-       /**
-        * Returns a map of space-separated key-value pairs from the specified key.
-        *
-        * @see IStoredSettings.getStrings(String key)
-        * @param n
-        * @return map of string, string
-        */
-       public static Map<String, String> getMap(String key) {
-               return self().settings.getMap(key);
-       }
-
-       /**
-        * Returns the list of keys whose name starts with the specified prefix. If
-        * the prefix is null or empty, all key names are returned.
-        *
-        * @see IStoredSettings.getAllKeys(String key)
-        * @param startingWith
-        * @return list of keys
-        */
-
-       public static List<String> getAllKeys(String startingWith) {
-               return self().settings.getAllKeys(startingWith);
+               return timezone;
        }
 
        /**
@@ -470,8 +341,9 @@ public class GitBlit implements ServletContextListener {
         *
         * @return true if Gitblit is running in debug mode
         */
-       public static boolean isDebugMode() {
-               return self().settings.getBoolean(Keys.web.debugMode, false);
+       @Override
+       public boolean isDebugMode() {
+               return settings.getBoolean(Keys.web.debugMode, false);
        }
 
        /**
@@ -479,8 +351,9 @@ public class GitBlit implements ServletContextListener {
         *
         * @return the file
         */
-       public static File getFileOrFolder(String key, String defaultFileOrFolder) {
-               String fileOrFolder = GitBlit.getString(key, defaultFileOrFolder);
+       @Override
+       public File getFileOrFolder(String key, String defaultFileOrFolder) {
+               String fileOrFolder = settings.getString(key, defaultFileOrFolder);
                return getFileOrFolder(fileOrFolder);
        }
 
@@ -493,9 +366,10 @@ public class GitBlit implements ServletContextListener {
         *
         * @return the file
         */
-       public static File getFileOrFolder(String fileOrFolder) {
+       @Override
+       public File getFileOrFolder(String fileOrFolder) {
                return com.gitblit.utils.FileUtils.resolveParameter(Constants.baseFolder$,
-                               self().baseFolder, fileOrFolder);
+                               baseFolder, fileOrFolder);
        }
 
        /**
@@ -504,7 +378,8 @@ public class GitBlit implements ServletContextListener {
         *
         * @return the repositories folder path
         */
-       public static File getRepositoriesFolder() {
+       @Override
+       public File getRepositoriesFolder() {
                return getFileOrFolder(Keys.git.repositoriesFolder, "${baseFolder}/git");
        }
 
@@ -514,7 +389,8 @@ public class GitBlit implements ServletContextListener {
         *
         * @return the proposals folder path
         */
-       public static File getProposalsFolder() {
+       @Override
+       public File getProposalsFolder() {
                return getFileOrFolder(Keys.federation.proposalsFolder, "${baseFolder}/proposals");
        }
 
@@ -524,20 +400,44 @@ public class GitBlit implements ServletContextListener {
         *
         * @return the Groovy scripts folder path
         */
-       public static File getGroovyScriptsFolder() {
+       @Override
+       public File getHooksFolder() {
                return getFileOrFolder(Keys.groovy.scriptsFolder, "${baseFolder}/groovy");
        }
 
        /**
-        * Updates the list of server settings.
+        * Returns the path of the Groovy Grape folder. This method checks to see if
+        * Gitblit is running on a cloud service and may return an adjusted path.
+        *
+        * @return the Groovy Grape folder path
+        */
+       @Override
+       public File getGrapesFolder() {
+               return getFileOrFolder(Keys.groovy.grapeFolder, "${baseFolder}/groovy/grape");
+       }
+
+       /**
+        * Returns the runtime settings.
+        *
+        * @return runtime settings
+        */
+       @Override
+       public IStoredSettings getSettings() {
+               return settings;
+       }
+
+       /**
+        * Updates the runtime settings.
         *
         * @param settings
         * @return true if the update succeeded
         */
+       @Override
        public boolean updateSettings(Map<String, String> updatedSettings) {
                return settings.saveSettings(updatedSettings);
        }
 
+       @Override
        public ServerStatus getStatus() {
                // update heap memory status
                serverStatus.heapAllocated = Runtime.getRuntime().totalMemory();
@@ -553,6 +453,7 @@ public class GitBlit implements ServletContextListener {
         * @param repository
         * @return a list of repository urls
         */
+       @Override
        public List<RepositoryUrl> getRepositoryUrls(HttpServletRequest request, UserModel user, RepositoryModel repository) {
                if (user == null) {
                        user = UserModel.ANONYMOUS;
@@ -650,6 +551,7 @@ public class GitBlit implements ServletContextListener {
         *
         * @return a collection of client applications
         */
+       @Override
        public Collection<GitClientApplication> getClientApplications() {
                // prefer user definitions, if they exist
                File userDefs = new File(baseFolder, "clientapps.json");
@@ -718,6 +620,7 @@ public class GitBlit implements ServletContextListener {
                this.userService.setup(settings);
        }
 
+       @Override
        public boolean supportsAddUser() {
                return supportsCredentialChanges(new UserModel(""));
        }
@@ -728,6 +631,7 @@ public class GitBlit implements ServletContextListener {
         * @param user
         * @return true if the user service supports credential changes
         */
+       @Override
        public boolean supportsCredentialChanges(UserModel user) {
                if (user == null) {
                        return false;
@@ -746,6 +650,7 @@ public class GitBlit implements ServletContextListener {
         * @param user
         * @return true if the user service supports display name changes
         */
+       @Override
        public boolean supportsDisplayNameChanges(UserModel user) {
                return (user != null && user.isLocalAccount()) || userService.supportsDisplayNameChanges();
        }
@@ -756,6 +661,7 @@ public class GitBlit implements ServletContextListener {
         * @param user
         * @return true if the user service supports email address changes
         */
+       @Override
        public boolean supportsEmailAddressChanges(UserModel user) {
                return (user != null && user.isLocalAccount()) || userService.supportsEmailAddressChanges();
        }
@@ -766,6 +672,7 @@ public class GitBlit implements ServletContextListener {
         * @param user
         * @return true if the user service supports team membership changes
         */
+       @Override
        public boolean supportsTeamMembershipChanges(UserModel user) {
                return (user != null && user.isLocalAccount()) || userService.supportsTeamMembershipChanges();
        }
@@ -790,6 +697,7 @@ public class GitBlit implements ServletContextListener {
         * @param password
         * @return a user object or null
         */
+       @Override
        public UserModel authenticate(String username, char[] password) {
                if (StringUtils.isEmpty(username)) {
                        // can not authenticate empty username
@@ -850,6 +758,7 @@ public class GitBlit implements ServletContextListener {
         * @param httpRequest
         * @return a user object or null
         */
+       @Override
        public UserModel authenticate(HttpServletRequest httpRequest) {
                return authenticate(httpRequest, false);
        }
@@ -864,10 +773,11 @@ public class GitBlit implements ServletContextListener {
         * @param requiresCertificate
         * @return a user object or null
         */
+       @Override
        public UserModel authenticate(HttpServletRequest httpRequest, boolean requiresCertificate) {
                // try to authenticate by certificate
                boolean checkValidity = settings.getBoolean(Keys.git.enforceCertificateValidity, true);
-               String [] oids = getStrings(Keys.git.certificateUsernameOIDs).toArray(new String[0]);
+               String [] oids = settings.getStrings(Keys.git.certificateUsernameOIDs).toArray(new String[0]);
                UserModel model = HttpUtils.getUserModelFromCertificate(httpRequest, checkValidity, oids);
                if (model != null) {
                        // grab real user model and preserve certificate serial number
@@ -921,7 +831,7 @@ public class GitBlit implements ServletContextListener {
                }
 
                // try to authenticate by cookie
-               if (allowCookieAuthentication()) {
+               if (supportsCookies()) {
                        UserModel user = authenticate(httpRequest.getCookies());
                        if (user != null) {
                                flagWicketSession(AuthenticationType.COOKIE);
@@ -985,7 +895,8 @@ public class GitBlit implements ServletContextListener {
         * @param response
         * @param user
         */
-       public void setCookie(WebResponse response, UserModel user) {
+       @Override
+       public void setCookie(HttpServletResponse response, UserModel user) {
                if (userService == null) {
                        return;
                }
@@ -1019,6 +930,7 @@ public class GitBlit implements ServletContextListener {
         *
         * @param user
         */
+       @Override
        public void logout(UserModel user) {
                if (userService == null) {
                        return;
@@ -1052,6 +964,7 @@ public class GitBlit implements ServletContextListener {
         * @see IUserService.getAllUsernames()
         * @return list of all usernames
         */
+       @Override
        public List<String> getAllUsernames() {
                List<String> names = new ArrayList<String>(userService.getAllUsernames());
                return names;
@@ -1063,6 +976,7 @@ public class GitBlit implements ServletContextListener {
         * @see IUserService.getAllUsernames()
         * @return list of all usernames
         */
+       @Override
        public List<UserModel> getAllUsers() {
                List<UserModel> users = userService.getAllUsers();
                return users;
@@ -1075,6 +989,7 @@ public class GitBlit implements ServletContextListener {
         * @param username
         * @return true if successful
         */
+       @Override
        public boolean deleteUser(String username) {
                if (StringUtils.isEmpty(username)) {
                        return false;
@@ -1083,7 +998,8 @@ public class GitBlit implements ServletContextListener {
                return userService.deleteUser(usernameDecoded);
        }
 
-       protected UserModel getFederationUser() {
+       @Override
+       public UserModel getFederationUser() {
                // the federation user is an administrator
                UserModel federationUser = new UserModel(Constants.FEDERATION_USER);
                federationUser.canAdmin = true;
@@ -1097,6 +1013,7 @@ public class GitBlit implements ServletContextListener {
         * @param username
         * @return a user object or null
         */
+       @Override
        public UserModel getUserModel(String username) {
                if (StringUtils.isEmpty(username)) {
                        return null;
@@ -1113,6 +1030,7 @@ public class GitBlit implements ServletContextListener {
         * @param user
         * @return the effective list of permissions for the user
         */
+       @Override
        public List<RegistrantAccessPermission> getUserAccessPermissions(UserModel user) {
                if (StringUtils.isEmpty(user.username)) {
                        // new user
@@ -1123,7 +1041,7 @@ public class GitBlit implements ServletContextListener {
                // Flag missing repositories
                for (RegistrantAccessPermission permission : set) {
                        if (permission.mutable && PermissionType.EXPLICIT.equals(permission.permissionType)) {
-                               RepositoryModel rm = GitBlit.self().getRepositoryModel(permission.registrant);
+                               RepositoryModel rm = getRepositoryModel(permission.registrant);
                                if (rm == null) {
                                        permission.permissionType = PermissionType.MISSING;
                                        permission.mutable = false;
@@ -1158,6 +1076,7 @@ public class GitBlit implements ServletContextListener {
         * @param repository
         * @return a list of RegistrantAccessPermissions
         */
+       @Override
        public List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository) {
                List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
                if (AccessRestrictionType.NONE.equals(repository.accessRestriction)) {
@@ -1185,6 +1104,7 @@ public class GitBlit implements ServletContextListener {
         * @param permissions
         * @return true if the user models have been updated
         */
+       @Override
        public boolean setUserAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions) {
                List<UserModel> users = new ArrayList<UserModel>();
                for (RegistrantAccessPermission up : permissions) {
@@ -1206,6 +1126,7 @@ public class GitBlit implements ServletContextListener {
         * @param repository
         * @return list of all usernames that have an access permission for the repository
         */
+       @Override
        public List<String> getRepositoryUsers(RepositoryModel repository) {
                return userService.getUsernamesForRepositoryRole(repository.name);
        }
@@ -1236,6 +1157,7 @@ public class GitBlit implements ServletContextListener {
         * @param isCreate
         * @throws GitBlitException
         */
+       @Override
        public void updateUserModel(String username, UserModel user, boolean isCreate)
                        throws GitBlitException {
                if (!username.equalsIgnoreCase(user.username)) {
@@ -1283,6 +1205,7 @@ public class GitBlit implements ServletContextListener {
         *
         * @return the list of teams
         */
+       @Override
        public List<TeamModel> getAllTeams() {
                List<TeamModel> teams = userService.getAllTeams();
                return teams;
@@ -1294,6 +1217,7 @@ public class GitBlit implements ServletContextListener {
         * @param teamname
         * @return a TeamModel object or null
         */
+       @Override
        public TeamModel getTeamModel(String teamname) {
                return userService.getTeamModel(teamname);
        }
@@ -1306,6 +1230,7 @@ public class GitBlit implements ServletContextListener {
         * @param repository
         * @return a list of RegistrantAccessPermissions
         */
+       @Override
        public List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository) {
                List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
                for (TeamModel team : userService.getAllTeams()) {
@@ -1325,6 +1250,7 @@ public class GitBlit implements ServletContextListener {
         * @param permissions
         * @return true if the team models have been updated
         */
+       @Override
        public boolean setTeamAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions) {
                List<TeamModel> teams = new ArrayList<TeamModel>();
                for (RegistrantAccessPermission tp : permissions) {
@@ -1346,6 +1272,7 @@ public class GitBlit implements ServletContextListener {
         * @param repository
         * @return list of all teamnames with explicit access permissions to the repository
         */
+       @Override
        public List<String> getRepositoryTeams(RepositoryModel repository) {
                return userService.getTeamnamesForRepositoryRole(repository.name);
        }
@@ -1373,6 +1300,7 @@ public class GitBlit implements ServletContextListener {
         * @param team
         * @param isCreate
         */
+       @Override
        public void updateTeamModel(String teamname, TeamModel team, boolean isCreate)
                        throws GitBlitException {
                if (!teamname.equalsIgnoreCase(team.name)) {
@@ -1394,6 +1322,7 @@ public class GitBlit implements ServletContextListener {
         * @param teamname
         * @return true if successful
         */
+       @Override
        public boolean deleteTeam(String teamname) {
                return userService.deleteTeam(teamname);
        }
@@ -1404,7 +1333,8 @@ public class GitBlit implements ServletContextListener {
         *
         * @param model
         */
-       private void addToCachedRepositoryList(RepositoryModel model) {
+       @Override
+       public void addToCachedRepositoryList(RepositoryModel model) {
                if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
                        repositoryListCache.put(model.name.toLowerCase(), model);
 
@@ -1445,6 +1375,7 @@ public class GitBlit implements ServletContextListener {
         * Resets the repository list cache.
         *
         */
+       @Override
        public void resetRepositoryListCache() {
                logger.info("Repository cache manually reset");
                repositoryListCache.clear();
@@ -1488,6 +1419,7 @@ public class GitBlit implements ServletContextListener {
         *
         * @return list of all repositories
         */
+       @Override
        public List<String> getRepositoryList() {
                if (repositoryListCache.size() == 0 || !isValidRepositoryList()) {
                        // we are not caching OR we have not yet cached OR the cached list is invalid
@@ -1505,7 +1437,7 @@ public class GitBlit implements ServletContextListener {
                        } else {
                                // we are caching this list
                                String msg = "{0} repositories identified in {1} msecs";
-                               if (getBoolean(Keys.web.showRepositorySizes, true)) {
+                               if (settings.getBoolean(Keys.web.showRepositorySizes, true)) {
                                        // optionally (re)calculate repository sizes
                                        msg = "{0} repositories identified with calculated folder sizes in {1} msecs";
                                }
@@ -1544,6 +1476,7 @@ public class GitBlit implements ServletContextListener {
         * @param repositoryName
         * @return repository or null
         */
+       @Override
        public Repository getRepository(String repositoryName) {
                return getRepository(repositoryName, true);
        }
@@ -1555,6 +1488,7 @@ public class GitBlit implements ServletContextListener {
         * @param logError
         * @return repository or null
         */
+       @Override
        public Repository getRepository(String repositoryName, boolean logError) {
                // Decode url-encoded repository name (issue-278)
                // http://stackoverflow.com/questions/17183110
@@ -1588,6 +1522,7 @@ public class GitBlit implements ServletContextListener {
         * @param user
         * @return list of repository models accessible to user
         */
+       @Override
        public List<RepositoryModel> getRepositoryModels(UserModel user) {
                long methodStart = System.currentTimeMillis();
                List<String> list = getRepositoryList();
@@ -1620,6 +1555,7 @@ public class GitBlit implements ServletContextListener {
         * @param repositoryName
         * @return repository model or null
         */
+       @Override
        public RepositoryModel getRepositoryModel(UserModel user, String repositoryName) {
                RepositoryModel model = getRepositoryModel(repositoryName);
                if (model == null) {
@@ -1641,6 +1577,7 @@ public class GitBlit implements ServletContextListener {
         * @param repositoryName
         * @return repository model or null
         */
+       @Override
        public RepositoryModel getRepositoryModel(String repositoryName) {
                // Decode url-encoded repository name (issue-278)
                // http://stackoverflow.com/questions/17183110
@@ -1702,6 +1639,7 @@ public class GitBlit implements ServletContextListener {
         * @param repository
         * @return the star count
         */
+       @Override
        public long getStarCount(RepositoryModel repository) {
                long count = 0;
                for (UserModel user : getAllUsers()) {
@@ -1752,7 +1690,7 @@ public class GitBlit implements ServletContextListener {
                        }
 
                        // project configs
-                       String rootName = GitBlit.getString(Keys.web.repositoryRootGroupName, "main");
+                       String rootName = settings.getString(Keys.web.repositoryRootGroupName, "main");
                        ProjectModel rootProject = new ProjectModel(rootName, true);
 
                        Map<String, ProjectModel> configs = new HashMap<String, ProjectModel>();
@@ -1787,6 +1725,7 @@ public class GitBlit implements ServletContextListener {
         * @param includeUsers
         * @return list of projects that are accessible to the user
         */
+       @Override
        public List<ProjectModel> getProjectModels(UserModel user, boolean includeUsers) {
                Map<String, ProjectModel> configs = getProjectConfigs();
 
@@ -1841,6 +1780,7 @@ public class GitBlit implements ServletContextListener {
         * @param user
         * @return a project model, or null if it does not exist
         */
+       @Override
        public ProjectModel getProjectModel(String name, UserModel user) {
                for (ProjectModel project : getProjectModels(user, true)) {
                        if (project.name.equalsIgnoreCase(name)) {
@@ -1856,6 +1796,7 @@ public class GitBlit implements ServletContextListener {
         * @param name a project name
         * @return a project model or null if the project does not exist
         */
+       @Override
        public ProjectModel getProjectModel(String name) {
                Map<String, ProjectModel> configs = getProjectConfigs();
                ProjectModel project = configs.get(name.toLowerCase());
@@ -1906,6 +1847,7 @@ public class GitBlit implements ServletContextListener {
         * @param includeUsers
         * @return a list of project models
         */
+       @Override
        public List<ProjectModel> getProjectModels(List<RepositoryModel> repositoryModels, boolean includeUsers) {
                Map<String, ProjectModel> projects = new LinkedHashMap<String, ProjectModel>();
                for (RepositoryModel repository : repositoryModels) {
@@ -2090,6 +2032,7 @@ public class GitBlit implements ServletContextListener {
         * @param n
         * @return true if the repository exists
         */
+       @Override
        public boolean hasRepository(String repositoryName) {
                return hasRepository(repositoryName, false);
        }
@@ -2101,6 +2044,7 @@ public class GitBlit implements ServletContextListener {
         * @param caseInsensitive
         * @return true if the repository exists
         */
+       @Override
        public boolean hasRepository(String repositoryName, boolean caseSensitiveCheck) {
                if (!caseSensitiveCheck && settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
                        // if we are caching use the cache to determine availability
@@ -2123,6 +2067,7 @@ public class GitBlit implements ServletContextListener {
         * @param origin
         * @return true the if the user has a fork
         */
+       @Override
        public boolean hasFork(String username, String origin) {
                return getFork(username, origin) != null;
        }
@@ -2135,6 +2080,7 @@ public class GitBlit implements ServletContextListener {
         * @param origin
         * @return the name of the user's fork, null otherwise
         */
+       @Override
        public String getFork(String username, String origin) {
                String userProject = ModelUtils.getPersonalPath(username);
                if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
@@ -2200,6 +2146,7 @@ public class GitBlit implements ServletContextListener {
         * @param repository
         * @return a ForkModel
         */
+       @Override
        public ForkModel getForkNetwork(String repository) {
                if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
                        // find the root, cached
@@ -2263,12 +2210,13 @@ public class GitBlit implements ServletContextListener {
         * @param model
         * @return size in bytes of the repository
         */
+       @Override
        public long updateLastChangeFields(Repository r, RepositoryModel model) {
                LastChange lc = JGitUtils.getLastChange(r);
                model.lastChange = lc.when;
                model.lastChangeAuthor = lc.who;
 
-               if (!getBoolean(Keys.web.showRepositorySizes, true) || model.skipSizeCalculation) {
+               if (!settings.getBoolean(Keys.web.showRepositorySizes, true) || model.skipSizeCalculation) {
                        model.size = null;
                        return 0L;
                }
@@ -2336,6 +2284,7 @@ public class GitBlit implements ServletContextListener {
         * @param repository
         * @return a new array list of metrics
         */
+       @Override
        public List<Metric> getRepositoryDefaultMetrics(RepositoryModel model, Repository repository) {
                if (repositoryMetricsCache.hasCurrent(model.name, model.lastChange)) {
                        return new ArrayList<Metric>(repositoryMetricsCache.getObject(model.name));
@@ -2410,6 +2359,7 @@ public class GitBlit implements ServletContextListener {
         * @param isCreate
         * @throws GitBlitException
         */
+       @Override
        public void updateRepositoryModel(String repositoryName, RepositoryModel repository,
                        boolean isCreate) throws GitBlitException {
                if (gcExecutor.isCollectingGarbage(repositoryName)) {
@@ -2419,7 +2369,7 @@ public class GitBlit implements ServletContextListener {
                Repository r = null;
                String projectPath = StringUtils.getFirstPathElement(repository.name);
                if (!StringUtils.isEmpty(projectPath)) {
-                       if (projectPath.equalsIgnoreCase(getString(Keys.web.repositoryRootGroupName, "main"))) {
+                       if (projectPath.equalsIgnoreCase(settings.getString(Keys.web.repositoryRootGroupName, "main"))) {
                                // strip leading group name
                                repository.name = repository.name.substring(projectPath.length() + 1);
                        }
@@ -2436,7 +2386,7 @@ public class GitBlit implements ServletContextListener {
                        }
                        // create repository
                        logger.info("create repository " + repository.name);
-                       String shared = getString(Keys.git.createRepositoriesShared, "FALSE");
+                       String shared = settings.getString(Keys.git.createRepositoriesShared, "FALSE");
                        r = JGitUtils.createRepository(repositoriesFolder, repository.name, shared);
                } else {
                        // rename repository
@@ -2538,9 +2488,9 @@ public class GitBlit implements ServletContextListener {
 
                        // Adjust permissions in case we updated the config files
                        JGitUtils.adjustSharedPerm(new File(r.getDirectory().getAbsolutePath(), "config"),
-                                       getString(Keys.git.createRepositoriesShared, "FALSE"));
+                                       settings.getString(Keys.git.createRepositoriesShared, "FALSE"));
                        JGitUtils.adjustSharedPerm(new File(r.getDirectory().getAbsolutePath(), "HEAD"),
-                                       getString(Keys.git.createRepositoriesShared, "FALSE"));
+                                       settings.getString(Keys.git.createRepositoriesShared, "FALSE"));
 
                        // close the repository object
                        r.close();
@@ -2560,6 +2510,7 @@ public class GitBlit implements ServletContextListener {
         * @param repository
         *            the Gitblit repository model
         */
+       @Override
        public void updateConfiguration(Repository r, RepositoryModel repository) {
                StoredConfig config = r.getConfig();
                config.setString(Constants.CONFIG_GITBLIT, null, "description", repository.description);
@@ -2659,6 +2610,7 @@ public class GitBlit implements ServletContextListener {
         * @param model
         * @return true if successful
         */
+       @Override
        public boolean deleteRepositoryModel(RepositoryModel model) {
                return deleteRepository(model.name);
        }
@@ -2670,6 +2622,7 @@ public class GitBlit implements ServletContextListener {
         * @param repositoryName
         * @return true if successful
         */
+       @Override
        public boolean deleteRepository(String repositoryName) {
                try {
                        closeRepository(repositoryName);
@@ -2791,8 +2744,9 @@ public class GitBlit implements ServletContextListener {
                return scheduledExecutor;
        }
 
-       public static boolean canFederate() {
-               String passphrase = getString(Keys.federation.passphrase, "");
+       @Override
+       public boolean canFederate() {
+               String passphrase = settings.getString(Keys.federation.passphrase, "");
                return !StringUtils.isEmpty(passphrase);
        }
 
@@ -2835,6 +2789,7 @@ public class GitBlit implements ServletContextListener {
         *
         * @return list of registered gitblit instances
         */
+       @Override
        public List<FederationModel> getFederationRegistrations() {
                if (federationRegistrations.isEmpty()) {
                        federationRegistrations.addAll(FederationUtils.getFederationRegistrations(settings));
@@ -2849,6 +2804,7 @@ public class GitBlit implements ServletContextListener {
         *            the name of the registration
         * @return a federation registration
         */
+       @Override
        public FederationModel getFederationRegistration(String url, String name) {
                // check registrations
                for (FederationModel r : getFederationRegistrations()) {
@@ -2871,6 +2827,7 @@ public class GitBlit implements ServletContextListener {
         *
         * @return list of federation sets
         */
+       @Override
        public List<FederationSet> getFederationSets(String gitblitUrl) {
                List<FederationSet> list = new ArrayList<FederationSet>();
                // generate standard tokens
@@ -2894,6 +2851,7 @@ public class GitBlit implements ServletContextListener {
         *
         * @return list of federation tokens
         */
+       @Override
        public List<String> getFederationTokens() {
                List<String> tokens = new ArrayList<String>();
                // generate standard tokens
@@ -2913,6 +2871,7 @@ public class GitBlit implements ServletContextListener {
         * @param type
         * @return a federation token
         */
+       @Override
        public String getFederationToken(FederationToken type) {
                return getFederationToken(type.name());
        }
@@ -2923,6 +2882,7 @@ public class GitBlit implements ServletContextListener {
         * @param value
         * @return a federation token
         */
+       @Override
        public String getFederationToken(String value) {
                String passphrase = settings.getString(Keys.federation.passphrase, "");
                return StringUtils.getSHA1(passphrase + "-" + value);
@@ -2936,6 +2896,7 @@ public class GitBlit implements ServletContextListener {
         * @param token
         * @return true if the request can be executed
         */
+       @Override
        public boolean validateFederationRequest(FederationRequest req, String token) {
                String all = getFederationToken(FederationToken.ALL);
                String unr = getFederationToken(FederationToken.USERS_AND_REPOSITORIES);
@@ -2964,6 +2925,7 @@ public class GitBlit implements ServletContextListener {
         *            the registration from the pulling Gitblit instance
         * @return true if acknowledged
         */
+       @Override
        public boolean acknowledgeFederationStatus(String identification, FederationModel registration) {
                // reset the url to the identification of the pulling Gitblit instance
                registration.url = identification;
@@ -2980,6 +2942,7 @@ public class GitBlit implements ServletContextListener {
         *
         * @return the list of registration results
         */
+       @Override
        public List<FederationModel> getFederationResultRegistrations() {
                return new ArrayList<FederationModel>(federationPullResults.values());
        }
@@ -2995,6 +2958,7 @@ public class GitBlit implements ServletContextListener {
         *            administrators
         * @return true if the proposal was submitted
         */
+       @Override
        public boolean submitFederationProposal(FederationProposal proposal, String gitblitUrl) {
                // convert proposal to json
                String json = JsonUtils.toJsonString(proposal);
@@ -3022,6 +2986,7 @@ public class GitBlit implements ServletContextListener {
         *
         * @return list of federation proposals
         */
+       @Override
        public List<FederationProposal> getPendingFederationProposals() {
                List<FederationProposal> list = new ArrayList<FederationProposal>();
                File folder = getProposalsFolder();
@@ -3052,9 +3017,10 @@ public class GitBlit implements ServletContextListener {
         *            the federation token
         * @return a map of <cloneurl, RepositoryModel>
         */
+       @Override
        public Map<String, RepositoryModel> getRepositories(String gitblitUrl, String token) {
                Map<String, String> federationSets = new HashMap<String, String>();
-               for (String set : getStrings(Keys.federation.sets)) {
+               for (String set : settings.getStrings(Keys.federation.sets)) {
                        federationSets.put(getFederationToken(set), set);
                }
 
@@ -3110,6 +3076,7 @@ public class GitBlit implements ServletContextListener {
         * @param token
         * @return a potential proposal
         */
+       @Override
        public FederationProposal createFederationProposal(String gitblitUrl, String token) {
                FederationToken tokenType = FederationToken.REPOSITORIES;
                for (FederationToken type : FederationToken.values()) {
@@ -3130,6 +3097,7 @@ public class GitBlit implements ServletContextListener {
         * @param token
         * @return the specified proposal or null
         */
+       @Override
        public FederationProposal getPendingFederationProposal(String token) {
                List<FederationProposal> list = getPendingFederationProposals();
                for (FederationProposal proposal : list) {
@@ -3147,6 +3115,7 @@ public class GitBlit implements ServletContextListener {
         *            proposal
         * @return true if the proposal was deleted
         */
+       @Override
        public boolean deletePendingFederationProposal(FederationProposal proposal) {
                File folder = getProposalsFolder();
                File file = new File(folder, proposal.token + Constants.PROPOSAL_EXT);
@@ -3159,8 +3128,9 @@ public class GitBlit implements ServletContextListener {
         *
         * @return list of available hook scripts
         */
+       @Override
        public List<String> getAllScripts() {
-               File groovyFolder = getGroovyScriptsFolder();
+               File groovyFolder = getHooksFolder();
                File[] files = groovyFolder.listFiles(new FileFilter() {
                        @Override
                        public boolean accept(File pathname) {
@@ -3185,10 +3155,11 @@ public class GitBlit implements ServletContextListener {
         *            if null only the globally specified scripts are returned
         * @return a list of scripts
         */
+       @Override
        public List<String> getPreReceiveScriptsInherited(RepositoryModel repository) {
                Set<String> scripts = new LinkedHashSet<String>();
                // Globals
-               for (String script : getStrings(Keys.groovy.preReceiveScripts)) {
+               for (String script : settings.getStrings(Keys.groovy.preReceiveScripts)) {
                        if (script.endsWith(".groovy")) {
                                scripts.add(script.substring(0, script.lastIndexOf('.')));
                        } else {
@@ -3217,6 +3188,7 @@ public class GitBlit implements ServletContextListener {
         *            optional parameter
         * @return list of available hook scripts
         */
+       @Override
        public List<String> getPreReceiveScriptsUnused(RepositoryModel repository) {
                Set<String> inherited = new TreeSet<String>(getPreReceiveScriptsInherited(repository));
 
@@ -3238,10 +3210,11 @@ public class GitBlit implements ServletContextListener {
         *            if null only the globally specified scripts are returned
         * @return a list of scripts
         */
+       @Override
        public List<String> getPostReceiveScriptsInherited(RepositoryModel repository) {
                Set<String> scripts = new LinkedHashSet<String>();
                // Global Scripts
-               for (String script : getStrings(Keys.groovy.postReceiveScripts)) {
+               for (String script : settings.getStrings(Keys.groovy.postReceiveScripts)) {
                        if (script.endsWith(".groovy")) {
                                scripts.add(script.substring(0, script.lastIndexOf('.')));
                        } else {
@@ -3269,6 +3242,7 @@ public class GitBlit implements ServletContextListener {
         *            optional parameter
         * @return list of available hook scripts
         */
+       @Override
        public List<String> getPostReceiveScriptsUnused(RepositoryModel repository) {
                Set<String> inherited = new TreeSet<String>(getPostReceiveScriptsInherited(repository));
 
@@ -3291,6 +3265,7 @@ public class GitBlit implements ServletContextListener {
         * @param repositories
         * @return
         */
+       @Override
        public List<SearchResult> search(String query, int page, int pageSize, List<String> repositories) {
                List<SearchResult> srs = luceneExecutor.search(query, page, pageSize, repositories);
                return srs;
@@ -3302,6 +3277,7 @@ public class GitBlit implements ServletContextListener {
         * @param subject
         * @param message
         */
+       @Override
        public void sendMailToAdministrators(String subject, String message) {
                List<String> toAddresses = settings.getStrings(Keys.mail.adminAddresses);
                sendMail(subject, message, toAddresses);
@@ -3314,6 +3290,7 @@ public class GitBlit implements ServletContextListener {
         * @param message
         * @param toAddresses
         */
+       @Override
        public void sendMail(String subject, String message, Collection<String> toAddresses) {
                this.sendMail(subject, message, toAddresses.toArray(new String[0]));
        }
@@ -3325,6 +3302,7 @@ public class GitBlit implements ServletContextListener {
         * @param message
         * @param toAddresses
         */
+       @Override
        public void sendMail(String subject, String message, String... toAddresses) {
                if (toAddresses == null || toAddresses.length == 0) {
                        logger.debug(MessageFormat.format("Dropping message {0} because there are no recipients", subject));
@@ -3358,6 +3336,7 @@ public class GitBlit implements ServletContextListener {
         * @param message
         * @param toAddresses
         */
+       @Override
        public void sendHtmlMail(String subject, String message, Collection<String> toAddresses) {
                this.sendHtmlMail(subject, message, toAddresses.toArray(new String[0]));
        }
@@ -3369,6 +3348,7 @@ public class GitBlit implements ServletContextListener {
         * @param message
         * @param toAddresses
         */
+       @Override
        public void sendHtmlMail(String subject, String message, String... toAddresses) {
                if (toAddresses == null || toAddresses.length == 0) {
                        logger.debug(MessageFormat.format("Dropping message {0} because there are no recipients", subject));
@@ -3400,6 +3380,7 @@ public class GitBlit implements ServletContextListener {
         *
         * @return SettingsModel
         */
+       @Override
        public ServerSettings getSettingsModel() {
                // ensure that the current values are updated in the setting models
                for (String key : settings.getAllKeys(null)) {
@@ -3524,7 +3505,7 @@ public class GitBlit implements ServletContextListener {
                logTimezone("JVM", TimeZone.getDefault());
                logTimezone(Constants.NAME, getTimezone());
 
-               serverStatus = new ServerStatus(isGO());
+               serverStatus = new ServerStatus(goSettings != null);
 
                if (this.userService == null) {
                        String realm = settings.getString(Keys.realm.userService, "${baseFolder}/users.properties");
@@ -3899,6 +3880,7 @@ public class GitBlit implements ServletContextListener {
         *
         * @return true if we are running the gc executor
         */
+       @Override
        public boolean isCollectingGarbage() {
                return gcExecutor.isRunning();
        }
@@ -3909,6 +3891,7 @@ public class GitBlit implements ServletContextListener {
         * @param repositoryName
         * @return true if actively collecting garbage
         */
+       @Override
        public boolean isCollectingGarbage(String repositoryName) {
                return gcExecutor.isCollectingGarbage(repositoryName);
        }
@@ -3923,6 +3906,7 @@ public class GitBlit implements ServletContextListener {
         * @return the repository model of the fork, if successful
         * @throws GitBlitException
         */
+       @Override
        public RepositoryModel fork(RepositoryModel repository, UserModel user) throws GitBlitException {
                String cloneName = MessageFormat.format("{0}/{1}.git", user.getPersonalPath(), StringUtils.stripDotGit(StringUtils.getLastPathElement(repository.name)));
                String fromUrl = MessageFormat.format("file://{0}/{1}", repositoriesFolder.getAbsolutePath(), repository.name);
@@ -3990,7 +3974,89 @@ public class GitBlit implements ServletContextListener {
         *
         * @return status of Cookie authentication enablement.
         */
-       public boolean allowCookieAuthentication() {
-               return GitBlit.getBoolean(Keys.web.allowCookieAuthentication, true) && userService.supportsCookies();
+       @Override
+       public boolean supportsCookies() {
+               return settings.getBoolean(Keys.web.allowCookieAuthentication, true) && userService.supportsCookies();
+       }
+
+       @Override
+       public String getCookie(UserModel model) {
+               return userService.getCookie(model);
+       }
+
+       @Override
+       public UserModel authenticate(char[] cookie) {
+               return userService.authenticate(cookie);
+       }
+
+       @Override
+       public boolean updateUserModel(UserModel model) {
+               return userService.updateUserModel(model);
+       }
+
+       @Override
+       public boolean updateUserModels(Collection<UserModel> models) {
+               return userService.updateUserModels(models);
+       }
+
+       @Override
+       public boolean updateUserModel(String username, UserModel model) {
+               return userService.updateUserModel(username, model);
+       }
+
+       @Override
+       public boolean deleteUserModel(UserModel model) {
+               return userService.deleteUserModel(model);
+       }
+
+       @Override
+       public List<String> getAllTeamNames() {
+               return userService.getAllTeamNames();
+       }
+
+       @Override
+       public List<String> getTeamnamesForRepositoryRole(String role) {
+               return userService.getTeamnamesForRepositoryRole(role);
+       }
+
+       @Override
+       public boolean updateTeamModel(TeamModel model) {
+               return userService.updateTeamModel(model);
+       }
+
+       @Override
+       public boolean updateTeamModels(Collection<TeamModel> models) {
+               return userService.updateTeamModels(models);
+       }
+
+       @Override
+       public boolean updateTeamModel(String teamname, TeamModel model) {
+               return userService.updateTeamModel(teamname, model);
+       }
+
+       @Override
+       public boolean deleteTeamModel(TeamModel model) {
+               return userService.deleteTeamModel(model);
+       }
+
+       @Override
+       public List<String> getUsernamesForRepositoryRole(String role) {
+               return userService.getUsernamesForRepositoryRole(role);
+       }
+
+       @Override
+       public boolean renameRepositoryRole(String oldRole, String newRole) {
+               return userService.renameRepositoryRole(oldRole, newRole);
+       }
+
+       @Override
+       public boolean deleteRepositoryRole(String role) {
+               return userService.deleteRepositoryRole(role);
+       }
+
+       @Override
+       public void logout(HttpServletResponse response, UserModel user) {
+               setCookie(response,  null);
+               userService.logout(user);
        }
 }
index 0c5000cfe250d1e34cb95ce09ab103201a7c76fd..ecb10011e41c737e597f45935b90c7ed9512433f 100644 (file)
@@ -410,7 +410,7 @@ public class GitBlitServer {
                }\r
 \r
                // Setup the GitBlit context\r
-               GitBlit gitblit = getGitBlitInstance();\r
+               GitBlit gitblit = newGitblit(settings, baseFolder);\r
                gitblit.configureContext(settings, baseFolder, true);\r
                rootContext.addEventListener(gitblit);\r
 \r
@@ -430,8 +430,8 @@ public class GitBlitServer {
                }\r
        }\r
 \r
-       protected GitBlit getGitBlitInstance() {\r
-               return GitBlit.self();\r
+       protected GitBlit newGitblit(IStoredSettings settings, File baseFolder) {\r
+               return new GitBlit(settings, baseFolder);\r
        }\r
 \r
        /**\r
index 5e18f5fdf7a8a4a0f4731b6f8037a4367562ff43..f52963f74e6e94706c3b0a6070b424af791bc3d9 100644 (file)
@@ -19,6 +19,8 @@ import java.text.MessageFormat;
 \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.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.StringUtils;\r
@@ -100,7 +102,8 @@ public class GitFilter extends AccessRestrictionFilter {
         */\r
        @Override\r
        protected boolean isCreationAllowed() {\r
-               return GitBlit.getBoolean(Keys.git.allowCreateOnPush, true);\r
+               IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+               return settings.getBoolean(Keys.git.allowCreateOnPush, true);\r
        }\r
 \r
        /**\r
@@ -119,7 +122,8 @@ public class GitFilter extends AccessRestrictionFilter {
 \r
        @Override\r
        protected boolean requiresClientCertificate() {\r
-               return GitBlit.getBoolean(Keys.git.requiresClientCertificate, false);\r
+               IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+               return settings.getBoolean(Keys.git.requiresClientCertificate, false);\r
        }\r
 \r
        /**\r
@@ -152,7 +156,8 @@ public class GitFilter extends AccessRestrictionFilter {
         */\r
        @Override\r
        protected boolean canAccess(RepositoryModel repository, UserModel user, String action) {\r
-               if (!GitBlit.getBoolean(Keys.git.enableGitServlet, true)) {\r
+               IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();\r
+               if (!settings.getBoolean(Keys.git.enableGitServlet, true)) {\r
                        // Git Servlet disabled\r
                        return false;\r
                }\r
@@ -223,15 +228,17 @@ public class GitFilter extends AccessRestrictionFilter {
                                        model.accessRestriction = AccessRestrictionType.VIEW;\r
                                } else {\r
                                        // common repository, user default server settings\r
-                                       model.authorizationControl = AuthorizationControl.fromName(GitBlit.getString(Keys.git.defaultAuthorizationControl, ""));\r
-                                       model.accessRestriction = AccessRestrictionType.fromName(GitBlit.getString(Keys.git.defaultAccessRestriction, "PUSH"));\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
-                                       GitBlit.self().updateRepositoryModel(model.name, model, true);\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 GitBlit.self().getRepositoryModel(model.name);\r
+                                       return repositoryManager.getRepositoryModel(model.name);\r
                                } catch (GitBlitException e) {\r
                                        logger.error(MessageFormat.format("{0} failed to create repository {1} ON-PUSH!", user.username, model.name), e);\r
                                }\r
index 677d63aefd9419692b206bbd98165607b1085062..ba4c9c5d9285b656e35e4e262bc2769bcd1ef51f 100644 (file)
@@ -25,6 +25,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;\r
 \r
 import com.gitblit.Constants.AccountType;\r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.models.TeamModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.DeepCopier;\r
@@ -59,7 +60,8 @@ public class GitblitUserService implements IUserService {
 \r
        @Override\r
        public void setup(IStoredSettings settings) {\r
-               File realmFile = GitBlit.getFileOrFolder(Keys.realm.userService, "${baseFolder}/users.conf");\r
+               IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+               File realmFile = runtimeManager.getFileOrFolder(Keys.realm.userService, "${baseFolder}/users.conf");\r
                serviceImpl = createUserService(realmFile);\r
                logger.info("GUS delegating to " + serviceImpl.toString());\r
        }\r
index 881f843a7e463623dadf023f6b65defcb93b3763..a98777b94a2efb3caf9cd043de8a194f33a652ed 100644 (file)
@@ -33,6 +33,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.gitblit.Constants.AccountType;
+import com.gitblit.manager.IRuntimeManager;
 import com.gitblit.models.UserModel;
 import com.gitblit.utils.ArrayUtils;
 import com.gitblit.utils.StringUtils;
@@ -125,8 +126,9 @@ public class HtpasswdUserService extends GitblitUserService
         this.settings = settings;
 
         // This is done in two steps in order to avoid calling GitBlit.getFileOrFolder(String, String) which will segfault for unit tests.
+        IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);
         String file = settings.getString(KEY_BACKING_US, DEFAULT_BACKING_US);
-        File realmFile = GitBlit.getFileOrFolder(file);
+        File realmFile = runtimeManager.getFileOrFolder(file);
         serviceImpl = createUserService(realmFile);
         logger.info("Htpasswd User Service backed by " + serviceImpl.toString());
 
@@ -291,7 +293,8 @@ public class HtpasswdUserService extends GitblitUserService
         if ( !file.equals(htpasswdFilePath) ) {
             // The htpasswd file setting changed. Rediscover the file.
             this.htpasswdFilePath = file;
-            this.htpasswdFile = GitBlit.getFileOrFolder(file);
+            IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);
+            this.htpasswdFile = runtimeManager.getFileOrFolder(file);
             this.htUsers.clear();
             this.forceReload = true;
         }
index 33c36ac550dea978fec932a6f56ab35c92033a8d..01c478f8d586f10f3ff4dd6ac8289b5849a65fea 100644 (file)
@@ -332,6 +332,16 @@ public abstract class IStoredSettings {
                overrides.put(key, "" + value);\r
        }\r
 \r
+       /**\r
+        * Override the specified key with the specified value.\r
+        *\r
+        * @param key\r
+        * @param value\r
+        */\r
+       public void overrideSetting(String key, boolean value) {\r
+               overrides.put(key, "" + value);\r
+       }\r
+\r
        /**\r
         * Updates the values for the specified keys and persists the entire\r
         * configuration file.\r
index 888d13c4be30e6caedf2b1697b279fb44e2d2663..e6951b40856b18c7dec5e16ac159fc1bea6241ae 100644 (file)
@@ -31,6 +31,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;\r
 \r
 import com.gitblit.Constants.AccountType;\r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.models.TeamModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.ArrayUtils;\r
@@ -83,7 +84,8 @@ public class LdapUserService extends GitblitUserService {
        public void setup(IStoredSettings settings) {\r
                this.settings = settings;\r
                String file = settings.getString(Keys.realm.ldap.backingUserService, "${baseFolder}/users.conf");\r
-               File realmFile = GitBlit.getFileOrFolder(file);\r
+               IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+               File realmFile = runtimeManager.getFileOrFolder(file);\r
 \r
                serviceImpl = createUserService(realmFile);\r
                logger.info("LDAP User Service backed by " + serviceImpl.toString());\r
index eb167e72e154e8b7e9506d843a57797c57cbfe1e..4222f8ff327356e07189d9eb8e89e884d2fce4ea 100644 (file)
@@ -27,6 +27,8 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;\r
 import javax.servlet.http.HttpServletResponse;\r
 \r
+import com.gitblit.manager.IRuntimeManager;\r
+\r
 /**\r
  * Handles requests for logo.png\r
  *\r
@@ -45,7 +47,8 @@ public class LogoServlet extends HttpServlet {
 \r
        @Override\r
        protected long getLastModified(HttpServletRequest req) {\r
-               File file = GitBlit.getFileOrFolder(Keys.web.headerLogo, "${baseFolder}/logo.png");\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
                } else {\r
@@ -59,7 +62,8 @@ public class LogoServlet extends HttpServlet {
                InputStream is = null;\r
                try {\r
                        String contentType = null;\r
-                       File file = GitBlit.getFileOrFolder(Keys.web.headerLogo, "${baseFolder}/logo.png");\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
                                ServletContext context = request.getSession().getServletContext();\r
@@ -88,7 +92,7 @@ public class LogoServlet extends HttpServlet {
                } catch (Exception e) {\r
                        e.printStackTrace();\r
                } finally {\r
-                       if(is != null) {\r
+                       if (is != null) {\r
                                is.close();\r
                        }\r
                }\r
index 28523cef18ba1e684325beac3890c317b6b7d1b1..19395b3bb82675590a03fa043f361a553772cab1 100644 (file)
@@ -85,6 +85,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;\r
 \r
 import com.gitblit.Constants.SearchObjectType;\r
+import com.gitblit.manager.IRepositoryManager;\r
 import com.gitblit.models.PathModel.PathChangeModel;\r
 import com.gitblit.models.RefModel;\r
 import com.gitblit.models.RepositoryModel;\r
@@ -160,17 +161,18 @@ public class LuceneExecutor implements Runnable {
                String exts = storedSettings.getString(Keys.web.luceneIgnoreExtensions, luceneIgnoreExtensions);\r
                excludedExtensions = new TreeSet<String>(StringUtils.getStringsFromValue(exts));\r
 \r
-               if (GitBlit.self().isCollectingGarbage()) {\r
+               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+               if (repositoryManager.isCollectingGarbage()) {\r
                        // busy collecting garbage, try again later\r
                        return;\r
                }\r
 \r
-               for (String repositoryName: GitBlit.self().getRepositoryList()) {\r
-                       RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
+               for (String repositoryName: repositoryManager.getRepositoryList()) {\r
+                       RepositoryModel model = repositoryManager.getRepositoryModel(repositoryName);\r
                        if (model.hasCommits && !ArrayUtils.isEmpty(model.indexedBranches)) {\r
-                               Repository repository = GitBlit.self().getRepository(model.name);\r
+                               Repository repository = repositoryManager.getRepository(model.name);\r
                                if (repository == null) {\r
-                                       if (GitBlit.self().isCollectingGarbage(model.name)) {\r
+                                       if (repositoryManager.isCollectingGarbage(model.name)) {\r
                                                logger.info(MessageFormat.format("Skipping Lucene index of {0}, busy garbage collecting", repositoryName));\r
                                        }\r
                                        continue;\r
index 21c194f6397e5e9641353028b3aabff7f3a1d43a..a96c955f1bc1c93ce4c24726fa82c0066c50ab55 100644 (file)
@@ -33,6 +33,7 @@ import org.eclipse.jgit.transport.TrackingRefUpdate;
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
+import com.gitblit.manager.IRepositoryManager;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.JGitUtils;\r
@@ -83,25 +84,27 @@ public class MirrorExecutor implements Runnable {
 \r
                running.set(true);\r
 \r
-               for (String repositoryName : GitBlit.self().getRepositoryList()) {\r
+               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+\r
+               for (String repositoryName : repositoryManager.getRepositoryList()) {\r
                        if (forceClose.get()) {\r
                                break;\r
                        }\r
-                       if (GitBlit.self().isCollectingGarbage(repositoryName)) {\r
+                       if (repositoryManager.isCollectingGarbage(repositoryName)) {\r
                                logger.debug("mirror is skipping {} garbagecollection", repositoryName);\r
                                continue;\r
                        }\r
                        RepositoryModel model = null;\r
                        Repository repository = null;\r
                        try {\r
-                               model = GitBlit.self().getRepositoryModel(repositoryName);\r
+                               model = repositoryManager.getRepositoryModel(repositoryName);\r
                                if (!model.isMirror && !model.isBare) {\r
                                        // repository must be a valid bare git mirror\r
                                        logger.debug("mirror is skipping {} !mirror !bare", repositoryName);\r
                                        continue;\r
                                }\r
 \r
-                               repository = GitBlit.self().getRepository(repositoryName);\r
+                               repository = repositoryManager.getRepository(repositoryName);\r
                                if (repository == null) {\r
                                        logger.warn(MessageFormat.format("MirrorExecutor is missing repository {0}?!?", repositoryName));\r
                                        continue;\r
index 2134023d26fefd8758f61672cfb88a8ec88eef2c..e6ab04a897e010ed4b83412d480e9bb4a789abc3 100644 (file)
@@ -24,6 +24,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;\r
 \r
 import com.gitblit.Constants.AccountType;\r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.ArrayUtils;\r
 import com.gitblit.utils.StringUtils;\r
@@ -48,7 +49,8 @@ public class PAMUserService extends GitblitUserService {
         this.settings = settings;\r
 \r
         String file = settings.getString(Keys.realm.pam.backingUserService, "${baseFolder}/users.conf");\r
-        File realmFile = GitBlit.getFileOrFolder(file);\r
+        IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+        File realmFile = runtimeManager.getFileOrFolder(file);\r
 \r
         serviceImpl = createUserService(realmFile);\r
         logger.info("PAM User Service backed by " + serviceImpl.toString());\r
index e8deb5d24dc68d809427083b88f0bee34a931252..a42d8a4a826722e4a4f47b3025bacdf0bc3eaef3 100644 (file)
@@ -18,6 +18,7 @@ package com.gitblit;
 import org.eclipse.jgit.lib.Repository;\r
 \r
 import com.gitblit.Constants.AccessRestrictionType;\r
+import com.gitblit.manager.IRepositoryManager;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 \r
@@ -49,7 +50,8 @@ public class PagesFilter extends AccessRestrictionFilter {
                        } else {\r
                                repository = url.substring(0, slash);\r
                        }\r
-                       r = GitBlit.self().getRepository(repository, false);\r
+                       IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+                       r = repositoryManager.getRepository(repository, false);\r
                        if (r == null) {\r
                                // try again\r
                                offset = slash + 1;\r
index 3ed5b262563cc921475cb44649dfc7e49bb75f87..5569ab3949c405c1f35fde9805c7100fdc525f94 100644 (file)
@@ -35,6 +35,8 @@ import org.eclipse.jgit.revwalk.RevTree;
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.models.PathModel;\r
 import com.gitblit.models.RefModel;\r
 import com.gitblit.utils.ArrayUtils;\r
@@ -99,6 +101,9 @@ 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
@@ -111,7 +116,7 @@ public class PagesServlet extends HttpServlet {
                        } else {\r
                                repository = path.substring(0, slash);\r
                        }\r
-                       r = GitBlit.self().getRepository(repository, false);\r
+                       r = repositoryManager.getRepository(repository, false);\r
                        offset = slash + 1;\r
                        if (offset > 0) {\r
                                resource = path.substring(offset);\r
@@ -148,8 +153,8 @@ public class PagesServlet extends HttpServlet {
                                return;\r
                        }\r
 \r
-                       MarkupProcessor processor = new MarkupProcessor(GitBlit.getSettings());\r
-                       String [] encodings = GitBlit.getEncodings();\r
+                       MarkupProcessor processor = new MarkupProcessor(settings);\r
+                       String [] encodings = settings.getStrings(Keys.web.blobEncodings).toArray(new String[0]);\r
 \r
                        RevTree tree = commit.getTree();\r
 \r
index f1a6742f4812c9580554a37daebb9db6e73634fc..1148925b61ad576115d9ab1e9cb2bb19314ee0af 100644 (file)
@@ -25,6 +25,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;\r
 \r
 import com.gitblit.Constants.AccountType;\r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.ArrayUtils;\r
 import com.gitblit.utils.ConnectionUtils;\r
@@ -63,7 +64,8 @@ public class RedmineUserService extends GitblitUserService {
         this.settings = settings;\r
 \r
         String file = settings.getString(Keys.realm.redmine.backingUserService, "${baseFolder}/users.conf");\r
-        File realmFile = GitBlit.getFileOrFolder(file);\r
+        IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+        File realmFile = runtimeManager.getFileOrFolder(file);\r
 \r
         serviceImpl = createUserService(realmFile);\r
         logger.info("Redmine User Service backed by " + serviceImpl.toString());\r
index dfc06b5d8ade8efb4e691ddba7996dbf8af9d90f..6a7c02d30eb1729333f5bf4a3feae22493b8e140 100644 (file)
@@ -23,6 +23,7 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;\r
 import javax.servlet.http.HttpServletResponse;\r
 \r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.utils.FileUtils;\r
 \r
 /**\r
@@ -54,7 +55,8 @@ 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
-               File file = GitBlit.getFileOrFolder(Keys.web.robots.txt, null);\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
                        content = FileUtils.readContent(file, "\n");\r
index 4c9e12b161c0fe96bc70aca980777a2fbfb001fb..161af9d59d89d87bdac743f568276a1658179138 100644 (file)
@@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;\r
 \r
 import com.gitblit.Constants.RpcRequest;\r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.models.UserModel;\r
 \r
 /**\r
@@ -64,17 +65,20 @@ 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
-               if (!GitBlit.getBoolean(Keys.web.enableRpcServlet, true)) {\r
+               if (!settings.getBoolean(Keys.web.enableRpcServlet, true)) {\r
                        logger.warn(Keys.web.enableRpcServlet + " must be set TRUE for rpc requests.");\r
                        httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);\r
                        return;\r
                }\r
 \r
-               boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, false);\r
-               boolean authenticateAdmin = GitBlit.getBoolean(Keys.web.authenticateAdminPages, true);\r
+               boolean authenticateView = settings.getBoolean(Keys.web.authenticateViewPages, false);\r
+               boolean authenticateAdmin = settings.getBoolean(Keys.web.authenticateAdminPages, true);\r
 \r
                // Wrap the HttpServletRequest with the RpcServletRequest which\r
                // overrides the servlet container user principal methods.\r
@@ -85,7 +89,7 @@ public class RpcFilter extends AuthenticationFilter {
                }\r
 \r
                // conditionally reject rpc management/administration requests\r
-               if (adminRequest && !GitBlit.getBoolean(Keys.web.enableRpcManagement, false)) {\r
+               if (adminRequest && !settings.getBoolean(Keys.web.enableRpcManagement, false)) {\r
                        logger.warn(MessageFormat.format("{0} must be set TRUE for {1} rpc requests.",\r
                                        Keys.web.enableRpcManagement, requestType.toString()));\r
                        httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);\r
@@ -96,7 +100,7 @@ public class RpcFilter extends AuthenticationFilter {
                if ((adminRequest && authenticateAdmin) || (!adminRequest && authenticateView)) {\r
                        if (user == null) {\r
                                // challenge client to provide credentials. send 401.\r
-                               if (GitBlit.isDebugMode()) {\r
+                               if (runtimeManager.isDebugMode()) {\r
                                        logger.info(MessageFormat.format("RPC: CHALLENGE {0}", fullUrl));\r
 \r
                                }\r
@@ -115,7 +119,7 @@ public class RpcFilter extends AuthenticationFilter {
                                        return;\r
                                }\r
                                // valid user, but not for requested access. send 403.\r
-                               if (GitBlit.isDebugMode()) {\r
+                               if (runtimeManager.isDebugMode()) {\r
                                        logger.info(MessageFormat.format("RPC: {0} forbidden to access {1}",\r
                                                        user.username, fullUrl));\r
                                }\r
@@ -124,7 +128,7 @@ public class RpcFilter extends AuthenticationFilter {
                        }\r
                }\r
 \r
-               if (GitBlit.isDebugMode()) {\r
+               if (runtimeManager.isDebugMode()) {\r
                        logger.info(MessageFormat.format("RPC: {0} ({1}) unauthenticated", fullUrl,\r
                                        HttpServletResponse.SC_CONTINUE));\r
                }\r
index 8b48fbe5a26507417dfc290394aea2b4c2fd6d7a..a8fa6f8393c018a22e4537b1aced789676248d08 100644 (file)
@@ -30,6 +30,11 @@ import javax.servlet.http.HttpServletResponse;
 import org.eclipse.jgit.lib.Repository;\r
 \r
 import com.gitblit.Constants.RpcRequest;\r
+import com.gitblit.manager.IFederationManager;\r
+import com.gitblit.manager.IGitblitManager;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
+import com.gitblit.manager.IUserManager;\r
 import com.gitblit.models.RefModel;\r
 import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.RepositoryModel;\r
@@ -74,13 +79,20 @@ 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
-                               && GitBlit.getBoolean(Keys.web.enableRpcManagement, false);\r
+                               && settings.getBoolean(Keys.web.enableRpcManagement, false);\r
 \r
                boolean allowAdmin = user != null && user.canAdmin()\r
-                               && GitBlit.getBoolean(Keys.web.enableRpcAdministration, false);\r
+                               && settings.getBoolean(Keys.web.enableRpcAdministration, false);\r
 \r
                Object result = null;\r
                if (RpcRequest.GET_PROTOCOL.equals(reqType)) {\r
@@ -96,7 +108,7 @@ public class RpcServlet extends JsonServlet {
                        String cloneUrl = sb.toString();\r
 \r
                        // list repositories\r
-                       List<RepositoryModel> list = GitBlit.self().getRepositoryModels(user);\r
+                       List<RepositoryModel> list = repositoryManager.getRepositoryModels(user);\r
                        Map<String, RepositoryModel> repositories = new HashMap<String, RepositoryModel>();\r
                        for (RepositoryModel model : list) {\r
                                String url = MessageFormat.format(cloneUrl, model.name);\r
@@ -106,7 +118,7 @@ public class RpcServlet extends JsonServlet {
                } else if (RpcRequest.LIST_BRANCHES.equals(reqType)) {\r
                        // list all local branches in all repositories accessible to user\r
                        Map<String, List<String>> localBranches = new HashMap<String, List<String>>();\r
-                       List<RepositoryModel> models = GitBlit.self().getRepositoryModels(user);\r
+                       List<RepositoryModel> models = repositoryManager.getRepositoryModels(user);\r
                        for (RepositoryModel model : models) {\r
                                if (!model.hasCommits) {\r
                                        // skip empty repository\r
@@ -118,7 +130,7 @@ public class RpcServlet extends JsonServlet {
                                        continue;\r
                                }\r
                                // get local branches\r
-                               Repository repository = GitBlit.self().getRepository(model.name);\r
+                               Repository repository = repositoryManager.getRepository(model.name);\r
                                List<RefModel> refs = JGitUtils.getLocalBranches(repository, false, -1);\r
                                if (model.showRemoteBranches) {\r
                                        // add remote branches if repository displays them\r
@@ -146,7 +158,7 @@ public class RpcServlet extends JsonServlet {
                        } else {\r
                                if (user.canAdmin() || objectName.equals(user.username)) {\r
                                        // return the specified user\r
-                                       UserModel requestedUser = GitBlit.self().getUserModel(objectName);\r
+                                       UserModel requestedUser = userManager.getUserModel(objectName);\r
                                        if (requestedUser == null) {\r
                                                response.setStatus(failureCode);\r
                                        } else {\r
@@ -158,25 +170,25 @@ public class RpcServlet extends JsonServlet {
                        }\r
                } else if (RpcRequest.LIST_USERS.equals(reqType)) {\r
                        // list users\r
-                       List<String> names = GitBlit.self().getAllUsernames();\r
+                       List<String> names = userManager.getAllUsernames();\r
                        List<UserModel> users = new ArrayList<UserModel>();\r
                        for (String name : names) {\r
-                               users.add(GitBlit.self().getUserModel(name));\r
+                               users.add(userManager.getUserModel(name));\r
                        }\r
                        result = users;\r
                } else if (RpcRequest.LIST_TEAMS.equals(reqType)) {\r
                        // list teams\r
-                       List<String> names = GitBlit.self().getAllTeamnames();\r
+                       List<String> names = userManager.getAllTeamNames();\r
                        List<TeamModel> teams = new ArrayList<TeamModel>();\r
                        for (String name : names) {\r
-                               teams.add(GitBlit.self().getTeamModel(name));\r
+                               teams.add(userManager.getTeamModel(name));\r
                        }\r
                        result = teams;\r
                } else if (RpcRequest.CREATE_REPOSITORY.equals(reqType)) {\r
                        // create repository\r
                        RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
                        try {\r
-                               GitBlit.self().updateRepositoryModel(model.name, model, true);\r
+                               repositoryManager.updateRepositoryModel(model.name, model, true);\r
                        } catch (GitBlitException e) {\r
                                response.setStatus(failureCode);\r
                        }\r
@@ -189,19 +201,19 @@ public class RpcServlet extends JsonServlet {
                                repoName = model.name;\r
                        }\r
                        try {\r
-                               GitBlit.self().updateRepositoryModel(repoName, model, false);\r
+                               repositoryManager.updateRepositoryModel(repoName, model, false);\r
                        } catch (GitBlitException e) {\r
                                response.setStatus(failureCode);\r
                        }\r
                } else if (RpcRequest.DELETE_REPOSITORY.equals(reqType)) {\r
                        // delete repository\r
                        RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
-                       GitBlit.self().deleteRepositoryModel(model);\r
+                       repositoryManager.deleteRepositoryModel(model);\r
                } else if (RpcRequest.CREATE_USER.equals(reqType)) {\r
                        // create user\r
                        UserModel model = deserialize(request, response, UserModel.class);\r
                        try {\r
-                               GitBlit.self().updateUserModel(model.username, model, true);\r
+                               gitblitManager.updateUserModel(model.username, model, true);\r
                        } catch (GitBlitException e) {\r
                                response.setStatus(failureCode);\r
                        }\r
@@ -214,21 +226,21 @@ public class RpcServlet extends JsonServlet {
                                username = model.username;\r
                        }\r
                        try {\r
-                               GitBlit.self().updateUserModel(username, model, false);\r
+                               gitblitManager.updateUserModel(username, model, false);\r
                        } catch (GitBlitException e) {\r
                                response.setStatus(failureCode);\r
                        }\r
                } else if (RpcRequest.DELETE_USER.equals(reqType)) {\r
                        // delete user\r
                        UserModel model = deserialize(request, response, UserModel.class);\r
-                       if (!GitBlit.self().deleteUser(model.username)) {\r
+                       if (!userManager.deleteUser(model.username)) {\r
                                response.setStatus(failureCode);\r
                        }\r
                } else if (RpcRequest.CREATE_TEAM.equals(reqType)) {\r
                        // create team\r
                        TeamModel model = deserialize(request, response, TeamModel.class);\r
                        try {\r
-                               GitBlit.self().updateTeamModel(model.name, model, true);\r
+                               gitblitManager.updateTeamModel(model.name, model, true);\r
                        } catch (GitBlitException e) {\r
                                response.setStatus(failureCode);\r
                        }\r
@@ -241,83 +253,83 @@ public class RpcServlet extends JsonServlet {
                                teamname = model.name;\r
                        }\r
                        try {\r
-                               GitBlit.self().updateTeamModel(teamname, model, false);\r
+                               gitblitManager.updateTeamModel(teamname, model, false);\r
                        } catch (GitBlitException e) {\r
                                response.setStatus(failureCode);\r
                        }\r
                } else if (RpcRequest.DELETE_TEAM.equals(reqType)) {\r
                        // delete team\r
                        TeamModel model = deserialize(request, response, TeamModel.class);\r
-                       if (!GitBlit.self().deleteTeam(model.name)) {\r
+                       if (!userManager.deleteTeam(model.name)) {\r
                                response.setStatus(failureCode);\r
                        }\r
                } else if (RpcRequest.LIST_REPOSITORY_MEMBERS.equals(reqType)) {\r
                        // get repository members\r
-                       RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
-                       result = GitBlit.self().getRepositoryUsers(model);\r
+                       RepositoryModel model = repositoryManager.getRepositoryModel(objectName);\r
+                       result = repositoryManager.getRepositoryUsers(model);\r
                } else if (RpcRequest.SET_REPOSITORY_MEMBERS.equals(reqType)) {\r
                        // rejected since 1.2.0\r
                        response.setStatus(failureCode);\r
                } else if (RpcRequest.LIST_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {\r
                        // get repository member permissions\r
-                       RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
-                       result = GitBlit.self().getUserAccessPermissions(model);\r
+                       RepositoryModel model = repositoryManager.getRepositoryModel(objectName);\r
+                       result = repositoryManager.getUserAccessPermissions(model);\r
                } else if (RpcRequest.SET_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {\r
                        // set the repository permissions for the specified users\r
-                       RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
+                       RepositoryModel model = repositoryManager.getRepositoryModel(objectName);\r
                        Collection<RegistrantAccessPermission> permissions = deserialize(request, response, RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
-                       result = GitBlit.self().setUserAccessPermissions(model, permissions);\r
+                       result = repositoryManager.setUserAccessPermissions(model, permissions);\r
                } else if (RpcRequest.LIST_REPOSITORY_TEAMS.equals(reqType)) {\r
                        // get repository teams\r
-                       RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
-                       result = GitBlit.self().getRepositoryTeams(model);\r
+                       RepositoryModel model = repositoryManager.getRepositoryModel(objectName);\r
+                       result = repositoryManager.getRepositoryTeams(model);\r
                } else if (RpcRequest.SET_REPOSITORY_TEAMS.equals(reqType)) {\r
                        // rejected since 1.2.0\r
                        response.setStatus(failureCode);\r
                } else if (RpcRequest.LIST_REPOSITORY_TEAM_PERMISSIONS.equals(reqType)) {\r
                        // get repository team permissions\r
-                       RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
-                       result = GitBlit.self().getTeamAccessPermissions(model);\r
+                       RepositoryModel model = repositoryManager.getRepositoryModel(objectName);\r
+                       result = repositoryManager.getTeamAccessPermissions(model);\r
                } else if (RpcRequest.SET_REPOSITORY_TEAM_PERMISSIONS.equals(reqType)) {\r
                        // set the repository permissions for the specified teams\r
-                       RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
+                       RepositoryModel model = repositoryManager.getRepositoryModel(objectName);\r
                        Collection<RegistrantAccessPermission> permissions = deserialize(request, response, RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
-                       result = GitBlit.self().setTeamAccessPermissions(model, permissions);\r
+                       result = repositoryManager.setTeamAccessPermissions(model, permissions);\r
                } else if (RpcRequest.LIST_FEDERATION_REGISTRATIONS.equals(reqType)) {\r
                        // return the list of federation registrations\r
                        if (allowAdmin) {\r
-                               result = GitBlit.self().getFederationRegistrations();\r
+                               result = federationManager.getFederationRegistrations();\r
                        } else {\r
                                response.sendError(notAllowedCode);\r
                        }\r
                } else if (RpcRequest.LIST_FEDERATION_RESULTS.equals(reqType)) {\r
                        // return the list of federation result registrations\r
-                       if (allowAdmin && GitBlit.canFederate()) {\r
-                               result = GitBlit.self().getFederationResultRegistrations();\r
+                       if (allowAdmin && federationManager.canFederate()) {\r
+                               result = federationManager.getFederationResultRegistrations();\r
                        } else {\r
                                response.sendError(notAllowedCode);\r
                        }\r
                } else if (RpcRequest.LIST_FEDERATION_PROPOSALS.equals(reqType)) {\r
                        // return the list of federation proposals\r
-                       if (allowAdmin && GitBlit.canFederate()) {\r
-                               result = GitBlit.self().getPendingFederationProposals();\r
+                       if (allowAdmin && federationManager.canFederate()) {\r
+                               result = federationManager.getPendingFederationProposals();\r
                        } else {\r
                                response.sendError(notAllowedCode);\r
                        }\r
                } else if (RpcRequest.LIST_FEDERATION_SETS.equals(reqType)) {\r
                        // return the list of federation sets\r
-                       if (allowAdmin && GitBlit.canFederate()) {\r
+                       if (allowAdmin && federationManager.canFederate()) {\r
                                String gitblitUrl = HttpUtils.getGitblitURL(request);\r
-                               result = GitBlit.self().getFederationSets(gitblitUrl);\r
+                               result = federationManager.getFederationSets(gitblitUrl);\r
                        } else {\r
                                response.sendError(notAllowedCode);\r
                        }\r
                } else if (RpcRequest.LIST_SETTINGS.equals(reqType)) {\r
                        // return the server's settings\r
-                       ServerSettings settings = GitBlit.self().getSettingsModel();\r
+                       ServerSettings serverSettings = runtimeManager.getSettingsModel();\r
                        if (allowAdmin) {\r
                                // return all settings\r
-                               result = settings;\r
+                               result = serverSettings;\r
                        } else {\r
                                // anonymous users get a few settings to allow browser launching\r
                                List<String> keys = new ArrayList<String>();\r
@@ -334,33 +346,33 @@ public class RpcServlet extends JsonServlet {
                                // build the settings\r
                                ServerSettings managementSettings = new ServerSettings();\r
                                for (String key : keys) {\r
-                                       managementSettings.add(settings.get(key));\r
+                                       managementSettings.add(serverSettings.get(key));\r
                                }\r
                                if (allowManagement) {\r
-                                       managementSettings.pushScripts = settings.pushScripts;\r
+                                       managementSettings.pushScripts = serverSettings.pushScripts;\r
                                }\r
                                result = managementSettings;\r
                        }\r
                } else if (RpcRequest.EDIT_SETTINGS.equals(reqType)) {\r
                        // update settings on the server\r
                        if (allowAdmin) {\r
-                               Map<String, String> settings = deserialize(request, response,\r
+                               Map<String, String> map = deserialize(request, response,\r
                                                RpcUtils.SETTINGS_TYPE);\r
-                               GitBlit.self().updateSettings(settings);\r
+                               runtimeManager.updateSettings(map);\r
                        } else {\r
                                response.sendError(notAllowedCode);\r
                        }\r
                } else if (RpcRequest.LIST_STATUS.equals(reqType)) {\r
                        // return the server's status information\r
                        if (allowAdmin) {\r
-                               result = GitBlit.self().getStatus();\r
+                               result = runtimeManager.getStatus();\r
                        } else {\r
                                response.sendError(notAllowedCode);\r
                        }\r
                } else if (RpcRequest.CLEAR_REPOSITORY_CACHE.equals(reqType)) {\r
                        // clear the repository list cache\r
                        if (allowManagement) {\r
-                               GitBlit.self().resetRepositoryListCache();\r
+                               repositoryManager.resetRepositoryListCache();\r
                        } else {\r
                                response.sendError(notAllowedCode);\r
                        }\r
index 5979f6312ce1344fc2d824f48d6727d409a360ee..bfc96be01dd73a0161b4ef63417489d0936e43e8 100644 (file)
@@ -6,6 +6,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.gitblit.Constants.AccountType;
+import com.gitblit.manager.IRuntimeManager;
 import com.gitblit.models.UserModel;
 import com.gitblit.utils.ArrayUtils;
 import com.gitblit.utils.StringUtils;
@@ -31,7 +32,8 @@ public class SalesforceUserService extends GitblitUserService {
                String file = settings.getString(
                                Keys.realm.salesforce.backingUserService,
                                "${baseFolder}/users.conf");
-               File realmFile = GitBlit.getFileOrFolder(file);
+               IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);
+               File realmFile = runtimeManager.getFileOrFolder(file);
 
                serviceImpl = createUserService(realmFile);
 
index 11a58dd19d230e114dfdd105a9c5f58e6ab804cc..9f6618b229268735f3e16eb902e907de15c7524f 100644 (file)
@@ -23,6 +23,10 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;\r
 import javax.servlet.http.HttpServletResponse;\r
 \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.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.StringUtils;\r
@@ -57,6 +61,11 @@ 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
@@ -77,9 +86,9 @@ public class SparkleShareInviteServlet extends HttpServlet {
                }\r
                UserModel user;\r
                if (StringUtils.isEmpty(username)) {\r
-                       user = GitBlit.self().authenticate(request);\r
+                       user = sessionManager.authenticate(request);\r
                } else {\r
-                       user = GitBlit.self().getUserModel(username);\r
+                       user = userManager.getUserModel(username);\r
                }\r
                if (user == null) {\r
                        user = UserModel.ANONYMOUS;\r
@@ -87,7 +96,7 @@ public class SparkleShareInviteServlet extends HttpServlet {
                }\r
 \r
                // ensure that the requested repository exists\r
-               RepositoryModel model = GitBlit.self().getRepositoryModel(path);\r
+               RepositoryModel model = repositoryManager.getRepositoryModel(path);\r
                if (model == null) {\r
                        response.setStatus(HttpServletResponse.SC_NOT_FOUND);\r
                        response.getWriter().append(MessageFormat.format("Repository \"{0}\" not found!", path));\r
@@ -99,9 +108,9 @@ public class SparkleShareInviteServlet extends HttpServlet {
                sb.append("<sparkleshare><invite>\n");\r
                sb.append(MessageFormat.format("<address>{0}</address>\n", host));\r
                sb.append(MessageFormat.format("<remote_path>{0}{1}</remote_path>\n", servletPath, model.name));\r
-               if (GitBlit.getInteger(Keys.fanout.port, 0) > 0) {\r
+               if (settings.getInteger(Keys.fanout.port, 0) > 0) {\r
                        // Gitblit is running it's own fanout service for pubsub notifications\r
-                       sb.append(MessageFormat.format("<announcements_url>tcp://{0}:{1}</announcements_url>\n", request.getServerName(), GitBlit.getString(Keys.fanout.port, "")));\r
+                       sb.append(MessageFormat.format("<announcements_url>tcp://{0}:{1}</announcements_url>\n", request.getServerName(), settings.getString(Keys.fanout.port, "")));\r
                }\r
                sb.append("</invite></sparkleshare>\n");\r
 \r
index 2c232ad8d85b0230fc8502631ba6f670a3f58960..ab854bb770207179365def9f3f722ee011db3c8e 100644 (file)
@@ -26,6 +26,9 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;\r
 \r
 import com.gitblit.Constants.AccessRestrictionType;\r
+import com.gitblit.manager.IProjectManager;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.models.ProjectModel;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
@@ -70,12 +73,16 @@ public class SyndicationFilter extends AuthenticationFilter {
                String fullUrl = getFullUrl(httpRequest);\r
                String name = extractRequestedName(fullUrl);\r
 \r
-               ProjectModel project = GitBlit.self().getProjectModel(name);\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
                if (project == null) {\r
                        // try loading a repository model\r
-                       model = GitBlit.self().getRepositoryModel(name);\r
+                       model = repositoryManager.getRepositoryModel(name);\r
                        if (model == null) {\r
                                // repository not found. send 404.\r
                                logger.info(MessageFormat.format("ARF: {0} ({1})", fullUrl,\r
@@ -105,7 +112,7 @@ public class SyndicationFilter extends AuthenticationFilter {
                        if (model.accessRestriction.atLeast(AccessRestrictionType.VIEW)) {\r
                                if (user == null) {\r
                                        // challenge client to provide credentials. send 401.\r
-                                       if (GitBlit.isDebugMode()) {\r
+                                       if (runtimeManager.isDebugMode()) {\r
                                                logger.info(MessageFormat.format("ARF: CHALLENGE {0}", fullUrl));\r
                                        }\r
                                        httpResponse.setHeader("WWW-Authenticate", CHALLENGE);\r
@@ -123,7 +130,7 @@ public class SyndicationFilter extends AuthenticationFilter {
                                                return;\r
                                        }\r
                                        // valid user, but not for requested access. send 403.\r
-                                       if (GitBlit.isDebugMode()) {\r
+                                       if (runtimeManager.isDebugMode()) {\r
                                                logger.info(MessageFormat.format("ARF: {0} forbidden to access {1}",\r
                                                                user.username, fullUrl));\r
                                        }\r
@@ -133,7 +140,7 @@ public class SyndicationFilter extends AuthenticationFilter {
                        }\r
                }\r
 \r
-               if (GitBlit.isDebugMode()) {\r
+               if (runtimeManager.isDebugMode()) {\r
                        logger.info(MessageFormat.format("ARF: {0} ({1}) unauthenticated", fullUrl,\r
                                        HttpServletResponse.SC_CONTINUE));\r
                }\r
index 6b3c01ca5cd4c208a13392cdb2299f43e9e36b8e..ae50c3e43d46127b3f3cd8dde930e6c96ad71f79 100644 (file)
@@ -31,6 +31,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;\r
 \r
 import com.gitblit.AuthenticationFilter.AuthenticatedRequest;\r
+import com.gitblit.manager.IProjectManager;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.models.FeedEntryModel;\r
 import com.gitblit.models.ProjectModel;\r
 import com.gitblit.models.RefModel;\r
@@ -38,6 +41,7 @@ import com.gitblit.models.RepositoryModel;
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.HttpUtils;\r
 import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.MessageProcessor;\r
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.utils.SyndicationUtils;\r
 \r
@@ -126,6 +130,10 @@ 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
@@ -143,7 +151,7 @@ public class SyndicationServlet extends HttpServlet {
                                searchType = type;\r
                        }\r
                }\r
-               int length = GitBlit.getInteger(Keys.web.syndicationEntries, 25);\r
+               int length = settings.getInteger(Keys.web.syndicationEntries, 25);\r
                if (StringUtils.isEmpty(objectId)) {\r
                        objectId = org.eclipse.jgit.lib.Constants.HEAD;\r
                }\r
@@ -175,7 +183,7 @@ public class SyndicationServlet extends HttpServlet {
                        if (request instanceof AuthenticatedRequest) {\r
                                user = ((AuthenticatedRequest) request).getUser();\r
                        }\r
-                       ProjectModel project = GitBlit.self().getProjectModel(repositoryName, user);\r
+                       ProjectModel project = projectManager.getProjectModel(repositoryName, user);\r
                        if (project != null) {\r
                                isProjectFeed = true;\r
                                repositories = new ArrayList<String>(project.repositories);\r
@@ -193,7 +201,7 @@ public class SyndicationServlet extends HttpServlet {
                }\r
 \r
 \r
-               boolean mountParameters = GitBlit.getBoolean(Keys.web.mountParameters, true);\r
+               boolean mountParameters = settings.getBoolean(Keys.web.mountParameters, true);\r
                String urlPattern;\r
                if (mountParameters) {\r
                        // mounted parameters\r
@@ -203,13 +211,13 @@ public class SyndicationServlet extends HttpServlet {
                        urlPattern = "{0}/commit/?r={1}&h={2}";\r
                }\r
                String gitblitUrl = HttpUtils.getGitblitURL(request);\r
-               char fsc = GitBlit.getChar(Keys.web.forwardSlashCharacter, '/');\r
+               char fsc = settings.getChar(Keys.web.forwardSlashCharacter, '/');\r
 \r
                List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();\r
 \r
                for (String name : repositories) {\r
-                       Repository repository = GitBlit.self().getRepository(name);\r
-                       RepositoryModel model = GitBlit.self().getRepositoryModel(name);\r
+                       Repository repository = repositoryManager.getRepository(name);\r
+                       RepositoryModel model = repositoryManager.getRepositoryModel(name);\r
 \r
                        if (repository == null) {\r
                                if (model.isCollectingGarbage) {\r
@@ -234,6 +242,7 @@ public class SyndicationServlet extends HttpServlet {
                                                offset, length);\r
                        }\r
                        Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository, model.showRemoteBranches);\r
+                       MessageProcessor processor = new MessageProcessor(settings);\r
 \r
                        // convert RevCommit to SyndicatedEntryModel\r
                        for (RevCommit commit : commits) {\r
@@ -244,8 +253,7 @@ public class SyndicationServlet extends HttpServlet {
                                                StringUtils.encodeURL(model.name.replace('/', fsc)), commit.getName());\r
                                entry.published = commit.getCommitterIdent().getWhen();\r
                                entry.contentType = "text/html";\r
-                               String message = GitBlit.self().processCommitMessage(model,\r
-                                               commit.getFullMessage());\r
+                               String message = processor.processCommitMessage(model, commit.getFullMessage());\r
                                entry.content = message;\r
                                entry.repository = model.name;\r
                                entry.branch = objectId;\r
index a65f44e1e743d117306b6e8ba3bec033911fe431..03d65e02354c205e782afc10b5ce100e128ede9f 100644 (file)
@@ -29,6 +29,7 @@ import waffle.windows.auth.IWindowsIdentity;
 import waffle.windows.auth.impl.WindowsAuthProviderImpl;\r
 \r
 import com.gitblit.Constants.AccountType;\r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.ArrayUtils;\r
 import com.gitblit.utils.StringUtils;\r
@@ -56,7 +57,8 @@ public class WindowsUserService extends GitblitUserService {
         this.settings = settings;\r
 \r
         String file = settings.getString(Keys.realm.windows.backingUserService, "${baseFolder}/users.conf");\r
-        File realmFile = GitBlit.getFileOrFolder(file);\r
+        IRuntimeManager runtimeManager = GitBlit.getManager(IRuntimeManager.class);\r
+        File realmFile = runtimeManager.getFileOrFolder(file);\r
 \r
         serviceImpl = createUserService(realmFile);\r
         logger.info("Windows User Service backed by " + serviceImpl.toString());\r
index 310d4da39b83dafd623d6efe1d39fbcb34e0ea93..0233cd90c2a0e1690515152d91fae1eee35eaa2c 100644 (file)
@@ -20,6 +20,7 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;\r
 \r
 import com.gitblit.GitBlit;\r
+import com.gitblit.manager.IRepositoryManager;\r
 \r
 /**\r
  * The GitServlet provides http/https access to Git repositories.\r
@@ -34,7 +35,8 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
 \r
        @Override\r
        public void init(ServletConfig config) throws ServletException {\r
-               setRepositoryResolver(new RepositoryResolver<HttpServletRequest>(GitBlit.getRepositoriesFolder()));\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
                super.init(config);\r
index ba200b25768e02b25799a317c763c24451e2ba16..8da603ac04dda8d8197bcf0c2ae9b4e75153c267 100644 (file)
@@ -45,8 +45,11 @@ import org.slf4j.LoggerFactory;
 import com.gitblit.Constants;\r
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.GitBlit;\r
+import com.gitblit.IStoredSettings;\r
 import com.gitblit.Keys;\r
 import com.gitblit.client.Translation;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.ArrayUtils;\r
@@ -90,12 +93,15 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
 \r
        public GitblitReceivePack(Repository db, RepositoryModel repository, UserModel user) {\r
                super(db);\r
+\r
+               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+\r
                this.repository = repository;\r
                this.user = user == null ? UserModel.ANONYMOUS : user;\r
-               this.groovyDir = GitBlit.getGroovyScriptsFolder();\r
+               this.groovyDir = repositoryManager.getHooksFolder();\r
                try {\r
                        // set Grape root\r
-                       File grapeRoot = GitBlit.getFileOrFolder(Keys.groovy.grapeFolder, "${baseFolder}/groovy/grape").getAbsoluteFile();\r
+                       File grapeRoot = repositoryManager.getGrapesFolder();\r
                        grapeRoot.mkdirs();\r
                        System.setProperty("grape.root", grapeRoot.getAbsolutePath());\r
                        this.gse = new GroovyScriptEngine(groovyDir.getAbsolutePath());\r
@@ -233,8 +239,9 @@ 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(GitBlit.self().getPreReceiveScriptsInherited(repository));\r
+               scripts.addAll(repositoryManager.getPreReceiveScriptsInherited(repository));\r
                if (!ArrayUtils.isEmpty(repository.preReceiveScripts)) {\r
                        scripts.addAll(repository.preReceiveScripts);\r
                }\r
@@ -259,6 +266,8 @@ 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
@@ -303,7 +312,7 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
                                        String msg = MessageFormat.format(template, branch);\r
                                        String prefix;\r
                                        if (StringUtils.isEmpty(repository.incrementalPushTagPrefix)) {\r
-                                               prefix = GitBlit.getString(Keys.git.defaultIncrementalPushTagPrefix, "r");\r
+                                               prefix = settings.getString(Keys.git.defaultIncrementalPushTagPrefix, "r");\r
                                        } else {\r
                                                prefix = repository.incrementalPushTagPrefix;\r
                                        }\r
@@ -327,9 +336,11 @@ 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(GitBlit.self().getPostReceiveScriptsInherited(repository));\r
+               scripts.addAll(repositoryManager.getPostReceiveScriptsInherited(repository));\r
                if (!ArrayUtils.isEmpty(repository.postReceiveScripts)) {\r
                        scripts.addAll(repository.postReceiveScripts);\r
                }\r
index b2862f037e7d8d2a812cabb9c7a3ba962b6102f3..a90c36b1df865c722370bd2dd60d4d99f492b004 100644 (file)
@@ -27,7 +27,11 @@ 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;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.IUserManager;
 import com.gitblit.models.RepositoryModel;
 import com.gitblit.models.UserModel;
 import com.gitblit.utils.HttpUtils;
@@ -48,6 +52,10 @@ public class GitblitReceivePackFactory<X> implements ReceivePackFactory<X> {
        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 = "";
@@ -66,7 +74,7 @@ public class GitblitReceivePackFactory<X> implements ReceivePackFactory<X> {
                        // determine pushing user
                        String username = request.getRemoteUser();
                        if (!StringUtils.isEmpty(username)) {
-                               UserModel u = GitBlit.self().getUserModel(username);
+                               UserModel u = userManager.getUserModel(username);
                                if (u != null) {
                                        user = u;
                                }
@@ -81,13 +89,13 @@ public class GitblitReceivePackFactory<X> implements ReceivePackFactory<X> {
                        timeout = client.getDaemon().getTimeout();
                }
 
-               boolean allowAnonymousPushes = GitBlit.getBoolean(Keys.git.allowAnonymousPushes, false);
+               boolean allowAnonymousPushes = settings.getBoolean(Keys.git.allowAnonymousPushes, false);
                if (!allowAnonymousPushes && UserModel.ANONYMOUS.equals(user)) {
                        // prohibit anonymous pushes
                        throw new ServiceNotEnabledException();
                }
 
-               final RepositoryModel repository = GitBlit.self().getRepositoryModel(repositoryName);
+               final RepositoryModel repository = repositoryManager.getRepositoryModel(repositoryName);
 
                final GitblitReceivePack rp = new GitblitReceivePack(db, repository, user);
                rp.setGitblitUrl(gitblitUrl);
index 90875b59942681779ebc9eb9face146fc74ddf48..180e8b55d2d80e0835d0f6a8a9fe2cdf5b02bc2c 100644 (file)
@@ -24,6 +24,7 @@ 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;
 
 /**
@@ -40,12 +41,13 @@ public class GitblitUploadPackFactory<X> implements UploadPackFactory<X> {
        public UploadPack create(X req, Repository db)
                        throws ServiceNotEnabledException, ServiceNotAuthorizedException {
 
+               ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);
                UserModel user = UserModel.ANONYMOUS;
                int timeout = 0;
 
                if (req instanceof HttpServletRequest) {
                        // http/https request may or may not be authenticated
-                       user = GitBlit.self().authenticate((HttpServletRequest) req);
+                       user = sessionManager.authenticate((HttpServletRequest) req);
                        if (user == null) {
                                user = UserModel.ANONYMOUS;
                        }
index e44b153f3269da89991f49dc5224e2404cd4b438..5441596db223804cab0900f0d24921a911da0fd5 100644 (file)
@@ -29,6 +29,8 @@ 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;
 import com.gitblit.models.UserModel;
 
@@ -74,7 +76,9 @@ public class RepositoryResolver<X> extends FileResolver<X> {
         */
        @Override
        protected boolean isExportOk(X req, String repositoryName, Repository db) throws IOException {
-               RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
+               IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
+               ISessionManager sessionManager = GitBlit.getManager(ISessionManager.class);
+               RepositoryModel model = repositoryManager.getRepositoryModel(repositoryName);
 
                String scheme = null;
                UserModel user = null;
@@ -92,7 +96,7 @@ public class RepositoryResolver<X> extends FileResolver<X> {
                        HttpServletRequest httpRequest = (HttpServletRequest) req;
                        scheme = httpRequest.getScheme();
                        origin = httpRequest.getRemoteAddr();
-                       user = GitBlit.self().authenticate(httpRequest);
+                       user = sessionManager.authenticate(httpRequest);
                        if (user == null) {
                                user = UserModel.ANONYMOUS;
                        }
diff --git a/src/main/java/com/gitblit/manager/IFederationManager.java b/src/main/java/com/gitblit/manager/IFederationManager.java
new file mode 100644 (file)
index 0000000..debe362
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * 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.manager;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import com.gitblit.Constants.FederationRequest;
+import com.gitblit.Constants.FederationToken;
+import com.gitblit.models.FederationModel;
+import com.gitblit.models.FederationProposal;
+import com.gitblit.models.FederationSet;
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.UserModel;
+
+public interface IFederationManager {
+
+       /**
+        * Returns the path of the proposals folder. This method checks to see if
+        * Gitblit is running on a cloud service and may return an adjusted path.
+        *
+        * @return the proposals folder path
+        */
+       File getProposalsFolder();
+
+       UserModel getFederationUser();
+
+       boolean canFederate();
+
+       /**
+        * Returns the list of federated gitblit instances that this instance will
+        * try to pull.
+        *
+        * @return list of registered gitblit instances
+        */
+       List<FederationModel> getFederationRegistrations();
+
+       /**
+        * Retrieve the specified federation registration.
+        *
+        * @param name
+        *            the name of the registration
+        * @return a federation registration
+        */
+       FederationModel getFederationRegistration(String url, String name);
+
+       /**
+        * Returns the list of federation sets.
+        *
+        * @return list of federation sets
+        */
+       List<FederationSet> getFederationSets(String gitblitUrl);
+
+       /**
+        * Returns the list of possible federation tokens for this Gitblit instance.
+        *
+        * @return list of federation tokens
+        */
+       List<String> getFederationTokens();
+
+       /**
+        * Returns the specified federation token for this Gitblit instance.
+        *
+        * @param type
+        * @return a federation token
+        */
+       String getFederationToken(FederationToken type);
+
+       /**
+        * Returns the specified federation token for this Gitblit instance.
+        *
+        * @param value
+        * @return a federation token
+        */
+       String getFederationToken(String value);
+
+       /**
+        * Compares the provided token with this Gitblit instance's tokens and
+        * determines if the requested permission may be granted to the token.
+        *
+        * @param req
+        * @param token
+        * @return true if the request can be executed
+        */
+       boolean validateFederationRequest(FederationRequest req, String token);
+
+       /**
+        * Acknowledge and cache the status of a remote Gitblit instance.
+        *
+        * @param identification
+        *            the identification of the pulling Gitblit instance
+        * @param registration
+        *            the registration from the pulling Gitblit instance
+        * @return true if acknowledged
+        */
+       boolean acknowledgeFederationStatus(String identification, FederationModel registration);
+
+       /**
+        * Returns the list of registration results.
+        *
+        * @return the list of registration results
+        */
+       List<FederationModel> getFederationResultRegistrations();
+
+       /**
+        * Submit a federation proposal. The proposal is cached locally and the
+        * Gitblit administrator(s) are notified via email.
+        *
+        * @param proposal
+        *            the proposal
+        * @param gitblitUrl
+        *            the url of your gitblit instance to send an email to
+        *            administrators
+        * @return true if the proposal was submitted
+        */
+       boolean submitFederationProposal(FederationProposal proposal, String gitblitUrl);
+
+       /**
+        * Returns the list of pending federation proposals
+        *
+        * @return list of federation proposals
+        */
+       List<FederationProposal> getPendingFederationProposals();
+
+       /**
+        * Get repositories for the specified token.
+        *
+        * @param gitblitUrl
+        *            the base url of this gitblit instance
+        * @param token
+        *            the federation token
+        * @return a map of <cloneurl, RepositoryModel>
+        */
+       Map<String, RepositoryModel> getRepositories(String gitblitUrl, String token);
+
+       /**
+        * Creates a proposal from the token.
+        *
+        * @param gitblitUrl
+        *            the url of this Gitblit instance
+        * @param token
+        * @return a potential proposal
+        */
+       FederationProposal createFederationProposal(String gitblitUrl, String token);
+
+       /**
+        * Returns the proposal identified by the supplied token.
+        *
+        * @param token
+        * @return the specified proposal or null
+        */
+       FederationProposal getPendingFederationProposal(String token);
+
+       /**
+        * Deletes a pending federation proposal.
+        *
+        * @param a
+        *            proposal
+        * @return true if the proposal was deleted
+        */
+       boolean deletePendingFederationProposal(FederationProposal proposal);
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/gitblit/manager/IGitblitManager.java b/src/main/java/com/gitblit/manager/IGitblitManager.java
new file mode 100644 (file)
index 0000000..2f5295b
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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.manager;
+
+import java.util.Collection;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import com.gitblit.GitBlitException;
+import com.gitblit.models.GitClientApplication;
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.RepositoryUrl;
+import com.gitblit.models.TeamModel;
+import com.gitblit.models.UserModel;
+
+public interface IGitblitManager {
+
+       /**
+        * Returns a list of repository URLs and the user access permission.
+        *
+        * @param request
+        * @param user
+        * @param repository
+        * @return a list of repository urls
+        */
+       List<RepositoryUrl> getRepositoryUrls(HttpServletRequest request, UserModel user, RepositoryModel repository);
+
+       /**
+        * Adds/updates a complete user object keyed by username. This method allows
+        * for renaming a user.
+        *
+        * @see IUserService.updateUserModel(String, UserModel)
+        * @param username
+        * @param user
+        * @param isCreate
+        * @throws GitBlitException
+        */
+       void updateUserModel(String username, UserModel user, boolean isCreate) throws GitBlitException;
+
+       /**
+        * Updates the TeamModel object for the specified name.
+        *
+        * @param teamname
+        * @param team
+        * @param isCreate
+        */
+       void updateTeamModel(String teamname, TeamModel team, boolean isCreate) throws GitBlitException;
+
+       /**
+        * Creates a personal fork of the specified repository. The clone is view
+        * restricted by default and the owner of the source repository is given
+        * access to the clone.
+        *
+        * @param repository
+        * @param user
+        * @return the repository model of the fork, if successful
+        * @throws GitBlitException
+        */
+       RepositoryModel fork(RepositoryModel repository, UserModel user) throws GitBlitException;
+
+       /**
+        * Returns the list of custom client applications to be used for the
+        * repository url panel;
+        *
+        * @return a collection of client applications
+        */
+       Collection<GitClientApplication> getClientApplications();
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/gitblit/manager/INotificationManager.java b/src/main/java/com/gitblit/manager/INotificationManager.java
new file mode 100644 (file)
index 0000000..f53ae68
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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.manager;
+
+import java.util.Collection;
+
+public interface INotificationManager {
+
+       /**
+        * Notify the administrators by email.
+        *
+        * @param subject
+        * @param message
+        */
+       void sendMailToAdministrators(String subject, String message);
+
+       /**
+        * Notify users by email of something.
+        *
+        * @param subject
+        * @param message
+        * @param toAddresses
+        */
+       void sendMail(String subject, String message, Collection<String> toAddresses);
+
+       /**
+        * Notify users by email of something.
+        *
+        * @param subject
+        * @param message
+        * @param toAddresses
+        */
+       void sendMail(String subject, String message, String... toAddresses);
+
+       /**
+        * Notify users by email of something.
+        *
+        * @param subject
+        * @param message
+        * @param toAddresses
+        */
+       void sendHtmlMail(String subject, String message, Collection<String> toAddresses);
+
+       /**
+        * Notify users by email of something.
+        *
+        * @param subject
+        * @param message
+        * @param toAddresses
+        */
+       void sendHtmlMail(String subject, String message, String... toAddresses);
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/gitblit/manager/IProjectManager.java b/src/main/java/com/gitblit/manager/IProjectManager.java
new file mode 100644 (file)
index 0000000..b2577f5
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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.manager;
+
+import java.util.List;
+
+import com.gitblit.models.ProjectModel;
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.UserModel;
+
+public interface IProjectManager {
+
+       /**
+        * Returns a list of project models for the user.
+        *
+        * @param user
+        * @param includeUsers
+        * @return list of projects that are accessible to the user
+        */
+       List<ProjectModel> getProjectModels(UserModel user, boolean includeUsers);
+
+       /**
+        * Returns the project model for the specified user.
+        *
+        * @param name
+        * @param user
+        * @return a project model, or null if it does not exist
+        */
+       ProjectModel getProjectModel(String name, UserModel user);
+
+       /**
+        * Returns a project model for the Gitblit/system user.
+        *
+        * @param name a project name
+        * @return a project model or null if the project does not exist
+        */
+       ProjectModel getProjectModel(String name);
+
+       /**
+        * Returns the list of project models that are referenced by the supplied
+        * repository model     list.  This is an alternative method exists to ensure
+        * Gitblit does not call getRepositoryModels(UserModel) twice in a request.
+        *
+        * @param repositoryModels
+        * @param includeUsers
+        * @return a list of project models
+        */
+       List<ProjectModel> getProjectModels(List<RepositoryModel> repositoryModels, boolean includeUsers);
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/gitblit/manager/IRepositoryManager.java b/src/main/java/com/gitblit/manager/IRepositoryManager.java
new file mode 100644 (file)
index 0000000..383ca0d
--- /dev/null
@@ -0,0 +1,396 @@
+/*
+ * 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.manager;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
+import org.eclipse.jgit.lib.Repository;
+
+import com.gitblit.GitBlitException;
+import com.gitblit.models.ForkModel;
+import com.gitblit.models.Metric;
+import com.gitblit.models.RegistrantAccessPermission;
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.SearchResult;
+import com.gitblit.models.UserModel;
+
+public interface IRepositoryManager {
+
+       /**
+        * Returns the path of the repositories folder. This method checks to see if
+        * Gitblit is running on a cloud service and may return an adjusted path.
+        *
+        * @return the repositories folder path
+        */
+       File getRepositoriesFolder();
+
+       /**
+        * Returns the path of the hooks folder. This method checks to see if
+        * Gitblit is running on a cloud service and may return an adjusted path.
+        *
+        * @return the Groovy hook scripts folder path
+        */
+       File getHooksFolder();
+
+       /**
+        * Returns the path of the grapes folder. This method checks to see if
+        * Gitblit is running on a cloud service and may return an adjusted path.
+        *
+        * @return the Groovy grapes folder path
+        */
+       File getGrapesFolder();
+
+       /**
+        * Returns the most recent change date of any repository served by Gitblit.
+        *
+        * @return a date
+        */
+       Date getLastActivityDate();
+
+       /**
+        * Returns the effective list of permissions for this user, taking into account
+        * team memberships, ownerships.
+        *
+        * @param user
+        * @return the effective list of permissions for the user
+        */
+       List<RegistrantAccessPermission> getUserAccessPermissions(UserModel user);
+
+       /**
+        * Returns the list of users and their access permissions for the specified
+        * repository including permission source information such as the team or
+        * regular expression which sets the permission.
+        *
+        * @param repository
+        * @return a list of RegistrantAccessPermissions
+        */
+       List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository);
+
+       /**
+        * Sets the access permissions to the specified repository for the specified users.
+        *
+        * @param repository
+        * @param permissions
+        * @return true if the user models have been updated
+        */
+       boolean setUserAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions);
+
+       /**
+        * Returns the list of all users who have an explicit access permission
+        * for the specified repository.
+        *
+        * @see IUserService.getUsernamesForRepositoryRole(String)
+        * @param repository
+        * @return list of all usernames that have an access permission for the repository
+        */
+       List<String> getRepositoryUsers(RepositoryModel repository);
+
+       /**
+        * Returns the list of teams and their access permissions for the specified
+        * repository including the source of the permission such as the admin flag
+        * or a regular expression.
+        *
+        * @param repository
+        * @return a list of RegistrantAccessPermissions
+        */
+       List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository);
+
+       /**
+        * Sets the access permissions to the specified repository for the specified teams.
+        *
+        * @param repository
+        * @param permissions
+        * @return true if the team models have been updated
+        */
+       boolean setTeamAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions);
+
+       /**
+        * Returns the list of all teams who have an explicit access permission for
+        * the specified repository.
+        *
+        * @see IUserService.getTeamnamesForRepositoryRole(String)
+        * @param repository
+        * @return list of all teamnames with explicit access permissions to the repository
+        */
+       List<String> getRepositoryTeams(RepositoryModel repository);
+
+       /**
+        * Adds the repository to the list of cached repositories if Gitblit is
+        * configured to cache the repository list.
+        *
+        * @param model
+        */
+       void addToCachedRepositoryList(RepositoryModel model);
+
+       /**
+        * Resets the repository list cache.
+        *
+        */
+       void resetRepositoryListCache();
+
+       /**
+        * Returns the list of all repositories available to Gitblit. This method
+        * does not consider user access permissions.
+        *
+        * @return list of all repositories
+        */
+       List<String> getRepositoryList();
+
+       /**
+        * Returns the JGit repository for the specified name.
+        *
+        * @param repositoryName
+        * @return repository or null
+        */
+       Repository getRepository(String repositoryName);
+
+       /**
+        * Returns the JGit repository for the specified name.
+        *
+        * @param repositoryName
+        * @param logError
+        * @return repository or null
+        */
+       Repository getRepository(String repositoryName, boolean logError);
+
+       /**
+        * Returns the list of repository models that are accessible to the user.
+        *
+        * @param user
+        * @return list of repository models accessible to user
+        */
+       List<RepositoryModel> getRepositoryModels(UserModel user);
+
+       /**
+        * Returns a repository model if the repository exists and the user may
+        * access the repository.
+        *
+        * @param user
+        * @param repositoryName
+        * @return repository model or null
+        */
+       RepositoryModel getRepositoryModel(UserModel user, String repositoryName);
+
+       /**
+        * Returns the repository model for the specified repository. This method
+        * does not consider user access permissions.
+        *
+        * @param repositoryName
+        * @return repository model or null
+        */
+       RepositoryModel getRepositoryModel(String repositoryName);
+
+       /**
+        * Returns the star count of the repository.
+        *
+        * @param repository
+        * @return the star count
+        */
+       long getStarCount(RepositoryModel repository);
+
+       /**
+        * Determines if this server has the requested repository.
+        *
+        * @param n
+        * @return true if the repository exists
+        */
+       boolean hasRepository(String repositoryName);
+
+       /**
+        * Determines if this server has the requested repository.
+        *
+        * @param n
+        * @param caseInsensitive
+        * @return true if the repository exists
+        */
+       boolean hasRepository(String repositoryName, boolean caseSensitiveCheck);
+
+       /**
+        * Determines if the specified user has a fork of the specified origin
+        * repository.
+        *
+        * @param username
+        * @param origin
+        * @return true the if the user has a fork
+        */
+       boolean hasFork(String username, String origin);
+
+       /**
+        * Gets the name of a user's fork of the specified origin
+        * repository.
+        *
+        * @param username
+        * @param origin
+        * @return the name of the user's fork, null otherwise
+        */
+       String getFork(String username, String origin);
+
+       /**
+        * Returns the fork network for a repository by traversing up the fork graph
+        * to discover the root and then down through all children of the root node.
+        *
+        * @param repository
+        * @return a ForkModel
+        */
+       ForkModel getForkNetwork(String repository);
+
+       /**
+        * Updates the last changed fields and optionally calculates the size of the
+        * repository.  Gitblit caches the repository sizes to reduce the performance
+        * penalty of recursive calculation. The cache is updated if the repository
+        * has been changed since the last calculation.
+        *
+        * @param model
+        * @return size in bytes of the repository
+        */
+       long updateLastChangeFields(Repository r, RepositoryModel model);
+
+       /**
+        * Returns the metrics for the default branch of the specified repository.
+        * This method builds a metrics cache. The cache is updated if the
+        * repository is updated. A new copy of the metrics list is returned on each
+        * call so that modifications to the list are non-destructive.
+        *
+        * @param model
+        * @param repository
+        * @return a new array list of metrics
+        */
+       List<Metric> getRepositoryDefaultMetrics(RepositoryModel model, Repository repository);
+
+       /**
+        * Creates/updates the repository model keyed by reopsitoryName. Saves all
+        * repository settings in .git/config. This method allows for renaming
+        * repositories and will update user access permissions accordingly.
+        *
+        * All repositories created by this method are bare and automatically have
+        * .git appended to their names, which is the standard convention for bare
+        * repositories.
+        *
+        * @param repositoryName
+        * @param repository
+        * @param isCreate
+        * @throws GitBlitException
+        */
+       void updateRepositoryModel(String repositoryName, RepositoryModel repository, boolean isCreate)
+                       throws GitBlitException;
+
+       /**
+        * Updates the Gitblit configuration for the specified repository.
+        *
+        * @param r
+        *            the Git repository
+        * @param repository
+        *            the Gitblit repository model
+        */
+       void updateConfiguration(Repository r, RepositoryModel repository);
+
+       /**
+        * Deletes the repository from the file system and removes the repository
+        * permission from all repository users.
+        *
+        * @param model
+        * @return true if successful
+        */
+       boolean deleteRepositoryModel(RepositoryModel model);
+
+       /**
+        * Deletes the repository from the file system and removes the repository
+        * permission from all repository users.
+        *
+        * @param repositoryName
+        * @return true if successful
+        */
+       boolean deleteRepository(String repositoryName);
+
+       /**
+        * Returns the list of all Groovy push hook scripts. Script files must have
+        * .groovy extension
+        *
+        * @return list of available hook scripts
+        */
+       List<String> getAllScripts();
+
+       /**
+        * Returns the list of pre-receive scripts the repository inherited from the
+        * global settings and team affiliations.
+        *
+        * @param repository
+        *            if null only the globally specified scripts are returned
+        * @return a list of scripts
+        */
+       List<String> getPreReceiveScriptsInherited(RepositoryModel repository);
+
+       /**
+        * Returns the list of all available Groovy pre-receive push hook scripts
+        * that are not already inherited by the repository. Script files must have
+        * .groovy extension
+        *
+        * @param repository
+        *            optional parameter
+        * @return list of available hook scripts
+        */
+       List<String> getPreReceiveScriptsUnused(RepositoryModel repository);
+
+       /**
+        * Returns the list of post-receive scripts the repository inherited from
+        * the global settings and team affiliations.
+        *
+        * @param repository
+        *            if null only the globally specified scripts are returned
+        * @return a list of scripts
+        */
+       List<String> getPostReceiveScriptsInherited(RepositoryModel repository);
+
+       /**
+        * Returns the list of unused Groovy post-receive push hook scripts that are
+        * not already inherited by the repository. Script files must have .groovy
+        * extension
+        *
+        * @param repository
+        *            optional parameter
+        * @return list of available hook scripts
+        */
+       List<String> getPostReceiveScriptsUnused(RepositoryModel repository);
+
+       /**
+        * Search the specified repositories using the Lucene query.
+        *
+        * @param query
+        * @param page
+        * @param pageSize
+        * @param repositories
+        * @return
+        */
+       List<SearchResult> search(String query, int page, int pageSize, List<String> repositories);
+
+       /**
+        *
+        * @return true if we are running the gc executor
+        */
+       boolean isCollectingGarbage();
+
+       /**
+        * Returns true if Gitblit is actively collecting garbage in this repository.
+        *
+        * @param repositoryName
+        * @return true if actively collecting garbage
+        */
+       boolean isCollectingGarbage(String repositoryName);
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/gitblit/manager/IRuntimeManager.java b/src/main/java/com/gitblit/manager/IRuntimeManager.java
new file mode 100644 (file)
index 0000000..178b93c
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * 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.manager;
+
+import java.io.File;
+import java.util.Date;
+import java.util.Map;
+import java.util.TimeZone;
+
+import com.gitblit.IStoredSettings;
+import com.gitblit.models.ServerSettings;
+import com.gitblit.models.ServerStatus;
+
+public interface IRuntimeManager {
+
+       void setBaseFolder(File folder);
+
+       File getBaseFolder();
+
+       /**
+        * Returns the preferred timezone for the Gitblit instance.
+        *
+        * @return a timezone
+        */
+       TimeZone getTimezone();
+
+       /**
+        * Determine if this Gitblit instance is actively serving git repositories
+        * or if it is merely a repository viewer.
+        *
+        * @return true if Gitblit is serving repositories
+        */
+       boolean isServingRepositories();
+
+       /**
+        * Determine if this Gitblit instance is running in debug mode
+        *
+        * @return true if Gitblit is running in debug mode
+        */
+       boolean isDebugMode();
+
+       /**
+        * Returns the boot date of the Gitblit server.
+        *
+        * @return the boot date of Gitblit
+        */
+       Date getBootDate();
+
+       ServerStatus getStatus();
+
+       /**
+        * Returns the descriptions/comments of the Gitblit config settings.
+        *
+        * @return SettingsModel
+        */
+       ServerSettings getSettingsModel();
+
+       /**
+        * Returns the file object for the specified configuration key.
+        *
+        * @return the file
+        */
+       File getFileOrFolder(String key, String defaultFileOrFolder);
+
+       /**
+        * Returns the file object which may have it's base-path determined by
+        * environment variables for running on a cloud hosting service. All Gitblit
+        * file or folder retrievals are (at least initially) funneled through this
+        * method so it is the correct point to globally override/alter filesystem
+        * access based on environment or some other indicator.
+        *
+        * @return the file
+        */
+       File getFileOrFolder(String fileOrFolder);
+
+       /**
+        * Returns the runtime settings.
+        *
+        * @return settings
+        */
+       IStoredSettings getSettings();
+
+       /**
+        * Updates the runtime settings.
+        *
+        * @param settings
+        * @return true if the update succeeded
+        */
+       boolean updateSettings(Map<String, String> updatedSettings);
+}
\ No newline at end of file
diff --git a/src/main/java/com/gitblit/manager/ISessionManager.java b/src/main/java/com/gitblit/manager/ISessionManager.java
new file mode 100644 (file)
index 0000000..09e306a
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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.manager;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.gitblit.models.UserModel;
+
+public interface ISessionManager {
+
+       /**
+        * Authenticate a user based on HTTP request parameters.
+        *
+        * Authentication by X509Certificate is tried first and then by cookie.
+        *
+        * @param httpRequest
+        * @return a user object or null
+        */
+       UserModel authenticate(HttpServletRequest httpRequest);
+
+       /**
+        * Authenticate a user based on HTTP request parameters.
+        *
+        * Authentication by X509Certificate, servlet container principal, cookie,
+        * and BASIC header.
+        *
+        * @param httpRequest
+        * @param requiresCertificate
+        * @return a user object or null
+        */
+       UserModel authenticate(HttpServletRequest httpRequest, boolean requiresCertificate);
+
+       UserModel authenticate(String username, char[] password);
+
+       /**
+        * Sets a cookie for the specified user.
+        *
+        * @param response
+        * @param user
+        */
+       void setCookie(HttpServletResponse response, UserModel user);
+
+       /**
+        * Logout a user.
+        *
+        * @param user
+        */
+       void logout(HttpServletResponse response, UserModel user);
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/gitblit/manager/IUserManager.java b/src/main/java/com/gitblit/manager/IUserManager.java
new file mode 100644 (file)
index 0000000..3ce1e74
--- /dev/null
@@ -0,0 +1,280 @@
+/*
+ * 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.manager;
+
+import java.util.Collection;
+import java.util.List;
+
+import com.gitblit.models.TeamModel;
+import com.gitblit.models.UserModel;
+
+public interface IUserManager {
+
+       boolean supportsAddUser();
+
+       /**
+        * Does the user service support changes to credentials?
+        *
+        * @return true or false
+        * @since 1.0.0
+        */
+       boolean supportsCredentialChanges(UserModel user);
+
+       /**
+        * Returns true if the user's display name can be changed.
+        *
+        * @param user
+        * @return true if the user service supports display name changes
+        */
+       boolean supportsDisplayNameChanges(UserModel user);
+
+       /**
+        * Returns true if the user's email address can be changed.
+        *
+        * @param user
+        * @return true if the user service supports email address changes
+        */
+       boolean supportsEmailAddressChanges(UserModel user);
+
+       /**
+        * Returns true if the user's team memberships can be changed.
+        *
+        * @param user
+        * @return true if the user service supports team membership changes
+        */
+       boolean supportsTeamMembershipChanges(UserModel user);
+
+       /**
+        * Does the user service support cookie authentication?
+        *
+        * @return true or false
+        */
+       boolean supportsCookies();
+
+       /**
+        * Returns the cookie value for the specified user.
+        *
+        * @param model
+        * @return cookie value
+        */
+       String getCookie(UserModel model);
+
+       /**
+        * Authenticate a user based on their cookie.
+        *
+        * @param cookie
+        * @return a user object or null
+        */
+       UserModel authenticate(char[] cookie);
+
+       /**
+        * Authenticate a user based on a username and password.
+        *
+        * @param username
+        * @param password
+        * @return a user object or null
+        */
+       UserModel authenticate(String username, char[] password);
+
+       /**
+        * Logout a user.
+        *
+        * @param user
+        */
+       void logout(UserModel user);
+
+       /**
+        * Retrieve the user object for the specified username.
+        *
+        * @param username
+        * @return a user object or null
+        */
+       UserModel getUserModel(String username);
+
+       /**
+        * Updates/writes a complete user object.
+        *
+        * @param model
+        * @return true if update is successful
+        */
+       boolean updateUserModel(UserModel model);
+
+       /**
+        * Updates/writes all specified user objects.
+        *
+        * @param models a list of user models
+        * @return true if update is successful
+        * @since 1.2.0
+        */
+       boolean updateUserModels(Collection<UserModel> models);
+
+       /**
+        * Adds/updates a user object keyed by username. This method allows for
+        * renaming a user.
+        *
+        * @param username
+        *            the old username
+        * @param model
+        *            the user object to use for username
+        * @return true if update is successful
+        */
+       boolean updateUserModel(String username, UserModel model);
+
+       /**
+        * Deletes the user object from the user service.
+        *
+        * @param model
+        * @return true if successful
+        */
+       boolean deleteUserModel(UserModel model);
+
+       /**
+        * Delete the user object with the specified username
+        *
+        * @param username
+        * @return true if successful
+        */
+       boolean deleteUser(String username);
+
+       /**
+        * Returns the list of all users available to the login service.
+        *
+        * @return list of all usernames
+        */
+       List<String> getAllUsernames();
+
+       /**
+        * Returns the list of all users available to the login service.
+        *
+        * @return list of all users
+        * @since 0.8.0
+        */
+       List<UserModel> getAllUsers();
+
+       /**
+        * Returns the list of all teams available to the login service.
+        *
+        * @return list of all teams
+        * @since 0.8.0
+        */
+       List<String> getAllTeamNames();
+
+       /**
+        * Returns the list of all teams available to the login service.
+        *
+        * @return list of all teams
+        * @since 0.8.0
+        */
+       List<TeamModel> getAllTeams();
+
+       /**
+        * Returns the list of all users who are allowed to bypass the access
+        * restriction placed on the specified repository.
+        *
+        * @param role
+        *            the repository name
+        * @return list of all usernames that can bypass the access restriction
+        * @since 0.8.0
+        */
+       List<String> getTeamnamesForRepositoryRole(String role);
+
+       /**
+        * Retrieve the team object for the specified team name.
+        *
+        * @param teamname
+        * @return a team object or null
+        * @since 0.8.0
+        */
+       TeamModel getTeamModel(String teamname);
+
+       /**
+        * Updates/writes a complete team object.
+        *
+        * @param model
+        * @return true if update is successful
+        * @since 0.8.0
+        */
+       boolean updateTeamModel(TeamModel model);
+
+       /**
+        * Updates/writes all specified team objects.
+        *
+        * @param models a list of team models
+        * @return true if update is successful
+        * @since 1.2.0
+        */
+       boolean updateTeamModels(Collection<TeamModel> models);
+
+       /**
+        * Updates/writes and replaces a complete team object keyed by teamname.
+        * This method allows for renaming a team.
+        *
+        * @param teamname
+        *            the old teamname
+        * @param model
+        *            the team object to use for teamname
+        * @return true if update is successful
+        * @since 0.8.0
+        */
+       boolean updateTeamModel(String teamname, TeamModel model);
+
+       /**
+        * Deletes the team object from the user service.
+        *
+        * @param model
+        * @return true if successful
+        * @since 0.8.0
+        */
+       boolean deleteTeamModel(TeamModel model);
+
+       /**
+        * Delete the team object with the specified teamname
+        *
+        * @param teamname
+        * @return true if successful
+        * @since 0.8.0
+        */
+       boolean deleteTeam(String teamname);
+
+       /**
+        * Returns the list of all users who are allowed to bypass the access
+        * restriction placed on the specified repository.
+        *
+        * @param role
+        *            the repository name
+        * @return list of all usernames that can bypass the access restriction
+        * @since 0.8.0
+        */
+       List<String> getUsernamesForRepositoryRole(String role);
+
+       /**
+        * Renames a repository role.
+        *
+        * @param oldRole
+        * @param newRole
+        * @return true if successful
+        */
+       boolean renameRepositoryRole(String oldRole, String newRole);
+
+       /**
+        * Removes a repository role from all users.
+        *
+        * @param role
+        * @return true if successful
+        */
+       boolean deleteRepositoryRole(String role);
+
+}
\ No newline at end of file
index ddd7e3717a7fe20b3075668a08e37db94c47d718..3a54d33f6caa78ef668eb97bb3584c152b56be19 100644 (file)
@@ -34,8 +34,9 @@ import java.util.TreeSet;
 import org.eclipse.jgit.lib.Constants;\r
 import org.eclipse.jgit.lib.Repository;\r
 \r
-import com.gitblit.GitBlit;\r
+import com.gitblit.IStoredSettings;\r
 import com.gitblit.Keys;\r
+import com.gitblit.manager.IRepositoryManager;\r
 import com.gitblit.models.Activity;\r
 import com.gitblit.models.GravatarProfile;\r
 import com.gitblit.models.RefModel;\r
@@ -55,6 +56,10 @@ public class ActivityUtils {
         * Gets the recent activity from the repositories for the last daysBack days\r
         * on the specified branch.\r
         *\r
+        * @param settings\r
+        *            the runtime settings\r
+        * @param repositoryManager\r
+        *            the repository manager\r
         * @param models\r
         *            the list of repositories to query\r
         * @param daysBack\r
@@ -66,8 +71,13 @@ public class ActivityUtils {
         *            the timezone for aggregating commits\r
         * @return\r
         */\r
-       public static List<Activity> getRecentActivity(List<RepositoryModel> models, int daysBack,\r
-                       String objectId, TimeZone timezone) {\r
+       public static List<Activity> getRecentActivity(\r
+                                       IStoredSettings settings,\r
+                                       IRepositoryManager repositoryManager,\r
+                                       List<RepositoryModel> models,\r
+                                       int daysBack,\r
+                                       String objectId,\r
+                                       TimeZone timezone) {\r
 \r
                // Activity panel shows last daysBack of activity across all\r
                // repositories.\r
@@ -82,7 +92,7 @@ public class ActivityUtils {
 \r
                // aggregate author exclusions\r
                Set<String> authorExclusions = new TreeSet<String>();\r
-               authorExclusions.addAll(GitBlit.getStrings(Keys.web.metricAuthorExclusions));\r
+               authorExclusions.addAll(settings.getStrings(Keys.web.metricAuthorExclusions));\r
                for (RepositoryModel model : models) {\r
                        if (!ArrayUtils.isEmpty(model.metricAuthorExclusions)) {\r
                                authorExclusions.addAll(model.metricAuthorExclusions);\r
@@ -99,8 +109,7 @@ public class ActivityUtils {
                                if (model.isCollectingGarbage) {\r
                                        continue;\r
                                }\r
-                               Repository repository = GitBlit.self()\r
-                                               .getRepository(model.name);\r
+                               Repository repository = repositoryManager.getRepository(model.name);\r
                                List<String> branches = new ArrayList<String>();\r
                                if (StringUtils.isEmpty(objectId)) {\r
                                        for (RefModel local : JGitUtils.getLocalBranches(\r
index 1a46a1f77c1abef213d37e32909a1a1979964b9f..46a3b067a921488a039e8f8385a0b775d1265451 100644 (file)
@@ -31,6 +31,14 @@ import org.apache.wicket.protocol.http.WebApplication;
 import com.gitblit.GitBlit;
 import com.gitblit.IStoredSettings;
 import com.gitblit.Keys;
+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.utils.StringUtils;
 import com.gitblit.wicket.pages.ActivityPage;
 import com.gitblit.wicket.pages.BlamePage;
@@ -80,7 +88,7 @@ public class GitBlitWebApp extends WebApplication {
        public void init() {
                super.init();
 
-               settings = GitBlit.getSettings();
+               settings = runtime().getSettings();
 
                // Setup page authorization mechanism
                boolean useAuthentication = settings.getBoolean(Keys.web.authenticateViewPages, false)
@@ -197,7 +205,7 @@ public class GitBlitWebApp extends WebApplication {
         * @return true if Gitblit is running in debug mode
         */
        public boolean isDebugMode() {
-               return GitBlit.isDebugMode();
+               return runtime().isDebugMode();
        }
 
        /*
@@ -205,47 +213,47 @@ public class GitBlitWebApp extends WebApplication {
         * step towards modularization across multiple commits.
         */
        public Date getBootDate() {
-               return GitBlit.getBootDate();
+               return runtime().getBootDate();
        }
 
        public Date getLastActivityDate() {
-               return GitBlit.getLastActivityDate();
+               return repositories().getLastActivityDate();
        }
 
-       public GitBlit runtime() {
-               return GitBlit.self();
+       public IRuntimeManager runtime() {
+               return GitBlit.getManager(IRuntimeManager.class);
        }
 
-       public GitBlit mail() {
-               return GitBlit.self();
+       public INotificationManager notifier() {
+               return GitBlit.getManager(INotificationManager.class);
        }
 
-       public GitBlit users() {
-               return GitBlit.self();
+       public IUserManager users() {
+               return GitBlit.getManager(IUserManager.class);
        }
 
-       public GitBlit session() {
-               return GitBlit.self();
+       public ISessionManager session() {
+               return GitBlit.getManager(ISessionManager.class);
        }
 
-       public GitBlit repositories() {
-               return GitBlit.self();
+       public IRepositoryManager repositories() {
+               return GitBlit.getManager(IRepositoryManager.class);
        }
 
-       public GitBlit projects() {
-               return GitBlit.self();
+       public IProjectManager projects() {
+               return GitBlit.getManager(IProjectManager.class);
        }
 
-       public GitBlit federation() {
-               return GitBlit.self();
+       public IFederationManager federation() {
+               return GitBlit.getManager(IFederationManager.class);
        }
 
-       public GitBlit gitblit() {
-               return GitBlit.self();
+       public IGitblitManager gitblit() {
+               return GitBlit.getManager(IGitblitManager.class);
        }
 
        public TimeZone getTimezone() {
-               return GitBlit.getTimezone();
+               return runtime().getTimezone();
        }
 
        @Override
index 0f639c747f4350fbc2aa93395cd7d16744ac8cf6..fbe68fe48a34e21f5412943bc3336ffb85bc4ab8 100644 (file)
@@ -25,7 +25,11 @@ import org.eclipse.jgit.lib.Repository;
 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.manager.IProjectManager;\r
+import com.gitblit.manager.IRepositoryManager;\r
+import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.models.ProjectModel;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.utils.JGitUtils;\r
@@ -77,18 +81,23 @@ public class GitblitWicketFilter extends WicketFilter {
                        commitId = servletRequest.getParameter("h");\r
                }\r
 \r
-               repo = repo.replace("%2f", "/").replace("%2F", "/").replace(GitBlit.getChar(Keys.web.forwardSlashCharacter, '/'), '/');\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
-               int expires = GitBlit.getInteger(Keys.web.pageCacheExpires, 0);\r
+               int expires = settings.getInteger(Keys.web.pageCacheExpires, 0);\r
                if (!StringUtils.isEmpty(page) && app.isCacheablePage(page) && expires > 0) {\r
                        // page can be cached by the browser\r
                        CacheControl cacheControl = app.getCacheControl(page);\r
-                       Date bootDate = GitBlit.getBootDate();\r
+                       Date bootDate = runtimeManager.getBootDate();\r
                        switch (cacheControl.value()) {\r
                        case ACTIVITY:\r
                                // returns the last activity date of the server\r
-                               Date activityDate = GitBlit.getLastActivityDate();\r
+                               Date activityDate = repositoryManager.getLastActivityDate();\r
                                if (activityDate != null) {\r
                                        return activityDate.after(bootDate) ? activityDate.getTime() : bootDate.getTime();\r
                                }\r
@@ -98,7 +107,7 @@ public class GitblitWicketFilter extends WicketFilter {
                                return bootDate.getTime();\r
                        case PROJECT:\r
                                // return the latest change date for the project OR the boot date\r
-                               ProjectModel project = GitBlit.self().getProjectModel(StringUtils.getRootPath(repo));\r
+                               ProjectModel project = projectManager.getProjectModel(StringUtils.getRootPath(repo));\r
                                if (project != null) {\r
                                        return project.lastChange.after(bootDate) ? project.lastChange.getTime() : bootDate.getTime();\r
                                }\r
@@ -106,7 +115,7 @@ public class GitblitWicketFilter extends WicketFilter {
                        case REPOSITORY:\r
                                // return the lastest change date for the repository OR the boot\r
                                // date, whichever is latest\r
-                               RepositoryModel repository = GitBlit.self().getRepositoryModel(repo);\r
+                               RepositoryModel repository = repositoryManager.getRepositoryModel(repo);\r
                                if (repository != null && repository.lastChange != null) {\r
                                        return repository.lastChange.after(bootDate) ? repository.lastChange.getTime() : bootDate.getTime();\r
                                }\r
@@ -121,7 +130,7 @@ public class GitblitWicketFilter extends WicketFilter {
                                        Repository r = null;\r
                                        try {\r
                                                // return the timestamp of the associated commit\r
-                                               r = GitBlit.self().getRepository(repo);\r
+                                               r = repositoryManager.getRepository(repo);\r
                                                if (r != null) {\r
                                                        RevCommit commit = JGitUtils.getCommit(r, commitId);\r
                                                        if (commit != null) {\r
index 5e7332f5a7047b41265736d7df78dbbe4b3ef783..070caf32846020e91db54494f7fe8df8a72b535f 100644 (file)
@@ -71,8 +71,13 @@ public class ActivityPage extends RootPage {
 \r
                // determine repositories to view and retrieve the activity\r
                List<RepositoryModel> models = getRepositories(params);\r
-               List<Activity> recentActivity = ActivityUtils.getRecentActivity(models,\r
-                               daysBack, objectId, getTimeZone());\r
+               List<Activity> recentActivity = ActivityUtils.getRecentActivity(\r
+                               app().settings(),\r
+                               app().repositories(),\r
+                               models,\r
+                               daysBack,\r
+                               objectId,\r
+                               getTimeZone());\r
 \r
                String headerPattern;\r
                if (daysBack == 1) {\r
index 3e308f1b8a580e21a48d4ace3be3979ddcac7f42..a3c1ece5fee7f593a9f7926cea6c4061fc3275c0 100644 (file)
@@ -97,10 +97,10 @@ public class ChangePasswordPage extends RootSubPage {
 \r
                                user.password = password;\r
                                try {\r
-                                       app().users().updateUserModel(user.username, user, false);\r
+                                       app().gitblit().updateUserModel(user.username, user, false);\r
                                        if (app().settings().getBoolean(Keys.web.allowCookieAuthentication, false)) {\r
                                                WebResponse response = (WebResponse) getRequestCycle().getResponse();\r
-                                               app().session().setCookie(response, user);\r
+                                               app().session().setCookie(response.getHttpServletResponse(), user);\r
                                        }\r
                                } catch (GitBlitException e) {\r
                                        error(e.getMessage());\r
index 76b34f3abba5f47e091e4c6e1a852eece3392880..a986fd53f5985608308f8f91ddc0d598494c2904 100644 (file)
@@ -169,7 +169,7 @@ public class EditRepositoryPage extends RootSubPage {
                final RegistrantPermissionsPanel usersPalette = new RegistrantPermissionsPanel("users",\r
                                RegistrantType.USER, app().users().getAllUsernames(), repositoryUsers, getAccessPermissions());\r
                final RegistrantPermissionsPanel teamsPalette = new RegistrantPermissionsPanel("teams",\r
-                               RegistrantType.TEAM, app().users().getAllTeamnames(), repositoryTeams, getAccessPermissions());\r
+                               RegistrantType.TEAM, app().users().getAllTeamNames(), repositoryTeams, getAccessPermissions());\r
 \r
                // owners palette\r
                List<String> owners = new ArrayList<String>(repositoryModel.owners);\r
index 32905c95b1bc462d115aa11c584257f2b2d8f491..4f548d4662989a73a3b5bdc99378100d65de1d63 100644 (file)
@@ -196,7 +196,7 @@ public class EditTeamPage extends RootSubPage {
                                teamModel.postReceiveScripts.addAll(postReceiveScripts);\r
 \r
                                try {\r
-                                       app().users().updateTeamModel(oldName, teamModel, isCreate);\r
+                                       app().gitblit().updateTeamModel(oldName, teamModel, isCreate);\r
                                } catch (GitBlitException e) {\r
                                        error(e.getMessage());\r
                                        return;\r
index d0e52f469a294ea51adb4b5ff1fc5e91268dde45..b2d3d3b1715452a1202b98911d0aba3cc834d138 100644 (file)
@@ -110,7 +110,7 @@ public class EditUserPage extends RootSubPage {
 \r
                final Palette<String> teams = new Palette<String>("teams", new ListModel<String>(\r
                                new ArrayList<String>(userTeams)), new CollectionModel<String>(app().users()\r
-                               .getAllTeamnames()), new StringChoiceRenderer(), 10, false);\r
+                               .getAllTeamNames()), new StringChoiceRenderer(), 10, false);\r
                Form<UserModel> form = new Form<UserModel>("editForm", model) {\r
 \r
                        private static final long serialVersionUID = 1L;\r
@@ -192,7 +192,7 @@ public class EditUserPage extends RootSubPage {
                                }\r
 \r
                                try {\r
-                                       app().users().updateUserModel(oldName, userModel, isCreate);\r
+                                       app().gitblit().updateUserModel(oldName, userModel, isCreate);\r
                                } catch (GitBlitException e) {\r
                                        error(e.getMessage());\r
                                        return;\r
index 9e4d355c9fd254f52010462ecbdc7dcd409bf199..06eb72aae162853bc03f499fc7721d07944c3c46 100644 (file)
@@ -58,7 +58,7 @@ public class EmptyRepositoryPage extends RootPage {
                }\r
 \r
                HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest();\r
-               List<RepositoryUrl> repositoryUrls = app().repositories().getRepositoryUrls(req, user, repository);\r
+               List<RepositoryUrl> repositoryUrls = app().gitblit().getRepositoryUrls(req, user, repository);\r
                RepositoryUrl primaryUrl = repositoryUrls.size() == 0 ? null : repositoryUrls.get(0);\r
                String url = primaryUrl != null ? primaryUrl.url : "";\r
 \r
index f7be99aea54931c64c47a0e5945568157482dbb2..d99c14664f59affba4d16e81b03695b40f5030de 100644 (file)
@@ -27,8 +27,7 @@ public class LogoutPage extends BasePage {
                super();\r
                GitBlitWebSession session = GitBlitWebSession.get();\r
                UserModel user = session.getUser();\r
-               app().session().setCookie((WebResponse) getResponse(), null);\r
-               app().session().logout(user);\r
+               app().session().logout(((WebResponse) getResponse()).getHttpServletResponse(), user);\r
                session.invalidate();\r
 \r
                /*\r
index e19c1955857560bee0cc3cadf7313b85595c6a9c..0552c3042312834d48df7f016a2aa6534dc79b83 100644 (file)
@@ -139,7 +139,7 @@ public abstract class RepositoryPage extends RootPage {
                                UserRepositoryPreferences prefs = user.getPreferences().getRepositoryPreferences(getRepositoryModel().name);\r
                                prefs.starred = star;\r
                                try {\r
-                                       app().users().updateUserModel(user.username, user, false);\r
+                                       app().gitblit().updateUserModel(user.username, user, false);\r
                                } catch (GitBlitException e) {\r
                                        logger.error("Failed to update user " + user.username, e);\r
                                        error(getString("gb.failedToUpdateUser"), false);\r
index 98a8cb3274cce56b1fba1352fa0cefa507ac67fe..1a43bf1e011944009a24969dc908128f8873dcff 100644 (file)
@@ -252,7 +252,7 @@ public abstract class RootPage extends BasePage {
                        // Set Cookie\r
                        if (app().settings().getBoolean(Keys.web.allowCookieAuthentication, false)) {\r
                                WebResponse response = (WebResponse) getRequestCycle().getResponse();\r
-                               app().session().setCookie(response, user);\r
+                               app().session().setCookie(response.getHttpServletResponse(), user);\r
                        }\r
 \r
                        if (!session.continueRequest()) {\r
index 886dd6e683a94d5ceca39e5444ea16435e79cd1d..a10102f47f1989cb0ccbb444d4537c4c2104fb7e 100644 (file)
@@ -70,7 +70,7 @@ public abstract class SessionPage extends WebPage {
 \r
                        // Set Cookie\r
                        WebResponse response = (WebResponse) getRequestCycle().getResponse();\r
-                       app().session().setCookie(response, user);\r
+                       app().session().setCookie(response.getHttpServletResponse(), user);\r
 \r
                        session.continueRequest();\r
                }\r
index 3c8d990206f408af946745f382a126af9bf02b33..b7382b87f817079796008073804c70080dbd6aea 100644 (file)
@@ -15,8 +15,6 @@
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-\r
 import java.io.IOException;\r
 \r
 import org.junit.Test;\r
@@ -24,7 +22,7 @@ import org.junit.Test;
 import com.gitblit.models.GravatarProfile;\r
 import com.gitblit.utils.ActivityUtils;\r
 \r
-public class ActivityTest {\r
+public class ActivityTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testGravatarProfile() throws IOException {\r
index 45964a1800a28b3cc33d1b50e9e12745053dbe4e..93089782fbb91b5385d0b40e2c1c93dae8e0d1fd 100644 (file)
@@ -15,9 +15,6 @@
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.util.ArrayList;\r
 import java.util.Arrays;\r
 import java.util.HashSet;\r
@@ -28,7 +25,7 @@ import org.junit.Test;
 \r
 import com.gitblit.utils.ArrayUtils;\r
 \r
-public class ArrayUtilsTest {\r
+public class ArrayUtilsTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testArrays() {\r
index 2962c36fd24ec23c59ccb30142e77130259e24ae..16ca2adb22bd32b8a87aea1bd3f6c731e797bb95 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-\r
 import org.junit.Test;\r
 \r
 import com.gitblit.utils.Base64;\r
 \r
-public class Base64Test {\r
+public class Base64Test extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testBase64() {\r
index ec3b395e8377dc2ac86261f503c86ae8a7356fe6..a6a98708ebad60d5eb9869cbc791291618d4e70c 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-\r
 import java.util.Locale;\r
 \r
 import org.junit.Test;\r
 \r
 import com.gitblit.utils.ByteFormat;\r
 \r
-public class ByteFormatTest {\r
+public class ByteFormatTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testByteFormat() throws Exception {\r
index 48cd19f80df1df546d5758720a44e042ccfeaf02..9d627b80116c2500c474e9f310efd7669bea593c 100644 (file)
@@ -15,9 +15,6 @@
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.util.List;\r
 \r
 import org.eclipse.jgit.lib.Repository;\r
@@ -29,7 +26,7 @@ import com.gitblit.utils.DiffUtils;
 import com.gitblit.utils.DiffUtils.DiffOutputType;\r
 import com.gitblit.utils.JGitUtils;\r
 \r
-public class DiffUtilsTest {\r
+public class DiffUtilsTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testDiffOutputTypes() throws Exception {\r
index 056a6c3440539d5df456cfee05e88049bad9d096..5ee0ac93cad8bb5335efa7a94e8869ca4dc08267 100644 (file)
@@ -15,8 +15,6 @@
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-\r
 import java.text.MessageFormat;\r
 import java.util.Date;\r
 import java.util.Map;\r
@@ -31,7 +29,7 @@ import com.gitblit.fanout.FanoutNioService;
 import com.gitblit.fanout.FanoutService;\r
 import com.gitblit.fanout.FanoutSocketService;\r
 \r
-public class FanoutServiceTest {\r
+public class FanoutServiceTest extends GitblitUnitTest {\r
 \r
        int fanoutPort = FanoutService.DEFAULT_PORT;\r
 \r
index 688ae289c578b6db938b2dc5a2bef2d90dc2f245..144fe3da8682784599f9a2127e344b6d35a4089c 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.util.Date;\r
 import java.util.HashMap;\r
 import java.util.List;\r
@@ -42,7 +38,7 @@ import com.gitblit.utils.FederationUtils;
 import com.gitblit.utils.JsonUtils;\r
 import com.gitblit.utils.RpcUtils;\r
 \r
-public class FederationTests {\r
+public class FederationTests extends GitblitUnitTest {\r
 \r
        String url = GitBlitSuite.url;\r
        String account = GitBlitSuite.account;\r
index f345690c4bbf8e5e4ff8f25060fa3ab7f7959b8c..fd970844b6ee70d29ce885f7a344864bfb8130f2 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.io.File;\r
 \r
 import org.junit.Test;\r
 \r
 import com.gitblit.utils.FileUtils;\r
 \r
-public class FileUtilsTest {\r
+public class FileUtilsTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testReadContent() throws Exception {\r
index 96787fdf22a545923eec29fa6f8748f4974ef362..f623032ccffc6cad5304d6aba8c596bb3d023ae2 100644 (file)
@@ -36,6 +36,7 @@ import org.junit.runners.Suite.SuiteClasses;
 import com.gitblit.GitBlit;\r
 import com.gitblit.GitBlitException;\r
 import com.gitblit.GitBlitServer;\r
+import com.gitblit.manager.IRepositoryManager;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.utils.JGitUtils;\r
 \r
@@ -179,9 +180,10 @@ public class GitBlitSuite {
 \r
        private static void showRemoteBranches(String repositoryName) {\r
                try {\r
-                       RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
+                       IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+                       RepositoryModel model = repositoryManager.getRepositoryModel(repositoryName);\r
                        model.showRemoteBranches = true;\r
-                       GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+                       repositoryManager.updateRepositoryModel(model.name, model, false);\r
                } catch (GitBlitException g) {\r
                        g.printStackTrace();\r
                }\r
@@ -189,9 +191,10 @@ public class GitBlitSuite {
 \r
        private static void automaticallyTagBranchTips(String repositoryName) {\r
                try {\r
-                       RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
+                       IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);\r
+                       RepositoryModel model = repositoryManager.getRepositoryModel(repositoryName);\r
                        model.useIncrementalPushTags = true;\r
-                       GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+                       repositoryManager.updateRepositoryModel(model.name, model, false);\r
                } catch (GitBlitException g) {\r
                        g.printStackTrace();\r
                }\r
index 4fb58642ec1fcdef0d52752d05ccaf01af9cc4eb..692afb767b29a4b394455475c6da7fac462680f8 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.util.List;\r
 \r
 import org.eclipse.jgit.lib.Repository;\r
@@ -27,48 +22,47 @@ import org.junit.Test;
 \r
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.FileSettings;\r
-import com.gitblit.GitBlit;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 \r
-public class GitBlitTest {\r
+public class GitBlitTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testRepositoryModel() throws Exception {\r
-               List<String> repositories = GitBlit.self().getRepositoryList();\r
+               List<String> repositories = repositories().getRepositoryList();\r
                assertTrue("Repository list is empty!", repositories.size() > 0);\r
                assertTrue(\r
                                "Missing Helloworld repository!",\r
                                repositories.contains(GitBlitSuite.getHelloworldRepository().getDirectory()\r
                                                .getName()));\r
                Repository r = GitBlitSuite.getHelloworldRepository();\r
-               RepositoryModel model = GitBlit.self().getRepositoryModel(r.getDirectory().getName());\r
+               RepositoryModel model = repositories().getRepositoryModel(r.getDirectory().getName());\r
                assertTrue("Helloworld model is null!", model != null);\r
                assertEquals(GitBlitSuite.getHelloworldRepository().getDirectory().getName(), model.name);\r
-               assertTrue(GitBlit.self().updateLastChangeFields(r, model) > 22000L);\r
+               assertTrue(repositories().updateLastChangeFields(r, model) > 22000L);\r
                r.close();\r
        }\r
 \r
        @Test\r
        public void testUserModel() throws Exception {\r
-               List<String> users = GitBlit.self().getAllUsernames();\r
+               List<String> users = users().getAllUsernames();\r
                assertTrue("No users found!", users.size() > 0);\r
                assertTrue("Admin not found", users.contains("admin"));\r
-               UserModel user = GitBlit.self().getUserModel("admin");\r
+               UserModel user = users().getUserModel("admin");\r
                assertEquals("admin", user.toString());\r
                assertTrue("Admin missing #admin role!", user.canAdmin);\r
                user.canAdmin = false;\r
                assertFalse("Admin should not have #admin!", user.canAdmin);\r
                String repository = GitBlitSuite.getHelloworldRepository().getDirectory().getName();\r
-               RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(repository);\r
+               RepositoryModel repositoryModel = repositories().getRepositoryModel(repository);\r
                repositoryModel.accessRestriction = AccessRestrictionType.VIEW;\r
                assertFalse("Admin can still access repository!",\r
                                user.canView(repositoryModel));\r
                user.addRepositoryPermission(repository);\r
                assertTrue("Admin can't access repository!", user.canView(repositoryModel));\r
-               assertEquals(GitBlit.self().getRepositoryModel(user, "pretend"), null);\r
-               assertNotNull(GitBlit.self().getRepositoryModel(user, repository));\r
-               assertTrue(GitBlit.self().getRepositoryModels(user).size() > 0);\r
+               assertEquals(repositories().getRepositoryModel(user, "pretend"), null);\r
+               assertNotNull(repositories().getRepositoryModel(user, repository));\r
+               assertTrue(repositories().getRepositoryModels(user).size() > 0);\r
        }\r
 \r
        @Test\r
@@ -156,34 +150,34 @@ public class GitBlitTest {
        @Test\r
        public void testGitblitSettings() throws Exception {\r
                // These are already tested by above test method.\r
-               assertTrue(GitBlit.getBoolean("missing", true));\r
-               assertEquals("default", GitBlit.getString("missing", "default"));\r
-               assertEquals(10, GitBlit.getInteger("missing", 10));\r
-               assertEquals(5, GitBlit.getInteger("realm.userService", 5));\r
-\r
-               assertTrue(GitBlit.getBoolean("git.enableGitServlet", false));\r
-               assertEquals(GitBlitSuite.USERSCONF.getAbsolutePath(), GitBlit.getString("realm.userService", null));\r
-               assertEquals(5, GitBlit.getInteger("realm.minPasswordLength", 0));\r
-               List<String> mdExtensions = GitBlit.getStrings("web.markdownExtensions");\r
+               assertTrue(settings().getBoolean("missing", true));\r
+               assertEquals("default", settings().getString("missing", "default"));\r
+               assertEquals(10, settings().getInteger("missing", 10));\r
+               assertEquals(5, settings().getInteger("realm.userService", 5));\r
+\r
+               assertTrue(settings().getBoolean("git.enableGitServlet", false));\r
+               assertEquals(GitBlitSuite.USERSCONF.getAbsolutePath(), settings().getString("realm.userService", null));\r
+               assertEquals(5, settings().getInteger("realm.minPasswordLength", 0));\r
+               List<String> mdExtensions = settings().getStrings("web.markdownExtensions");\r
                assertTrue(mdExtensions.size() > 0);\r
                assertTrue(mdExtensions.contains("md"));\r
 \r
-               List<String> keys = GitBlit.getAllKeys("server");\r
+               List<String> keys = settings().getAllKeys("server");\r
                assertTrue(keys.size() > 0);\r
                assertTrue(keys.contains("server.httpsPort"));\r
 \r
-               assertTrue(GitBlit.getChar("web.forwardSlashCharacter", ' ') == '/');\r
-               assertFalse(GitBlit.isDebugMode());\r
+               assertTrue(settings().getChar("web.forwardSlashCharacter", ' ') == '/');\r
+               assertFalse(runtime().isDebugMode());\r
        }\r
 \r
        @Test\r
        public void testAuthentication() throws Exception {\r
-               assertTrue(GitBlit.self().authenticate("admin", "admin".toCharArray()) != null);\r
+               assertTrue(session().authenticate("admin", "admin".toCharArray()) != null);\r
        }\r
 \r
        @Test\r
        public void testRepositories() throws Exception {\r
-               assertTrue(GitBlit.self().getRepository("missing") == null);\r
-               assertTrue(GitBlit.self().getRepositoryModel("missing") == null);\r
+               assertTrue(repositories().getRepository("missing") == null);\r
+               assertTrue(repositories().getRepositoryModel("missing") == null);\r
        }\r
 }\r
index 7febc7a1c83c989ec1dba48dbcbe0f5380669082..6e940cbe9945e432568e0e91cd9d9d481aafa099 100644 (file)
  */
 package com.gitblit.tests;
 
-import org.junit.Assert;
 import org.junit.Test;
 
 import com.gitblit.git.GitDaemon;
 
-public class GitDaemonStopTest extends Assert {
+public class GitDaemonStopTest extends GitblitUnitTest {
 
        @Test
        public void testGitDaemonStop() throws Exception {
index a283e6b07165736183f6c13ca40d5bd77027a823..74af251f38050e186f382a01f6da043b9357ce59 100644 (file)
@@ -31,16 +31,14 @@ import org.eclipse.jgit.transport.RemoteRefUpdate;
 import org.eclipse.jgit.transport.RemoteRefUpdate.Status;
 import org.eclipse.jgit.util.FileUtils;
 import org.junit.AfterClass;
-import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.gitblit.Constants.AccessRestrictionType;
 import com.gitblit.Constants.AuthorizationControl;
-import com.gitblit.GitBlit;
 import com.gitblit.models.RepositoryModel;
 
-public class GitDaemonTest extends Assert {
+public class GitDaemonTest extends GitblitUnitTest {
 
        static File ticgitFolder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit");
 
@@ -94,10 +92,10 @@ public class GitDaemonTest extends Assert {
                }
 
                // set push restriction
-               RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
+               RepositoryModel model = repositories().getRepositoryModel("ticgit.git");
                model.accessRestriction = AccessRestrictionType.PUSH;
                model.authorizationControl = AuthorizationControl.NAMED;
-               GitBlit.self().updateRepositoryModel(model.name, model, false);
+               repositories().updateRepositoryModel(model.name, model, false);
 
                CloneCommand clone = Git.cloneRepository();
                clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
@@ -110,7 +108,7 @@ public class GitDaemonTest extends Assert {
                // restore anonymous repository access
                model.accessRestriction = AccessRestrictionType.NONE;
                model.authorizationControl = AuthorizationControl.NAMED;
-               GitBlit.self().updateRepositoryModel(model.name, model, false);
+               repositories().updateRepositoryModel(model.name, model, false);
        }
 
        @Test
@@ -121,10 +119,10 @@ public class GitDaemonTest extends Assert {
                }
 
                // restrict repository access
-               RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
+               RepositoryModel model = repositories().getRepositoryModel("ticgit.git");
                model.accessRestriction = AccessRestrictionType.CLONE;
                model.authorizationControl = AuthorizationControl.NAMED;
-               GitBlit.self().updateRepositoryModel(model.name, model, false);
+               repositories().updateRepositoryModel(model.name, model, false);
 
                // delete any existing working folder
                boolean cloned = false;
@@ -147,7 +145,7 @@ public class GitDaemonTest extends Assert {
                // restore anonymous repository access
                model.accessRestriction = AccessRestrictionType.NONE;
                model.authorizationControl = AuthorizationControl.NAMED;
-               GitBlit.self().updateRepositoryModel(model.name, model, false);
+               repositories().updateRepositoryModel(model.name, model, false);
        }
 
        @Test
@@ -158,10 +156,10 @@ public class GitDaemonTest extends Assert {
                }
 
                // restore anonymous repository access
-               RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
+               RepositoryModel model = repositories().getRepositoryModel("ticgit.git");
                model.accessRestriction = AccessRestrictionType.NONE;
                model.authorizationControl = AuthorizationControl.NAMED;
-               GitBlit.self().updateRepositoryModel(model.name, model, false);
+               repositories().updateRepositoryModel(model.name, model, false);
 
                CloneCommand clone = Git.cloneRepository();
                clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
@@ -196,10 +194,10 @@ public class GitDaemonTest extends Assert {
                }
 
                // restore anonymous repository access
-               RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
+               RepositoryModel model = repositories().getRepositoryModel("ticgit.git");
                model.accessRestriction = AccessRestrictionType.PUSH;
                model.authorizationControl = AuthorizationControl.NAMED;
-               GitBlit.self().updateRepositoryModel(model.name, model, false);
+               repositories().updateRepositoryModel(model.name, model, false);
 
                CloneCommand clone = Git.cloneRepository();
                clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
@@ -242,9 +240,9 @@ public class GitDaemonTest extends Assert {
                assertTrue(true);
 
                // freeze repo
-               RepositoryModel model = GitBlit.self().getRepositoryModel("test/jgit.git");
+               RepositoryModel model = repositories().getRepositoryModel("test/jgit.git");
                model.isFrozen = true;
-               GitBlit.self().updateRepositoryModel(model.name, model, false);
+               repositories().updateRepositoryModel(model.name, model, false);
 
                Git git = Git.open(jgitFolder);
                File file = new File(jgitFolder, "TODO");
@@ -264,7 +262,7 @@ public class GitDaemonTest extends Assert {
 
                // unfreeze repo
                model.isFrozen = false;
-               GitBlit.self().updateRepositoryModel(model.name, model, false);
+               repositories().updateRepositoryModel(model.name, model, false);
 
                results = git.push().setPushAll().call();
                GitBlitSuite.close(git);
index 08c4a234a993c19cdf4c9c080f9a473b97c95873..b197a915633f82bdda3cc9d98c788f1c67a076e9 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.io.BufferedWriter;\r
 import java.io.File;\r
 import java.io.FileOutputStream;\r
@@ -53,7 +49,6 @@ import org.junit.Test;
 import com.gitblit.Constants.AccessPermission;\r
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.Constants.AuthorizationControl;\r
-import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
 import com.gitblit.models.RefLogEntry;\r
 import com.gitblit.models.RepositoryModel;\r
@@ -62,7 +57,7 @@ import com.gitblit.utils.ArrayUtils;
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.utils.RefLogUtils;\r
 \r
-public class GitServletTest {\r
+public class GitServletTest extends GitblitUnitTest {\r
 \r
        static File ticgitFolder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit");\r
 \r
@@ -87,8 +82,8 @@ public class GitServletTest {
        }\r
 \r
        private static void delete(UserModel user) {\r
-               if (GitBlit.self().getUserModel(user.username) != null) {\r
-                       GitBlit.self().deleteUser(user.username);\r
+               if (users().getUserModel(user.username) != null) {\r
+                       users().deleteUser(user.username);\r
                }\r
        }\r
 \r
@@ -148,9 +143,9 @@ public class GitServletTest {
        @Test\r
        public void testBogusLoginClone() throws Exception {\r
                // restrict repository access\r
-               RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");\r
+               RepositoryModel model = repositories().getRepositoryModel("ticgit.git");\r
                model.accessRestriction = AccessRestrictionType.CLONE;\r
-               GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+               repositories().updateRepositoryModel(model.name, model, false);\r
 \r
                // delete any existing working folder\r
                boolean cloned = false;\r
@@ -169,7 +164,7 @@ public class GitServletTest {
 \r
                // restore anonymous repository access\r
                model.accessRestriction = AccessRestrictionType.NONE;\r
-               GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+               repositories().updateRepositoryModel(model.name, model, false);\r
 \r
                assertFalse("Bogus login cloned a repository?!", cloned);\r
        }\r
@@ -177,13 +172,13 @@ public class GitServletTest {
        @Test\r
        public void testUnauthorizedLoginClone() throws Exception {\r
                // restrict repository access\r
-               RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");\r
+               RepositoryModel model = repositories().getRepositoryModel("ticgit.git");\r
                model.accessRestriction = AccessRestrictionType.CLONE;\r
                model.authorizationControl = AuthorizationControl.NAMED;\r
                UserModel user = new UserModel("james");\r
                user.password = "james";\r
-               GitBlit.self().updateUserModel(user.username, user, true);\r
-               GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+               gitblit().updateUserModel(user.username, user, true);\r
+               repositories().updateRepositoryModel(model.name, model, false);\r
 \r
                FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE);\r
 \r
@@ -208,7 +203,7 @@ public class GitServletTest {
 \r
                // switch to authenticated\r
                model.authorizationControl = AuthorizationControl.AUTHENTICATED;\r
-               GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+               repositories().updateRepositoryModel(model.name, model, false);\r
 \r
                // try clone again\r
                cloned = false;\r
@@ -228,7 +223,7 @@ public class GitServletTest {
                // restore anonymous repository access\r
                model.accessRestriction = AccessRestrictionType.NONE;\r
                model.authorizationControl = AuthorizationControl.NAMED;\r
-               GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+               repositories().updateRepositoryModel(model.name, model, false);\r
 \r
                delete(user);\r
        }\r
@@ -240,9 +235,9 @@ public class GitServletTest {
                        FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);\r
                }\r
 \r
-               RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");\r
+               RepositoryModel model = repositories().getRepositoryModel("ticgit.git");\r
                model.accessRestriction = AccessRestrictionType.NONE;\r
-               GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+               repositories().updateRepositoryModel(model.name, model, false);\r
 \r
                CloneCommand clone = Git.cloneRepository();\r
                clone.setURI(MessageFormat.format("{0}/ticgit.git", url));\r
@@ -320,9 +315,9 @@ public class GitServletTest {
                assertTrue(true);\r
 \r
                // freeze repo\r
-               RepositoryModel model = GitBlit.self().getRepositoryModel("test/jgit.git");\r
+               RepositoryModel model = repositories().getRepositoryModel("test/jgit.git");\r
                model.isFrozen = true;\r
-               GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+               repositories().updateRepositoryModel(model.name, model, false);\r
 \r
                Git git = Git.open(jgitFolder);\r
                File file = new File(jgitFolder, "TODO");\r
@@ -342,7 +337,7 @@ public class GitServletTest {
 \r
                // unfreeze repo\r
                model.isFrozen = false;\r
-               GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+               repositories().updateRepositoryModel(model.name, model, false);\r
 \r
                results = git.push().setPushAll().setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password)).call();\r
                GitBlitSuite.close(git);\r
@@ -428,7 +423,7 @@ public class GitServletTest {
                GitBlitSuite.close(clone.call());\r
 \r
                // require push permissions and committer verification\r
-               RepositoryModel model = GitBlit.self().getRepositoryModel("refchecks/verify-committer.git");\r
+               RepositoryModel model = repositories().getRepositoryModel("refchecks/verify-committer.git");\r
                model.authorizationControl = AuthorizationControl.NAMED;\r
                model.accessRestriction = AccessRestrictionType.PUSH;\r
                model.verifyCommitter = true;\r
@@ -436,8 +431,8 @@ public class GitServletTest {
                // grant user push permission\r
                user.setRepositoryPermission(model.name, AccessPermission.PUSH);\r
 \r
-               GitBlit.self().updateUserModel(user.username, user, true);\r
-               GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+               gitblit().updateUserModel(user.username, user, true);\r
+               repositories().updateRepositoryModel(model.name, model, false);\r
 \r
                // clone temp bare repo to working copy\r
                File local = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-wc");\r
@@ -513,7 +508,7 @@ public class GitServletTest {
                GitBlitSuite.close(clone.call());\r
 \r
                // require push permissions and committer verification\r
-               RepositoryModel model = GitBlit.self().getRepositoryModel("refchecks/verify-committer.git");\r
+               RepositoryModel model = repositories().getRepositoryModel("refchecks/verify-committer.git");\r
                model.authorizationControl = AuthorizationControl.NAMED;\r
                model.accessRestriction = AccessRestrictionType.PUSH;\r
                model.verifyCommitter = true;\r
@@ -521,8 +516,8 @@ public class GitServletTest {
                // grant user push permission\r
                user.setRepositoryPermission(model.name, AccessPermission.PUSH);\r
 \r
-               GitBlit.self().updateUserModel(user.username, user, true);\r
-               GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+               gitblit().updateUserModel(user.username, user, true);\r
+               repositories().updateRepositoryModel(model.name, model, false);\r
 \r
                // clone temp bare repo to working copy\r
                File local = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-wc");\r
@@ -648,7 +643,7 @@ public class GitServletTest {
                GitBlitSuite.close(clone.call());\r
 \r
                // elevate repository to clone permission\r
-               RepositoryModel model = GitBlit.self().getRepositoryModel("refchecks/ticgit.git");\r
+               RepositoryModel model = repositories().getRepositoryModel("refchecks/ticgit.git");\r
                switch (permission) {\r
                        case VIEW:\r
                                model.accessRestriction = AccessRestrictionType.CLONE;\r
@@ -664,8 +659,8 @@ public class GitServletTest {
                // grant user specified\r
                user.setRepositoryPermission(model.name, permission);\r
 \r
-               GitBlit.self().updateUserModel(user.username, user, true);\r
-               GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+               gitblit().updateUserModel(user.username, user, true);\r
+               repositories().updateRepositoryModel(model.name, model, false);\r
 \r
                // clone temp bare repo to working copy\r
                File local = new File(GitBlitSuite.REPOSITORIES, "refchecks/ticgit-wc");\r
@@ -834,7 +829,7 @@ public class GitServletTest {
                user.canCreate = canCreate;\r
                user.canAdmin = canAdmin;\r
 \r
-               GitBlit.self().updateUserModel(user.username, user, true);\r
+               gitblit().updateUserModel(user.username, user, true);\r
 \r
                CredentialsProvider cp = new UsernamePasswordCredentialsProvider(user.username, user.password);\r
 \r
@@ -885,7 +880,7 @@ public class GitServletTest {
                        assertTrue("User canAdmin:" + user.canAdmin + " canCreate:" + user.canCreate, user.canAdmin || user.canCreate);\r
 \r
                        // confirm default personal repository permissions\r
-                       RepositoryModel model = GitBlit.self().getRepositoryModel(MessageFormat.format("~{0}/ticgit.git", user.username));\r
+                       RepositoryModel model = repositories().getRepositoryModel(MessageFormat.format("~{0}/ticgit.git", user.username));\r
                        assertEquals("Unexpected owner", user.username, ArrayUtils.toString(model.owners));\r
                        assertEquals("Unexpected authorization control", AuthorizationControl.NAMED, model.authorizationControl);\r
                        assertEquals("Unexpected access restriction", AccessRestrictionType.VIEW, model.accessRestriction);\r
@@ -909,10 +904,10 @@ public class GitServletTest {
                        assertTrue("User canAdmin:" + user.canAdmin, user.canAdmin);\r
 \r
                        // confirm default project repository permissions\r
-                       RepositoryModel model = GitBlit.self().getRepositoryModel("project/ticgit.git");\r
+                       RepositoryModel model = repositories().getRepositoryModel("project/ticgit.git");\r
                        assertEquals("Unexpected owner", user.username, ArrayUtils.toString(model.owners));\r
-                       assertEquals("Unexpected authorization control", AuthorizationControl.fromName(GitBlit.getString(Keys.git.defaultAuthorizationControl, "NAMED")), model.authorizationControl);\r
-                       assertEquals("Unexpected access restriction", AccessRestrictionType.fromName(GitBlit.getString(Keys.git.defaultAccessRestriction, "NONE")), model.accessRestriction);\r
+                       assertEquals("Unexpected authorization control", AuthorizationControl.fromName(settings().getString(Keys.git.defaultAuthorizationControl, "NAMED")), model.authorizationControl);\r
+                       assertEquals("Unexpected access restriction", AccessRestrictionType.fromName(settings().getString(Keys.git.defaultAccessRestriction, "NONE")), model.accessRestriction);\r
 \r
                } catch (GitAPIException e) {\r
                        assertTrue(e.getMessage(), e.getMessage().contains("git-receive-pack not found"));\r
diff --git a/src/test/java/com/gitblit/tests/GitblitUnitTest.java b/src/test/java/com/gitblit/tests/GitblitUnitTest.java
new file mode 100644 (file)
index 0000000..fc70e10
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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 com.gitblit.GitBlit;
+import com.gitblit.IStoredSettings;
+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;
+
+
+public class GitblitUnitTest extends org.junit.Assert {
+
+       public static IStoredSettings settings() {
+               return runtime().getSettings();
+       }
+
+       public static IRuntimeManager runtime() {
+               return GitBlit.getManager(IRuntimeManager.class);
+       }
+
+       public static INotificationManager notifier() {
+               return GitBlit.getManager(INotificationManager.class);
+       }
+
+       public static IUserManager users() {
+               return GitBlit.getManager(IUserManager.class);
+       }
+
+       public static ISessionManager session() {
+               return GitBlit.getManager(ISessionManager.class);
+       }
+
+       public static IRepositoryManager repositories() {
+               return GitBlit.getManager(IRepositoryManager.class);
+       }
+
+       public static IProjectManager projects() {
+               return GitBlit.getManager(IProjectManager.class);
+       }
+
+       public static IFederationManager federation() {
+               return GitBlit.getManager(IFederationManager.class);
+       }
+
+       public static IGitblitManager gitblit() {
+               return GitBlit.getManager(IGitblitManager.class);
+       }
+}
index 2aa881f854ab6cd61007d5e3db3148ed050ccad9..1b5b0f39e3b9addc9d17fd24418fcca1ac58797d 100644 (file)
@@ -15,8 +15,6 @@
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
 import groovy.lang.Binding;\r
 import groovy.util.GroovyScriptEngine;\r
 \r
@@ -41,7 +39,6 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;\r
 import org.junit.Test;\r
 \r
-import com.gitblit.GitBlit;\r
 import com.gitblit.GitBlitException;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.TeamModel;\r
@@ -54,7 +51,7 @@ import com.gitblit.utils.StringUtils;
  * @author James Moger\r
  *\r
  */\r
-public class GroovyScriptTest {\r
+public class GroovyScriptTest extends GitblitUnitTest {\r
 \r
        private static final AtomicBoolean started = new AtomicBoolean(false);\r
 \r
@@ -83,7 +80,7 @@ public class GroovyScriptTest {
                                .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId\r
                                .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));\r
 \r
-               RepositoryModel repository = GitBlit.self().getRepositoryModel("helloworld.git");\r
+               RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");\r
                repository.customFields = new HashMap<String,String>();\r
                repository.customFields.put( "fogbugzUrl", "http://bugs.test.com" );\r
                repository.customFields.put( "fogbugzRepositoryId", "1" );\r
@@ -105,7 +102,7 @@ public class GroovyScriptTest {
                                .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId\r
                                .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));\r
 \r
-               RepositoryModel repository = GitBlit.self().getRepositoryModel("helloworld.git");\r
+               RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");\r
                repository.mailingLists.add("list@helloworld.git");\r
 \r
                test("sendmail-html.groovy", gitblit, logger, clientLogger, commands, repository);\r
@@ -130,7 +127,7 @@ public class GroovyScriptTest {
                                .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId\r
                                .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));\r
 \r
-               RepositoryModel repository = GitBlit.self().getRepositoryModel("helloworld.git");\r
+               RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");\r
                repository.mailingLists.add("list@helloworld.git");\r
 \r
                test("sendmail.groovy", gitblit, logger, clientLogger, commands, repository);\r
@@ -270,7 +267,7 @@ public class GroovyScriptTest {
 \r
                RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());\r
 \r
-               File groovyDir = GitBlit.getGroovyScriptsFolder();\r
+               File groovyDir = repositories().getHooksFolder();\r
                File tempScript = File.createTempFile("testClientLogging", "groovy", groovyDir);\r
                tempScript.deleteOnExit();\r
 \r
@@ -291,7 +288,7 @@ public class GroovyScriptTest {
 \r
                String gitblitUrl = GitBlitSuite.url;\r
 \r
-               File groovyDir = GitBlit.getGroovyScriptsFolder();\r
+               File groovyDir = repositories().getHooksFolder();\r
                GroovyScriptEngine gse = new GroovyScriptEngine(groovyDir.getAbsolutePath());\r
 \r
                Binding binding = new Binding();\r
index e223e6bb830cc3dc0f03310a58502d557ecb143a..e20c82a77640b9d00951385b0a8b393c87711fd6 100644 (file)
  */
 package com.gitblit.tests;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
 import java.io.File;
 import java.io.FilenameFilter;
 import java.io.IOException;
@@ -40,7 +34,7 @@ import com.gitblit.utils.StringUtils;
  * Test the Htpasswd user service.
  *
  */
-public class HtpasswdUserServiceTest {
+public class HtpasswdUserServiceTest extends GitblitUnitTest {
 
     private static final String RESOURCE_DIR = "src/test/resources/htpasswdUSTest/";
     private static final String KEY_SUPPORT_PLAINTEXT_PWD = "realm.htpasswd.supportPlaintextPasswords";
index 8e2acaf8405e4425852b5fbba22a5ddd2f383cd2..df2ccd0b165ba760425aa20756f60f0fe8f227e9 100644 (file)
@@ -17,7 +17,6 @@ package com.gitblit.tests;
 \r
 import java.io.File;\r
 \r
-import org.junit.Assert;\r
 import org.junit.Test;\r
 \r
 import com.gitblit.ConfigUserService;\r
@@ -40,7 +39,7 @@ import com.gitblit.models.UserModel;
  * @author James Moger\r
  *\r
  */\r
-public class Issue0259Test extends Assert {\r
+public class Issue0259Test extends GitblitUnitTest {\r
 \r
        RepositoryModel repo(String name, AccessRestrictionType restriction) {\r
                RepositoryModel repo = new RepositoryModel();\r
index 8bab8f2c17caea72c9b359b46c2e0a335252b081..15c6ff2310fc83d6a3ccb8a5cf1458c1666dd544 100644 (file)
@@ -17,7 +17,6 @@ package com.gitblit.tests;
 \r
 import java.io.File;\r
 \r
-import org.junit.Assert;\r
 import org.junit.Test;\r
 \r
 import com.gitblit.ConfigUserService;\r
@@ -37,7 +36,7 @@ import com.gitblit.models.UserModel;
  * @author James Moger\r
  *\r
  */\r
-public class Issue0271Test extends Assert {\r
+public class Issue0271Test extends GitblitUnitTest {\r
 \r
        RepositoryModel repo(String name, AccessRestrictionType restriction) {\r
                RepositoryModel repo = new RepositoryModel();\r
index a93749584f30663d73d7d7b2226e82a38f43f28f..f60343ae224f4e284e3f7c52320345b574a45d9e 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertNull;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.io.File;\r
 import java.io.FileOutputStream;\r
 import java.text.SimpleDateFormat;\r
@@ -57,7 +51,7 @@ import com.gitblit.utils.JGitUtils;
 import com.gitblit.utils.JnaUtils;\r
 import com.gitblit.utils.StringUtils;\r
 \r
-public class JGitUtilsTest {\r
+public class JGitUtilsTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testDisplayName() throws Exception {\r
index 96782156d0deda5aa48b36e0fa0e22c791de2f77..c7d5be931b33ba16ef74d853e571afd85826fb48 100644 (file)
  */
 package com.gitblit.tests;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
 import java.io.File;
 import java.io.IOException;
 
@@ -36,7 +32,7 @@ import com.gitblit.utils.JnaUtils;
  *
  * @author Florian Zschocke
  */
-public class JnaUtilsTest {
+public class JnaUtilsTest extends GitblitUnitTest {
 
        @Test
        public void testGetgid() {
index 40e8f97545d505a142b4870002d1470f029231b5..1cd31b8b7e6f9eaadc5d2f46c53dcfe74255f6f4 100644 (file)
@@ -15,8 +15,6 @@
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-\r
 import java.text.SimpleDateFormat;\r
 import java.util.Date;\r
 import java.util.HashMap;\r
@@ -27,7 +25,7 @@ import org.junit.Test;
 import com.gitblit.utils.JsonUtils;\r
 import com.google.gson.reflect.TypeToken;\r
 \r
-public class JsonUtilsTest {\r
+public class JsonUtilsTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testSerialization() {\r
index ae8933eaedf7af570f53290e505e98b23b8b2f26..86d1f3ca8e52a899660f577549356b90e1564602 100644 (file)
  */
 package com.gitblit.tests;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
 import java.util.HashMap;
 import java.util.Map;
 
@@ -44,7 +39,7 @@ import com.unboundid.ldif.LDIFReader;
  * @author jcrygier
  *
  */
-public class LdapUserServiceTest {
+public class LdapUserServiceTest extends GitblitUnitTest {
 
        private LdapUserService ldapUserService;
 
index ec25c51936911126e3a7810386b0501fb0dc530b..0f7e55ca701ad2061ee88bc6df12c0a9679ce0bd 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.util.ArrayList;\r
 import java.util.HashMap;\r
 import java.util.List;\r
@@ -43,7 +39,7 @@ import com.gitblit.utils.JGitUtils;
  * @author James Moger\r
  *\r
  */\r
-public class LuceneExecutorTest {\r
+public class LuceneExecutorTest extends GitblitUnitTest {\r
 \r
        LuceneExecutor lucene;\r
 \r
index 4feedb060a68a440bae11eee787475895fdcb5d8..7598568bca2a2f87d146fd69f1ad9ec65b41ad77 100644 (file)
@@ -15,8 +15,6 @@
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertTrue;\r
-\r
 import javax.mail.Message;\r
 \r
 import org.junit.Test;\r
@@ -25,7 +23,7 @@ import com.gitblit.FileSettings;
 import com.gitblit.Keys;\r
 import com.gitblit.MailExecutor;\r
 \r
-public class MailTest {\r
+public class MailTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testSendMail() throws Exception {\r
index 3458374799becb0e1ffaa6b5c7f80b6f40b79e82..e40f1057a42584f776417f8954593f7b29b236b8 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-\r
 import org.junit.Test;\r
 \r
 import com.gitblit.utils.MarkdownUtils;\r
 \r
-public class MarkdownUtilsTest {\r
+public class MarkdownUtilsTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testMarkdown() throws Exception {\r
index bb8261afc8bafc23d4ad2a0cee52f413986619dd..4d620ae6aa5656c69697b22eda7b21b113c6df57 100644 (file)
@@ -15,9 +15,6 @@
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.util.List;\r
 import java.util.TimeZone;\r
 \r
@@ -27,7 +24,7 @@ import org.junit.Test;
 import com.gitblit.models.Metric;\r
 import com.gitblit.utils.MetricUtils;\r
 \r
-public class MetricUtilsTest {\r
+public class MetricUtilsTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testMetrics() throws Exception {\r
index 9dd29b64b96c14430f3d086fd907525efc25f135..e34e0aa47bd1f54c8f9fd284658ae1f0042202b5 100644 (file)
@@ -1,16 +1,12 @@
 package com.gitblit.tests;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
 import org.junit.After;
 import org.junit.Test;
 
 import com.gitblit.Constants;
 import com.gitblit.utils.ModelUtils;
 
-public class ModelUtilsTest {
+public class ModelUtilsTest extends GitblitUnitTest {
 
        @After
        public void resetPrefix()
index 8d07fe65cfdfe6d4ea7871975c6b402cdb685db7..0330f06249131d5bc4dfb5ef3f7f867956e7d198 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.util.Date;\r
 \r
 import org.junit.Test;\r
 \r
 import com.gitblit.utils.ObjectCache;\r
 \r
-public class ObjectCacheTest {\r
+public class ObjectCacheTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testCache() throws Exception {\r
index 42ef9935b2ce1d32ae50f0526a962c540563ba6f..cffce51b15a06db2e7af1dc0a76494f0cac2a43e 100644 (file)
@@ -17,7 +17,6 @@ package com.gitblit.tests;
 
 import java.util.Date;
 
-import org.junit.Assert;
 import org.junit.Test;
 
 import com.gitblit.Constants.AccessPermission;
@@ -33,7 +32,7 @@ import com.gitblit.models.UserModel;
  * @author James Moger
  *
  */
-public class PermissionsTest extends Assert {
+public class PermissionsTest extends GitblitUnitTest {
 
        /**
         * Admin access rights/permissions
index f5d5965bc0714b02d156de1ef626fb5248784756..be097cc43e798d35bba97ff142d103375a89aa85 100644 (file)
@@ -28,7 +28,7 @@ import org.junit.Test;
 import com.gitblit.models.RefLogEntry;\r
 import com.gitblit.utils.RefLogUtils;\r
 \r
-public class PushLogTest {\r
+public class PushLogTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testPushLog() throws IOException {\r
index 7e04a915896d7660ce3419bb5e7f9701d42ca443..753762390c2d1377405e4d81bc5de4682818b9cc 100644 (file)
@@ -1,10 +1,6 @@
 package com.gitblit.tests;\r
 \r
 import static org.hamcrest.CoreMatchers.is;\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertThat;\r
-import static org.junit.Assert.assertTrue;\r
 \r
 import java.util.HashMap;\r
 \r
@@ -15,7 +11,7 @@ import com.gitblit.models.UserModel;
 import com.gitblit.tests.mock.MemorySettings;\r
 import com.gitblit.utils.StringUtils;\r
 \r
-public class RedmineUserServiceTest {\r
+public class RedmineUserServiceTest extends GitblitUnitTest {\r
 \r
     private static final String JSON = "{\"user\":{\"created_on\":\"2011-03-28T00:41:29Z\",\"lastname\":\"foo\","\r
         + "\"last_login_on\":\"2012-09-06T23:59:26Z\",\"firstname\":\"baz\","\r
index 56c1ebbc33838a823ff7731f56dce4985b9cb2e1..4520adad9a6192ded580737307406663a940b986 100644 (file)
@@ -16,8 +16,6 @@
  */
 package com.gitblit.tests;
 
-import static org.junit.Assert.assertEquals;
-
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.lib.StoredConfig;
 import org.junit.After;
@@ -27,10 +25,9 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.gitblit.Constants;
-import com.gitblit.GitBlit;
 import com.gitblit.models.RepositoryModel;
 
-public class RepositoryModelTest {
+public class RepositoryModelTest extends GitblitUnitTest {
 
        private static boolean wasStarted = false;
 
@@ -68,7 +65,7 @@ public class RepositoryModelTest {
 
        @Test
        public void testGetCustomProperty() throws Exception {
-               RepositoryModel model = GitBlit.self().getRepositoryModel(
+               RepositoryModel model = repositories().getRepositoryModel(
                                GitBlitSuite.getHelloworldRepository().getDirectory().getName());
 
                assertEquals("\\d", model.customFields.get("commitMessageRegEx"));
@@ -77,16 +74,16 @@ public class RepositoryModelTest {
 
        @Test
        public void testSetCustomProperty() throws Exception {
-               RepositoryModel model = GitBlit.self().getRepositoryModel(
+               RepositoryModel model = repositories().getRepositoryModel(
                                GitBlitSuite.getHelloworldRepository().getDirectory().getName());
 
                assertEquals("\\d", model.customFields.get("commitMessageRegEx"));
                assertEquals("Hello", model.customFields.get("anotherProperty"));
 
                assertEquals("Hello", model.customFields.put("anotherProperty", "GoodBye"));
-               GitBlit.self().updateRepositoryModel(model.name, model, false);
+               repositories().updateRepositoryModel(model.name, model, false);
 
-               model = GitBlit.self().getRepositoryModel(
+               model = repositories().getRepositoryModel(
                                GitBlitSuite.getHelloworldRepository().getDirectory().getName());
 
                assertEquals("\\d", model.customFields.get("commitMessageRegEx"));
index f816ff63a2bd039310b66b8dbc0d4950fb88fac4..33e8505e2fe89f25d18cae78130e5699d4bfdccc 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertNull;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.io.IOException;\r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
@@ -58,7 +53,7 @@ import com.gitblit.utils.RpcUtils;
  * @author James Moger\r
  *\r
  */\r
-public class RpcTests {\r
+public class RpcTests extends GitblitUnitTest {\r
 \r
        String url = GitBlitSuite.url;\r
        String account = GitBlitSuite.account;\r
index bec5c542408e6b9fa35557e2483154a03aac99a0..0fd42aad6688236a1a50c39e52adfcd720bc7c8f 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.util.Arrays;\r
 import java.util.List;\r
 \r
@@ -26,7 +22,7 @@ import org.junit.Test;
 \r
 import com.gitblit.utils.StringUtils;\r
 \r
-public class StringUtilsTest {\r
+public class StringUtilsTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testIsEmpty() throws Exception {\r
index 66d0c3a904951136419497f1de711ed08b426f83..d206bbdb3484bfd08b88d1f1c8637bd6be0bf513 100644 (file)
@@ -15,9 +15,6 @@
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.io.ByteArrayOutputStream;\r
 import java.util.ArrayList;\r
 import java.util.Date;\r
@@ -31,7 +28,7 @@ import com.gitblit.Constants.SearchType;
 import com.gitblit.models.FeedEntryModel;\r
 import com.gitblit.utils.SyndicationUtils;\r
 \r
-public class SyndicationUtilsTest {\r
+public class SyndicationUtilsTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testSyndication() throws Exception {\r
index 851fb453eec1ab88d671eb67113a4fad7aa1584d..fb38ffd3266c39cdfb67772e7af230651a2e76b4 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.util.Date;\r
 \r
 import org.junit.Test;\r
 \r
 import com.gitblit.utils.TimeUtils;\r
 \r
-public class TimeUtilsTest {\r
+public class TimeUtilsTest extends GitblitUnitTest {\r
 \r
        private Date offset(long subtract) {\r
                return new Date(System.currentTimeMillis() - subtract);\r
index f6cdd6a336129418596f7f80bd1df7a0b466c409..613e46df80d4f6a56a651a4ad54dca6d9d1b4349 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-\r
 import java.io.File;\r
 import java.io.IOException;\r
 \r
@@ -31,7 +27,7 @@ import com.gitblit.models.RepositoryModel;
 import com.gitblit.models.TeamModel;\r
 import com.gitblit.models.UserModel;\r
 \r
-public class UserServiceTest {\r
+public class UserServiceTest extends GitblitUnitTest {\r
 \r
        @Test\r
        public void testConfigUserService() throws IOException {\r
index 668626baffd66973ff878978cf83475334e64f3f..740f908b89ffed2820f029be47d0b4daad23bc0e 100644 (file)
@@ -26,7 +26,6 @@ import java.util.zip.ZipInputStream;
 \r
 import org.eclipse.jgit.util.FileUtils;\r
 import org.junit.After;\r
-import org.junit.Assert;\r
 import org.junit.Before;\r
 import org.junit.Test;\r
 \r
@@ -43,7 +42,7 @@ import com.gitblit.utils.X509Utils.X509Metadata;
  * @author James Moger\r
  *\r
  */\r
-public class X509UtilsTest extends Assert {\r
+public class X509UtilsTest extends GitblitUnitTest {\r
 \r
        // passwords are case-sensitive and may be length-limited\r
        // based on the JCE policy files\r
index 966d72b1c58e78f0be60d0f25c023c9a057b9f0d..d4e3222212da40447e80c9d8d091d8411c42e1e1 100644 (file)
@@ -9,6 +9,7 @@ public class GitBlit4UITests extends GitBlit {
        private boolean luceneIndexingEnabled;
 
        public GitBlit4UITests(boolean luceneIndexingEnabled) {
+               super(null);
                this.luceneIndexingEnabled = luceneIndexingEnabled;
        }
 
@@ -21,5 +22,5 @@ public class GitBlit4UITests extends GitBlit {
                                        .info("Lucene executor is scheduled to process indexed branches every 2 minutes.");
                }
        }
-       
+
 }
index 2d54be2a3505be156701894ea169f55d46e338f7..6ee98a038a690591b8265dd4da81444623ac67a9 100644 (file)
@@ -1,5 +1,6 @@
 package de.akquinet.devops;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -7,6 +8,8 @@ import com.beust.jcommander.JCommander;
 import com.beust.jcommander.ParameterException;
 import com.gitblit.GitBlit;
 import com.gitblit.GitBlitServer;
+import com.gitblit.IStoredSettings;
+import com.gitblit.Keys;
 
 public class GitBlitServer4UITests extends GitBlitServer {
 
@@ -50,13 +53,9 @@ public class GitBlitServer4UITests extends GitBlitServer {
                }
        }
 
-       private GitBlit4UITests instance;
-
        @Override
-       protected GitBlit getGitBlitInstance() {
-               if (instance == null) {
-                       instance = new GitBlit4UITests(false);
-               }
-               return instance;
+       protected GitBlit newGitblit(IStoredSettings settings, File baseFolder) {
+               settings.overrideSetting(Keys.web.allowLuceneIndexing, false);
+               return new GitBlit(settings, baseFolder);
        }
 }