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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.tasks;
25
26 import hudson.Extension;
27 import hudson.ExtensionList;
28 import hudson.ExtensionListView;
29 import hudson.ExtensionPoint;
30 import jenkins.model.Jenkins;
31 import hudson.model.User;
32
33 import java.util.List;
34
35 /**
36 * Finds full name off the user when none is specified.
37 *
38 * <p>
39 * This is an extension point of Hudson. Plugins tha contribute new implementation
40 * of this class should use {@link Extension} to register the instance into Hudson, like this:
41 *
42 * <pre>
43 * &#64;Extension
44 * class MyserNameResolver extends UserNameResolver {
45 * ...
46 * }
47 * </pre>
48 *
49 * @author Kohsuke Kawaguchi
50 * @since 1.192
51 */
52 public abstract class UserNameResolver implements ExtensionPoint {
53
54 /**
55 * Finds full name of the given user.
56 *
57 * <p>
58 * This method is called when a {@link User} without explicitly name is used.
59 *
60 * <p>
61 * When multiple resolvers are installed, they are consulted in order and
62 * the search will be over when a name is found by someoene.
63 *
64 * <p>
65 * Since {@link UserNameResolver} is singleton, this method can be invoked concurrently
66 * from multiple threads.
67 *
68 * @return
69 * null if the inference failed.
70 */
71 public abstract String findNameFor(User u);
72
73 public static String resolve(User u) {
74 for (UserNameResolver r : all()) {
75 String name = r.findNameFor(u);
76 if(name!=null) return name;
77 }
78
79 return null;
80 }
81
82 /**
83 * Returns all the registered {@link UserNameResolver} descriptors.
84 */
85 public static ExtensionList<UserNameResolver> all() {
86 return Jenkins.getInstance().getExtensionList(UserNameResolver.class);
87 }
88
89 /**
90 * All registered {@link UserNameResolver} implementations.
91 *
92 * @deprecated since 2009-02-24.
93 * Use {@link #all()} for read access, and use {@link Extension} for registration.
94 */
95 public static final List<UserNameResolver> LIST = ExtensionListView.createList(UserNameResolver.class);
96 }
97