Various changes and additions for UCM and testing things
[clearscm.git] / lib / Clearcase / UCM / Stream.pm
1 =pod
2
3 =head1 NAME $RCSfile: Stream.pm,v $
4
5 Object oriented interface to UCM Streams
6
7 =head1 VERSION
8
9 =over
10
11 =item Author
12
13 Andrew DeFaria <Andrew@ClearSCM.com>
14
15 =item Revision
16
17 $Revision: 1.8 $
18
19 =item Created
20
21 Fri May 14 18:16:16 PDT 2010
22
23 =item Modified
24
25 $Date: 2011/11/15 02:00:58 $
26
27 =back
28
29 =head1 SYNOPSIS
30
31 Provides access to information about Clearcase Streams.
32
33   my $stream = new Clearcase::UCM::Stream ($name, $pvob);
34
35 =head1 DESCRIPTION
36
37 This module implements a UCM Stream object
38
39 =head1 ROUTINES
40
41 The following routines are exported:
42
43 =cut
44
45 package Clearcase::UCM::Stream;
46
47 use strict;
48 use warnings;
49
50 sub new ($$) {
51   my ($class, $name, $pvob) = @_;
52
53 =pod
54
55 =head2 new
56
57 Construct a new Clearcase Stream object.
58
59 Parameters:
60
61 =for html <blockquote>
62
63 =over
64
65 =item name
66
67 Name of stream
68
69 =item pvob
70
71 Associated pvob
72
73 =back
74
75 =for html </blockquote>
76
77 Returns:
78
79 =for html <blockquote>
80
81 =over
82
83 =item Clearcase Stream object
84
85 =back
86
87 =for html </blockquote>
88
89 =cut
90
91   $class = bless {
92     name => $name,
93     pvob => $pvob,
94   }, $class; # bless
95     
96   return $class; 
97 } # new
98   
99 sub name () {
100   my ($self) = @_;
101     
102 =pod
103
104 =head2 name
105
106 Returns the name of the stream
107
108 Parameters:
109
110 =for html <blockquote>
111
112 =over
113
114 =item none
115
116 =back
117
118 =for html </blockquote>
119
120 Returns:
121
122 =for html <blockquote>
123
124 =over
125
126 =item stream's name
127
128 =back
129
130 =for html </blockquote>
131
132 =cut
133
134   return $self->{name};
135 } # name
136
137 sub pvob () {
138   my ($self) = @_;
139   
140 =pod
141
142 =head2 pvob
143
144 Returns the pvob of the stream
145
146 Parameters:
147
148 =for html <blockquote>
149
150 =over
151
152 =item none
153
154 =back
155
156 =for html </blockquote>
157
158 Returns:
159
160 =for html <blockquote>
161
162 =over
163
164 =item stream's pvob
165
166 =back
167
168 =for html </blockquote>
169
170 =cut
171
172   return $self->{pvob};
173 } # pvob
174   
175 sub create ($;$) {
176   my ($self, $project, $opts) = @_;
177
178 =pod
179
180 =head2 create
181
182 Creates a new UCM Stream Object
183
184 Parameters:
185
186 =for html <blockquote>
187
188 =over
189
190 =item project
191
192 Project that this stream will be created in
193
194 =item opts
195
196 Options: Additional options to use (e.g. -baseline/-readonly)
197
198 =back
199
200 =for html </blockquote>
201
202 Returns:
203
204 =for html <blockquote>
205
206 =over
207
208 =item $status
209
210 Status from cleartool
211
212 =item @output
213
214 Ouput from cleartool
215
216 =back
217
218 =for html </blockquote>
219
220 =cut
221
222   return (0, ()) if $self->exists;
223
224   $opts ||= '';
225
226   $self->{readonly} = $opts =~ /-readonly/;
227
228   return $Clearcase::CC->execute(
229     "mkstream $opts -in "
230        . $project->name . '@' . $self->{pvob}->tag . ' '
231        . $self->name    . '@' . $self->{pvob}->tag
232   );
233 } # create
234
235 sub remove () {
236   my ($self) = @_;
237
238 =pod
239
240 =head2 remove
241
242 Removes UCM Stream
243
244 Parameters:
245
246 =for html <blockquote>
247
248 =over
249
250 =back
251
252 =for html </blockquote>
253
254 Returns:
255
256 =for html <blockquote>
257
258 =over
259
260 =item $status
261
262 Status from cleartool
263
264 =item @output
265
266 Ouput from cleartool
267
268 =back
269
270 =for html </blockquote>
271
272 =cut
273
274   return $Clearcase::CC->execute 
275     ('rmstream -f ' . $self->{name} . '@' . $self->{pvob}->name);
276 } # rmStream
277
278 sub rebase($;$) {
279   my ($self, $baseline, $opts) = @_;
280
281 =pod
282
283 =head2 rebase
284
285 Rebases a UCM Stream
286
287 Parameters:
288
289 =for html <blockquote>
290
291 =over
292
293 =item baseline
294
295 Baseline to rebase to
296
297 =item opts
298
299 Any additional opts
300
301 =back
302
303 =for html </blockquote>
304
305 Returns:
306
307 =for html <blockquote>
308
309 =over
310
311 =item $status
312
313 Status from cleartool
314
315 =item @output
316
317 Ouput from cleartool
318
319 =back
320
321 =for html </blockquote>
322
323 =cut
324
325   $opts ||= '';
326
327   $opts .= ' -baseline ' . $baseline  .
328            ' -stream '   . $self->name . '@' . $self->{pvob}->name;
329
330   return $Clearcase::CC->execute("rebase $opts");
331 } # rebase
332
333 sub recommend($) {
334   my ($self, $baseline) = @_;
335
336 =pod
337
338 =head2 recommend
339
340 Recommends a baseline in a UCM Stream
341
342 Parameters:
343
344 =for html <blockquote>
345
346 =over
347
348 =item baseline
349
350 Baseline to recommend
351
352 =back
353
354 =for html </blockquote>
355
356 Returns:
357
358 =for html <blockquote>
359
360 =over
361
362 =item $status
363
364 Status from cleartool
365
366 =item @output
367
368 Ouput from cleartool
369
370 =back
371
372 =for html </blockquote>
373
374 =cut
375
376   return $Clearcase::CC->execute(
377     "chstream -recommended $baseline " . $self->name . '@' . $self->{pvob}->tag
378   );
379 } # recommend
380
381 sub baselines () {
382   my ($self) = @_;
383
384 =pod
385
386 =head2 baselines
387
388 Returns baseline objects associated with the stream
389
390 Parameters:
391
392 =for html <blockquote>
393
394 =over
395
396 =item none
397
398 =back
399
400 =for html </blockquote>
401
402 Returns:
403
404 =for html <blockquote>
405
406 =over
407
408 =item @baselines
409
410 An array of baseline objects for this stream
411
412 =back
413
414 =for html </blockquote>
415
416 =cut
417
418   my $cmd = "lsbl -short -stream $self->{name}\@$self->{pvob}";
419   
420   $Clearcase::CC->execute ($cmd); 
421
422   return if $Clearcase::CC->status;
423
424   my @baselines;
425   
426   for ($Clearcase::CC->output) {
427     my $baseline = Clearcase::UCM::Baseline->new ($_, $self->{pvob});
428     
429     push @baselines, $baseline;
430   } # for
431   
432   return @baselines;
433 } # baselines
434
435 sub exists() {
436   my ($self) = @_;
437
438 =pod
439
440 =head3 exists
441
442 Return true if the stream exists - false otherwise
443
444 Paramters:
445
446 =for html <blockquote>
447
448 =over 
449
450 =item none
451
452 =back
453
454 =for html </blockquote>
455
456 Returns:
457
458 =for html <blockquote>
459
460 =over
461
462 =item boolean
463
464 =back
465
466 =for html </blockquote>
467
468 =cut
469
470   my ($status, @output) = $Clearcase::CC->execute(
471     'lsstream ' . $self->{name} . '@' . $self->{pvob}->name
472   );
473
474   return !$status;
475 } # exists
476
477 1;
478
479 =head1 DEPENDENCIES
480
481 =head2 ClearSCM Perl Modules
482
483 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
484
485 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase/UCM/Baseline.pm">Clearcase::UCM::Baseline</a></p>
486 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase/UCM/Project.pm">Clearcase::UCM::Project</a></p>
487
488 =head1 INCOMPATABILITIES
489
490 None
491
492 =head1 BUGS AND LIMITATIONS
493
494 There are no known bugs in this module.
495
496 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
497
498 =head1 LICENSE AND COPYRIGHT
499
500 Copyright (c) 2007, ClearSCM, Inc. All rights reserved.
501
502 =cut