You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IRepositoryManager.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /*
  2. * Copyright 2013 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.manager;
  17. import java.io.File;
  18. import java.util.Collection;
  19. import java.util.Date;
  20. import java.util.List;
  21. import org.eclipse.jgit.lib.Repository;
  22. import com.gitblit.GitBlitException;
  23. import com.gitblit.models.ForkModel;
  24. import com.gitblit.models.Metric;
  25. import com.gitblit.models.RegistrantAccessPermission;
  26. import com.gitblit.models.RepositoryModel;
  27. import com.gitblit.models.SearchResult;
  28. import com.gitblit.models.UserModel;
  29. public interface IRepositoryManager {
  30. /**
  31. * Returns the path of the repositories folder. This method checks to see if
  32. * Gitblit is running on a cloud service and may return an adjusted path.
  33. *
  34. * @return the repositories folder path
  35. */
  36. File getRepositoriesFolder();
  37. /**
  38. * Returns the path of the hooks folder. This method checks to see if
  39. * Gitblit is running on a cloud service and may return an adjusted path.
  40. *
  41. * @return the Groovy hook scripts folder path
  42. */
  43. File getHooksFolder();
  44. /**
  45. * Returns the path of the grapes folder. This method checks to see if
  46. * Gitblit is running on a cloud service and may return an adjusted path.
  47. *
  48. * @return the Groovy grapes folder path
  49. */
  50. File getGrapesFolder();
  51. /**
  52. * Returns the most recent change date of any repository served by Gitblit.
  53. *
  54. * @return a date
  55. */
  56. Date getLastActivityDate();
  57. /**
  58. * Returns the effective list of permissions for this user, taking into account
  59. * team memberships, ownerships.
  60. *
  61. * @param user
  62. * @return the effective list of permissions for the user
  63. */
  64. List<RegistrantAccessPermission> getUserAccessPermissions(UserModel user);
  65. /**
  66. * Returns the list of users and their access permissions for the specified
  67. * repository including permission source information such as the team or
  68. * regular expression which sets the permission.
  69. *
  70. * @param repository
  71. * @return a list of RegistrantAccessPermissions
  72. */
  73. List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository);
  74. /**
  75. * Sets the access permissions to the specified repository for the specified users.
  76. *
  77. * @param repository
  78. * @param permissions
  79. * @return true if the user models have been updated
  80. */
  81. boolean setUserAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions);
  82. /**
  83. * Returns the list of all users who have an explicit access permission
  84. * for the specified repository.
  85. *
  86. * @see IUserService.getUsernamesForRepositoryRole(String)
  87. * @param repository
  88. * @return list of all usernames that have an access permission for the repository
  89. */
  90. List<String> getRepositoryUsers(RepositoryModel repository);
  91. /**
  92. * Returns the list of teams and their access permissions for the specified
  93. * repository including the source of the permission such as the admin flag
  94. * or a regular expression.
  95. *
  96. * @param repository
  97. * @return a list of RegistrantAccessPermissions
  98. */
  99. List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository);
  100. /**
  101. * Sets the access permissions to the specified repository for the specified teams.
  102. *
  103. * @param repository
  104. * @param permissions
  105. * @return true if the team models have been updated
  106. */
  107. boolean setTeamAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions);
  108. /**
  109. * Returns the list of all teams who have an explicit access permission for
  110. * the specified repository.
  111. *
  112. * @see IUserService.getTeamnamesForRepositoryRole(String)
  113. * @param repository
  114. * @return list of all teamnames with explicit access permissions to the repository
  115. */
  116. List<String> getRepositoryTeams(RepositoryModel repository);
  117. /**
  118. * Adds the repository to the list of cached repositories if Gitblit is
  119. * configured to cache the repository list.
  120. *
  121. * @param model
  122. */
  123. void addToCachedRepositoryList(RepositoryModel model);
  124. /**
  125. * Resets the repository list cache.
  126. *
  127. */
  128. void resetRepositoryListCache();
  129. /**
  130. * Returns the list of all repositories available to Gitblit. This method
  131. * does not consider user access permissions.
  132. *
  133. * @return list of all repositories
  134. */
  135. List<String> getRepositoryList();
  136. /**
  137. * Returns the JGit repository for the specified name.
  138. *
  139. * @param repositoryName
  140. * @return repository or null
  141. */
  142. Repository getRepository(String repositoryName);
  143. /**
  144. * Returns the JGit repository for the specified name.
  145. *
  146. * @param repositoryName
  147. * @param logError
  148. * @return repository or null
  149. */
  150. Repository getRepository(String repositoryName, boolean logError);
  151. /**
  152. * Returns the list of repository models that are accessible to the user.
  153. *
  154. * @param user
  155. * @return list of repository models accessible to user
  156. */
  157. List<RepositoryModel> getRepositoryModels(UserModel user);
  158. /**
  159. * Returns a repository model if the repository exists and the user may
  160. * access the repository.
  161. *
  162. * @param user
  163. * @param repositoryName
  164. * @return repository model or null
  165. */
  166. RepositoryModel getRepositoryModel(UserModel user, String repositoryName);
  167. /**
  168. * Returns the repository model for the specified repository. This method
  169. * does not consider user access permissions.
  170. *
  171. * @param repositoryName
  172. * @return repository model or null
  173. */
  174. RepositoryModel getRepositoryModel(String repositoryName);
  175. /**
  176. * Returns the star count of the repository.
  177. *
  178. * @param repository
  179. * @return the star count
  180. */
  181. long getStarCount(RepositoryModel repository);
  182. /**
  183. * Determines if this server has the requested repository.
  184. *
  185. * @param n
  186. * @return true if the repository exists
  187. */
  188. boolean hasRepository(String repositoryName);
  189. /**
  190. * Determines if this server has the requested repository.
  191. *
  192. * @param n
  193. * @param caseInsensitive
  194. * @return true if the repository exists
  195. */
  196. boolean hasRepository(String repositoryName, boolean caseSensitiveCheck);
  197. /**
  198. * Determines if the specified user has a fork of the specified origin
  199. * repository.
  200. *
  201. * @param username
  202. * @param origin
  203. * @return true the if the user has a fork
  204. */
  205. boolean hasFork(String username, String origin);
  206. /**
  207. * Gets the name of a user's fork of the specified origin
  208. * repository.
  209. *
  210. * @param username
  211. * @param origin
  212. * @return the name of the user's fork, null otherwise
  213. */
  214. String getFork(String username, String origin);
  215. /**
  216. * Returns the fork network for a repository by traversing up the fork graph
  217. * to discover the root and then down through all children of the root node.
  218. *
  219. * @param repository
  220. * @return a ForkModel
  221. */
  222. ForkModel getForkNetwork(String repository);
  223. /**
  224. * Updates the last changed fields and optionally calculates the size of the
  225. * repository. Gitblit caches the repository sizes to reduce the performance
  226. * penalty of recursive calculation. The cache is updated if the repository
  227. * has been changed since the last calculation.
  228. *
  229. * @param model
  230. * @return size in bytes of the repository
  231. */
  232. long updateLastChangeFields(Repository r, RepositoryModel model);
  233. /**
  234. * Returns the metrics for the default branch of the specified repository.
  235. * This method builds a metrics cache. The cache is updated if the
  236. * repository is updated. A new copy of the metrics list is returned on each
  237. * call so that modifications to the list are non-destructive.
  238. *
  239. * @param model
  240. * @param repository
  241. * @return a new array list of metrics
  242. */
  243. List<Metric> getRepositoryDefaultMetrics(RepositoryModel model, Repository repository);
  244. /**
  245. * Creates/updates the repository model keyed by reopsitoryName. Saves all
  246. * repository settings in .git/config. This method allows for renaming
  247. * repositories and will update user access permissions accordingly.
  248. *
  249. * All repositories created by this method are bare and automatically have
  250. * .git appended to their names, which is the standard convention for bare
  251. * repositories.
  252. *
  253. * @param repositoryName
  254. * @param repository
  255. * @param isCreate
  256. * @throws GitBlitException
  257. */
  258. void updateRepositoryModel(String repositoryName, RepositoryModel repository, boolean isCreate)
  259. throws GitBlitException;
  260. /**
  261. * Updates the Gitblit configuration for the specified repository.
  262. *
  263. * @param r
  264. * the Git repository
  265. * @param repository
  266. * the Gitblit repository model
  267. */
  268. void updateConfiguration(Repository r, RepositoryModel repository);
  269. /**
  270. * Deletes the repository from the file system and removes the repository
  271. * permission from all repository users.
  272. *
  273. * @param model
  274. * @return true if successful
  275. */
  276. boolean deleteRepositoryModel(RepositoryModel model);
  277. /**
  278. * Deletes the repository from the file system and removes the repository
  279. * permission from all repository users.
  280. *
  281. * @param repositoryName
  282. * @return true if successful
  283. */
  284. boolean deleteRepository(String repositoryName);
  285. /**
  286. * Returns the list of all Groovy push hook scripts. Script files must have
  287. * .groovy extension
  288. *
  289. * @return list of available hook scripts
  290. */
  291. List<String> getAllScripts();
  292. /**
  293. * Returns the list of pre-receive scripts the repository inherited from the
  294. * global settings and team affiliations.
  295. *
  296. * @param repository
  297. * if null only the globally specified scripts are returned
  298. * @return a list of scripts
  299. */
  300. List<String> getPreReceiveScriptsInherited(RepositoryModel repository);
  301. /**
  302. * Returns the list of all available Groovy pre-receive push hook scripts
  303. * that are not already inherited by the repository. Script files must have
  304. * .groovy extension
  305. *
  306. * @param repository
  307. * optional parameter
  308. * @return list of available hook scripts
  309. */
  310. List<String> getPreReceiveScriptsUnused(RepositoryModel repository);
  311. /**
  312. * Returns the list of post-receive scripts the repository inherited from
  313. * the global settings and team affiliations.
  314. *
  315. * @param repository
  316. * if null only the globally specified scripts are returned
  317. * @return a list of scripts
  318. */
  319. List<String> getPostReceiveScriptsInherited(RepositoryModel repository);
  320. /**
  321. * Returns the list of unused Groovy post-receive push hook scripts that are
  322. * not already inherited by the repository. Script files must have .groovy
  323. * extension
  324. *
  325. * @param repository
  326. * optional parameter
  327. * @return list of available hook scripts
  328. */
  329. List<String> getPostReceiveScriptsUnused(RepositoryModel repository);
  330. /**
  331. * Search the specified repositories using the Lucene query.
  332. *
  333. * @param query
  334. * @param page
  335. * @param pageSize
  336. * @param repositories
  337. * @return
  338. */
  339. List<SearchResult> search(String query, int page, int pageSize, List<String> repositories);
  340. /**
  341. *
  342. * @return true if we are running the gc executor
  343. */
  344. boolean isCollectingGarbage();
  345. /**
  346. * Returns true if Gitblit is actively collecting garbage in this repository.
  347. *
  348. * @param repositoryName
  349. * @return true if actively collecting garbage
  350. */
  351. boolean isCollectingGarbage(String repositoryName);
  352. }