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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2011, CloudBees, 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 jenkins.model;
25
26 import hudson.console.ModelHyperlinkNote;
27 import hudson.model.Executor;
28 import hudson.model.Result;
29 import hudson.model.TaskListener;
30 import hudson.model.User;
31 import org.kohsuke.stapler.export.Exported;
32 import org.kohsuke.stapler.export.ExportedBean;
33
34 /**
35 * Records why an {@linkplain Executor#interrupt() executor is interrupted}.
36 *
37 * <h2>View</h2>
38 * <tt>summary.groovy/.jelly</tt> should do one-line HTML rendering to be used while rendering
39 * "build history" widget, next to the blocking build. By default it simply renders
40 * {@link #getShortDescription()} text.
41 *
42 * <h2>Value equality semantics</h2>
43 * <p>
44 * Two {@link CauseOfInterruption}s that are {@linkplain Object#equals(Object) equal} will get
45 * merged together.
46 *
47 * @author Kohsuke Kawaguchi
48 * @since 1.425
49 * @see Executor#interrupt(Result, CauseOfInterruption...)
50 * @see InterruptedBuildAction
51 */
52 @ExportedBean
53 public abstract class CauseOfInterruption {
54 /**
55 * Human readable description of why the build is cancelled.
56 */
57 @Exported
58 public abstract String getShortDescription();
59
60 /**
61 * Report a line to the listener about this cause.
62 */
63 public void print(TaskListener listener) {
64 listener.getLogger().println(getShortDescription());
65 }
66
67 /**
68 * Indicates that the build was interrupted from UI.
69 */
70 public static final class UserInterruption extends CauseOfInterruption {
71 private final String user;
72
73 public UserInterruption(User user) {
74 this.user = user.getId();
75 }
76
77 public UserInterruption(String userId) {
78 this.user = userId;
79 }
80
81 public User getUser() {
82 return User.get(user);
83 }
84
85 public String getShortDescription() {
86 return Messages.CauseOfInterruption_ShortDescription(user);
87 }
88
89 @Override
90 public void print(TaskListener listener) {
91 listener.getLogger().println(
92 Messages.CauseOfInterruption_ShortDescription(ModelHyperlinkNote.encodeTo(getUser())));
93 }
94
95 @Override
96 public boolean equals(Object o) {
97 if (o == null || getClass() != o.getClass()) return false;
98 UserInterruption that = (UserInterruption) o;
99 return user.equals(that.user);
100 }
101
102 @Override
103 public int hashCode() {
104 return user.hashCode();
105 }
106 }
107 }
108