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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Jorg Heymans
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.model;
25
26 import hudson.console.AnnotatedLargeText;
27 import org.kohsuke.stapler.framework.io.LargeText;
28 import org.kohsuke.stapler.StaplerRequest;
29 import org.kohsuke.stapler.StaplerResponse;
30
31 import javax.servlet.ServletException;
32 import javax.servlet.http.HttpServletResponse;
33 import java.lang.ref.WeakReference;
34 import java.io.IOException;
35
36 import hudson.security.Permission;
37 import hudson.security.ACL;
38
39 /**
40 * Partial {@link Action} implementation for those who kick some
41 * processing asynchronously (such as SCM tagging.)
42 *
43 * <p>
44 * The class offers the basic set of functionality to do it.
45 *
46 * @author Kohsuke Kawaguchi
47 * @since 1.191
48 * @see TaskThread
49 */
50 public abstract class TaskAction extends AbstractModelObject implements Action {
51 /**
52 * If non-null, that means either the activitiy is in progress
53 * asynchronously, or it failed unexpectedly and the thread is dead.
54 */
55 protected transient volatile TaskThread workerThread;
56
57 /**
58 * Hold the log of the tagging operation.
59 */
60 protected transient WeakReference<AnnotatedLargeText> log;
61
62 /**
63 * Gets the permission object that represents the permission to perform this task.
64 */
65 protected abstract Permission getPermission();
66
67 /**
68 * Gets the {@link ACL} against which the permissions are checked.
69 */
70 protected abstract ACL getACL();
71
72 /**
73 * @deprecated as of 1.350
74 * Use {@link #obtainLog()}, which returns the same object in a more type-safe signature.
75 */
76 public LargeText getLog() {
77 return obtainLog();
78 }
79
80 /**
81 * Obtains the log file.
82 *
83 * <p>
84 * The default implementation get this from {@link #workerThread},
85 * so when it's complete, the log could be gone any time.
86 *
87 * <p>
88 * Derived classes that persist the text should override this
89 * method so that it fetches the file from disk.
90 */
91 public AnnotatedLargeText obtainLog() {
92 WeakReference<AnnotatedLargeText> l = log;
93 if(l==null) return null;
94 return l.get();
95 }
96
97 public String getSearchUrl() {
98 return getUrlName();
99 }
100
101 public TaskThread getWorkerThread() {
102 return workerThread;
103 }
104
105 /**
106 * Handles incremental log output.
107 */
108 public void doProgressiveLog( StaplerRequest req, StaplerResponse rsp) throws IOException {
109 AnnotatedLargeText text = obtainLog();
110 if(text!=null) {
111 text.doProgressText(req,rsp);
112 return;
113 }
114 rsp.setStatus(HttpServletResponse.SC_OK);
115 }
116
117 /**
118 * Handles incremental log output.
119 */
120 public void doProgressiveHtml( StaplerRequest req, StaplerResponse rsp) throws IOException {
121 AnnotatedLargeText text = obtainLog();
122 if(text!=null) {
123 text.doProgressiveHtml(req,rsp);
124 return;
125 }
126 rsp.setStatus(HttpServletResponse.SC_OK);
127 }
128
129 /**
130 * Clears the error status.
131 */
132 public synchronized void doClearError(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
133 getACL().checkPermission(getPermission());
134
135 if(workerThread!=null && !workerThread.isRunning())
136 workerThread = null;
137 rsp.sendRedirect(".");
138 }
139 }
140
141