File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\maven-plugin\src\main\java\hudson\maven\MavenReporterDescriptor.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.maven;
25
26 import hudson.maven.reporters.MavenArtifactArchiver;
27 import hudson.model.Descriptor;
28 import hudson.model.Describable;
29 import jenkins.model.Jenkins;
30 import org.apache.commons.jelly.JellyException;
31 import org.kohsuke.stapler.MetaClass;
32 import org.kohsuke.stapler.StaplerRequest;
33 import org.kohsuke.stapler.WebApp;
34 import org.kohsuke.stapler.jelly.JellyClassTearOff;
35
36 import java.util.Collection;
37
38 /**
39 * {@link Descriptor} for {@link MavenReporter}.
40 *
41 * @author Kohsuke Kawaguchi
42 */
43 public abstract class MavenReporterDescriptor extends Descriptor<MavenReporter> {
44 protected MavenReporterDescriptor(Class<? extends MavenReporter> clazz) {
45 super(clazz);
46 }
47
48 /**
49 * Infers the type of the corresponding {@link Describable} from the outer class.
50 * This version works when you follow the common convention, where a descriptor
51 * is written as the static nested class of the describable class.
52 *
53 * @since 1.278
54 */
55 protected MavenReporterDescriptor() {
56 }
57
58 /**
59 * Returns an instance used for automatic {@link MavenReporter} activation.
60 *
61 * <p>
62 * Some {@link MavenReporter}s, such as {@link MavenArtifactArchiver},
63 * can work just with the configuration in POM and don't need any additional
64 * Hudson configuration. They also don't need any explicit enabling/disabling
65 * as they can activate themselves by listening to the callback from the build
66 * (for example javadoc archiver can do the work in response to the execution
67 * of the javadoc target.)
68 *
69 * <p>
70 * Those {@link MavenReporter}s should return a valid instance
71 * from this method. Such instance will then participate into the build
72 * and receive event callbacks.
73 */
74 public MavenReporter newAutoInstance(MavenModule module) {
75 return null;
76 }
77
78 /**
79 * If {@link #hasConfigScreen() the reporter has no configuration screen},
80 * this method can safely return null, which is the default implementation.
81 */
82 @Deprecated
83 public MavenReporter newInstance(StaplerRequest req) throws FormException {
84 return null;
85 }
86
87 /**
88 * Returns true if this descriptor has <tt>config.jelly</tt>.
89 */
90 public final boolean hasConfigScreen() {
91 MetaClass c = WebApp.getCurrent().getMetaClass(getClass());
92 try {
93 JellyClassTearOff tearOff = c.loadTearOff(JellyClassTearOff.class);
94 return tearOff.findScript(getConfigPage())!=null;
95 } catch(JellyException e) {
96 return false;
97 }
98 }
99
100 /**
101 * Lists all the currently registered instances of {@link MavenReporterDescriptor}.
102 */
103 public static Collection<MavenReporterDescriptor> all() {
104 // use getDescriptorList and not getExtensionList to pick up legacy instances
105 return Jenkins.getInstance().<MavenReporter,MavenReporterDescriptor>getDescriptorList(MavenReporter.class);
106 }
107 }
108