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