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