1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.ci.comm;
17
18 import java.util.Properties;
19
20 import de.smartics.ci.comm.command.CommandException;
21 import de.smartics.ci.comm.command.CommandResult;
22 import de.smartics.ci.comm.command.LoginCommandException;
23 import de.smartics.ci.comm.hudson.command.HudsonCheckStatusJobCommand;
24 import de.smartics.ci.comm.hudson.command.HudsonCreateJobCommand;
25 import de.smartics.ci.comm.hudson.command.HudsonDeleteJobCommand;
26 import de.smartics.ci.comm.hudson.command.HudsonDisableJobCommand;
27 import de.smartics.ci.comm.hudson.command.HudsonEnableJobCommand;
28 import de.smartics.ci.comm.hudson.command.HudsonGenericJobCommand;
29 import de.smartics.ci.comm.hudson.command.HudsonLoginCommand;
30 import de.smartics.ci.comm.hudson.command.HudsonUpdateJobCommand;
31
32
33
34
35 public final class CiController
36 {
37
38
39
40
41
42
43
44
45
46 private Credentials loginCredentials;
47
48
49
50
51 private ProxyInformation proxy;
52
53
54
55
56 private HudsonLoginCommand loginCommand;
57
58
59
60
61 private HudsonDeleteJobCommand deleteJobCommand;
62
63
64
65
66 private HudsonCreateJobCommand createJobCommand;
67
68
69
70
71 private HudsonUpdateJobCommand updateJobCommand;
72
73
74
75
76 private HudsonEnableJobCommand enableJobCommand;
77
78
79
80
81 private HudsonDisableJobCommand disableJobCommand;
82
83
84
85
86 private HudsonCheckStatusJobCommand checkStatusJobCommand;
87
88
89
90
91 private HudsonGenericJobCommand genericJobCommand;
92
93
94
95
96 private final CiSystem target;
97
98
99
100
101 private LogLevel logLevel;
102
103
104
105
106
107
108
109
110
111
112 public CiController(final CiSystem system)
113 {
114 this.target = system;
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 public void setLogLevel(final LogLevel logLevel)
131 {
132 this.logLevel = logLevel;
133 }
134
135
136
137
138
139
140 public void setLoginCredentials(final Credentials loginCredentials)
141 {
142 this.loginCredentials = loginCredentials;
143 }
144
145
146
147
148
149
150
151 public void setProxyInformation(final ProxyInformation proxy)
152 {
153 this.proxy = proxy;
154 }
155
156
157
158
159
160
161 public void setLoginCommand(final HudsonLoginCommand loginCommand)
162 {
163 this.loginCommand = loginCommand;
164 loginCommand.setLogLevel(logLevel);
165 }
166
167
168
169
170
171
172 public void setDeleteJobCommand(final HudsonDeleteJobCommand deleteJobCommand)
173 {
174 this.deleteJobCommand = deleteJobCommand;
175 deleteJobCommand.setLogLevel(logLevel);
176 }
177
178
179
180
181
182
183 public void setCreateJobCommand(final HudsonCreateJobCommand createJobCommand)
184 {
185 this.createJobCommand = createJobCommand;
186 createJobCommand.setLogLevel(logLevel);
187 }
188
189
190
191
192
193
194
195
196 public void setUpdateJobCommand(final HudsonUpdateJobCommand updateJobCommand)
197 {
198 this.updateJobCommand = updateJobCommand;
199 updateJobCommand.setLogLevel(logLevel);
200 }
201
202
203
204
205
206
207 public void setEnableJobCommand(final HudsonEnableJobCommand enableJobCommand)
208 {
209 this.enableJobCommand = enableJobCommand;
210 enableJobCommand.setLogLevel(logLevel);
211 }
212
213
214
215
216
217
218 public void setDisableJobCommand(
219 final HudsonDisableJobCommand disableJobCommand)
220 {
221 this.disableJobCommand = disableJobCommand;
222 disableJobCommand.setLogLevel(logLevel);
223 }
224
225
226
227
228
229
230 public void setStatusJobCommand(
231 final HudsonCheckStatusJobCommand statusJobCommand)
232 {
233 this.checkStatusJobCommand = statusJobCommand;
234 checkStatusJobCommand.setLogLevel(logLevel);
235 }
236
237
238
239
240
241
242 public void setGenericJobCommand(
243 final HudsonGenericJobCommand genericJobCommand)
244 {
245 this.genericJobCommand = genericJobCommand;
246 genericJobCommand.setLogLevel(logLevel);
247 }
248
249
250
251
252
253
254
255
256 public void login() throws LoginCommandException
257 {
258 loginCommand.setLoginCredentials(loginCredentials);
259 loginCommand.setProxyInformation(proxy);
260 loginCommand.execute(target);
261 }
262
263
264
265
266
267
268
269
270 public void createJob(final String jobName, final String configString)
271 throws CommandException
272 {
273 createJobCommand.setJobName(jobName);
274 createJobCommand.setConfigString(configString);
275 createJobCommand.execute(target);
276 }
277
278
279
280
281
282
283
284
285 public void updateJob(final String jobName, final String configString)
286 throws CommandException
287 {
288 updateJobCommand.setJobName(jobName);
289 updateJobCommand.setConfigString(configString);
290 updateJobCommand.execute(target);
291 }
292
293
294
295
296
297
298
299 public void disableJob(final String jobName) throws CommandException
300 {
301 disableJobCommand.setJobName(jobName);
302 disableJobCommand.execute(target);
303 }
304
305
306
307
308
309
310
311 public void enableJob(final String jobName) throws CommandException
312 {
313 enableJobCommand.setJobName(jobName);
314 enableJobCommand.execute(target);
315 }
316
317
318
319
320
321
322
323 public void deleteJob(final String jobName) throws CommandException
324 {
325 deleteJobCommand.setJobName(jobName);
326 deleteJobCommand.execute(target);
327 }
328
329
330
331
332
333
334
335
336
337
338
339 public CommandResult<?> checkStatusJob(final String jobName,
340 final String xmlQueryString, final Properties properties)
341 throws CommandException
342 {
343 checkStatusJobCommand.setJobName(jobName);
344 checkStatusJobCommand.setXmlQueryString(xmlQueryString);
345 checkStatusJobCommand.setKeyValuePairs(properties);
346 checkStatusJobCommand.execute(target);
347 return checkStatusJobCommand.getResult();
348 }
349
350
351
352
353
354
355
356
357
358
359
360
361
362 public CommandResult<?> executeGenericJobCommand(final String jobName,
363 final String apiUrl, final String xmlQueryString, final String regexp,
364 final Properties properties) throws CommandException
365 {
366 genericJobCommand.setJobName(jobName);
367 genericJobCommand.setCiXmlJobApiUrl(apiUrl);
368 genericJobCommand.setXmlQueryString(xmlQueryString);
369 genericJobCommand.setResponseCheckingRegexp(regexp);
370 genericJobCommand.setKeyValuePairs(properties);
371 genericJobCommand.execute(target);
372 return genericJobCommand.getResult();
373 }
374
375
376
377 }