UserNameResolver.java 3.2 KB
Newer Older
K
kohsuke 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * The MIT License
 * 
 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
24 25
package hudson.tasks;

26 27 28
import hudson.Extension;
import hudson.ExtensionList;
import hudson.ExtensionListView;
29
import hudson.ExtensionPoint;
30
import jenkins.model.Jenkins;
31 32 33 34 35 36 37 38 39
import hudson.model.User;

import java.util.List;

/**
 * Finds full name off the user when none is specified.
 *
 * <p>
 * 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 44 45
 * &#64;Extension
 * class MyserNameResolver extends UserNameResolver {
 *   ...
46 47 48 49 50 51 52 53
 * }
 * </pre>
 *
 * @author Kohsuke Kawaguchi
 * @since 1.192
 */
public abstract class UserNameResolver implements ExtensionPoint {

54
    /**
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
     * Finds full name of the given user.
     *
     * <p>
     * This method is called when a {@link User} without explicitly name is used.
     *
     * <p>
     * When multiple resolvers are installed, they are consulted in order and
     * the search will be over when a name is found by someoene.
     *
     * <p>
     * Since {@link UserNameResolver} is singleton, this method can be invoked concurrently
     * from multiple threads.
     *
     * @return
     *      null if the inference failed.
     */
    public abstract String findNameFor(User u);
    
    public static String resolve(User u) {
74
        for (UserNameResolver r : all()) {
75 76 77 78
            String name = r.findNameFor(u);
            if(name!=null) return name;
        }

K
kohsuke 已提交
79
        return null;
80 81
    }

82 83 84 85
    /**
     * Returns all the registered {@link UserNameResolver} descriptors.
     */
    public static ExtensionList<UserNameResolver> all() {
86
        return ExtensionList.lookup(UserNameResolver.class);
87 88
    }

89 90
    /**
     * All registered {@link UserNameResolver} implementations.
91
     *
M
mindless 已提交
92
     * @deprecated since 2009-02-24.
93
     *      Use {@link #all()} for read access, and use {@link Extension} for registration.
94
     */
95
    @Deprecated
96
    public static final List<UserNameResolver> LIST = ExtensionListView.createList(UserNameResolver.class);
97
}