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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2010, Sun Microsystems, Inc.
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.console;
25
26 import hudson.DescriptorExtensionList;
27 import hudson.ExtensionPoint;
28 import hudson.model.Descriptor;
29 import jenkins.model.Jenkins;
30 import hudson.util.TimeUnit2;
31 import org.kohsuke.stapler.StaplerRequest;
32 import org.kohsuke.stapler.StaplerResponse;
33 import org.kohsuke.stapler.WebMethod;
34
35 import javax.servlet.ServletException;
36 import java.io.IOException;
37 import java.net.URL;
38
39 /**
40 * Descriptor for {@link ConsoleNote}.
41 *
42 * @author Kohsuke Kawaguchi
43 * @since 1.349
44 */
45 public abstract class ConsoleAnnotationDescriptor extends Descriptor<ConsoleNote<?>> implements ExtensionPoint {
46 public ConsoleAnnotationDescriptor(Class<? extends ConsoleNote<?>> clazz) {
47 super(clazz);
48 }
49
50 public ConsoleAnnotationDescriptor() {
51 }
52
53 /**
54 * {@inheritDoc}
55 *
56 * Users use this name to enable/disable annotations.
57 */
58 public abstract String getDisplayName();
59
60 /**
61 * Returns true if this descriptor has a JavaScript to be inserted on applicable console page.
62 */
63 public boolean hasScript() {
64 return hasResource("/script.js") !=null;
65 }
66
67 /**
68 * Returns true if this descriptor has a stylesheet to be inserted on applicable console page.
69 */
70 public boolean hasStylesheet() {
71 return hasResource("/style.css") !=null;
72 }
73
74 private URL hasResource(String name) {
75 return clazz.getClassLoader().getResource(clazz.getName().replace('.','/').replace('$','/')+ name);
76 }
77
78 @WebMethod(name="script.js")
79 public void doScriptJs(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
80 rsp.serveFile(req, hasResource("/script.js"), TimeUnit2.DAYS.toMillis(1));
81 }
82
83 @WebMethod(name="style.css")
84 public void doStyleCss(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
85 rsp.serveFile(req, hasResource("/style.css"), TimeUnit2.DAYS.toMillis(1));
86 }
87
88 /**
89 * Returns all the registered {@link ConsoleAnnotationDescriptor} descriptors.
90 */
91 public static DescriptorExtensionList<ConsoleNote<?>,ConsoleAnnotationDescriptor> all() {
92 return (DescriptorExtensionList) Jenkins.getInstance().getDescriptorList(ConsoleNote.class);
93 }
94 }
95