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.

Constants.java 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /*
  2. * Copyright 2011 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;
  17. import java.lang.annotation.Documented;
  18. import java.lang.annotation.Retention;
  19. import java.lang.annotation.RetentionPolicy;
  20. /**
  21. * Constant values used by Gitblit.
  22. *
  23. * @author James Moger
  24. *
  25. */
  26. public class Constants {
  27. public static final String NAME = "Gitblit";
  28. public static final String FULL_NAME = "Gitblit - a pure Java Git solution";
  29. // The build script extracts this exact line so be careful editing it
  30. // and only use A-Z a-z 0-9 .-_ in the string.
  31. public static final String VERSION = "1.2.0-SNAPSHOT";
  32. // The build script extracts this exact line so be careful editing it
  33. // and only use A-Z a-z 0-9 .-_ in the string.
  34. public static final String VERSION_DATE = "PENDING";
  35. // The build script extracts this exact line so be careful editing it
  36. // and only use A-Z a-z 0-9 .-_ in the string.
  37. public static final String JGIT_VERSION = "JGit 2.2.0 (201212191850-r)";
  38. public static final String ADMIN_ROLE = "#admin";
  39. public static final String FORK_ROLE = "#fork";
  40. public static final String CREATE_ROLE = "#create";
  41. public static final String NOT_FEDERATED_ROLE = "#notfederated";
  42. public static final String NO_ROLE = "#none";
  43. public static final String PROPERTIES_FILE = "gitblit.properties";
  44. public static final String GIT_PATH = "/git/";
  45. public static final String ZIP_PATH = "/zip/";
  46. public static final String SYNDICATION_PATH = "/feed/";
  47. public static final String FEDERATION_PATH = "/federation/";
  48. public static final String RPC_PATH = "/rpc/";
  49. public static final String PAGES= "/pages/";
  50. public static final String BORDER = "***********************************************************";
  51. public static final String FEDERATION_USER = "$gitblit";
  52. public static final String PROPOSAL_EXT = ".json";
  53. public static final String ENCODING = "UTF-8";
  54. public static final int LEN_SHORTLOG = 78;
  55. public static final int LEN_SHORTLOG_REFS = 60;
  56. public static final String DEFAULT_BRANCH = "default";
  57. public static final String CONFIG_GITBLIT = "gitblit";
  58. public static final String CONFIG_CUSTOM_FIELDS = "customFields";
  59. public static final String ISO8601 = "yyyy-MM-dd'T'HH:mm:ssZ";
  60. public static String getGitBlitVersion() {
  61. return NAME + " v" + VERSION;
  62. }
  63. /**
  64. * Enumeration representing the four access restriction levels.
  65. */
  66. public static enum AccessRestrictionType {
  67. NONE, PUSH, CLONE, VIEW;
  68. public static AccessRestrictionType fromName(String name) {
  69. for (AccessRestrictionType type : values()) {
  70. if (type.name().equalsIgnoreCase(name)) {
  71. return type;
  72. }
  73. }
  74. return NONE;
  75. }
  76. public boolean exceeds(AccessRestrictionType type) {
  77. return this.ordinal() > type.ordinal();
  78. }
  79. public boolean atLeast(AccessRestrictionType type) {
  80. return this.ordinal() >= type.ordinal();
  81. }
  82. public String toString() {
  83. return name();
  84. }
  85. }
  86. /**
  87. * Enumeration representing the types of authorization control for an
  88. * access restricted resource.
  89. */
  90. public static enum AuthorizationControl {
  91. AUTHENTICATED, NAMED;
  92. public static AuthorizationControl fromName(String name) {
  93. for (AuthorizationControl type : values()) {
  94. if (type.name().equalsIgnoreCase(name)) {
  95. return type;
  96. }
  97. }
  98. return NAMED;
  99. }
  100. public String toString() {
  101. return name();
  102. }
  103. }
  104. /**
  105. * Enumeration representing the types of federation tokens.
  106. */
  107. public static enum FederationToken {
  108. ALL, USERS_AND_REPOSITORIES, REPOSITORIES;
  109. public static FederationToken fromName(String name) {
  110. for (FederationToken type : values()) {
  111. if (type.name().equalsIgnoreCase(name)) {
  112. return type;
  113. }
  114. }
  115. return REPOSITORIES;
  116. }
  117. public String toString() {
  118. return name();
  119. }
  120. }
  121. /**
  122. * Enumeration representing the types of federation requests.
  123. */
  124. public static enum FederationRequest {
  125. POKE, PROPOSAL, PULL_REPOSITORIES, PULL_USERS, PULL_TEAMS, PULL_SETTINGS, PULL_SCRIPTS, STATUS;
  126. public static FederationRequest fromName(String name) {
  127. for (FederationRequest type : values()) {
  128. if (type.name().equalsIgnoreCase(name)) {
  129. return type;
  130. }
  131. }
  132. return PULL_REPOSITORIES;
  133. }
  134. public String toString() {
  135. return name();
  136. }
  137. }
  138. /**
  139. * Enumeration representing the statii of federation requests.
  140. */
  141. public static enum FederationPullStatus {
  142. PENDING, FAILED, SKIPPED, PULLED, MIRRORED, NOCHANGE, EXCLUDED;
  143. public static FederationPullStatus fromName(String name) {
  144. for (FederationPullStatus type : values()) {
  145. if (type.name().equalsIgnoreCase(name)) {
  146. return type;
  147. }
  148. }
  149. return PENDING;
  150. }
  151. @Override
  152. public String toString() {
  153. return name();
  154. }
  155. }
  156. /**
  157. * Enumeration representing the federation types.
  158. */
  159. public static enum FederationStrategy {
  160. EXCLUDE, FEDERATE_THIS, FEDERATE_ORIGIN;
  161. public static FederationStrategy fromName(String name) {
  162. for (FederationStrategy type : values()) {
  163. if (type.name().equalsIgnoreCase(name)) {
  164. return type;
  165. }
  166. }
  167. return FEDERATE_THIS;
  168. }
  169. public boolean exceeds(FederationStrategy type) {
  170. return this.ordinal() > type.ordinal();
  171. }
  172. public boolean atLeast(FederationStrategy type) {
  173. return this.ordinal() >= type.ordinal();
  174. }
  175. @Override
  176. public String toString() {
  177. return name();
  178. }
  179. }
  180. /**
  181. * Enumeration representing the possible results of federation proposal
  182. * requests.
  183. */
  184. public static enum FederationProposalResult {
  185. ERROR, FEDERATION_DISABLED, MISSING_DATA, NO_PROPOSALS, NO_POKE, ACCEPTED;
  186. @Override
  187. public String toString() {
  188. return name();
  189. }
  190. }
  191. /**
  192. * Enumeration representing the possible remote procedure call requests from
  193. * a client.
  194. */
  195. public static enum RpcRequest {
  196. // Order is important here. anything above LIST_SETTINGS requires
  197. // administrator privileges and web.allowRpcManagement.
  198. CLEAR_REPOSITORY_CACHE, GET_PROTOCOL, LIST_REPOSITORIES, LIST_BRANCHES, LIST_SETTINGS,
  199. CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY,
  200. LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER,
  201. LIST_TEAMS, CREATE_TEAM, EDIT_TEAM, DELETE_TEAM,
  202. LIST_REPOSITORY_MEMBERS, SET_REPOSITORY_MEMBERS, LIST_REPOSITORY_TEAMS, SET_REPOSITORY_TEAMS,
  203. LIST_REPOSITORY_MEMBER_PERMISSIONS, SET_REPOSITORY_MEMBER_PERMISSIONS, LIST_REPOSITORY_TEAM_PERMISSIONS, SET_REPOSITORY_TEAM_PERMISSIONS,
  204. LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS, LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS,
  205. EDIT_SETTINGS, LIST_STATUS;
  206. public static RpcRequest fromName(String name) {
  207. for (RpcRequest type : values()) {
  208. if (type.name().equalsIgnoreCase(name)) {
  209. return type;
  210. }
  211. }
  212. return null;
  213. }
  214. public boolean exceeds(RpcRequest type) {
  215. return this.ordinal() > type.ordinal();
  216. }
  217. @Override
  218. public String toString() {
  219. return name();
  220. }
  221. }
  222. /**
  223. * Enumeration of the search types.
  224. */
  225. public static enum SearchType {
  226. AUTHOR, COMMITTER, COMMIT;
  227. public static SearchType forName(String name) {
  228. for (SearchType type : values()) {
  229. if (type.name().equalsIgnoreCase(name)) {
  230. return type;
  231. }
  232. }
  233. return COMMIT;
  234. }
  235. @Override
  236. public String toString() {
  237. return name().toLowerCase();
  238. }
  239. }
  240. /**
  241. * The types of objects that can be indexed and queried.
  242. */
  243. public static enum SearchObjectType {
  244. commit, blob, issue;
  245. static SearchObjectType fromName(String name) {
  246. for (SearchObjectType value : values()) {
  247. if (value.name().equals(name)) {
  248. return value;
  249. }
  250. }
  251. return null;
  252. }
  253. }
  254. /**
  255. * The access permissions available for a repository.
  256. */
  257. public static enum AccessPermission {
  258. NONE("N"), EXCLUDE("X"), VIEW("V"), CLONE("R"), PUSH("RW"), CREATE("RWC"), DELETE("RWD"), REWIND("RW+"), OWNER("RW+");
  259. public static final AccessPermission [] NEWPERMISSIONS = { EXCLUDE, VIEW, CLONE, PUSH, CREATE, DELETE, REWIND };
  260. public static AccessPermission LEGACY = REWIND;
  261. public final String code;
  262. private AccessPermission(String code) {
  263. this.code = code;
  264. }
  265. public boolean atLeast(AccessPermission perm) {
  266. return ordinal() >= perm.ordinal();
  267. }
  268. public boolean exceeds(AccessPermission perm) {
  269. return ordinal() > perm.ordinal();
  270. }
  271. public String asRole(String repository) {
  272. return code + ":" + repository;
  273. }
  274. @Override
  275. public String toString() {
  276. return code;
  277. }
  278. public static AccessPermission permissionFromRole(String role) {
  279. String [] fields = role.split(":", 2);
  280. if (fields.length == 1) {
  281. // legacy/undefined assume full permissions
  282. return AccessPermission.LEGACY;
  283. } else {
  284. // code:repository
  285. return AccessPermission.fromCode(fields[0]);
  286. }
  287. }
  288. public static String repositoryFromRole(String role) {
  289. String [] fields = role.split(":", 2);
  290. if (fields.length == 1) {
  291. // legacy/undefined assume full permissions
  292. return role;
  293. } else {
  294. // code:repository
  295. return fields[1];
  296. }
  297. }
  298. public static AccessPermission fromCode(String code) {
  299. for (AccessPermission perm : values()) {
  300. if (perm.code.equalsIgnoreCase(code)) {
  301. return perm;
  302. }
  303. }
  304. return AccessPermission.NONE;
  305. }
  306. }
  307. public static enum RegistrantType {
  308. REPOSITORY, USER, TEAM;
  309. }
  310. public static enum PermissionType {
  311. MISSING, EXPLICIT, TEAM, REGEX, OWNER, ADMINISTRATOR;
  312. }
  313. public static enum GCStatus {
  314. READY, COLLECTING;
  315. public boolean exceeds(GCStatus s) {
  316. return ordinal() > s.ordinal();
  317. }
  318. }
  319. public static enum AuthenticationType {
  320. CREDENTIALS, COOKIE, CERTIFICATE, CONTAINER;
  321. public boolean isStandard() {
  322. return ordinal() <= COOKIE.ordinal();
  323. }
  324. }
  325. @Documented
  326. @Retention(RetentionPolicy.RUNTIME)
  327. public @interface Unused {
  328. }
  329. }