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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
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.ExtensionPoint;
27 import hudson.DescriptorExtensionList;
28 import hudson.Extension;
29 import hudson.model.AbstractDescribableImpl;
30 import hudson.model.Descriptor;
31 import jenkins.model.Jenkins;
32
33 import java.io.IOException;
34 import java.io.Serializable;
35 import java.net.URL;
36 import java.net.MalformedURLException;
37
38 import org.kohsuke.stapler.export.ExportedBean;
39
40 /**
41 * Connects Hudson to repository browsers like ViewCVS or FishEye,
42 * so that Hudson can generate links to them.
43 *
44 * <p>
45 * {@link RepositoryBrowser} instance is normally created as
46 * a result of job configuration, and stores immutable
47 * configuration information (such as the URL of the FishEye site).
48 *
49 * <p>
50 * {@link RepositoryBrowser} is persisted with {@link SCM}.
51 *
52 * <p>
53 * To have Hudson recognize {@link RepositoryBrowser}, put {@link Extension} on your {@link Descriptor}.
54 *
55 * @author Kohsuke Kawaguchi
56 * @since 1.89
57 * @see RepositoryBrowsers
58 */
59 @ExportedBean
60 public abstract class RepositoryBrowser<E extends ChangeLogSet.Entry> extends AbstractDescribableImpl<RepositoryBrowser<?>> implements ExtensionPoint, Serializable {
61 /**
62 * Determines the link to the given change set.
63 *
64 * @return
65 * null if this repository browser doesn't have any meaningful
66 * URL for a change set (for example, ViewCVS doesn't have
67 * any page for a change set, whereas FishEye does.)
68 */
69 public abstract URL getChangeSetLink(E changeSet) throws IOException;
70
71 /**
72 * If the given string starts with '/', return a string that removes it.
73 */
74 protected static String trimHeadSlash(String s) {
75 if(s.startsWith("/")) return s.substring(1);
76 return s;
77 }
78
79 /**
80 * Normalize the URL so that it ends with '/'.
81 * <p>
82 * An attention is paid to preserve the query parameters in URL if any.
83 */
84 protected static URL normalizeToEndWithSlash(URL url) {
85 if(url.getPath().endsWith("/"))
86 return url;
87
88 // normalize
89 String q = url.getQuery();
90 q = q!=null?('?'+q):"";
91 try {
92 return new URL(url,url.getPath()+'/'+q);
93 } catch (MalformedURLException e) {
94 // impossible
95 throw new Error(e);
96 }
97 }
98
99 /**
100 * Returns all the registered {@link RepositoryBrowser} descriptors.
101 */
102 public static DescriptorExtensionList<RepositoryBrowser<?>,Descriptor<RepositoryBrowser<?>>> all() {
103 return (DescriptorExtensionList) Jenkins.getInstance().getDescriptorList(RepositoryBrowser.class);
104 }
105
106 private static final long serialVersionUID = 1L;
107 }
108