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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Daniel Dyer, Stephen Connolly
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.scm;
25
26 import hudson.model.Descriptor;
27 import hudson.model.Descriptor.FormException;
28 import hudson.util.DescriptorList;
29 import hudson.Extension;
30 import org.kohsuke.stapler.StaplerRequest;
31
32 import java.util.ArrayList;
33 import java.util.List;
34
35 import net.sf.json.JSONObject;
36
37 /**
38 * List of all installed {@link RepositoryBrowsers}.
39 *
40 * @author Kohsuke Kawaguchi
41 */
42 public class RepositoryBrowsers {
43 /**
44 * List of all installed {@link RepositoryBrowsers}.
45 *
46 * @deprecated as of 1.286.
47 * Use {@link RepositoryBrowser#all()} for read access and {@link Extension} for registration.
48 */
49 public static final List<Descriptor<RepositoryBrowser<?>>> LIST = new DescriptorList<RepositoryBrowser<?>>((Class)RepositoryBrowser.class);
50
51 /**
52 * Only returns those {@link RepositoryBrowser} descriptors that extend from the given type.
53 */
54 public static List<Descriptor<RepositoryBrowser<?>>> filter(Class<? extends RepositoryBrowser> t) {
55 List<Descriptor<RepositoryBrowser<?>>> r = new ArrayList<Descriptor<RepositoryBrowser<?>>>();
56 for (Descriptor<RepositoryBrowser<?>> d : RepositoryBrowser.all())
57 if(d.isSubTypeOf(t))
58 r.add(d);
59 return r;
60 }
61
62 /**
63 * Creates an instance of {@link RepositoryBrowser} from a form submission.
64 *
65 * @deprecated since 2008-06-19.
66 * Use {@link #createInstance(Class, StaplerRequest, JSONObject, String)}.
67 */
68 public static <T extends RepositoryBrowser>
69 T createInstance(Class<T> type, StaplerRequest req, String fieldName) throws FormException {
70 List<Descriptor<RepositoryBrowser<?>>> list = filter(type);
71 String value = req.getParameter(fieldName);
72 if(value==null || value.equals("auto"))
73 return null;
74
75 return type.cast(list.get(Integer.parseInt(value)).newInstance(req,null/*TODO*/));
76 }
77
78 /**
79 * Creates an instance of {@link RepositoryBrowser} from a form submission.
80 *
81 * @since 1.227
82 */
83 public static <T extends RepositoryBrowser>
84 T createInstance(Class<T> type, StaplerRequest req, JSONObject parent, String fieldName) throws FormException {
85 JSONObject o = (JSONObject)parent.get(fieldName);
86 if(o==null) return null;
87
88 return req.bindJSON(type,o);
89 }
90 }
91