James Moger
2012-12-31 160ee43394f6c645465b2b1dd80c460766d122bc
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.
160ee4 37     public static final String VERSION = "1.2.0";
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.
160ee4 41     public static final String VERSION_DATE = "2012-12-31";
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     
831469 91     public static String getGitBlitVersion() {
JM 92         return NAME + " v" + VERSION;
93     }
94
88598b 95     /**
831469 96      * Enumeration representing the four access restriction levels.
88598b 97      */
dfb889 98     public static enum AccessRestrictionType {
JM 99         NONE, PUSH, CLONE, VIEW;
100
d0d438 101         public static AccessRestrictionType fromName(String name) {
dfb889 102             for (AccessRestrictionType type : values()) {
d0d438 103                 if (type.name().equalsIgnoreCase(name)) {
dfb889 104                     return type;
JM 105                 }
106             }
107             return NONE;
108         }
f98825 109
JM 110         public boolean exceeds(AccessRestrictionType type) {
111             return this.ordinal() > type.ordinal();
112         }
113
dfb889 114         public boolean atLeast(AccessRestrictionType type) {
JM 115             return this.ordinal() >= type.ordinal();
116         }
117
118         public String toString() {
f98825 119             return name();
dfb889 120         }
JM 121     }
6adf56 122     
JM 123     /**
124      * Enumeration representing the types of authorization control for an
125      * access restricted resource.
126      */
127     public static enum AuthorizationControl {
128         AUTHENTICATED, NAMED;
129         
130         public static AuthorizationControl fromName(String name) {
131             for (AuthorizationControl type : values()) {
132                 if (type.name().equalsIgnoreCase(name)) {
133                     return type;
134                 }
135             }
136             return NAMED;
137         }
138         
139         public String toString() {
140             return name();
141         }
142     }
143
dfb889 144
831469 145     /**
JM 146      * Enumeration representing the types of federation tokens.
147      */
148     public static enum FederationToken {
149         ALL, USERS_AND_REPOSITORIES, REPOSITORIES;
150
151         public static FederationToken fromName(String name) {
152             for (FederationToken type : values()) {
153                 if (type.name().equalsIgnoreCase(name)) {
154                     return type;
155                 }
156             }
157             return REPOSITORIES;
158         }
159
160         public String toString() {
161             return name();
162         }
5fe7df 163     }
831469 164
JM 165     /**
166      * Enumeration representing the types of federation requests.
167      */
168     public static enum FederationRequest {
df162c 169         POKE, PROPOSAL, PULL_REPOSITORIES, PULL_USERS, PULL_TEAMS, PULL_SETTINGS, PULL_SCRIPTS, STATUS;
831469 170
JM 171         public static FederationRequest fromName(String name) {
172             for (FederationRequest type : values()) {
173                 if (type.name().equalsIgnoreCase(name)) {
174                     return type;
175                 }
176             }
177             return PULL_REPOSITORIES;
178         }
179
180         public String toString() {
181             return name();
182         }
183     }
184
185     /**
186      * Enumeration representing the statii of federation requests.
187      */
188     public static enum FederationPullStatus {
c729c5 189         PENDING, FAILED, SKIPPED, PULLED, MIRRORED, NOCHANGE, EXCLUDED;
831469 190
JM 191         public static FederationPullStatus fromName(String name) {
192             for (FederationPullStatus type : values()) {
193                 if (type.name().equalsIgnoreCase(name)) {
194                     return type;
195                 }
196             }
197             return PENDING;
198         }
199
200         @Override
201         public String toString() {
202             return name();
203         }
204     }
8f73a7 205
831469 206     /**
JM 207      * Enumeration representing the federation types.
208      */
209     public static enum FederationStrategy {
210         EXCLUDE, FEDERATE_THIS, FEDERATE_ORIGIN;
211
212         public static FederationStrategy fromName(String name) {
213             for (FederationStrategy type : values()) {
214                 if (type.name().equalsIgnoreCase(name)) {
215                     return type;
216                 }
217             }
218             return FEDERATE_THIS;
219         }
220
8f73a7 221         public boolean exceeds(FederationStrategy type) {
JM 222             return this.ordinal() > type.ordinal();
223         }
224
225         public boolean atLeast(FederationStrategy type) {
226             return this.ordinal() >= type.ordinal();
227         }
228
831469 229         @Override
JM 230         public String toString() {
231             return name();
232         }
233     }
234
4aafd4 235     /**
JM 236      * Enumeration representing the possible results of federation proposal
237      * requests.
238      */
239     public static enum FederationProposalResult {
240         ERROR, FEDERATION_DISABLED, MISSING_DATA, NO_PROPOSALS, NO_POKE, ACCEPTED;
241
242         @Override
243         public String toString() {
244             return name();
245         }
246     }
93f0b1 247
JM 248     /**
249      * Enumeration representing the possible remote procedure call requests from
250      * a client.
251      */
252     public static enum RpcRequest {
ec5a88 253         // Order is important here.  anything above LIST_SETTINGS requires
JM 254         // administrator privileges and web.allowRpcManagement.
4ebaf6 255         CLEAR_REPOSITORY_CACHE, GET_PROTOCOL, LIST_REPOSITORIES, LIST_BRANCHES, LIST_SETTINGS,
f08aab 256         CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY, 
JM 257         LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER, 
258         LIST_TEAMS, CREATE_TEAM, EDIT_TEAM, DELETE_TEAM,
259         LIST_REPOSITORY_MEMBERS, SET_REPOSITORY_MEMBERS, LIST_REPOSITORY_TEAMS, SET_REPOSITORY_TEAMS, 
822dfe 260         LIST_REPOSITORY_MEMBER_PERMISSIONS, SET_REPOSITORY_MEMBER_PERMISSIONS, LIST_REPOSITORY_TEAM_PERMISSIONS, SET_REPOSITORY_TEAM_PERMISSIONS, 
f08aab 261         LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS, LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS,
4ebaf6 262         EDIT_SETTINGS, LIST_STATUS;
31abc2 263
93f0b1 264         public static RpcRequest fromName(String name) {
JM 265             for (RpcRequest type : values()) {
266                 if (type.name().equalsIgnoreCase(name)) {
267                     return type;
268                 }
269             }
b2fde8 270             return null;
ec5a88 271         }        
31abc2 272
ca9d0f 273         public boolean exceeds(RpcRequest type) {
JM 274             return this.ordinal() > type.ordinal();
275         }
31abc2 276
93f0b1 277         @Override
JM 278         public String toString() {
279             return name();
280         }
281     }
33d8d8 282
JM 283     /**
284      * Enumeration of the search types.
285      */
286     public static enum SearchType {
287         AUTHOR, COMMITTER, COMMIT;
288     
289         public static SearchType forName(String name) {
290             for (SearchType type : values()) {
291                 if (type.name().equalsIgnoreCase(name)) {
292                     return type;
293                 }
294             }
295             return COMMIT;
296         }
297     
298         @Override
299         public String toString() {
300             return name().toLowerCase();
301         }
302     }
d896e6 303     
JM 304     /**
305      * The types of objects that can be indexed and queried.
306      */
307     public static enum SearchObjectType {
308         commit, blob, issue;
309
310         static SearchObjectType fromName(String name) {
311             for (SearchObjectType value : values()) {
312                 if (value.name().equals(name)) {
313                     return value;
314                 }
315             }
316             return null;
317         }
318     }
20714a 319     
JM 320     /**
321      * The access permissions available for a repository. 
322      */
323     public static enum AccessPermission {
7ba85b 324         NONE("N"), EXCLUDE("X"), VIEW("V"), CLONE("R"), PUSH("RW"), CREATE("RWC"), DELETE("RWD"), REWIND("RW+"), OWNER("RW+");
20714a 325         
2d48e2 326         public static final AccessPermission [] NEWPERMISSIONS = { EXCLUDE, VIEW, CLONE, PUSH, CREATE, DELETE, REWIND };
b0e164 327         
20714a 328         public static AccessPermission LEGACY = REWIND;
JM 329         
330         public final String code;
331         
332         private AccessPermission(String code) {
333             this.code = code;
334         }
335         
336         public boolean atLeast(AccessPermission perm) {
337             return ordinal() >= perm.ordinal();
338         }
339
340         public boolean exceeds(AccessPermission perm) {
341             return ordinal() > perm.ordinal();
342         }
343         
344         public String asRole(String repository) {
345             return code + ":" + repository;
346         }
347         
348         @Override
349         public String toString() {
350             return code;
351         }
352         
353         public static AccessPermission permissionFromRole(String role) {
354             String [] fields = role.split(":", 2);
355             if (fields.length == 1) {
356                 // legacy/undefined assume full permissions
357                 return AccessPermission.LEGACY;
358             } else {
359                 // code:repository
360                 return AccessPermission.fromCode(fields[0]);
361             }
362         }
363         
364         public static String repositoryFromRole(String role) {
365             String [] fields = role.split(":", 2);
366             if (fields.length == 1) {
367                 // legacy/undefined assume full permissions
368                 return role;
369             } else {
370                 // code:repository
371                 return fields[1];
372             }
373         }
374         
375         public static AccessPermission fromCode(String code) {
376             for (AccessPermission perm : values()) {
377                 if (perm.code.equalsIgnoreCase(code)) {
378                     return perm;
379                 }
380             }
381             return AccessPermission.NONE;
382         }
383     }
384     
822dfe 385     public static enum RegistrantType {
JM 386         REPOSITORY, USER, TEAM;
387     }
388     
092f0a 389     public static enum PermissionType {
7ba85b 390         MISSING, EXPLICIT, TEAM, REGEX, OWNER, ADMINISTRATOR;
092f0a 391     }
JM 392     
e92c6d 393     public static enum GCStatus {
JM 394         READY, COLLECTING;
395         
396         public boolean exceeds(GCStatus s) {
397             return ordinal() > s.ordinal();
398         }
399     }
8fef1f 400
JM 401     public static enum AuthenticationType {
37fa66 402         CREDENTIALS, COOKIE, CERTIFICATE, CONTAINER;
8fef1f 403         
JM 404         public boolean isStandard() {
405             return ordinal() <= COOKIE.ordinal();
406         }
407     }
408
20714a 409     @Documented
JM 410     @Retention(RetentionPolicy.RUNTIME)
411     public @interface Unused {
412     }
5fe7df 413 }