James Moger
2013-01-15 eec3ef21b9a4503c11f21c292b843adbdc3ee7fc
commit | author | age
f13c4c 1 /*
JM 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  */
5fe7df 16 package com.gitblit;
JM 17
20714a 18 import java.lang.annotation.Documented;
JM 19 import java.lang.annotation.Retention;
20 import java.lang.annotation.RetentionPolicy;
21
d896e6 22
892570 23 /**
JM 24  * Constant values used by Gitblit.
25  * 
26  * @author James Moger
27  * 
28  */
5fe7df 29 public class Constants {
JM 30
2a7306 31     public static final String NAME = "Gitblit";
5fe7df 32
2a7306 33     public static final String FULL_NAME = "Gitblit - a pure Java Git solution";
155bf7 34
a4d249 35     // The build script extracts this exact line so be careful editing it
JM 36     // and only use A-Z a-z 0-9 .-_ in the string.
eec3ef 37     public static final String VERSION = "1.2.1";
d39680 38
JM 39     // The build script extracts this exact line so be careful editing it
40     // and only use A-Z a-z 0-9 .-_ in the string.
eec3ef 41     public static final String VERSION_DATE = "2012-01-15";
a4d249 42
2a7306 43     // The build script extracts this exact line so be careful editing it
JM 44     // and only use A-Z a-z 0-9 .-_ in the string.
ed3213 45     public static final String JGIT_VERSION = "JGit 2.2.0 (201212191850-r)";
155bf7 46
2a7306 47     public static final String ADMIN_ROLE = "#admin";
1e1b85 48     
JM 49     public static final String FORK_ROLE = "#fork";
6662e3 50     
JM 51     public static final String CREATE_ROLE = "#create";
2a7306 52
831469 53     public static final String NOT_FEDERATED_ROLE = "#notfederated";
ce2a40 54     
JM 55     public static final String NO_ROLE = "#none";
831469 56
2a7306 57     public static final String PROPERTIES_FILE = "gitblit.properties";
JM 58
5450d0 59     public static final String GIT_PATH = "/git/";
2a7306 60
5450d0 61     public static final String ZIP_PATH = "/zip/";
85c2e6 62
5450d0 63     public static final String SYNDICATION_PATH = "/feed/";
85c2e6 64
831469 65     public static final String FEDERATION_PATH = "/federation/";
31abc2 66
93f0b1 67     public static final String RPC_PATH = "/rpc/";
6d874a 68     
JM 69     public static final String PAGES= "/pages/";
831469 70
1f9dae 71     public static final String BORDER = "***********************************************************";
db653a 72
831469 73     public static final String FEDERATION_USER = "$gitblit";
JM 74
75     public static final String PROPOSAL_EXT = ".json";
6d874a 76     
JM 77     public static final String ENCODING = "UTF-8";
78     
75705a 79     public static final int LEN_SHORTLOG = 78;
a45caa 80     
JM 81     public static final int LEN_SHORTLOG_REFS = 60;
82     
1aabf0 83     public static final String DEFAULT_BRANCH = "default";
JM 84     
380afa 85     public static final String CONFIG_GITBLIT = "gitblit";
4a5a55 86     
380afa 87     public static final String CONFIG_CUSTOM_FIELDS = "customFields";
4a5a55 88     
e92c6d 89     public static final String ISO8601 = "yyyy-MM-dd'T'HH:mm:ssZ";
JM 90     
f8bb95 91     public static final String R_GITBLIT = "refs/gitblit/";
JM 92     
93d506 93     public static final String baseFolder = "baseFolder";
JM 94     
95     public static final String baseFolder$ = "${" + baseFolder + "}";
96     
97     public static final String contextFolder$ = "${contextFolder}";
98     
831469 99     public static String getGitBlitVersion() {
JM 100         return NAME + " v" + VERSION;
101     }
93d506 102     
88598b 103     /**
831469 104      * Enumeration representing the four access restriction levels.
88598b 105      */
dfb889 106     public static enum AccessRestrictionType {
JM 107         NONE, PUSH, CLONE, VIEW;
108
d0d438 109         public static AccessRestrictionType fromName(String name) {
dfb889 110             for (AccessRestrictionType type : values()) {
d0d438 111                 if (type.name().equalsIgnoreCase(name)) {
dfb889 112                     return type;
JM 113                 }
114             }
115             return NONE;
116         }
f98825 117
JM 118         public boolean exceeds(AccessRestrictionType type) {
119             return this.ordinal() > type.ordinal();
120         }
121
dfb889 122         public boolean atLeast(AccessRestrictionType type) {
JM 123             return this.ordinal() >= type.ordinal();
124         }
125
126         public String toString() {
f98825 127             return name();
dfb889 128         }
JM 129     }
6adf56 130     
JM 131     /**
132      * Enumeration representing the types of authorization control for an
133      * access restricted resource.
134      */
135     public static enum AuthorizationControl {
136         AUTHENTICATED, NAMED;
137         
138         public static AuthorizationControl fromName(String name) {
139             for (AuthorizationControl type : values()) {
140                 if (type.name().equalsIgnoreCase(name)) {
141                     return type;
142                 }
143             }
144             return NAMED;
145         }
146         
147         public String toString() {
148             return name();
149         }
150     }
151
dfb889 152
831469 153     /**
JM 154      * Enumeration representing the types of federation tokens.
155      */
156     public static enum FederationToken {
157         ALL, USERS_AND_REPOSITORIES, REPOSITORIES;
158
159         public static FederationToken fromName(String name) {
160             for (FederationToken type : values()) {
161                 if (type.name().equalsIgnoreCase(name)) {
162                     return type;
163                 }
164             }
165             return REPOSITORIES;
166         }
167
168         public String toString() {
169             return name();
170         }
5fe7df 171     }
831469 172
JM 173     /**
174      * Enumeration representing the types of federation requests.
175      */
176     public static enum FederationRequest {
df162c 177         POKE, PROPOSAL, PULL_REPOSITORIES, PULL_USERS, PULL_TEAMS, PULL_SETTINGS, PULL_SCRIPTS, STATUS;
831469 178
JM 179         public static FederationRequest fromName(String name) {
180             for (FederationRequest type : values()) {
181                 if (type.name().equalsIgnoreCase(name)) {
182                     return type;
183                 }
184             }
185             return PULL_REPOSITORIES;
186         }
187
188         public String toString() {
189             return name();
190         }
191     }
192
193     /**
194      * Enumeration representing the statii of federation requests.
195      */
196     public static enum FederationPullStatus {
c729c5 197         PENDING, FAILED, SKIPPED, PULLED, MIRRORED, NOCHANGE, EXCLUDED;
831469 198
JM 199         public static FederationPullStatus fromName(String name) {
200             for (FederationPullStatus type : values()) {
201                 if (type.name().equalsIgnoreCase(name)) {
202                     return type;
203                 }
204             }
205             return PENDING;
206         }
207
208         @Override
209         public String toString() {
210             return name();
211         }
212     }
8f73a7 213
831469 214     /**
JM 215      * Enumeration representing the federation types.
216      */
217     public static enum FederationStrategy {
218         EXCLUDE, FEDERATE_THIS, FEDERATE_ORIGIN;
219
220         public static FederationStrategy fromName(String name) {
221             for (FederationStrategy type : values()) {
222                 if (type.name().equalsIgnoreCase(name)) {
223                     return type;
224                 }
225             }
226             return FEDERATE_THIS;
227         }
228
8f73a7 229         public boolean exceeds(FederationStrategy type) {
JM 230             return this.ordinal() > type.ordinal();
231         }
232
233         public boolean atLeast(FederationStrategy type) {
234             return this.ordinal() >= type.ordinal();
235         }
236
831469 237         @Override
JM 238         public String toString() {
239             return name();
240         }
241     }
242
4aafd4 243     /**
JM 244      * Enumeration representing the possible results of federation proposal
245      * requests.
246      */
247     public static enum FederationProposalResult {
248         ERROR, FEDERATION_DISABLED, MISSING_DATA, NO_PROPOSALS, NO_POKE, ACCEPTED;
249
250         @Override
251         public String toString() {
252             return name();
253         }
254     }
93f0b1 255
JM 256     /**
257      * Enumeration representing the possible remote procedure call requests from
258      * a client.
259      */
260     public static enum RpcRequest {
ec5a88 261         // Order is important here.  anything above LIST_SETTINGS requires
JM 262         // administrator privileges and web.allowRpcManagement.
4ebaf6 263         CLEAR_REPOSITORY_CACHE, GET_PROTOCOL, LIST_REPOSITORIES, LIST_BRANCHES, LIST_SETTINGS,
f08aab 264         CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY, 
JM 265         LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER, 
266         LIST_TEAMS, CREATE_TEAM, EDIT_TEAM, DELETE_TEAM,
267         LIST_REPOSITORY_MEMBERS, SET_REPOSITORY_MEMBERS, LIST_REPOSITORY_TEAMS, SET_REPOSITORY_TEAMS, 
822dfe 268         LIST_REPOSITORY_MEMBER_PERMISSIONS, SET_REPOSITORY_MEMBER_PERMISSIONS, LIST_REPOSITORY_TEAM_PERMISSIONS, SET_REPOSITORY_TEAM_PERMISSIONS, 
f08aab 269         LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS, LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS,
4ebaf6 270         EDIT_SETTINGS, LIST_STATUS;
31abc2 271
93f0b1 272         public static RpcRequest fromName(String name) {
JM 273             for (RpcRequest type : values()) {
274                 if (type.name().equalsIgnoreCase(name)) {
275                     return type;
276                 }
277             }
b2fde8 278             return null;
ec5a88 279         }        
31abc2 280
ca9d0f 281         public boolean exceeds(RpcRequest type) {
JM 282             return this.ordinal() > type.ordinal();
283         }
31abc2 284
93f0b1 285         @Override
JM 286         public String toString() {
287             return name();
288         }
289     }
33d8d8 290
JM 291     /**
292      * Enumeration of the search types.
293      */
294     public static enum SearchType {
295         AUTHOR, COMMITTER, COMMIT;
296     
297         public static SearchType forName(String name) {
298             for (SearchType type : values()) {
299                 if (type.name().equalsIgnoreCase(name)) {
300                     return type;
301                 }
302             }
303             return COMMIT;
304         }
305     
306         @Override
307         public String toString() {
308             return name().toLowerCase();
309         }
310     }
d896e6 311     
JM 312     /**
313      * The types of objects that can be indexed and queried.
314      */
315     public static enum SearchObjectType {
316         commit, blob, issue;
317
318         static SearchObjectType fromName(String name) {
319             for (SearchObjectType value : values()) {
320                 if (value.name().equals(name)) {
321                     return value;
322                 }
323             }
324             return null;
325         }
326     }
20714a 327     
JM 328     /**
329      * The access permissions available for a repository. 
330      */
331     public static enum AccessPermission {
7ba85b 332         NONE("N"), EXCLUDE("X"), VIEW("V"), CLONE("R"), PUSH("RW"), CREATE("RWC"), DELETE("RWD"), REWIND("RW+"), OWNER("RW+");
20714a 333         
2d48e2 334         public static final AccessPermission [] NEWPERMISSIONS = { EXCLUDE, VIEW, CLONE, PUSH, CREATE, DELETE, REWIND };
b0e164 335         
20714a 336         public static AccessPermission LEGACY = REWIND;
JM 337         
338         public final String code;
339         
340         private AccessPermission(String code) {
341             this.code = code;
342         }
343         
344         public boolean atLeast(AccessPermission perm) {
345             return ordinal() >= perm.ordinal();
346         }
347
348         public boolean exceeds(AccessPermission perm) {
349             return ordinal() > perm.ordinal();
350         }
351         
352         public String asRole(String repository) {
353             return code + ":" + repository;
354         }
355         
356         @Override
357         public String toString() {
358             return code;
359         }
360         
361         public static AccessPermission permissionFromRole(String role) {
362             String [] fields = role.split(":", 2);
363             if (fields.length == 1) {
364                 // legacy/undefined assume full permissions
365                 return AccessPermission.LEGACY;
366             } else {
367                 // code:repository
368                 return AccessPermission.fromCode(fields[0]);
369             }
370         }
371         
372         public static String repositoryFromRole(String role) {
373             String [] fields = role.split(":", 2);
374             if (fields.length == 1) {
375                 // legacy/undefined assume full permissions
376                 return role;
377             } else {
378                 // code:repository
379                 return fields[1];
380             }
381         }
382         
383         public static AccessPermission fromCode(String code) {
384             for (AccessPermission perm : values()) {
385                 if (perm.code.equalsIgnoreCase(code)) {
386                     return perm;
387                 }
388             }
389             return AccessPermission.NONE;
390         }
391     }
392     
822dfe 393     public static enum RegistrantType {
JM 394         REPOSITORY, USER, TEAM;
395     }
396     
092f0a 397     public static enum PermissionType {
7ba85b 398         MISSING, EXPLICIT, TEAM, REGEX, OWNER, ADMINISTRATOR;
092f0a 399     }
JM 400     
e92c6d 401     public static enum GCStatus {
JM 402         READY, COLLECTING;
403         
404         public boolean exceeds(GCStatus s) {
405             return ordinal() > s.ordinal();
406         }
407     }
8fef1f 408
JM 409     public static enum AuthenticationType {
37fa66 410         CREDENTIALS, COOKIE, CERTIFICATE, CONTAINER;
8fef1f 411         
JM 412         public boolean isStandard() {
413             return ordinal() <= COOKIE.ordinal();
414         }
415     }
4e3c15 416     
JM 417     public static enum AccountType {
418         LOCAL, LDAP, REDMINE;
419         
420         public boolean isLocal() {
421             return this == LOCAL;
422         }
423     }
8fef1f 424
20714a 425     @Documented
JM 426     @Retention(RetentionPolicy.RUNTIME)
427     public @interface Unused {
428     }
5fe7df 429 }