File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\maven-plugin\src\main\java\hudson\maven\MavenBuildProxy.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.FilePath;
27 import hudson.model.Result;
28 import hudson.remoting.Callable;
29 import hudson.remoting.DelegatingCallable;
30
31 import java.io.IOException;
32 import java.io.Serializable;
33 import java.util.Calendar;
34 import java.util.List;
35
36 /**
37 * Remoting proxy interface for {@link MavenReporter}s to talk to {@link MavenBuild}
38 * during the build.
39 *
40 * That is, this represents {@link MavenBuild} objects in the master's JVM to code
41 * running inside Maven JVM.
42 *
43 * @author Kohsuke Kawaguchi
44 */
45 public interface MavenBuildProxy {
46 /**
47 * Executes the given {@link BuildCallable} on the master, where one
48 * has access to {@link MavenBuild} and all the other Hudson objects.
49 *
50 * <p>
51 * The parameter, return value, and exception are all transfered by using
52 * Java serialization.
53 *
54 * @return
55 * the value that {@link BuildCallable} returned.
56 * @throws T
57 * if {@link BuildCallable} throws this exception.
58 * @throws IOException
59 * if the remoting failed.
60 * @throws InterruptedException
61 * if the remote execution is aborted.
62 * @see #executeAsync(BuildCallable)
63 */
64 <V,T extends Throwable> V execute( BuildCallable<V,T> program ) throws T, IOException, InterruptedException;
65
66 /**
67 * Executes the given {@link BuildCallable} asynchronously on the master.
68 * <p>
69 * This method works like {@link #execute(BuildCallable)} except that
70 * the method returns immediately and doesn't wait for the completion of the program.
71 * <p>
72 * The completions of asynchronous executions are accounted for before
73 * the build completes. If they throw exceptions, they'll be reported
74 * and the build will be marked as a failure.
75 */
76 void executeAsync( BuildCallable<?,?> program ) throws IOException;
77
78 /**
79 * Root directory of the build.
80 *
81 * @see MavenBuild#getRootDir()
82 */
83 FilePath getRootDir();
84
85 /**
86 * Root directory of the parent of this build.
87 */
88 FilePath getProjectRootDir();
89
90 /**
91 * Root directory of the owner {@link MavenModuleSet}
92 */
93 FilePath getModuleSetRootDir();
94
95 /**
96 * @see MavenBuild#getArtifactsDir()
97 */
98 FilePath getArtifactsDir();
99
100 /**
101 * @see MavenBuild#setResult(Result)
102 */
103 void setResult(Result result);
104
105 /**
106 * @see MavenBuild#getTimestamp()
107 */
108 Calendar getTimestamp();
109
110 /**
111 * # of milliseconds elapsed since {@link #getTimestamp()}.
112 *
113 * Where the clock skew is involved between the master and the Maven JVM, comparing
114 * current time on Maven JVM with {@link #getTimestamp()} could be problematic,
115 * but this value is more robust.
116 */
117 long getMilliSecsSinceBuildStart();
118
119 /**
120 * If true, artifacts will not actually be archived to master. Calls {@link MavenModuleSet#isArchivingDisabled()}.
121 */
122 boolean isArchivingDisabled();
123
124 /**
125 * Nominates that the reporter will contribute a project action
126 * for this build by using {@link MavenReporter#getProjectActions(MavenModule)}.
127 *
128 * <p>
129 * The specified {@link MavenReporter} object will be transfered to the master
130 * and will become a persisted part of the {@link MavenBuild}.
131 */
132 void registerAsProjectAction(MavenReporter reporter);
133
134 /**
135 * Nominates that the reporter will contribute a project action
136 * for this build by using {@link MavenReporter#getProjectActions(MavenModule)}.
137 *
138 * <p>
139 * The specified {@link MavenReporter} object will be transferred to the master
140 * and will become a persisted part of the {@link MavenBuild}.
141 *
142 * @since 1.372
143 */
144 void registerAsProjectAction(MavenProjectActionBuilder builder);
145
146 /**
147 * Nominates that the reporter will contribute a project action
148 * for this build by using {@link MavenReporter#getAggregatedProjectAction(MavenModuleSet)}.
149 *
150 * <p>
151 * The specified {@link MavenReporter} object will be transfered to the master
152 * and will become a persisted part of the {@link MavenModuleSetBuild}.
153 */
154 void registerAsAggregatedProjectAction(MavenReporter reporter);
155
156 /**
157 * Called at the end of the build to record what mojos are executed.
158 */
159 void setExecutedMojos(List<ExecutedMojo> executedMojos);
160
161 interface BuildCallable<V,T extends Throwable> extends Serializable {
162 /**
163 * Performs computation and returns the result,
164 * or throws some exception.
165 *
166 * @throws InterruptedException
167 * if the processing is interrupted in the middle. Exception will be
168 * propagated to the caller.
169 * @throws IOException
170 * if the program simply wishes to propage the exception, it may throw
171 * {@link IOException}.
172 */
173 V call(MavenBuild build) throws T, IOException, InterruptedException;
174 }
175
176 MavenBuildInformation getMavenBuildInformation();
177
178 /**
179 * Filter for {@link MavenBuildProxy}.
180 *
181 * Meant to be useful as the base class for other filters.
182 */
183 /*package*/ abstract class Filter<CORE extends MavenBuildProxy> implements MavenBuildProxy, Serializable {
184 protected final CORE core;
185
186 protected Filter(CORE core) {
187 this.core = core;
188 }
189
190 public <V, T extends Throwable> V execute(BuildCallable<V, T> program) throws T, IOException, InterruptedException {
191 return core.execute(program);
192 }
193
194 public void executeAsync(BuildCallable<?, ?> program) throws IOException {
195 core.executeAsync(program);
196 }
197
198 public FilePath getRootDir() {
199 return core.getRootDir();
200 }
201
202 public FilePath getProjectRootDir() {
203 return core.getProjectRootDir();
204 }
205
206 public FilePath getModuleSetRootDir() {
207 return core.getModuleSetRootDir();
208 }
209
210 public FilePath getArtifactsDir() {
211 return core.getArtifactsDir();
212 }
213
214 public void setResult(Result result) {
215 core.setResult(result);
216 }
217
218 public Calendar getTimestamp() {
219 return core.getTimestamp();
220 }
221
222 public long getMilliSecsSinceBuildStart() {
223 return core.getMilliSecsSinceBuildStart();
224 }
225
226 public boolean isArchivingDisabled() {
227 return core.isArchivingDisabled();
228 }
229
230 public void registerAsProjectAction(MavenReporter reporter) {
231 core.registerAsProjectAction(reporter);
232 }
233
234 public void registerAsProjectAction(MavenProjectActionBuilder builder) {
235 core.registerAsProjectAction(builder);
236 }
237
238 public void registerAsAggregatedProjectAction(MavenReporter reporter) {
239 core.registerAsAggregatedProjectAction(reporter);
240 }
241
242 public void setExecutedMojos(List<ExecutedMojo> executedMojos) {
243 core.setExecutedMojos(executedMojos);
244 }
245
246 public MavenBuildInformation getMavenBuildInformation() {
247 return core.getMavenBuildInformation();
248 }
249
250 private static final long serialVersionUID = 1L;
251
252 /**
253 * {@link Callable} for invoking {@link BuildCallable} asynchronously.
254 */
255 protected static final class AsyncInvoker implements DelegatingCallable<Object,Throwable> {
256 private final MavenBuildProxy proxy;
257 private final BuildCallable<?,?> program;
258
259 public AsyncInvoker(MavenBuildProxy proxy, BuildCallable<?,?> program) {
260 this.proxy = proxy;
261 this.program = program;
262 }
263
264 public ClassLoader getClassLoader() {
265 return program.getClass().getClassLoader();
266 }
267
268 public Object call() throws Throwable {
269 // by the time this method is invoked on the master, proxy points to a real object
270 proxy.execute(program);
271 return null; // ignore the result, as there's no point in sending it back
272 }
273
274 private static final long serialVersionUID = 1L;
275 }
276 }
277 }
278