From 32539684194f55a76ec171852f582bdafa4c5631 Mon Sep 17 00:00:00 2001 From: James Moger Date: Tue, 19 Nov 2013 16:11:29 -0500 Subject: [PATCH] Create a Gitblit aggregate manager delegate for git upload/receive tasks Change-Id: I2c4a5ddf051f228c0bd949c6cd4fd44c3da81d26 --- src/main/java/com/gitblit/DaggerModule.java | 24 + src/main/java/com/gitblit/GitBlit.java | 4 +- src/main/java/com/gitblit/Gitblit.java | 731 ++++++++++++++++++ src/main/java/com/gitblit/git/GitDaemon.java | 19 +- src/main/java/com/gitblit/git/GitServlet.java | 30 +- .../com/gitblit/git/GitblitReceivePack.java | 23 +- .../git/GitblitReceivePackFactory.java | 29 +- .../com/gitblit/git/RepositoryResolver.java | 21 +- 8 files changed, 796 insertions(+), 85 deletions(-) create mode 100644 src/main/java/com/gitblit/Gitblit.java diff --git a/src/main/java/com/gitblit/DaggerModule.java b/src/main/java/com/gitblit/DaggerModule.java index 7ee8ecd6..d25126a1 100644 --- a/src/main/java/com/gitblit/DaggerModule.java +++ b/src/main/java/com/gitblit/DaggerModule.java @@ -52,6 +52,9 @@ import dagger.Provides; IGitblitManager.class, IFederationManager.class, + // the monolithic manager + Gitblit.class, + // filters & servlets GitServlet.class, GitFilter.class, @@ -113,6 +116,27 @@ public class DaggerModule { return gitblit; } + @Provides @Singleton Gitblit provideGitblit( + IRuntimeManager runtimeManager, + INotificationManager notificationManager, + IUserManager userManager, + ISessionManager sessionManager, + IRepositoryManager repositoryManager, + IProjectManager projectManager, + IGitblitManager gitblitManager, + IFederationManager federationManager) { + + return new Gitblit( + runtimeManager, + notificationManager, + userManager, + sessionManager, + repositoryManager, + projectManager, + federationManager, + gitblitManager); + } + @Provides @Singleton WebApplication provideWebApplication( IRuntimeManager runtimeManager, INotificationManager notificationManager, diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java index 737167fe..b121b2b9 100644 --- a/src/main/java/com/gitblit/GitBlit.java +++ b/src/main/java/com/gitblit/GitBlit.java @@ -3641,7 +3641,9 @@ public class GitBlit extends DaggerContextListener String bindInterface = settings.getString(Keys.git.daemonBindInterface, "localhost"); if (port > 0) { try { - gitDaemon = new GitDaemon(this, this, this, this); + // HACK temporary pending manager separation and injection + Gitblit gitblit = new Gitblit(this, this, this, this, this, this, this, this); + gitDaemon = new GitDaemon(gitblit); gitDaemon.start(); } catch (IOException e) { gitDaemon = null; diff --git a/src/main/java/com/gitblit/Gitblit.java b/src/main/java/com/gitblit/Gitblit.java new file mode 100644 index 00000000..32157545 --- /dev/null +++ b/src/main/java/com/gitblit/Gitblit.java @@ -0,0 +1,731 @@ +/* + * Copyright 2013 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit; + +import java.io.File; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.TimeZone; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.jgit.lib.Repository; + +import com.gitblit.Constants.FederationRequest; +import com.gitblit.Constants.FederationToken; +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; +import com.gitblit.models.ForkModel; +import com.gitblit.models.GitClientApplication; +import com.gitblit.models.Metric; +import com.gitblit.models.ProjectModel; +import com.gitblit.models.RegistrantAccessPermission; +import com.gitblit.models.RepositoryModel; +import com.gitblit.models.RepositoryUrl; +import com.gitblit.models.SearchResult; +import com.gitblit.models.ServerSettings; +import com.gitblit.models.ServerStatus; +import com.gitblit.models.TeamModel; +import com.gitblit.models.UserModel; + +/** + * Gitblit is an aggregate interface delegate. It implements all the manager + * interfaces and delegates all methods calls to the actual manager implementations. + * It's primary purpose is to provide complete management control to the git + * upload and receive pack functions. + * + * @author James Moger + * + */ +@Singleton +public class Gitblit implements IRuntimeManager, + INotificationManager, + IUserManager, + ISessionManager, + IRepositoryManager, + IProjectManager, + IGitblitManager, + IFederationManager { + + private final IRuntimeManager runtimeManager; + + private final INotificationManager notificationManager; + + private final IUserManager userManager; + + private final ISessionManager sessionManager; + + private final IRepositoryManager repositoryManager; + + private final IProjectManager projectManager; + + private final IFederationManager federationManager; + + private final IGitblitManager gitblitManager; + + @Inject + public Gitblit( + IRuntimeManager runtimeManager, + INotificationManager notificationManager, + IUserManager userManager, + ISessionManager sessionManager, + IRepositoryManager repositoryManager, + IProjectManager projectManager, + IFederationManager federationManager, + IGitblitManager gitblitManager) { + + this.runtimeManager = runtimeManager; + this.notificationManager = notificationManager; + this.userManager = userManager; + this.sessionManager = sessionManager; + this.repositoryManager = repositoryManager; + this.projectManager = projectManager; + this.federationManager = federationManager; + this.gitblitManager = gitblitManager; + } + + /* + * RUNTIME MANAGER + */ + + @Override + public File getBaseFolder() { + return runtimeManager.getBaseFolder(); + } + + @Override + public void setBaseFolder(File folder) { + runtimeManager.setBaseFolder(folder); + } + + @Override + public Date getBootDate() { + return runtimeManager.getBootDate(); + } + + @Override + public ServerSettings getSettingsModel() { + return runtimeManager.getSettingsModel(); + } + + @Override + public boolean isServingRepositories() { + return runtimeManager.isServingRepositories(); + } + + @Override + public TimeZone getTimezone() { + return runtimeManager.getTimezone(); + } + + @Override + public boolean isDebugMode() { + return runtimeManager.isDebugMode(); + } + + @Override + public File getFileOrFolder(String key, String defaultFileOrFolder) { + return runtimeManager.getFileOrFolder(key, defaultFileOrFolder); + } + + @Override + public File getFileOrFolder(String fileOrFolder) { + return runtimeManager.getFileOrFolder(fileOrFolder); + } + + @Override + public IStoredSettings getSettings() { + return runtimeManager.getSettings(); + } + + @Override + public boolean updateSettings(Map updatedSettings) { + return runtimeManager.updateSettings(updatedSettings); + } + + @Override + public ServerStatus getStatus() { + return runtimeManager.getStatus(); + } + + /* + * NOTIFICATION MANAGER + */ + + @Override + public void sendMailToAdministrators(String subject, String message) { + notificationManager.sendMailToAdministrators(subject, message); + } + + @Override + public void sendMail(String subject, String message, Collection toAddresses) { + notificationManager.sendMail(subject, message, toAddresses); + } + + @Override + public void sendMail(String subject, String message, String... toAddresses) { + notificationManager.sendMail(subject, message, toAddresses); + } + + @Override + public void sendHtmlMail(String subject, String message, Collection toAddresses) { + notificationManager.sendHtmlMail(subject, message, toAddresses); + } + + @Override + public void sendHtmlMail(String subject, String message, String... toAddresses) { + notificationManager.sendHtmlMail(subject, message, toAddresses); + } + + /* + * SESSION MANAGER + */ + + @Override + public UserModel authenticate(String username, char[] password) { + return sessionManager.authenticate(username, password); + } + + @Override + public UserModel authenticate(HttpServletRequest httpRequest) { + return sessionManager.authenticate(httpRequest, false); + } + @Override + public UserModel authenticate(HttpServletRequest httpRequest, boolean requiresCertificate) { + return sessionManager.authenticate(httpRequest, requiresCertificate); + } + + @Override + public void setCookie(HttpServletResponse response, UserModel user) { + sessionManager.setCookie(response, user); + } + + @Override + public void logout(HttpServletResponse response, UserModel user) { + sessionManager.logout(response, user); + } + + /* + * USER MANAGER + */ + + @Override + public boolean supportsAddUser() { + return userManager.supportsAddUser(); + } + + @Override + public boolean supportsCredentialChanges(UserModel user) { + return userManager.supportsCredentialChanges(user); + } + + @Override + public boolean supportsDisplayNameChanges(UserModel user) { + return userManager.supportsDisplayNameChanges(user); + } + + @Override + public boolean supportsEmailAddressChanges(UserModel user) { + return userManager.supportsEmailAddressChanges(user); + } + + @Override + public boolean supportsTeamMembershipChanges(UserModel user) { + return userManager.supportsTeamMembershipChanges(user); + } + + @Override + public void logout(UserModel user) { + userManager.logout(user); + } + + @Override + public List getAllUsernames() { + return userManager.getAllUsernames(); + } + + @Override + public List getAllUsers() { + return userManager.getAllUsers(); + } + + @Override + public boolean deleteUser(String username) { + return userManager.deleteUser(username); + } + + @Override + public UserModel getUserModel(String username) { + return userManager.getUserModel(username); + } + + @Override + public List getAllTeams() { + return userManager.getAllTeams(); + } + + @Override + public TeamModel getTeamModel(String teamname) { + return userManager.getTeamModel(teamname); + } + + @Override + public boolean supportsCookies() { + return userManager.supportsCookies(); + } + + @Override + public String getCookie(UserModel model) { + return userManager.getCookie(model); + } + + @Override + public UserModel authenticate(char[] cookie) { + return userManager.authenticate(cookie); + } + + @Override + public boolean updateUserModel(UserModel model) { + return userManager.updateUserModel(model); + } + + @Override + public boolean updateUserModels(Collection models) { + return userManager.updateUserModels(models); + } + + @Override + public boolean updateUserModel(String username, UserModel model) { + return userManager.updateUserModel(username, model); + } + + @Override + public boolean deleteUserModel(UserModel model) { + return userManager.deleteUserModel(model); + } + + @Override + public List getAllTeamNames() { + return userManager.getAllTeamNames(); + } + + @Override + public List getTeamnamesForRepositoryRole(String role) { + return userManager.getTeamnamesForRepositoryRole(role); + } + + @Override + public boolean updateTeamModel(TeamModel model) { + return userManager.updateTeamModel(model); + } + + @Override + public boolean updateTeamModels(Collection models) { + return userManager.updateTeamModels(models); + } + + @Override + public boolean updateTeamModel(String teamname, TeamModel model) { + return userManager.updateTeamModel(teamname, model); + } + + @Override + public boolean deleteTeamModel(TeamModel model) { + return userManager.deleteTeamModel(model); + } + + @Override + public List getUsernamesForRepositoryRole(String role) { + return userManager.getUsernamesForRepositoryRole(role); + } + + @Override + public boolean renameRepositoryRole(String oldRole, String newRole) { + return userManager.renameRepositoryRole(oldRole, newRole); + } + + @Override + public boolean deleteRepositoryRole(String role) { + return userManager.deleteRepositoryRole(role); + } + + @Override + public boolean deleteTeam(String teamname) { + return userManager.deleteTeam(teamname); + } + + /* + * REPOSITORY MANAGER + */ + + @Override + public Date getLastActivityDate() { + return repositoryManager.getLastActivityDate(); + } + + @Override + public File getRepositoriesFolder() { + return repositoryManager.getRepositoriesFolder(); + } + + @Override + public File getHooksFolder() { + return repositoryManager.getHooksFolder(); + } + + @Override + public File getGrapesFolder() { + return repositoryManager.getGrapesFolder(); + } + + @Override + public List getUserAccessPermissions(UserModel user) { + return repositoryManager.getUserAccessPermissions(user); + } + + @Override + public List getUserAccessPermissions(RepositoryModel repository) { + return repositoryManager.getUserAccessPermissions(repository); + } + + @Override + public boolean setUserAccessPermissions(RepositoryModel repository, Collection permissions) { + return repositoryManager.setUserAccessPermissions(repository, permissions); + } + + @Override + public List getRepositoryUsers(RepositoryModel repository) { + return repositoryManager.getRepositoryUsers(repository); + } + + @Override + public List getTeamAccessPermissions(RepositoryModel repository) { + return repositoryManager.getTeamAccessPermissions(repository); + } + + @Override + public boolean setTeamAccessPermissions(RepositoryModel repository, Collection permissions) { + return repositoryManager.setTeamAccessPermissions(repository, permissions); + } + + @Override + public List getRepositoryTeams(RepositoryModel repository) { + return repositoryManager.getRepositoryTeams(repository); + } + @Override + public void addToCachedRepositoryList(RepositoryModel model) { + repositoryManager.addToCachedRepositoryList(model); + } + + @Override + public void resetRepositoryListCache() { + repositoryManager.resetRepositoryListCache(); + } + + @Override + public List getRepositoryList() { + return repositoryManager.getRepositoryList(); + } + + @Override + public Repository getRepository(String repositoryName) { + return repositoryManager.getRepository(repositoryName); + } + + @Override + public Repository getRepository(String repositoryName, boolean logError) { + return repositoryManager.getRepository(repositoryName, logError); + } + + @Override + public List getRepositoryModels(UserModel user) { + return repositoryManager.getRepositoryModels(user); + } + + @Override + public RepositoryModel getRepositoryModel(UserModel user, String repositoryName) { + return repositoryManager.getRepositoryModel(repositoryName); + } + + @Override + public RepositoryModel getRepositoryModel(String repositoryName) { + return repositoryManager.getRepositoryModel(repositoryName); + } + + @Override + public long getStarCount(RepositoryModel repository) { + return repositoryManager.getStarCount(repository); + } + + @Override + public boolean hasRepository(String repositoryName) { + return repositoryManager.hasRepository(repositoryName); + } + + @Override + public boolean hasRepository(String repositoryName, boolean caseSensitiveCheck) { + return repositoryManager.hasRepository(repositoryName, caseSensitiveCheck); + } + + @Override + public boolean hasFork(String username, String origin) { + return repositoryManager.hasFork(username, origin); + } + + @Override + public String getFork(String username, String origin) { + return repositoryManager.getFork(username, origin); + } + + @Override + public ForkModel getForkNetwork(String repository) { + return repositoryManager.getForkNetwork(repository); + } + + @Override + public long updateLastChangeFields(Repository r, RepositoryModel model) { + return repositoryManager.updateLastChangeFields(r, model); + } + + @Override + public List getRepositoryDefaultMetrics(RepositoryModel model, Repository repository) { + return repositoryManager.getRepositoryDefaultMetrics(model, repository); + } + + @Override + public void updateRepositoryModel(String repositoryName, RepositoryModel repository, + boolean isCreate) throws GitBlitException { + repositoryManager.updateRepositoryModel(repositoryName, repository, isCreate); + } + + @Override + public void updateConfiguration(Repository r, RepositoryModel repository) { + repositoryManager.updateConfiguration(r, repository); + } + + @Override + public boolean deleteRepositoryModel(RepositoryModel model) { + return repositoryManager.deleteRepositoryModel(model); + } + + @Override + public boolean deleteRepository(String repositoryName) { + return repositoryManager.deleteRepository(repositoryName); + } + + @Override + public List getAllScripts() { + return repositoryManager.getAllScripts(); + } + + @Override + public List getPreReceiveScriptsInherited(RepositoryModel repository) { + return repositoryManager.getPreReceiveScriptsInherited(repository); + } + + @Override + public List getPreReceiveScriptsUnused(RepositoryModel repository) { + return repositoryManager.getPreReceiveScriptsUnused(repository); + } + + @Override + public List getPostReceiveScriptsInherited(RepositoryModel repository) { + return repositoryManager.getPostReceiveScriptsInherited(repository); + } + + @Override + public List getPostReceiveScriptsUnused(RepositoryModel repository) { + return repositoryManager.getPostReceiveScriptsUnused(repository); + } + + @Override + public List search(String query, int page, int pageSize, List repositories) { + return repositoryManager.search(query, page, pageSize, repositories); + } + + @Override + public boolean isCollectingGarbage() { + return repositoryManager.isCollectingGarbage(); + } + + @Override + public boolean isCollectingGarbage(String repositoryName) { + return repositoryManager.isCollectingGarbage(repositoryName); + } + + /* + * PROJECT MANAGER + */ + + @Override + public List getProjectModels(UserModel user, boolean includeUsers) { + return projectManager.getProjectModels(user, includeUsers); + } + + @Override + public ProjectModel getProjectModel(String name, UserModel user) { + return projectManager.getProjectModel(name, user); + } + + @Override + public ProjectModel getProjectModel(String name) { + return projectManager.getProjectModel(name); + } + + @Override + public List getProjectModels(List repositoryModels, boolean includeUsers) { + return projectManager.getProjectModels(repositoryModels, includeUsers); + } + + /* + * FEDERATION MANAGER + */ + + @Override + public File getProposalsFolder() { + return federationManager.getProposalsFolder(); + } + + @Override + public UserModel getFederationUser() { + return federationManager.getFederationUser(); + } + + @Override + public boolean canFederate() { + return federationManager.canFederate(); + } + + @Override + public List getFederationRegistrations() { + return federationManager.getFederationRegistrations(); + } + + @Override + public FederationModel getFederationRegistration(String url, String name) { + return federationManager.getFederationRegistration(url, name); + } + + @Override + public List getFederationSets(String gitblitUrl) { + return federationManager.getFederationSets(gitblitUrl); + } + + @Override + public List getFederationTokens() { + return federationManager.getFederationTokens(); + } + + @Override + public String getFederationToken(FederationToken type) { + return federationManager.getFederationToken(type); + } + + @Override + public String getFederationToken(String value) { + return federationManager.getFederationToken(value); + } + + @Override + public boolean validateFederationRequest(FederationRequest req, String token) { + return federationManager.validateFederationRequest(req, token); + } + + @Override + public boolean acknowledgeFederationStatus(String identification, FederationModel registration) { + return federationManager.acknowledgeFederationStatus(identification, registration); + } + + @Override + public List getFederationResultRegistrations() { + return federationManager.getFederationResultRegistrations(); + } + + @Override + public boolean submitFederationProposal(FederationProposal proposal, String gitblitUrl) { + return federationManager.submitFederationProposal(proposal, gitblitUrl); + } + + @Override + public List getPendingFederationProposals() { + return federationManager.getPendingFederationProposals(); + } + + @Override + public Map getRepositories(String gitblitUrl, String token) { + return federationManager.getRepositories(gitblitUrl, token); + } + + @Override + public FederationProposal createFederationProposal(String gitblitUrl, String token) { + return federationManager.createFederationProposal(gitblitUrl, token); + } + + @Override + public FederationProposal getPendingFederationProposal(String token) { + return federationManager.getPendingFederationProposal(token); + } + + @Override + public boolean deletePendingFederationProposal(FederationProposal proposal) { + return federationManager.deletePendingFederationProposal(proposal); + } + + /* + * GITBLIT MANAGER + */ + + @Override + public RepositoryModel fork(RepositoryModel repository, UserModel user) throws GitBlitException { + return gitblitManager.fork(repository, user); + } + + @Override + public void updateTeamModel(String teamname, TeamModel team, boolean isCreate) + throws GitBlitException { + gitblitManager.updateTeamModel(teamname, team, isCreate); + } + + @Override + public void updateUserModel(String username, UserModel user, boolean isCreate) + throws GitBlitException { + gitblitManager.updateUserModel(username, user, isCreate); + } + + @Override + public List getRepositoryUrls(HttpServletRequest request, UserModel user, RepositoryModel repository) { + return gitblitManager.getRepositoryUrls(request, user, repository); + } + + @Override + public Collection getClientApplications() { + return gitblitManager.getClientApplications(); + } +} diff --git a/src/main/java/com/gitblit/git/GitDaemon.java b/src/main/java/com/gitblit/git/GitDaemon.java index 40cbe704..a7e7cd55 100644 --- a/src/main/java/com/gitblit/git/GitDaemon.java +++ b/src/main/java/com/gitblit/git/GitDaemon.java @@ -67,12 +67,9 @@ import org.eclipse.jgit.transport.resolver.UploadPackFactory; 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.ISessionManager; -import com.gitblit.manager.IUserManager; import com.gitblit.utils.StringUtils; /** @@ -111,13 +108,9 @@ public class GitDaemon { private ReceivePackFactory receivePackFactory; - public GitDaemon( - IRuntimeManager runtimeManager, - IUserManager userManager, - ISessionManager sessionManager, - IRepositoryManager repositoryManager) { + public GitDaemon(Gitblit gitblit) { - IStoredSettings settings = runtimeManager.getSettings(); + IStoredSettings settings = gitblit.getSettings(); int port = settings.getInteger(Keys.git.daemonPort, 0); String bindInterface = settings.getString(Keys.git.daemonBindInterface, "localhost"); @@ -127,9 +120,9 @@ public class GitDaemon { myAddress = new InetSocketAddress(bindInterface, port); } - repositoryResolver = new RepositoryResolver(sessionManager, repositoryManager); - uploadPackFactory = new GitblitUploadPackFactory(sessionManager); - receivePackFactory = new GitblitReceivePackFactory(runtimeManager, userManager, repositoryManager); + repositoryResolver = new RepositoryResolver(gitblit); + uploadPackFactory = new GitblitUploadPackFactory(gitblit); + receivePackFactory = new GitblitReceivePackFactory(gitblit); run = new AtomicBoolean(false); processors = new ThreadGroup("Git-Daemon"); diff --git a/src/main/java/com/gitblit/git/GitServlet.java b/src/main/java/com/gitblit/git/GitServlet.java index e4719d9b..35470a29 100644 --- a/src/main/java/com/gitblit/git/GitServlet.java +++ b/src/main/java/com/gitblit/git/GitServlet.java @@ -21,10 +21,7 @@ import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; -import com.gitblit.manager.IRepositoryManager; -import com.gitblit.manager.IRuntimeManager; -import com.gitblit.manager.ISessionManager; -import com.gitblit.manager.IUserManager; +import com.gitblit.Gitblit; /** * The GitServlet provides http/https access to Git repositories. @@ -38,32 +35,19 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet { private static final long serialVersionUID = 1L; - private final IRuntimeManager runtimeManager; - - private final IUserManager userManager; - - private final ISessionManager sessionManager; - - private final IRepositoryManager repositoryManager; + private final Gitblit gitblit; @Inject - public GitServlet( - IRuntimeManager runtimeManager, - IUserManager userManager, - ISessionManager sessionManager, - IRepositoryManager repositoryManager) { + public GitServlet(Gitblit gitblit) { super(); - this.runtimeManager = runtimeManager; - this.userManager = userManager; - this.sessionManager = sessionManager; - this.repositoryManager = repositoryManager; + this.gitblit = gitblit; } @Override public void init(ServletConfig config) throws ServletException { - setRepositoryResolver(new RepositoryResolver(sessionManager, repositoryManager)); - setUploadPackFactory(new GitblitUploadPackFactory(sessionManager)); - setReceivePackFactory(new GitblitReceivePackFactory(runtimeManager, userManager, repositoryManager)); + setRepositoryResolver(new RepositoryResolver(gitblit)); + setUploadPackFactory(new GitblitUploadPackFactory(gitblit)); + setReceivePackFactory(new GitblitReceivePackFactory(gitblit)); super.init(config); } } diff --git a/src/main/java/com/gitblit/git/GitblitReceivePack.java b/src/main/java/com/gitblit/git/GitblitReceivePack.java index 44e2bef5..cc1490e6 100644 --- a/src/main/java/com/gitblit/git/GitblitReceivePack.java +++ b/src/main/java/com/gitblit/git/GitblitReceivePack.java @@ -44,12 +44,10 @@ import org.slf4j.LoggerFactory; import com.gitblit.Constants; import com.gitblit.Constants.AccessRestrictionType; -import com.gitblit.GitBlit; +import com.gitblit.Gitblit; import com.gitblit.IStoredSettings; import com.gitblit.Keys; import com.gitblit.client.Translation; -import com.gitblit.manager.IRepositoryManager; -import com.gitblit.manager.IRuntimeManager; import com.gitblit.models.RepositoryModel; import com.gitblit.models.UserModel; import com.gitblit.utils.ArrayUtils; @@ -93,24 +91,23 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P private final IStoredSettings settings; - private final IRepositoryManager repositoryManager; + private final Gitblit gitblit; public GitblitReceivePack( - IRuntimeManager runtimeManager, - IRepositoryManager repositoryManager, + Gitblit gitblit, Repository db, RepositoryModel repository, UserModel user) { super(db); - this.settings = runtimeManager.getSettings(); - this.repositoryManager = repositoryManager; + this.settings = gitblit.getSettings(); + this.gitblit = gitblit; this.repository = repository; this.user = user == null ? UserModel.ANONYMOUS : user; - this.groovyDir = repositoryManager.getHooksFolder(); + this.groovyDir = gitblit.getHooksFolder(); try { // set Grape root - File grapeRoot = repositoryManager.getGrapesFolder(); + File grapeRoot = gitblit.getGrapesFolder(); grapeRoot.mkdirs(); System.setProperty("grape.root", grapeRoot.getAbsolutePath()); this.gse = new GroovyScriptEngine(groovyDir.getAbsolutePath()); @@ -249,7 +246,7 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P } Set scripts = new LinkedHashSet(); - scripts.addAll(repositoryManager.getPreReceiveScriptsInherited(repository)); + scripts.addAll(gitblit.getPreReceiveScriptsInherited(repository)); if (!ArrayUtils.isEmpty(repository.preReceiveScripts)) { scripts.addAll(repository.preReceiveScripts); } @@ -344,7 +341,7 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P // run Groovy hook scripts Set scripts = new LinkedHashSet(); - scripts.addAll(repositoryManager.getPostReceiveScriptsInherited(repository)); + scripts.addAll(gitblit.getPostReceiveScriptsInherited(repository)); if (!ArrayUtils.isEmpty(repository.postReceiveScripts)) { scripts.addAll(repository.postReceiveScripts); } @@ -459,7 +456,7 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P } Binding binding = new Binding(); - binding.setVariable("gitblit", GitBlit.self()); + binding.setVariable("gitblit", gitblit); binding.setVariable("repository", repository); binding.setVariable("receivePack", this); binding.setVariable("user", user); diff --git a/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java b/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java index 2cdb9856..71a8e68b 100644 --- a/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java +++ b/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java @@ -26,11 +26,9 @@ import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.gitblit.Gitblit; import com.gitblit.IStoredSettings; import com.gitblit.Keys; -import com.gitblit.manager.IRepositoryManager; -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; @@ -49,23 +47,12 @@ public class GitblitReceivePackFactory implements ReceivePackFactory { private final IStoredSettings settings; - private final IRuntimeManager runtimeManager; - - private final IUserManager userManager; - - private final IRepositoryManager repositoryManager; - - public GitblitReceivePackFactory( - IRuntimeManager runtimeManager, - IUserManager userManager, - IRepositoryManager repositoryManager) { + private final Gitblit gitblit; + public GitblitReceivePackFactory(Gitblit gitblit) { super(); - this.settings = runtimeManager.getSettings(); - this.runtimeManager = runtimeManager; - this.userManager = userManager; - this.repositoryManager = repositoryManager; - + this.settings = gitblit.getSettings(); + this.gitblit = gitblit; } @Override @@ -90,7 +77,7 @@ public class GitblitReceivePackFactory implements ReceivePackFactory { // determine pushing user String username = request.getRemoteUser(); if (!StringUtils.isEmpty(username)) { - UserModel u = userManager.getUserModel(username); + UserModel u = gitblit.getUserModel(username); if (u != null) { user = u; } @@ -111,9 +98,9 @@ public class GitblitReceivePackFactory implements ReceivePackFactory { throw new ServiceNotEnabledException(); } - final RepositoryModel repository = repositoryManager.getRepositoryModel(repositoryName); + final RepositoryModel repository = gitblit.getRepositoryModel(repositoryName); - final GitblitReceivePack rp = new GitblitReceivePack(runtimeManager, repositoryManager, db, repository, user); + final GitblitReceivePack rp = new GitblitReceivePack(gitblit, db, repository, user); rp.setGitblitUrl(gitblitUrl); rp.setRepositoryUrl(repositoryUrl); rp.setRefLogIdent(new PersonIdent(user.username, user.username + "@" + origin)); diff --git a/src/main/java/com/gitblit/git/RepositoryResolver.java b/src/main/java/com/gitblit/git/RepositoryResolver.java index 87795c07..39d1f396 100644 --- a/src/main/java/com/gitblit/git/RepositoryResolver.java +++ b/src/main/java/com/gitblit/git/RepositoryResolver.java @@ -27,8 +27,7 @@ import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.gitblit.manager.IRepositoryManager; -import com.gitblit.manager.ISessionManager; +import com.gitblit.Gitblit; import com.gitblit.models.RepositoryModel; import com.gitblit.models.UserModel; @@ -42,17 +41,11 @@ public class RepositoryResolver extends FileResolver { private final Logger logger = LoggerFactory.getLogger(RepositoryResolver.class); - private final ISessionManager sessionManager; + private final Gitblit gitblit; - private final IRepositoryManager repositoryManager; - - public RepositoryResolver( - ISessionManager sessionManager, - IRepositoryManager repositoryManager) { - - super(repositoryManager.getRepositoriesFolder(), true); - this.sessionManager = sessionManager; - this.repositoryManager = repositoryManager; + public RepositoryResolver(Gitblit gitblit) { + super(gitblit.getRepositoriesFolder(), true); + this.gitblit = gitblit; } /** @@ -83,7 +76,7 @@ public class RepositoryResolver extends FileResolver { */ @Override protected boolean isExportOk(X req, String repositoryName, Repository db) throws IOException { - RepositoryModel model = repositoryManager.getRepositoryModel(repositoryName); + RepositoryModel model = gitblit.getRepositoryModel(repositoryName); String scheme = null; UserModel user = null; @@ -101,7 +94,7 @@ public class RepositoryResolver extends FileResolver { HttpServletRequest httpRequest = (HttpServletRequest) req; scheme = httpRequest.getScheme(); origin = httpRequest.getRemoteAddr(); - user = sessionManager.authenticate(httpRequest); + user = gitblit.authenticate(httpRequest); if (user == null) { user = UserModel.ANONYMOUS; } -- 2.39.5