/
ClearCaseSCM.java
621 lines (554 loc) · 27.3 KB
/
ClearCaseSCM.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/**
* The MIT License
*
* Copyright (c) 2007-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt,
* Henrik Lynggaard, Peter Liljenberg, Andrew Bayer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.plugins.clearcase;
import static hudson.Util.fixEmpty;
import static hudson.Util.fixEmptyAndTrim;
import hudson.Launcher;
import hudson.Util;
import hudson.model.ModelObject;
import hudson.model.TaskListener;
import hudson.model.AbstractBuild;
import hudson.model.Hudson;
import hudson.plugins.clearcase.action.BaseDynamicCheckoutAction;
import hudson.plugins.clearcase.action.BaseSnapshotCheckoutAction;
import hudson.plugins.clearcase.action.CheckoutAction;
import hudson.plugins.clearcase.action.SaveChangeLogAction;
import hudson.plugins.clearcase.base.BaseHistoryAction;
import hudson.plugins.clearcase.base.BaseSaveChangeLogAction;
import hudson.plugins.clearcase.base.ClearCaseSCMRevisionState;
import hudson.plugins.clearcase.history.Filter;
import hudson.plugins.clearcase.history.FilterChain;
import hudson.plugins.clearcase.history.HistoryAction;
import hudson.plugins.clearcase.history.LabelFilter;
import hudson.plugins.clearcase.util.BuildUtils;
import hudson.plugins.clearcase.util.BuildVariableResolver;
import hudson.plugins.clearcase.util.PathUtil;
import hudson.plugins.clearcase.viewstorage.ViewStorage;
import hudson.scm.ChangeLogParser;
import hudson.scm.SCMRevisionState;
import hudson.scm.SCM;
import hudson.util.ArgumentListBuilder;
import hudson.util.FormValidation;
import hudson.util.VariableResolver;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.servlet.ServletException;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.framework.io.ByteBuffer;
/**
* Base ClearCase SCM. This SCM is for base ClearCase repositories.
*
* @author Erik Ramfelt
*/
public class ClearCaseSCM extends AbstractClearCaseScm {
/**
* ClearCase SCM descriptor
*
* @author Erik Ramfelt
*/
public static class ClearCaseScmDescriptor extends AbstractClearCaseScmDescriptor<ClearCaseSCM> implements ModelObject {
private static final int DEFAULT_CHANGE_LOG_MERGE_TIME_WINDOW = 5;
private static final int DEFAULT_ENDVIEW_DELAY = 0;
private int changeLogMergeTimeWindow = DEFAULT_CHANGE_LOG_MERGE_TIME_WINDOW;
private String defaultUnixDynStorageDir;
private String defaultViewName;
private String defaultViewPath;
private ViewStorage defaultViewStorage;
private String defaultWinDynStorageDir;
/**
* This is a delay applied after calling the endview command as it may return before the process is really done.
* see https://groups.google.com/d/msg/jenkinsci-users/cWNvmxBf1WI/Z_WHm_ay4VEJ
*/
private int endViewDelay;
public ClearCaseScmDescriptor() {
super(ClearCaseSCM.class, null);
load();
}
@Override
public boolean configure(StaplerRequest req, JSONObject json) {
req.bindJSON(this, json);
defaultViewName = fixEmpty(req.getParameter("clearcase.defaultViewName").trim());
defaultViewPath = fixEmpty(req.getParameter("clearcase.defaultViewPath").trim());
defaultWinDynStorageDir = fixEmpty(req.getParameter("clearcase.defaultWinDynStorageDir").trim());
defaultUnixDynStorageDir = fixEmpty(req.getParameter("clearcase.defaultUnixDynStorageDir").trim());
defaultViewStorage = req.bindJSON(ViewStorage.class, json.getJSONObject("defaultViewStorage"));
String mergeTimeWindow = fixEmpty(req.getParameter("clearcase.logmergetimewindow"));
if (mergeTimeWindow != null) {
try {
changeLogMergeTimeWindow = NumberFormat.getIntegerInstance().parse(mergeTimeWindow).intValue();
} catch (ParseException e) {
changeLogMergeTimeWindow = DEFAULT_CHANGE_LOG_MERGE_TIME_WINDOW;
}
} else {
changeLogMergeTimeWindow = DEFAULT_CHANGE_LOG_MERGE_TIME_WINDOW;
}
save();
return true;
}
/**
* Checks if cleartool executable exists.
*/
public FormValidation doCleartoolExeCheck(@QueryParameter final String value) throws IOException, ServletException {
return FormValidation.validateExecutable(value);
}
public FormValidation doConfigSpecCheck(@QueryParameter final String value) throws IOException, ServletException {
String v = fixEmpty(value);
if (v == null) {
return FormValidation.error("Config spec is mandatory");
}
/*
* for (String cSpecLine : v.split("[\\r\\n]+")) { if (cSpecLine.startsWith("load ")) { return
* FormValidation.error("Config spec can not contain load rules"); } }
*/
// all tests passed so far
return FormValidation.ok();
}
/**
* Validates the excludedRegions Regex
*/
public FormValidation doExcludedRegionsCheck(@QueryParameter final String value) throws IOException, ServletException {
String v = fixEmptyAndTrim(value);
if (v != null) {
String[] regions = v.split("[\\r\\n]+");
for (String region : regions) {
try {
Pattern.compile(region);
} catch (PatternSyntaxException e) {
return FormValidation.error("Invalid regular expression. " + e.getMessage());
}
}
}
return FormValidation.ok();
}
public void doListViews(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, InterruptedException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Hudson.getInstance().createLauncher(TaskListener.NULL).launch().cmds(getCleartoolExe(), "lsview", "-short").stdout(baos).join();
rsp.setContentType("text/plain");
rsp.getOutputStream().println("ClearCase Views found:\n");
baos.writeTo(rsp.getOutputStream());
}
/**
* Raises an error if the parameter value isnt set.
*
* @throws IOException
* @throws ServletException
*/
public FormValidation doMandatoryCheck(@QueryParameter final String value, @QueryParameter final String errorText) throws IOException, ServletException {
String v = fixEmpty(value);
if (v == null) {
return FormValidation.error(errorText);
}
// all tests passed so far
return FormValidation.ok();
}
/**
* Displays "cleartool -version" for trouble shooting.
*/
public void doVersion(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, InterruptedException {
ByteBuffer baos = new ByteBuffer();
try {
Hudson.getInstance().createLauncher(TaskListener.NULL).launch().cmds(getCleartoolExe(), "-version").stdout(baos).join();
rsp.setContentType("text/plain");
baos.writeTo(rsp.getOutputStream());
} catch (IOException e) {
req.setAttribute("error", e);
rsp.forward(this, "versionCheckError", req);
}
}
public String getDefaultUnixDynStorageDir() {
return defaultUnixDynStorageDir;
}
public String getDefaultViewName() {
String instanceId = Hudson.getInstance().getDisplayName();
return StringUtils.defaultString(defaultViewName, instanceId + "_${USER_NAME}_${NODE_NAME}_${JOB_NAME}${DASH_WORKSPACE_NUMBER}");
}
public String getDefaultViewPath() {
return StringUtils.defaultString(defaultViewPath, "view");
}
public ViewStorage getDefaultViewStorage() {
if (defaultViewStorage == null) {
return ViewStorage.createDefault();
}
return defaultViewStorage;
}
public String getDefaultWinDynStorageDir() {
if (defaultWinDynStorageDir == null) {
return "\\\\${HOST}" + DEFAULT_VALUE_WIN_DYN_STORAGE_DIR;
}
return defaultWinDynStorageDir;
}
/*
* public FormValidation doConfigSpecFileNameCheck(@QueryParameter final String value) throws IOException, ServletException { String v =
* fixEmpty(value); if (v == null) { return FormValidation.error("Config spec file is mandatory"); } // all tests passed so far return
* FormValidation.ok(); }
*
* public FormValidation doLoadRulesCheck(@QueryParameter final String value) throws IOException, ServletException { String v = fixEmpty(value); if (v
* == null) { return FormValidation.error("Load rules are mandatory"); } // all tests passed so far return FormValidation.ok(); }
*/
@Override
public String getDisplayName() {
return "Base ClearCase";
}
public int getLogMergeTimeWindow() {
return changeLogMergeTimeWindow;
}
public void setEndViewDelay(int endViewDelay) {
this.endViewDelay = endViewDelay;
}
public int getEndViewDelay() {
return endViewDelay;
}
@Override
public SCM newInstance(StaplerRequest req, JSONObject formData) throws FormException {
AbstractClearCaseScm scm = new ClearCaseSCM(req.getParameter("cc.branch"), req.getParameter("cc.label"),
req.getParameter("cc.getConfigSpecFromFile") != null, req.getParameter("cc.configSpecFileName"),
req.getParameter("cc.refreshConfigSpec") != null, req.getParameter("cc.refreshConfigSpecCommand"), req.getParameter("cc.configspec"),
req.getParameter("cc.viewname"), req.getParameter("cc.useupdate") != null, req.getParameter("cc.extractLoadRules") != null,
req.getParameter("cc.loadrules"), req.getParameter("cc.useOtherLoadRulesForPolling") != null, req.getParameter("cc.loadRulesForPolling"),
req.getParameter("cc.usedynamicview") != null, req.getParameter("cc.viewdrive"), req.getParameter("cc.mkviewoptionalparam"),
req.getParameter("cc.filterOutDestroySubBranchEvent") != null, req.getParameter("cc.doNotUpdateConfigSpec") != null,
req.getParameter("cc.rmviewonrename") != null, req.getParameter("cc.excludedRegions"),
fixEmpty(req.getParameter("cc.multiSitePollBuffer")), req.getParameter("cc.useTimeRule") != null,
req.getParameter("cc.createDynView") != null, req.getParameter("cc.viewpath"), ChangeSetLevel.fromString(req.getParameter("cc.changeset")),
extractViewStorage(req, formData));
return scm;
}
}
public static final String CLEARCASE_CSFILENAME_ENVSTR = "CLEARCASE_CSFILENAME";
private static final String DEFAULT_VALUE_WIN_DYN_STORAGE_DIR = "\\views\\dynamic";
private final String branch;
private String configSpec;
private String configSpecFileName;
private boolean doNotUpdateConfigSpec;
private boolean extractConfigSpec;
private final String label;
private boolean refreshConfigSpec;
private String refreshConfigSpecCommand;
private boolean useTimeRule;
@DataBoundConstructor
public ClearCaseSCM(String branch, String label, boolean extractConfigSpec, String configSpecFileName, boolean refreshConfigSpec,
String refreshConfigSpecCommand, String configSpec, String viewTag, boolean useupdate, boolean extractLoadRules, String loadRules,
boolean useOtherLoadRulesForPolling, String loadRulesForPolling, boolean usedynamicview, String viewdrive, String mkviewoptionalparam,
boolean filterOutDestroySubBranchEvent, boolean doNotUpdateConfigSpec, boolean rmviewonrename, String excludedRegions, String multiSitePollBuffer,
boolean useTimeRule, boolean createDynView, String viewPath, ChangeSetLevel changeset, ViewStorage viewStorage) {
super(viewTag, mkviewoptionalparam, filterOutDestroySubBranchEvent, (!usedynamicview) && useupdate, rmviewonrename, excludedRegions, usedynamicview,
viewdrive, extractLoadRules, loadRules, useOtherLoadRulesForPolling, loadRulesForPolling, multiSitePollBuffer, createDynView, false, false,
viewPath, changeset, viewStorage);
this.branch = branch;
this.label = label;
this.extractConfigSpec = extractConfigSpec;
this.configSpecFileName = configSpecFileName;
this.refreshConfigSpec = refreshConfigSpec;
this.refreshConfigSpecCommand = refreshConfigSpecCommand;
this.configSpec = configSpec;
this.doNotUpdateConfigSpec = doNotUpdateConfigSpec;
this.useTimeRule = useTimeRule;
}
public ClearCaseSCM(String branch, String label, String configspec, String viewTag, boolean useupdate, String loadRules, boolean usedynamicview,
String viewdrive, String mkviewoptionalparam, boolean filterOutDestroySubBranchEvent, boolean doNotUpdateConfigSpec, boolean rmviewonrename) {
this(branch, label, false, null, false, null, configspec, viewTag, useupdate, false, loadRules, false, null, usedynamicview, viewdrive,
mkviewoptionalparam, filterOutDestroySubBranchEvent, doNotUpdateConfigSpec, rmviewonrename, null, null, false, false, "viewpath",
ChangeSetLevel.defaultLevel(), null);
}
/**
* Adds the env variable for the ClearCase SCMs.
* <ul>
* <li>CLEARCASE_CSFILENAME - The name of the clearcase config spec file.</li>
* </ul>
*/
@Override
public void buildEnvVars(AbstractBuild<?, ?> build, Map<String, String> env) {
super.buildEnvVars(build, env);
if (isUseDynamicView()) {
if (getViewDrive() != null) {
env.put(CLEARCASE_VIEWPATH_ENVSTR, getViewDrive() + PathUtil.fileSepForOS(BuildUtils.isRunningOnUnix(build)) + getNormalizedViewName());
} else {
env.remove(CLEARCASE_VIEWPATH_ENVSTR);
}
}
if (isExtractConfigSpec()) {
@SuppressWarnings("unchecked")
VariableResolver.Union<String> variableResolver = new VariableResolver.Union<String>(new BuildVariableResolver(build, true),
new VariableResolver.ByMap<String>(env));
env.put(CLEARCASE_CSFILENAME_ENVSTR, getConfigSpecFileName(variableResolver));
}
}
@Override
public Filter configureFilters(VariableResolver<String> variableResolver, AbstractBuild build, Launcher launcher) throws IOException, InterruptedException {
Filter filter = super.configureFilters(variableResolver, build, launcher);
if (StringUtils.isNotBlank(label)) {
ArrayList<Filter> filters = new ArrayList<Filter>();
filters.add(filter);
filters.add(new LabelFilter(getLabelNames(variableResolver)));
filter = new FilterChain(filters);
}
return filter;
}
@Override
public ChangeLogParser createChangeLogParser() {
return new ClearCaseChangeLogParser();
}
public String getBranch() {
return branch;
}
/**
* Split the branch names into a string array.
*
* @param branchString
* string containing none or several branches
* @return a string array (never empty)
*/
@Override
public String[] getBranchNames(VariableResolver<String> variableResolver) {
// split by whitespace, except "\ "
String[] branchArray = Util.replaceMacro(branch, variableResolver).split("(?<!\\\\)[ \\r\\n]+");
// now replace "\ " to " ".
for (int i = 0; i < branchArray.length; i++) {
branchArray[i] = branchArray[i].replaceAll("\\\\ ", " ");
}
return branchArray;
}
public String getConfigSpec() {
return configSpec;
}
public String getConfigSpec(VariableResolver<String> variableResolver) {
if (variableResolver != null) {
return Util.replaceMacro(configSpec, variableResolver);
}
return configSpec;
}
public String getConfigSpecFileName() {
return configSpecFileName;
}
public String getConfigSpecFileName(VariableResolver<String> variableResolver) {
if (variableResolver != null) {
return Util.replaceMacro(configSpecFileName, variableResolver);
}
return configSpecFileName;
}
@Override
public ClearCaseScmDescriptor getDescriptor() {
return PluginImpl.BASE_DESCRIPTOR;
}
public String getLabel() {
return label;
}
public String[] getLabelNames(VariableResolver<String> variableResolver) {
return Util.replaceMacro(label, variableResolver).split("\\s+");
}
public String getRefreshConfigSpecCommand() {
return refreshConfigSpecCommand;
}
public String getRefreshConfigSpecCommand(VariableResolver<String> variableResolver) {
if (variableResolver != null) {
return Util.replaceMacro(refreshConfigSpecCommand, variableResolver);
}
return refreshConfigSpecCommand;
}
public boolean isDoNotUpdateConfigSpec() {
return doNotUpdateConfigSpec;
}
public boolean isExtractConfigSpec() {
return extractConfigSpec;
}
public boolean isRefreshConfigSpec() {
return refreshConfigSpec;
}
public boolean isUseTimeRule() {
return useTimeRule;
}
public String setConfigSpec(String scpec) {
return configSpec = scpec;
}
@Override
protected CheckoutAction createCheckOutAction(VariableResolver<String> variableResolver, ClearToolLauncher launcher, AbstractBuild<?, ?> build)
throws IOException, InterruptedException {
CheckoutAction action;
String effectiveConfigSpec = Util.replaceMacro(configSpec, variableResolver);
ViewStorage decoratedViewStorage = getViewStorageOrDefault().decorate(variableResolver);
if (isUseDynamicView()) {
action = new BaseDynamicCheckoutAction(createClearTool(variableResolver, launcher), effectiveConfigSpec, doNotUpdateConfigSpec, useTimeRule,
isCreateDynView(), decoratedViewStorage, build);
} else {
action = new BaseSnapshotCheckoutAction(createClearTool(variableResolver, launcher), new ConfigSpec(effectiveConfigSpec, launcher.getLauncher()
.isUnix()), getViewPaths(variableResolver, build, launcher.getLauncher(), false), isUseUpdate(), getViewPath(variableResolver),
decoratedViewStorage, build);
}
return action;
}
@Override
protected HistoryAction createHistoryAction(VariableResolver<String> variableResolver, ClearToolLauncher launcher, AbstractBuild<?, ?> build,
SCMRevisionState baseline, boolean useRecurse) throws IOException, InterruptedException {
ClearTool ct = createClearTool(variableResolver, launcher);
BaseHistoryAction action = new BaseHistoryAction(ct, isUseDynamicView(), configureFilters(variableResolver, build, launcher.getLauncher()),
getChangeset(), useRecurse, getDescriptor().getLogMergeTimeWindow());
setExtendedViewPath(variableResolver, ct, action);
return action;
}
@Override
protected SaveChangeLogAction createSaveChangeLogAction(ClearToolLauncher launcher) {
return new BaseSaveChangeLogAction();
}
@Override
protected boolean hasNewConfigSpec(VariableResolver<String> variableResolver, ClearToolLauncher cclauncher) throws IOException, InterruptedException {
if (useTimeRule) {
// Disable this feature if time rule is enabled, since the config spec changes all the time
return false;
}
boolean ret = false;
Launcher launcher = cclauncher.getLauncher();
// get user configured config spec
ConfigSpec actualConfigSpec = new ConfigSpec(getConfigSpec(variableResolver), launcher.isUnix());
// get real view config spec
ClearTool cleartool = createClearTool(variableResolver, cclauncher);
PrintStream logger = launcher.getListener().getLogger();
logger.println("*************************** get view CSPEC ***********************");
ConfigSpec viewConfigSpec = new ConfigSpec(cleartool.catcs(getViewName(variableResolver)), launcher.isUnix());
logger.println("******************************************************************");
// first check configured (expected or default) config spec with CATCS
boolean configuredCSEqualsCatcs = actualConfigSpec.stripLoadRules().equals(viewConfigSpec.stripLoadRules());
if (!configuredCSEqualsCatcs) {
logger.println("[WARNING] CSPEC configured != catcs (view)");
ret = true;
}
if (isExtractConfigSpec()) {
// refresh if needed
doRefreshConfigSpec(variableResolver, launcher);
// get config spec from file
String cs = getConfigSpecFromFile(getConfigSpecFileName(variableResolver), launcher);
if (cs != null) {
// get new config spec
ConfigSpec fileConfigSpec = new ConfigSpec(Util.replaceMacro(cs, variableResolver), launcher.isUnix());
ret = !viewConfigSpec.stripLoadRules().equals(fileConfigSpec.stripLoadRules());
logger.println("[INFO] CSPEC changed = " + ret);
if (ret) {
String viewCS = viewConfigSpec.stripLoadRules().getRaw();
String fileCS = fileConfigSpec.stripLoadRules().getRaw();
logger.println("*** CATCS CSPEC ***");
logger.println(viewCS);
logger.println("******************************************************************");
logger.println("*** FILE CSPEC ***");
logger.println(fileCS);
logger.println("******************************************************************");
}
} else {
logger.println("ERROR: extracted CSPEC is empty!");
ret = false;
}
}
return ret;
}
@Override
protected void inspectConfigAction(VariableResolver<String> variableResolver, ClearToolLauncher cclauncher) throws IOException, InterruptedException {
Launcher launcher = cclauncher.getLauncher();
doRefreshConfigSpec(variableResolver, launcher);
doExtractConfigSpec(variableResolver, launcher);
doExtractLoadRules(variableResolver, launcher);
// verify
PrintStream logger = launcher.getListener().getLogger();
if (StringUtils.isEmpty(configSpec)) {
logger.println("[WARNING] config spec is empty!");
}
if (StringUtils.isEmpty(getLoadRules())) {
logger.println("[WARNING] load rules are empty!");
}
}
@Override
protected boolean isFirstBuild(SCMRevisionState baseline) {
return baseline == null || !(baseline instanceof ClearCaseSCMRevisionState);
}
@Override
protected SCMRevisionState createRevisionState(AbstractBuild<?, ?> build, Launcher launcher, TaskListener taskListener, Date date)
throws IOException, InterruptedException {
ClearCaseSCMRevisionState revisionState = new ClearCaseSCMRevisionState(date);
VariableResolver<String> variableResolver = new BuildVariableResolver(build);
revisionState.setLoadRules(getViewPaths(variableResolver, build, launcher, true));
return revisionState;
}
private boolean doExtractConfigSpec(VariableResolver<String> variableResolver, Launcher launcher) {
boolean ret = true;
// get config spec from file
if (isExtractConfigSpec()) {
String cs = null;
cs = getConfigSpecFromFile(getConfigSpecFileName(variableResolver), launcher);
if (cs != null) {
configSpec = cs;
} else {
launcher.getListener().getLogger().println("Fall back to config spec field...");
ret = false;
}
}
return ret;
}
private boolean doExtractLoadRules(VariableResolver<String> variableResolver, Launcher launcher) {
boolean ret = true;
// extract rules from config spec
if (isExtractLoadRules()) {
ConfigSpec cfgSpec = new ConfigSpec(configSpec, launcher.isUnix());
setLoadRules(cfgSpec.getLoadRulesString());
}
return ret;
}
@SuppressWarnings("deprecation")
private boolean doRefreshConfigSpec(VariableResolver<String> variableResolver, Launcher launcher) {
int cmdResult = 1;
// execute refresh command
if (isRefreshConfigSpec()) {
ArgumentListBuilder cmd = new ArgumentListBuilder();
cmd.addTokenized(getRefreshConfigSpecCommand(variableResolver));
PrintStream logger = launcher.getListener().getLogger();
try {
cmdResult = launcher.launch(cmd.toCommandArray(), new String[0], null, logger, null).join();
} catch (IOException e) {
e.printStackTrace(logger);
} catch (InterruptedException e) {
e.printStackTrace(logger);
}
}
return (cmdResult == 0);
}
private String getConfigSpecFromFile(String fileName, Launcher launcher) {
String cs = null;
try {
cs = PathUtil.readFileAsString(fileName);
} catch (IOException e) {
launcher.getListener().getLogger().println("ERROR: Cannot open config spec file '" + fileName + "'");
}
return cs;
}
}