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

1 package hudson.model;
2
3 import hudson.ExtensionList;
4 import hudson.ExtensionPoint;
5 import hudson.scm.SCMDescriptor;
6 import jenkins.ExtensionFilter;
7 import jenkins.model.Jenkins;
8
9 import java.util.ArrayList;
10 import java.util.List;
11
12 /**
13 * Hides {@link Descriptor}s from users.
14 *
15 * @author Kohsuke Kawaguchi
16 * @since 1.393
17 * @see ExtensionFilter
18 */
19 public abstract class DescriptorVisibilityFilter implements ExtensionPoint {
20
21 /**
22 * Decides if the given descriptor should be visible to the user.
23 *
24 * @param context
25 * The object that indicates where the visibility of a descriptor is evaluated.
26 * For example, if Hudson is deciding whether a {@link FreeStyleProject} should gets a
27 * {@link SCMDescriptor}, the context object will be the {@link FreeStyleProject}.
28 * The caller can pass in null if there's no context.
29 * @param descriptor
30 * Descriptor whose visibility is evaluated. Never null.
31 *
32 * @return
33 * true to allow the descriptor to be visible. false to hide it.
34 * If any of the installed {@link DescriptorVisibilityFilter} returns false,
35 * the descriptor is not shown.
36 */
37 public abstract boolean filter(Object context, Descriptor descriptor);
38
39 public static ExtensionList<DescriptorVisibilityFilter> all() {
40 return Jenkins.getInstance().getExtensionList(DescriptorVisibilityFilter.class);
41 }
42
43 public static <T extends Descriptor> List<T> apply(Object context, Iterable<T> source) {
44 ExtensionList<DescriptorVisibilityFilter> filters = all();
45 List<T> r = new ArrayList<T>();
46
47 OUTER:
48 for (T d : source) {
49 for (DescriptorVisibilityFilter f : filters) {
50 if (!f.filter(context,d))
51 continue OUTER; // veto-ed. not shown
52 }
53 r.add(d);
54 }
55 return r;
56 }
57 }
58