| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import org.eclipse.jgit.api.CloneCommand; |
| | | import org.eclipse.jgit.api.FetchCommand; |
| | | import org.eclipse.jgit.api.Git; |
| | | import org.eclipse.jgit.lib.Ref; |
| | | import org.eclipse.jgit.lib.Repository; |
| | | import org.eclipse.jgit.transport.RefSpec; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import ro.fortsoft.pf4j.PluginState; |
| | | import ro.fortsoft.pf4j.PluginWrapper; |
| | | |
| | | import com.gitblit.Constants; |
| | | import com.gitblit.Constants.AccessPermission; |
| | |
| | | import com.gitblit.models.FederationSet; |
| | | import com.gitblit.models.ForkModel; |
| | | import com.gitblit.models.GitClientApplication; |
| | | import com.gitblit.models.Mailing; |
| | | import com.gitblit.models.Metric; |
| | | import com.gitblit.models.PluginRegistry.InstallState; |
| | | import com.gitblit.models.PluginRegistry.PluginRegistration; |
| | | import com.gitblit.models.PluginRegistry.PluginRelease; |
| | | import com.gitblit.models.ProjectModel; |
| | | import com.gitblit.models.RegistrantAccessPermission; |
| | | import com.gitblit.models.RepositoryModel; |
| | |
| | | import com.gitblit.models.SettingModel; |
| | | import com.gitblit.models.TeamModel; |
| | | import com.gitblit.models.UserModel; |
| | | import com.gitblit.tickets.ITicketService; |
| | | import com.gitblit.transport.ssh.IPublicKeyManager; |
| | | import com.gitblit.transport.ssh.SshKey; |
| | | import com.gitblit.utils.ArrayUtils; |
| | | import com.gitblit.utils.HttpUtils; |
| | | import com.gitblit.utils.JGitUtils; |
| | | import com.gitblit.utils.JsonUtils; |
| | | import com.gitblit.utils.ObjectCache; |
| | | import com.gitblit.utils.StringUtils; |
| | |
| | | |
| | | protected final IRuntimeManager runtimeManager; |
| | | |
| | | protected final IPluginManager pluginManager; |
| | | |
| | | protected final INotificationManager notificationManager; |
| | | |
| | | protected final IUserManager userManager; |
| | | |
| | | protected final IAuthenticationManager authenticationManager; |
| | | |
| | | protected final IPublicKeyManager publicKeyManager; |
| | | |
| | | protected final IRepositoryManager repositoryManager; |
| | | |
| | |
| | | |
| | | public GitblitManager( |
| | | IRuntimeManager runtimeManager, |
| | | IPluginManager pluginManager, |
| | | INotificationManager notificationManager, |
| | | IUserManager userManager, |
| | | IAuthenticationManager authenticationManager, |
| | | IPublicKeyManager publicKeyManager, |
| | | IRepositoryManager repositoryManager, |
| | | IProjectManager projectManager, |
| | | IFederationManager federationManager) { |
| | | |
| | | this.settings = runtimeManager.getSettings(); |
| | | this.runtimeManager = runtimeManager; |
| | | this.pluginManager = pluginManager; |
| | | this.notificationManager = notificationManager; |
| | | this.userManager = userManager; |
| | | this.authenticationManager = authenticationManager; |
| | | this.publicKeyManager = publicKeyManager; |
| | | this.repositoryManager = repositoryManager; |
| | | this.projectManager = projectManager; |
| | | this.federationManager = federationManager; |
| | |
| | | |
| | | // clone the repository |
| | | try { |
| | | JGitUtils.cloneRepository(repositoryManager.getRepositoriesFolder(), cloneName, fromUrl, true, null); |
| | | Repository canonical = getRepository(repository.name); |
| | | File folder = new File(repositoryManager.getRepositoriesFolder(), cloneName); |
| | | CloneCommand clone = new CloneCommand(); |
| | | clone.setBare(true); |
| | | |
| | | // fetch branches with exclusions |
| | | Collection<Ref> branches = canonical.getRefDatabase().getRefs(Constants.R_HEADS).values(); |
| | | List<String> branchesToClone = new ArrayList<String>(); |
| | | for (Ref branch : branches) { |
| | | String name = branch.getName(); |
| | | if (name.startsWith(Constants.R_TICKET)) { |
| | | // exclude ticket branches |
| | | continue; |
| | | } |
| | | branchesToClone.add(name); |
| | | } |
| | | clone.setBranchesToClone(branchesToClone); |
| | | clone.setURI(fromUrl); |
| | | clone.setDirectory(folder); |
| | | Git git = clone.call(); |
| | | |
| | | // fetch tags |
| | | FetchCommand fetch = git.fetch(); |
| | | fetch.setRefSpecs(new RefSpec("+refs/tags/*:refs/tags/*")); |
| | | fetch.call(); |
| | | |
| | | git.getRepository().close(); |
| | | } catch (Exception e) { |
| | | throw new GitBlitException(e); |
| | | } |
| | |
| | | repositoryManager.updateRepositoryModel(model.name, model, false); |
| | | } |
| | | } |
| | | |
| | | // rename the user's ssh public keystore |
| | | getPublicKeyManager().renameUser(username, user.username); |
| | | } |
| | | if (!userManager.updateUserModel(username, user)) { |
| | | throw new GitBlitException("Failed to update user!"); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Throws an exception if trying to get a ticket service. |
| | | * |
| | | */ |
| | | @Override |
| | | public ITicketService getTicketService() { |
| | | throw new RuntimeException("This class does not have a ticket service!"); |
| | | } |
| | | |
| | | @Override |
| | | public IPublicKeyManager getPublicKeyManager() { |
| | | return publicKeyManager; |
| | | } |
| | | |
| | | /* |
| | | * ISTOREDSETTINGS |
| | | * |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void sendMail(String subject, String message, String... toAddresses) { |
| | | notificationManager.sendMail(subject, message, toAddresses); |
| | | } |
| | | |
| | | @Override |
| | | public void sendHtmlMail(String subject, String message, Collection<String> toAddresses) { |
| | | notificationManager.sendHtmlMail(subject, message, toAddresses); |
| | | } |
| | | |
| | | @Override |
| | | public void sendHtmlMail(String subject, String message, String... toAddresses) { |
| | | notificationManager.sendHtmlMail(subject, message, toAddresses); |
| | | } |
| | | |
| | | @Override |
| | | public void sendHtmlMail(String from, String subject, String message, Collection<String> toAddresses) { |
| | | notificationManager.sendHtmlMail(from, subject, message, toAddresses); |
| | | } |
| | | |
| | | @Override |
| | | public void sendHtmlMail(String from, String subject, String message, String... toAddresses) { |
| | | notificationManager.sendHtmlMail(from, subject, message, toAddresses); |
| | | public void send(Mailing mail) { |
| | | notificationManager.send(mail); |
| | | } |
| | | |
| | | /* |
| | |
| | | } |
| | | return user; |
| | | } |
| | | |
| | | @Override |
| | | public UserModel authenticate(String username, SshKey key) { |
| | | return authenticationManager.authenticate(username, key); |
| | | } |
| | | |
| | | @Override |
| | | public UserModel authenticate(HttpServletRequest httpRequest, boolean requiresCertificate) { |
| | | UserModel user = authenticationManager.authenticate(httpRequest, requiresCertificate); |
| | |
| | | public boolean deletePendingFederationProposal(FederationProposal proposal) { |
| | | return federationManager.deletePendingFederationProposal(proposal); |
| | | } |
| | | |
| | | @Override |
| | | public void closeAll() { |
| | | repositoryManager.closeAll(); |
| | | } |
| | | |
| | | @Override |
| | | public void close(String repository) { |
| | | repositoryManager.close(repository); |
| | | } |
| | | |
| | | @Override |
| | | public boolean isIdle(Repository repository) { |
| | | return repositoryManager.isIdle(repository); |
| | | } |
| | | |
| | | /* |
| | | * PLUGIN MANAGER |
| | | */ |
| | | |
| | | @Override |
| | | public void startPlugins() { |
| | | pluginManager.startPlugins(); |
| | | } |
| | | |
| | | @Override |
| | | public void stopPlugins() { |
| | | pluginManager.stopPlugins(); |
| | | } |
| | | |
| | | @Override |
| | | public List<PluginWrapper> getPlugins() { |
| | | return pluginManager.getPlugins(); |
| | | } |
| | | |
| | | @Override |
| | | public PluginWrapper getPlugin(String pluginId) { |
| | | return pluginManager.getPlugin(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public List<Class<?>> getExtensionClasses(String pluginId) { |
| | | return pluginManager.getExtensionClasses(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public <T> List<T> getExtensions(Class<T> clazz) { |
| | | return pluginManager.getExtensions(clazz); |
| | | } |
| | | |
| | | @Override |
| | | public PluginWrapper whichPlugin(Class<?> clazz) { |
| | | return pluginManager.whichPlugin(clazz); |
| | | } |
| | | |
| | | @Override |
| | | public PluginState startPlugin(String pluginId) { |
| | | return pluginManager.startPlugin(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public PluginState stopPlugin(String pluginId) { |
| | | return pluginManager.stopPlugin(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean disablePlugin(String pluginId) { |
| | | return pluginManager.disablePlugin(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean enablePlugin(String pluginId) { |
| | | return pluginManager.enablePlugin(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean deletePlugin(String pluginId) { |
| | | return pluginManager.deletePlugin(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean refreshRegistry(boolean verifyChecksum) { |
| | | return pluginManager.refreshRegistry(verifyChecksum); |
| | | } |
| | | |
| | | @Override |
| | | public boolean installPlugin(String url, boolean verifyChecksum) throws IOException { |
| | | return pluginManager.installPlugin(url, verifyChecksum); |
| | | } |
| | | |
| | | @Override |
| | | public boolean upgradePlugin(String pluginId, String url, boolean verifyChecksum) throws IOException { |
| | | return pluginManager.upgradePlugin(pluginId, url, verifyChecksum); |
| | | } |
| | | |
| | | @Override |
| | | public List<PluginRegistration> getRegisteredPlugins() { |
| | | return pluginManager.getRegisteredPlugins(); |
| | | } |
| | | |
| | | @Override |
| | | public List<PluginRegistration> getRegisteredPlugins(InstallState state) { |
| | | return pluginManager.getRegisteredPlugins(state); |
| | | } |
| | | |
| | | @Override |
| | | public PluginRegistration lookupPlugin(String pluginId) { |
| | | return pluginManager.lookupPlugin(pluginId); |
| | | } |
| | | |
| | | @Override |
| | | public PluginRelease lookupRelease(String pluginId, String version) { |
| | | return pluginManager.lookupRelease(pluginId, version); |
| | | } |
| | | } |