cf765a2be0dc3d6992b9f0a457be43ce7f8c5eea
[clearscm.git] / lib / Clearcase / UCM / Baseline.pm
1 =pod
2
3 =head1 NAME $RCSfile: Baseline.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.4 $
18
19 =item Created
20
21 Fri May 14 18:16:16 PDT 2010
22
23 =item Modified
24
25 $Date: 2011/11/15 01:59:07 $
26
27 =back
28
29 =head1 SYNOPSIS
30
31 Provides access to information about Clearcase Elements.
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::Baseline;
46
47 use strict;
48 use warnings;
49
50 use Carp;
51
52 sub _processOpts(%) {
53   my ($self, %opts) = @_;
54
55   my $opts;
56   
57   for (keys %opts) {
58     if ($_ eq 'cq' or $_ eq 'cqe' or $_ eq 'force' or $_ eq 'nc') {
59       $opts .= "-$_ ";
60     } elsif ($_ eq 'c' or $_ eq 'cfile') {
61       $opts .= "-$_ $opts{$_}";
62     } # if
63   } # for
64   
65   
66   return $opts;
67 } # _processOpts
68
69 sub new($$) {
70   my ($class, $baseline, $pvob) = @_;
71
72 =pod
73
74 =head2 new
75
76 Construct a new Clearcase Stream object.
77
78 Parameters:
79
80 =for html <blockquote>
81
82 =over
83
84 =item stream name
85
86 Name of stream
87
88 =back
89
90 =for html </blockquote>
91
92 Returns:
93
94 =for html <blockquote>
95
96 =over
97
98 =item Clearcase Stream object
99
100 =back
101
102 =for html </blockquote>
103
104 =cut
105
106   $class = bless {
107     name => $baseline,
108     pvob => $pvob,
109   }, $class; # bless
110     
111   return $class;
112 } # new
113
114 sub name() {
115   my ($self) = @_;
116     
117 =pod
118
119 =head2 name
120
121 Returns the name of the stream
122
123 Parameters:
124
125 =for html <blockquote>
126
127 =over
128
129 =item none
130
131 =back
132
133 =for html </blockquote>
134
135 Returns:
136
137 =for html <blockquote>
138
139 =over
140
141 =item stream's name
142
143 =back
144
145 =for html </blockquote>
146
147 =cut
148
149   return $self->{name};
150 } # name
151
152 sub pvob() {
153   my ($self) = @_;
154   
155 =pod
156
157 =head2 pvob
158
159 Returns the pvob of the stream
160
161 Parameters:
162
163 =for html <blockquote>
164
165 =over
166
167 =item none
168
169 =back
170
171 =for html </blockquote>
172
173 Returns:
174
175 =for html <blockquote>
176
177 =over
178
179 =item stream's pvob
180
181 =back
182
183 =for html </blockquote>
184
185 =cut
186
187   return $self->{pvob};
188 } # pvob
189   
190 sub create($;$$$) {
191   my ($self, $view, $comment, $opts) = @_;
192
193 =pod
194
195 =head2 create
196
197 Creates a new UCM Baseline Object
198
199 Parameters:
200
201 =for html <blockquote>
202
203 =over
204
205 =item opts
206
207 Options: Additional options to use
208
209 =back
210
211 =for html </blockquote>
212
213 Returns:
214
215 =for html <blockquote>
216
217 =over
218
219 =item $status
220
221 Status from cleartool
222
223 =item @output
224
225 Ouput from cleartool
226
227 =back
228
229 =for html </blockquote>
230
231 =cut
232     
233   $opts ||= '';
234       
235   $comment = Clearcase::_setComment $comment;
236
237   return $Clearcase::CC->execute(
238     "mkbl $comment $opts -view " . $view->tag . ' ' . $self->{name}
239   );
240 } # create
241
242 sub remove($) {
243   my ($self, $opts) = @_;
244
245 =pod
246
247 =head2 remove
248
249 Removes UCM Baseline
250
251 Parameters:
252
253 =for html <blockquote>
254
255 =over
256
257 =item none
258
259 =item %opts
260
261 Options: Additional options to use (e.g. -c, -force, etc.)
262
263 =back
264
265 =for html </blockquote>
266
267 Returns:
268
269 =for html <blockquote>
270
271 =over
272
273 =item nothing
274
275 Remember to check status method for error, and/or output method for output.
276
277 =back
278
279 =for html </blockquote>
280
281 =cut
282
283   $opts ||= '';
284   
285   return $Clearcase::CC->execute(
286     "rmbl $opts -force " . $self->{name} . '@' . $self->{pvob}->name
287   ):
288 } # remove
289
290 sub attributes () {
291   my ($self) = @_;
292
293 =pod
294
295 =head2 attributes
296
297 Returns a hash of the attributes associated with a baseline
298
299 Parameters:
300
301 =for html <blockquote>
302
303 =over
304
305 =item none
306
307 =back
308
309 =for html </blockquote>
310
311 Returns:
312
313 =for html <blockquote>
314
315 =over
316
317 =item %attributes
318
319 Hash of attributes for this baseline
320
321 =back
322
323 =for html </blockquote>
324
325 =cut
326
327   return $self->Clearcase::attributes(
328     'baseline',
329     "$self->{name}\@" . $self->{pvob}->name
330   );
331 } # attributes
332
333 sub diff($;$$) {
334   my ($self, $type, $baseline, %opts) = @_;
335   
336 =pod
337
338 =head2 diff
339
340 Returns a hash of information regarding the difference between two baselines or
341 a baseline and the stream (AKA "top of stream").
342
343 Parameters:
344
345 =for html <blockquote>
346
347 =over
348
349 =item [activities|versions|baselines]
350
351 Must specify one of [activities|versions|baselines]. Information will be 
352 returned based on this parameter.
353
354 =item $baseline or $stream
355
356 Specify the baseline or stream to compare to. If not specified a -predeccsor 
357 diffbl will be done. If a stream use "stream:<stream>" otherwise use 
358 "baseline:<baseline>" or simply "<baseline>".
359
360 =item %opts
361
362 Additional options.
363
364 =back
365
366 =for html </blockquote>
367
368 Returns:
369
370 =for html <blockquote>
371
372 =over
373
374 =item %info
375
376 Depending on whether activites, versions or baselines were specified, the 
377 returned hash will be constructed with the key being the activity, version 
378 string or baseline name as the key with additional information specified as the
379 value.
380
381 =back
382
383 =for html </blockquote>
384
385 =cut
386
387   unless ($type =~ /^activities$/i or
388           $type =~ /^versions$/i   or
389           $type =~ /^baselines$/i) {
390     croak "Type must be one of activities, versions or baselines in "
391         . "Clearcase::UCM::Baseline::diff - not $type";
392   } # unless
393   
394   my $myBaseline = "$self->{name}\@$self->{pvob}";
395   
396   my $cmd = "diffbl -$type";
397   
398   if ($baseline) {
399     if ($baseline =~ /(\S+):/) {
400       unless ($1 eq 'baseline' or $1 eq 'stream') {
401         croak "Baseline should be baseline:<baseline> or stream:<stream> or "
402             . "just <baseline>";
403       } # unless
404     } # if
405     
406     $baseline .= "\@$self->{pvob}" unless $baseline =~ /\@/;
407     
408     $cmd .= " $myBaseline $baseline";
409   } else {
410     $cmd .= " -predeccsor";
411   } # if
412   
413   $Clearcase::CC->execute($cmd);
414   
415   return if $Clearcase::CC->status;
416   
417   my @output = $Clearcase::CC->output;
418
419   my %info;
420     
421   for (@output) {
422     next unless /^(\>\>|\<\<)/;
423     
424     if (/(\>\>|\<\<)\s+(\S+)\@/) {
425       $info{$2} = Clearcase::UCM::Activity->new($2, $self->{pvob});
426     } # if
427   } # for
428   
429   return %info;
430 } # diff
431
432 1;
433
434 =head1 DEPENDENCIES
435
436 =head2 ClearSCM Perl Modules
437
438 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
439
440 =head1 INCOMPATABILITIES
441
442 None
443
444 =head1 BUGS AND LIMITATIONS
445
446 There are no known bugs in this module.
447
448 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
449
450 =head1 LICENSE AND COPYRIGHT
451
452 Copyright (c) 2007, ClearSCM, Inc. All rights reserved.
453
454 =cut