File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\tasks\Publisher.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.tasks;
25
26 import hudson.DescriptorExtensionList;
27 import hudson.Extension;
28 import hudson.ExtensionComponent;
29 import hudson.model.Action;
30 import hudson.model.Build;
31 import hudson.model.BuildListener;
32 import hudson.model.Describable;
33 import hudson.model.Project;
34 import hudson.model.Descriptor;
35 import jenkins.model.Jenkins;
36
37 import java.util.List;
38 import java.util.ArrayList;
39 import java.util.Collections;
40 import java.util.Comparator;
41
42 /**
43 * {@link BuildStep}s that run after the build is completed.
44 *
45 * <p>
46 * To register a custom {@link Publisher} from a plugin,
47 * put {@link Extension} on your descriptor implementation.
48 *
49 * <p>
50 * Starting 1.178, publishers are exposed to all kinds of different
51 * project type, not just the freestyle project type (in particular,
52 * the native maven2 job type.) This is convenient default for
53 * {@link Publisher}s in particular initially, but we encourage advanced
54 * plugins to consider writing MavenReporter, as it offers the
55 * potential of reducing the amount of configuration needed to run the plugin.
56 *
57 * For those plugins that don't want {@link Publisher} to show up in
58 * different job type, use {@link BuildStepDescriptor} for the base type
59 * of your descriptor to control which job type it supports.
60 *
61 * @author Kohsuke Kawaguchi
62 */
63 public abstract class Publisher extends BuildStepCompatibilityLayer implements BuildStep, Describable<Publisher> {
64 /**
65 * @deprecated
66 * Don't extend from {@link Publisher} directly. Instead, choose {@link Recorder} or {@link Notifier}
67 * as your base class.
68 */
69 @Deprecated
70 protected Publisher() {
71 }
72
73 //
74 // these two methods need to remain to keep binary compatibility with plugins built with Hudson < 1.150
75 //
76 /**
77 * Default implementation that does nothing.
78 * @deprecated since 1.150
79 */
80 @Deprecated @Override
81 public boolean prebuild(Build build, BuildListener listener) {
82 return true;
83 }
84
85 /**
86 * Default implementation that does nothing.
87 * @deprecated since 1.150
88 */
89 @Deprecated @Override
90 public Action getProjectAction(Project project) {
91 return null;
92 }
93
94 /**
95 * Return true if this {@link Publisher} needs to run after the build result is
96 * fully finalized.
97 *
98 * <p>
99 * The execution of normal {@link Publisher}s are considered within a part
100 * of the build. This allows publishers to mark the build as a failure, or
101 * to include their execution time in the total build time.
102 *
103 * <p>
104 * So normally, that is the preferrable behavior, but in a few cases
105 * this is problematic. One of such cases is when a publisher needs to
106 * trigger other builds, which in turn need to see this build as a
107 * completed build. Those plugins that need to do this can return true
108 * from this method, so that the {@link #perform(AbstractBuild, Launcher, BuildListener)}
109 * method is called after the build is marked as completed.
110 *
111 * <p>
112 * When {@link Publisher} behaves this way, note that they can no longer
113 * change the build status anymore.
114 *
115 * @author Kohsuke Kawaguchi
116 * @since 1.153
117 */
118 public boolean needsToRunAfterFinalized() {
119 return false;
120 }
121
122 public Descriptor<Publisher> getDescriptor() {
123 return Jenkins.getInstance().getDescriptorOrDie(getClass());
124 }
125
126 /**
127 * {@link Publisher} has a special sort semantics that requires a subtype.
128 *
129 * @see DescriptorExtensionList#createDescriptorList(hudson.model.Hudson, Class
130 */
131 public static final class DescriptorExtensionListImpl extends DescriptorExtensionList<Publisher,Descriptor<Publisher>>
132 implements Comparator<ExtensionComponent<Descriptor<Publisher>>> {
133 public DescriptorExtensionListImpl(Jenkins hudson) {
134 super(hudson,Publisher.class);
135 }
136
137 @Override
138 protected List<ExtensionComponent<Descriptor<Publisher>>> sort(List<ExtensionComponent<Descriptor<Publisher>>> r) {
139 List<ExtensionComponent<Descriptor<Publisher>>> copy = new ArrayList<ExtensionComponent<Descriptor<Publisher>>>(r);
140 Collections.sort(copy,this);
141 return copy;
142 }
143
144 public int compare(ExtensionComponent<Descriptor<Publisher>> lhs, ExtensionComponent<Descriptor<Publisher>> rhs) {
145 int r = classify(lhs.getInstance())-classify(rhs.getInstance());
146 if (r!=0) return r;
147 return lhs.compareTo(rhs);
148 }
149
150 /**
151 * If recorder, return 0, if unknown return 1, if notifier returns 2.
152 * This is used as a sort key.
153 */
154 private int classify(Descriptor<Publisher> d) {
155 if(d.isSubTypeOf(Recorder.class)) return 0;
156 if(d.isSubTypeOf(Notifier.class)) return 2;
157
158 // for compatibility, if the descriptor is manually registered in a specific way, detect that.
159 Class<? extends Publisher> kind = PublisherList.KIND.get(d);
160 if(kind==Recorder.class) return 0;
161 if(kind==Notifier.class) return 2;
162
163 return 1;
164 }
165 }
166
167 /**
168 * Returns all the registered {@link Publisher} descriptors.
169 */
170 // for backward compatibility, the signature is not BuildStepDescriptor
171 public static DescriptorExtensionList<Publisher,Descriptor<Publisher>> all() {
172 return Jenkins.getInstance().<Publisher,Descriptor<Publisher>>getDescriptorList(Publisher.class);
173 }
174 }
175