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 15KB

13 years ago
Ticket tracker with patchset contributions A basic issue tracker styled as a hybrid of GitHub and BitBucket issues. You may attach commits to an existing ticket or you can push a single commit to create a *proposal* ticket. Tickets keep track of patchsets (one or more commits) and allow patchset rewriting (rebase, amend, squash) by detecing the non-fast-forward update and assigning a new patchset number to the new commits. Ticket tracker -------------- The ticket tracker stores tickets as an append-only journal of changes. The journals are deserialized and a ticket is built by applying the journal entries. Tickets are indexed using Apache Lucene and all queries and searches are executed against this Lucene index. There is one trade-off to this persistence design: user attributions are non-relational. What does that mean? Each journal entry stores the username of the author. If the username changes in the user service, the journal entry will not reflect that change because the values are hard-coded. Here are a few reasons/justifications for this design choice: 1. commit identifications (author, committer, tagger) are non-relational 2. maintains the KISS principle 3. your favorite text editor can still be your administration tool Persistence Choices ------------------- **FileTicketService**: stores journals on the filesystem **BranchTicketService**: stores journals on an orphan branch **RedisTicketService**: stores journals in a Redis key-value datastore It should be relatively straight-forward to develop other backends (MongoDB, etc) as long as the journal design is preserved. Pushing Commits --------------- Each push to a ticket is identified as a patchset revision. A patchset revision may add commits to the patchset (fast-forward) OR a patchset revision may rewrite history (rebase, squash, rebase+squash, or amend). Patchset authors should not be afraid to polish, revise, and rewrite their code before merging into the proposed branch. Gitblit will create one ref for each patchset. These refs are updated for fast-forward pushes or created for rewrites. They are formatted as `refs/tickets/{shard}/{id}/{patchset}`. The *shard* is the last two digits of the id. If the id < 10, prefix a 0. The *shard* is always two digits long. The shard's purpose is to ensure Gitblit doesn't exceed any filesystem directory limits for file creation. **Creating a Proposal Ticket** You may create a new change proposal ticket just by pushing a **single commit** to `refs/for/{branch}` where branch is the proposed integration branch OR `refs/for/new` or `refs/for/default` which both will use the default repository branch. git push origin HEAD:refs/for/new **Updating a Patchset** The safe way to update an existing patchset is to push to the patchset ref. git push origin HEAD:refs/heads/ticket/{id} This ensures you do not accidentally create a new patchset in the event that the patchset was updated after you last pulled. The not-so-safe way to update an existing patchset is to push using the magic ref. git push origin HEAD:refs/for/{id} This push ref will update an exisitng patchset OR create a new patchset if the update is non-fast-forward. **Rebasing, Squashing, Amending** Gitblit makes rebasing, squashing, and amending patchsets easy. Normally, pushing a non-fast-forward update would require rewind (RW+) repository permissions. Gitblit provides a magic ref which will allow ticket participants to rewrite a ticket patchset as long as the ticket is open. git push origin HEAD:refs/for/{id} Pushing changes to this ref allows the patchset authors to rebase, squash, or amend the patchset commits without requiring client-side use of the *--force* flag on push AND without requiring RW+ permission to the repository. Since each patchset is tracked with a ref it is easy to recover from accidental non-fast-forward updates. Features -------- - Ticket tracker with status changes and responsible assignments - Patchset revision scoring mechanism - Update/Rewrite patchset handling - Close-on-push detection - Server-side Merge button for simple merges - Comments with Markdown syntax support - Rich mail notifications - Voting - Mentions - Watch lists - Querying - Searches - Partial miletones support - Multiple backend options
10 years ago
Ticket tracker with patchset contributions A basic issue tracker styled as a hybrid of GitHub and BitBucket issues. You may attach commits to an existing ticket or you can push a single commit to create a *proposal* ticket. Tickets keep track of patchsets (one or more commits) and allow patchset rewriting (rebase, amend, squash) by detecing the non-fast-forward update and assigning a new patchset number to the new commits. Ticket tracker -------------- The ticket tracker stores tickets as an append-only journal of changes. The journals are deserialized and a ticket is built by applying the journal entries. Tickets are indexed using Apache Lucene and all queries and searches are executed against this Lucene index. There is one trade-off to this persistence design: user attributions are non-relational. What does that mean? Each journal entry stores the username of the author. If the username changes in the user service, the journal entry will not reflect that change because the values are hard-coded. Here are a few reasons/justifications for this design choice: 1. commit identifications (author, committer, tagger) are non-relational 2. maintains the KISS principle 3. your favorite text editor can still be your administration tool Persistence Choices ------------------- **FileTicketService**: stores journals on the filesystem **BranchTicketService**: stores journals on an orphan branch **RedisTicketService**: stores journals in a Redis key-value datastore It should be relatively straight-forward to develop other backends (MongoDB, etc) as long as the journal design is preserved. Pushing Commits --------------- Each push to a ticket is identified as a patchset revision. A patchset revision may add commits to the patchset (fast-forward) OR a patchset revision may rewrite history (rebase, squash, rebase+squash, or amend). Patchset authors should not be afraid to polish, revise, and rewrite their code before merging into the proposed branch. Gitblit will create one ref for each patchset. These refs are updated for fast-forward pushes or created for rewrites. They are formatted as `refs/tickets/{shard}/{id}/{patchset}`. The *shard* is the last two digits of the id. If the id < 10, prefix a 0. The *shard* is always two digits long. The shard's purpose is to ensure Gitblit doesn't exceed any filesystem directory limits for file creation. **Creating a Proposal Ticket** You may create a new change proposal ticket just by pushing a **single commit** to `refs/for/{branch}` where branch is the proposed integration branch OR `refs/for/new` or `refs/for/default` which both will use the default repository branch. git push origin HEAD:refs/for/new **Updating a Patchset** The safe way to update an existing patchset is to push to the patchset ref. git push origin HEAD:refs/heads/ticket/{id} This ensures you do not accidentally create a new patchset in the event that the patchset was updated after you last pulled. The not-so-safe way to update an existing patchset is to push using the magic ref. git push origin HEAD:refs/for/{id} This push ref will update an exisitng patchset OR create a new patchset if the update is non-fast-forward. **Rebasing, Squashing, Amending** Gitblit makes rebasing, squashing, and amending patchsets easy. Normally, pushing a non-fast-forward update would require rewind (RW+) repository permissions. Gitblit provides a magic ref which will allow ticket participants to rewrite a ticket patchset as long as the ticket is open. git push origin HEAD:refs/for/{id} Pushing changes to this ref allows the patchset authors to rebase, squash, or amend the patchset commits without requiring client-side use of the *--force* flag on push AND without requiring RW+ permission to the repository. Since each patchset is tracked with a ref it is easy to recover from accidental non-fast-forward updates. Features -------- - Ticket tracker with status changes and responsible assignments - Patchset revision scoring mechanism - Update/Rewrite patchset handling - Close-on-push detection - Server-side Merge button for simple merges - Comments with Markdown syntax support - Rich mail notifications - Voting - Mentions - Watch lists - Querying - Searches - Partial miletones support - Multiple backend options
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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. import java.net.URL;
  21. import java.util.Arrays;
  22. import java.util.List;
  23. import java.util.jar.Attributes;
  24. import java.util.jar.Manifest;
  25. /**
  26. * Constant values used by Gitblit.
  27. *
  28. * @author James Moger
  29. *
  30. */
  31. public class Constants {
  32. public static final String NAME = "Gitblit";
  33. public static final String FULL_NAME = "Gitblit - a pure Java Git solution";
  34. public static final String ADMIN_ROLE = "#admin";
  35. public static final String FORK_ROLE = "#fork";
  36. public static final String CREATE_ROLE = "#create";
  37. public static final String NOT_FEDERATED_ROLE = "#notfederated";
  38. public static final String NO_ROLE = "#none";
  39. public static final String EXTERNAL_ACCOUNT = "#externalAccount";
  40. public static final String PROPERTIES_FILE = "gitblit.properties";
  41. public static final String DEFAULT_USER_REPOSITORY_PREFIX = "~";
  42. public static final String R_PATH = "/r/";
  43. public static final String GIT_PATH = "/git/";
  44. public static final String ZIP_PATH = "/zip/";
  45. public static final String SYNDICATION_PATH = "/feed/";
  46. public static final String FEDERATION_PATH = "/federation/";
  47. public static final String RPC_PATH = "/rpc/";
  48. public static final String PAGES = "/pages/";
  49. public static final String SPARKLESHARE_INVITE_PATH = "/sparkleshare/";
  50. public static final String RAW_PATH = "/raw/";
  51. public static final String BRANCH_GRAPH_PATH = "/graph/";
  52. public static final String BORDER = "*****************************************************************";
  53. public static final String BORDER2 = "#################################################################";
  54. public static final String FEDERATION_USER = "$gitblit";
  55. public static final String PROPOSAL_EXT = ".json";
  56. public static final String ENCODING = "UTF-8";
  57. public static final int LEN_SHORTLOG = 78;
  58. public static final int LEN_SHORTLOG_REFS = 60;
  59. public static final String DEFAULT_BRANCH = "default";
  60. public static final String CONFIG_GITBLIT = "gitblit";
  61. public static final String CONFIG_CUSTOM_FIELDS = "customFields";
  62. public static final String ISO8601 = "yyyy-MM-dd'T'HH:mm:ssZ";
  63. public static final String baseFolder = "baseFolder";
  64. public static final String baseFolder$ = "${" + baseFolder + "}";
  65. public static final String contextFolder$ = "${contextFolder}";
  66. public static final String HEAD = "HEAD";
  67. public static final String R_META = "refs/meta/";
  68. public static final String R_HEADS = "refs/heads/";
  69. public static final String R_NOTES = "refs/notes/";
  70. public static final String R_CHANGES = "refs/changes/";
  71. public static final String R_PULL = "refs/pull/";
  72. public static final String R_TAGS = "refs/tags/";
  73. public static final String R_REMOTES = "refs/remotes/";
  74. public static final String R_FOR = "refs/for/";
  75. public static final String R_TICKET = "refs/heads/ticket/";
  76. public static final String R_TICKETS_PATCHSETS = "refs/tickets/";
  77. public static final String R_MASTER = "refs/heads/master";
  78. public static final String MASTER = "master";
  79. public static final String R_DEVELOP = "refs/heads/develop";
  80. public static final String DEVELOP = "develop";
  81. public static String getVersion() {
  82. String v = Constants.class.getPackage().getImplementationVersion();
  83. if (v == null) {
  84. return "0.0.0-SNAPSHOT";
  85. }
  86. return v;
  87. }
  88. public static String getGitBlitVersion() {
  89. return NAME + " v" + getVersion();
  90. }
  91. public static String getBuildDate() {
  92. return getManifestValue("build-date", "PENDING");
  93. }
  94. private static String getManifestValue(String attrib, String defaultValue) {
  95. Class<?> clazz = Constants.class;
  96. String className = clazz.getSimpleName() + ".class";
  97. String classPath = clazz.getResource(className).toString();
  98. if (!classPath.startsWith("jar")) {
  99. // Class not from JAR
  100. return defaultValue;
  101. }
  102. try {
  103. String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
  104. Manifest manifest = new Manifest(new URL(manifestPath).openStream());
  105. Attributes attr = manifest.getMainAttributes();
  106. String value = attr.getValue(attrib);
  107. return value;
  108. } catch (Exception e) {
  109. }
  110. return defaultValue;
  111. }
  112. /**
  113. * Enumeration representing the four access restriction levels.
  114. */
  115. public static enum AccessRestrictionType {
  116. NONE, PUSH, CLONE, VIEW;
  117. private static final AccessRestrictionType [] AUTH_TYPES = { PUSH, CLONE, VIEW };
  118. public static AccessRestrictionType fromName(String name) {
  119. for (AccessRestrictionType type : values()) {
  120. if (type.name().equalsIgnoreCase(name)) {
  121. return type;
  122. }
  123. }
  124. return NONE;
  125. }
  126. public static List<AccessRestrictionType> choices(boolean allowAnonymousPush) {
  127. if (allowAnonymousPush) {
  128. return Arrays.asList(values());
  129. }
  130. return Arrays.asList(AUTH_TYPES);
  131. }
  132. public boolean exceeds(AccessRestrictionType type) {
  133. return this.ordinal() > type.ordinal();
  134. }
  135. public boolean atLeast(AccessRestrictionType type) {
  136. return this.ordinal() >= type.ordinal();
  137. }
  138. @Override
  139. public String toString() {
  140. return name();
  141. }
  142. public boolean isValidPermission(AccessPermission permission) {
  143. switch (this) {
  144. case VIEW:
  145. // VIEW restriction
  146. // all access permissions are valid
  147. return true;
  148. case CLONE:
  149. // CLONE restriction
  150. // only CLONE or greater access permissions are valid
  151. return permission.atLeast(AccessPermission.CLONE);
  152. case PUSH:
  153. // PUSH restriction
  154. // only PUSH or greater access permissions are valid
  155. return permission.atLeast(AccessPermission.PUSH);
  156. case NONE:
  157. // NO access restriction
  158. // all access permissions are invalid
  159. return false;
  160. }
  161. return false;
  162. }
  163. }
  164. /**
  165. * Enumeration representing the types of authorization control for an
  166. * access restricted resource.
  167. */
  168. public static enum AuthorizationControl {
  169. AUTHENTICATED, NAMED;
  170. public static AuthorizationControl fromName(String name) {
  171. for (AuthorizationControl type : values()) {
  172. if (type.name().equalsIgnoreCase(name)) {
  173. return type;
  174. }
  175. }
  176. return NAMED;
  177. }
  178. @Override
  179. public String toString() {
  180. return name();
  181. }
  182. }
  183. /**
  184. * Enumeration representing the types of federation tokens.
  185. */
  186. public static enum FederationToken {
  187. ALL, USERS_AND_REPOSITORIES, REPOSITORIES;
  188. public static FederationToken fromName(String name) {
  189. for (FederationToken type : values()) {
  190. if (type.name().equalsIgnoreCase(name)) {
  191. return type;
  192. }
  193. }
  194. return REPOSITORIES;
  195. }
  196. @Override
  197. public String toString() {
  198. return name();
  199. }
  200. }
  201. /**
  202. * Enumeration representing the types of federation requests.
  203. */
  204. public static enum FederationRequest {
  205. POKE, PROPOSAL, PULL_REPOSITORIES, PULL_USERS, PULL_TEAMS, PULL_SETTINGS, PULL_SCRIPTS, STATUS;
  206. public static FederationRequest fromName(String name) {
  207. for (FederationRequest type : values()) {
  208. if (type.name().equalsIgnoreCase(name)) {
  209. return type;
  210. }
  211. }
  212. return PULL_REPOSITORIES;
  213. }
  214. @Override
  215. public String toString() {
  216. return name();
  217. }
  218. }
  219. /**
  220. * Enumeration representing the statii of federation requests.
  221. */
  222. public static enum FederationPullStatus {
  223. PENDING, FAILED, SKIPPED, PULLED, MIRRORED, NOCHANGE, EXCLUDED;
  224. public static FederationPullStatus fromName(String name) {
  225. for (FederationPullStatus type : values()) {
  226. if (type.name().equalsIgnoreCase(name)) {
  227. return type;
  228. }
  229. }
  230. return PENDING;
  231. }
  232. @Override
  233. public String toString() {
  234. return name();
  235. }
  236. }
  237. /**
  238. * Enumeration representing the federation types.
  239. */
  240. public static enum FederationStrategy {
  241. EXCLUDE, FEDERATE_THIS, FEDERATE_ORIGIN;
  242. public static FederationStrategy fromName(String name) {
  243. for (FederationStrategy type : values()) {
  244. if (type.name().equalsIgnoreCase(name)) {
  245. return type;
  246. }
  247. }
  248. return FEDERATE_THIS;
  249. }
  250. public boolean exceeds(FederationStrategy type) {
  251. return this.ordinal() > type.ordinal();
  252. }
  253. public boolean atLeast(FederationStrategy type) {
  254. return this.ordinal() >= type.ordinal();
  255. }
  256. @Override
  257. public String toString() {
  258. return name();
  259. }
  260. }
  261. /**
  262. * Enumeration representing the possible results of federation proposal
  263. * requests.
  264. */
  265. public static enum FederationProposalResult {
  266. ERROR, FEDERATION_DISABLED, MISSING_DATA, NO_PROPOSALS, NO_POKE, ACCEPTED;
  267. @Override
  268. public String toString() {
  269. return name();
  270. }
  271. }
  272. /**
  273. * Enumeration representing the possible remote procedure call requests from
  274. * a client.
  275. */
  276. public static enum RpcRequest {
  277. // Order is important here. anything after LIST_SETTINGS requires
  278. // administrator privileges and web.allowRpcManagement.
  279. CLEAR_REPOSITORY_CACHE, REINDEX_TICKETS, GET_PROTOCOL, LIST_REPOSITORIES, LIST_BRANCHES, GET_USER,
  280. FORK_REPOSITORY, LIST_SETTINGS,
  281. CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY,
  282. LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER,
  283. LIST_TEAMS, CREATE_TEAM, EDIT_TEAM, DELETE_TEAM,
  284. LIST_REPOSITORY_MEMBERS, SET_REPOSITORY_MEMBERS, LIST_REPOSITORY_TEAMS, SET_REPOSITORY_TEAMS,
  285. LIST_REPOSITORY_MEMBER_PERMISSIONS, SET_REPOSITORY_MEMBER_PERMISSIONS, LIST_REPOSITORY_TEAM_PERMISSIONS, SET_REPOSITORY_TEAM_PERMISSIONS,
  286. LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS, LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS,
  287. EDIT_SETTINGS, LIST_STATUS;
  288. public static RpcRequest fromName(String name) {
  289. for (RpcRequest type : values()) {
  290. if (type.name().equalsIgnoreCase(name)) {
  291. return type;
  292. }
  293. }
  294. return null;
  295. }
  296. public boolean exceeds(RpcRequest type) {
  297. return this.ordinal() > type.ordinal();
  298. }
  299. @Override
  300. public String toString() {
  301. return name();
  302. }
  303. }
  304. /**
  305. * Enumeration of the search types.
  306. */
  307. public static enum SearchType {
  308. AUTHOR, COMMITTER, COMMIT;
  309. public static SearchType forName(String name) {
  310. for (SearchType type : values()) {
  311. if (type.name().equalsIgnoreCase(name)) {
  312. return type;
  313. }
  314. }
  315. return COMMIT;
  316. }
  317. @Override
  318. public String toString() {
  319. return name().toLowerCase();
  320. }
  321. }
  322. /**
  323. * Enumeration of the feed content object types.
  324. */
  325. public static enum FeedObjectType {
  326. COMMIT, TAG;
  327. public static FeedObjectType forName(String name) {
  328. for (FeedObjectType type : values()) {
  329. if (type.name().equalsIgnoreCase(name)) {
  330. return type;
  331. }
  332. }
  333. return COMMIT;
  334. }
  335. @Override
  336. public String toString() {
  337. return name().toLowerCase();
  338. }
  339. }
  340. /**
  341. * The types of objects that can be indexed and queried.
  342. */
  343. public static enum SearchObjectType {
  344. commit, blob;
  345. public static SearchObjectType fromName(String name) {
  346. for (SearchObjectType value : values()) {
  347. if (value.name().equals(name)) {
  348. return value;
  349. }
  350. }
  351. return null;
  352. }
  353. }
  354. /**
  355. * The access permissions available for a repository.
  356. */
  357. public static enum AccessPermission {
  358. NONE("N"), EXCLUDE("X"), VIEW("V"), CLONE("R"), PUSH("RW"), CREATE("RWC"), DELETE("RWD"), REWIND("RW+"), OWNER("RW+");
  359. public static final AccessPermission [] NEWPERMISSIONS = { EXCLUDE, VIEW, CLONE, PUSH, CREATE, DELETE, REWIND };
  360. public static final AccessPermission [] SSHPERMISSIONS = { VIEW, CLONE, PUSH };
  361. public static AccessPermission LEGACY = REWIND;
  362. public final String code;
  363. private AccessPermission(String code) {
  364. this.code = code;
  365. }
  366. public boolean atMost(AccessPermission perm) {
  367. return ordinal() <= perm.ordinal();
  368. }
  369. public boolean atLeast(AccessPermission perm) {
  370. return ordinal() >= perm.ordinal();
  371. }
  372. public boolean exceeds(AccessPermission perm) {
  373. return ordinal() > perm.ordinal();
  374. }
  375. public String asRole(String repository) {
  376. return code + ":" + repository;
  377. }
  378. @Override
  379. public String toString() {
  380. return code;
  381. }
  382. public static AccessPermission permissionFromRole(String role) {
  383. String [] fields = role.split(":", 2);
  384. if (fields.length == 1) {
  385. // legacy/undefined assume full permissions
  386. return AccessPermission.LEGACY;
  387. } else {
  388. // code:repository
  389. return AccessPermission.fromCode(fields[0]);
  390. }
  391. }
  392. public static String repositoryFromRole(String role) {
  393. String [] fields = role.split(":", 2);
  394. if (fields.length == 1) {
  395. // legacy/undefined assume full permissions
  396. return role;
  397. } else {
  398. // code:repository
  399. return fields[1];
  400. }
  401. }
  402. public static AccessPermission fromCode(String code) {
  403. for (AccessPermission perm : values()) {
  404. if (perm.code.equalsIgnoreCase(code)) {
  405. return perm;
  406. }
  407. }
  408. return AccessPermission.NONE;
  409. }
  410. }
  411. public static enum RegistrantType {
  412. REPOSITORY, USER, TEAM;
  413. }
  414. public static enum PermissionType {
  415. MISSING, ANONYMOUS, EXPLICIT, TEAM, REGEX, OWNER, ADMINISTRATOR;
  416. }
  417. public static enum GCStatus {
  418. READY, COLLECTING;
  419. public boolean exceeds(GCStatus s) {
  420. return ordinal() > s.ordinal();
  421. }
  422. }
  423. public static enum AuthenticationType {
  424. PUBLIC_KEY, CREDENTIALS, COOKIE, CERTIFICATE, CONTAINER;
  425. public boolean isStandard() {
  426. return ordinal() <= COOKIE.ordinal();
  427. }
  428. }
  429. public static enum AccountType {
  430. LOCAL, EXTERNAL, CONTAINER, LDAP, REDMINE, SALESFORCE, WINDOWS, PAM, HTPASSWD;
  431. public static AccountType fromString(String value) {
  432. for (AccountType type : AccountType.values()) {
  433. if (type.name().equalsIgnoreCase(value)) {
  434. return type;
  435. }
  436. }
  437. return AccountType.LOCAL;
  438. }
  439. public boolean isLocal() {
  440. return this == LOCAL;
  441. }
  442. }
  443. public static enum CommitMessageRenderer {
  444. PLAIN, MARKDOWN;
  445. public static CommitMessageRenderer fromName(String name) {
  446. for (CommitMessageRenderer renderer : values()) {
  447. if (renderer.name().equalsIgnoreCase(name)) {
  448. return renderer;
  449. }
  450. }
  451. return CommitMessageRenderer.PLAIN;
  452. }
  453. }
  454. public static enum Transport {
  455. // ordered for url advertisements, assuming equal access permissions
  456. SSH, HTTPS, HTTP, GIT;
  457. public static Transport fromString(String value) {
  458. for (Transport t : values()) {
  459. if (t.name().equalsIgnoreCase(value)) {
  460. return t;
  461. }
  462. }
  463. return null;
  464. }
  465. public static Transport fromUrl(String url) {
  466. int delim = url.indexOf("://");
  467. if (delim == -1) {
  468. // if no protocol is specified, SSH is assumed by git clients
  469. return SSH;
  470. }
  471. String scheme = url.substring(0, delim);
  472. return fromString(scheme);
  473. }
  474. }
  475. @Documented
  476. @Retention(RetentionPolicy.RUNTIME)
  477. public @interface Unused {
  478. }
  479. }