File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\jenkins\model\DefaultUserCanonicalIdResolver.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2012, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt,
5 * Tom Huybrechts, Vincent Latombe
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25 package jenkins.model;
26
27 import hudson.Extension;
28 import hudson.Functions;
29 import hudson.model.Descriptor;
30 import hudson.model.User;
31
32 import java.util.Map;
33
34 /**
35 * Default User.CanonicalIdResolver to escape unsupported characters and generate user ID.
36 * Compared to other implementations, this resolver will always return an ID
37 *
38 * @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
39 */
40 @Extension
41 public class DefaultUserCanonicalIdResolver extends User.CanonicalIdResolver {
42
43 @Override
44 public String resolveCanonicalId(String idOrFullName, Map<String, ?> context) {
45 String id = idOrFullName.replace('\\', '_').replace('/', '_').replace('<','_')
46 .replace('>', '_'); // 4 replace() still faster than regex
47 if (Functions.isWindows()) id = id.replace(':','_');
48 return id;
49 }
50
51 @Override
52 public int getPriority() {
53 return Integer.MIN_VALUE;
54 }
55
56 @Override
57 public Descriptor<User.CanonicalIdResolver> getDescriptor() {
58 return DESCRIPTOR;
59 }
60
61 public static final Descriptor<User.CanonicalIdResolver> DESCRIPTOR = new Descriptor<User.CanonicalIdResolver>() {
62 public String getDisplayName() {
63 return "compute default user ID";
64 }
65 };
66
67 }
68