File Coverage

lib/Clearcase/UCM/Activity.pm
Criterion Covered Total %
statement 6 105 5.7
branch 0 42 0.0
condition 0 14 0.0
subroutine 2 20 10.0
pod 16 17 94.1
total 24 198 12.1


line stmt bran cond sub pod time code
1              
2             =pod
3              
4             =head1 NAME Activity.pm
5              
6             Object oriented interface to UCM Activities
7              
8             =head1 VERSION
9              
10             =over
11              
12             =item Author
13              
14             Andrew DeFaria
15              
16             =item Revision
17              
18             $Revision: 1.10 $
19              
20             =item Created
21              
22             Fri May 14 18:16:16 PDT 2010
23              
24             =item Modified
25              
26             $Date: 2011/11/15 01:56:40 $
27              
28             =back
29              
30             =head1 SYNOPSIS
31              
32             Provides access to information about Clearcase Activites.
33              
34             my $activity = new Clearcase::UCM::Activity ($name, $pvob);
35            
36             my @changeset = $activity->changeset;
37            
38             for my $element (@changeset) {
39             print "Element name: " . $element->pname . "\n";
40             print "Element verison: " . $element->version . "\n";
41             } # for
42              
43             =head1 DESCRIPTION
44              
45             This module implements a UCM Activity object
46              
47             =head1 ROUTINES
48              
49             The following routines are exported:
50              
51             =cut
52              
53             package Clearcase::UCM::Activity;
54              
55 1     1   974 use strict;
  1         15  
  1         28  
56 1     1   3 use warnings;
  1         1  
  1         1537  
57              
58             # We should really inherit these from a more generic super class...
59             sub _processOpts(%) {
60 0     0     my ($self, %opts) = @_;
61              
62 0           my $opts;
63              
64 0           for (keys %opts) {
65 0 0 0       if ($_ eq 'cq' or $_ eq 'cqe' or $_ eq 'force' or $_ eq 'nc') {
    0 0        
      0        
      0        
66 0           $opts .= "-$_ ";
67             } elsif ($_ eq 'c' or $_ eq 'cfile') {
68 0           $opts .= "-$_ $opts{$_}";
69             } # if
70             } # for
71              
72 0           return $opts;
73             } # _processOpts
74              
75             sub new($$) {
76 0     0 1   my ($class, $activity, $pvob) = @_;
77              
78             =pod
79              
80             =head2 new
81              
82             Construct a new Clearcase Activity object.
83              
84             Parameters:
85              
86             =for html
87              
88             =over
89              
90             =item activity name
91              
92             Name of activity
93              
94             =back
95              
96             =for html
97              
98             Returns:
99              
100             =for html
101              
102             =over
103              
104             =item Clearcase Activity object
105              
106             =back
107              
108             =for html
109              
110             =cut
111              
112 0 0         $class = bless {
113             name => $activity,
114             pvob => $pvob,
115             type => $activity =~ /^(deliver|rebase)./ ? 'integration' : 'regular',
116             },
117             $class; # bless
118              
119 0           return $class;
120             } # new
121              
122             sub name() {
123 0     0 1   my ($self) = @_;
124              
125             =pod
126              
127             =head2 name
128              
129             Returns the name of the activity
130              
131             Parameters:
132              
133             =for html
134              
135             =over
136              
137             =item none
138              
139             =back
140              
141             =for html
142              
143             Returns:
144              
145             =for html
146              
147             =over
148              
149             =item activity's name
150              
151             =back
152              
153             =for html
154              
155             =cut
156              
157 0           return $self->{name};
158             } # name
159              
160             sub pvob() {
161 0     0 1   my ($self) = @_;
162              
163             =pod
164              
165             =head2 pvob
166              
167             Returns the pvob of the activity
168              
169             Parameters:
170              
171             =for html
172              
173             =over
174              
175             =item none
176              
177             =back
178              
179             =for html
180              
181             Returns:
182              
183             =for html
184              
185             =over
186              
187             =item activity's pvob
188              
189             =back
190              
191             =for html
192              
193             =cut
194              
195 0           return $self->{pvob};
196             } # pvob
197              
198             sub type() {
199 0     0 1   my ($self) = @_;
200              
201             =pod
202              
203             =head2 type
204              
205             Returns the type of the activity
206              
207             Parameters:
208              
209             =for html
210              
211             =over
212              
213             =item none
214              
215             =back
216              
217             =for html
218              
219             Returns:
220              
221             =for html
222              
223             =over
224              
225             =item activity's type
226              
227             =back
228              
229             =for html
230              
231             =cut
232              
233 0           return $self->{type};
234             } # type
235              
236             sub contrib_acts() {
237 0     0 1   my ($self) = @_;
238              
239             =pod
240              
241             =head2 contrib_acts
242              
243             Returns the contributing activities
244              
245             Parameters:
246              
247             =for html
248              
249             =over
250              
251             =item none
252              
253             =back
254              
255             =for html
256              
257             Returns:
258              
259             =for html
260              
261             =over
262              
263             =item Array of contributing activities
264              
265             =back
266              
267             =for html
268              
269             =cut
270              
271 0 0         $self->updateActivityInfo () unless $self->{contrib_acts};
272              
273 0           return $self->{contrib_acts};
274             } # crm_record
275              
276             sub crm_record_id() {
277 0     0 1   my ($self) = @_;
278              
279             =pod
280              
281             =head2 crm_record_id
282              
283             Returns the crm_record_id of the activity
284              
285             Parameters:
286              
287             =for html
288              
289             =over
290              
291             =item none
292              
293             =back
294              
295             =for html
296              
297             Returns:
298              
299             =for html
300              
301             =over
302              
303             =item activity's crm_record_id
304              
305             =back
306              
307             =for html
308              
309             =cut
310              
311 0 0         $self->updateActivityInfo () unless $self->{crm_record_id};
312              
313 0           return $self->{crm_record_id};
314             } # crm_record_id
315              
316             sub crm_record_type() {
317 0     0 1   my ($self) = @_;
318              
319             =pod
320              
321             =head2 crm_record_type
322              
323             Returns the crm_record_type of the activity
324              
325             Parameters:
326              
327             =for html
328              
329             =over
330              
331             =item none
332              
333             =back
334              
335             =for html
336              
337             Returns:
338              
339             =for html
340              
341             =over
342              
343             =item activity's crm_record_type
344              
345             =back
346              
347             =for html
348              
349             =cut
350              
351 0 0         $self->updateActivityInfo () unless $self->{crm_record_type};
352              
353 0           return $self->{crm_record_type};
354             } # crm_record_type
355              
356             sub crm_state() {
357 0     0 1   my ($self) = @_;
358              
359             =pod
360              
361             =head2 crm_state
362              
363             Returns the crm_state of the activity
364              
365             Parameters:
366              
367             =for html
368              
369             =over
370              
371             =item none
372              
373             =back
374              
375             =for html
376              
377             Returns:
378              
379             =for html
380              
381             =over
382              
383             =item activity's crm_state
384              
385             =back
386              
387             =for html
388              
389             =cut
390              
391 0 0         $self->updateActivityInfo () unless $self->{crm_state};
392              
393 0           return $self->{crm_state};
394             } # crm_state
395              
396             sub headline() {
397 0     0 1   my ($self) = @_;
398              
399             =pod
400              
401             =head2 headline
402              
403             Returns the headline of the activity
404              
405             Parameters:
406              
407             =for html
408              
409             =over
410              
411             =item none
412              
413             =back
414              
415             =for html
416              
417             Returns:
418              
419             =for html
420              
421             =over
422              
423             =item activity's headline
424              
425             =back
426              
427             =for html
428              
429             =cut
430              
431 0 0         $self->updateActivityInfo () unless $self->{headline};
432              
433 0           return $self->{headline};
434             } # headline
435              
436             sub name_resolver_view() {
437 0     0 1   my ($self) = @_;
438              
439             =pod
440              
441             =head2 name_resolver_view
442              
443             Returns the name_resolver_view of the activity
444              
445             Parameters:
446              
447             =for html
448              
449             =over
450              
451             =item none
452              
453             =back
454              
455             =for html
456              
457             Returns:
458              
459             =for html
460              
461             =over
462              
463             =item activity's name_resolver_view
464              
465             =back
466              
467             =for html
468              
469             =cut
470              
471 0 0         $self->updateActivityInfo () unless $self->{name_resolver_view};
472              
473 0           return $self->{name_resolver_view};
474             } # name_resolver_view
475              
476             sub stream() {
477 0     0 1   my ($self) = @_;
478              
479             =pod
480              
481             =head2 stream
482              
483             Returns the stream of the activity
484              
485             Parameters:
486              
487             =for html
488              
489             =over
490              
491             =item none
492              
493             =back
494              
495             =for html
496              
497             Returns:
498              
499             =for html
500              
501             =over
502              
503             =item activity's stream
504              
505             =back
506              
507             =for html
508              
509             =cut
510              
511 0 0         $self->updateActivityInfo () unless $self->{stream};
512              
513 0           return $self->{stream};
514             } # stream
515              
516             sub changeset(;$) {
517 0     0 1   my ($self, $recalc) = @_;
518              
519             =pod
520              
521             =head2 changeset
522              
523             Returns the changeset of the activity
524              
525             Parameters:
526              
527             =for html
528              
529             =over
530              
531             =item none
532              
533             =back
534              
535             =for html
536              
537             Returns:
538              
539             =for html
540              
541             =over
542              
543             =item An array containing Clearcase::Element objects.
544              
545             =back
546              
547             =for html
548              
549             =cut
550              
551 0 0         if ($self->{changeset}) {
552 0 0         return $self->{changeset} unless ($recalc);
553             } # if
554              
555 0           my $pvob = Clearcase::vobtag $self->{pvob};
556              
557 0           my $cmd = "lsact -fmt \"%[versions]CQp\" $self->{name}\@$pvob";
558              
559 0           my ($status, @output) = $Clearcase::CC->execute ($cmd);
560              
561 0 0         return ($status, @output)
562             if $status;
563              
564             # Need to split up change set. It's presented to us as quoted and space
565             # separated however the change set elements themselves can have spaces in
566             # them! e.g.:
567             #
568             # "/vob/foo/file name with spaces@@/main/1", "/vob/foo/file name2@@/main/2"
569             #
570             # So we'll split on '", ""'! Note that this will leave us with the first
571             # element with a leading '"' and the last element with a trailing '"' which
572             # we will have to handle.
573             #
574             # Additionally we will call collapseOverExtendedViewPathname to normalize
575             # the over extended pathnames to element hashes.
576 0           my (@changeset);
577              
578 0 0         @output = split /\", \"/, $output[0]
579             if $output[0];
580              
581 0           for (@output) {
582              
583             # Skip any cleartool warnings. We are getting warnings of the form:
584             # "A version in the change set of activity "63332.4" is currently
585             # unavailable". Probably some sort of subtle corruption that we can ignore.
586             # (It should be fixed but we aren't going to be doing that here!)
587 0 0         next if /cleartool: Warning/;
588              
589             # Strip any remaining '"'s
590 0           s/^\"//;
591 0           s/\"$//;
592              
593 0           my %element = Clearcase::Element::collapseOverExtendedVersionPathname $_;
594 0           my $element = Clearcase::Element->new ($element{name});
595              
596             # Sometimes $element{name} refers to a long path name we can't easily see
597             # in our current view. In such cases the above Clearcase::Element->new will
598             # return us an element where the version is missing. Since we already have
599             # the version information we will replace it here.
600             #
601             # The following may look odd since we use similar names against different
602             # Perl variables. $element->{version} means look into the $element object
603             # returned from new above at the member version. $element{version} says
604             # refer to the %element hash defined above for the version key. And finally
605             # $element->version says call the method version of the element object.
606             # So we are saying, if the version member of the element object is not
607             # defined (i.e. $element->version) then set it (i.e. $element->{version})
608             # by using the value of the hash %element with the key version.
609             $element->{version} = $element{version}
610 0 0         unless $element->version;
611              
612             # Additionally we will set into the $element object the extended name. This
613             # is the long pathname that we need to use from our current context to be
614             # able to access the element.
615             #$element->setExtendedName($_);
616              
617 0           push @changeset, $element;
618             } # for
619              
620 0           $self->{changeset} = \@changeset;
621              
622 0           return @changeset;
623             } # changeset
624              
625             sub exists() {
626 0     0 0   my ($self) = @_;
627              
628             my ($status, @output) = $Clearcase::CC->execute (
629 0           'lsactivity ' . $self->{name} . '@' . $self->pvob->tag);
630              
631 0           return !$status;
632             } # exists
633              
634             sub create($$$;$) {
635 0     0 1   my ($self, $stream, $headline, $opts) = @_;
636              
637             =pod
638              
639             =head2 create
640              
641             Creates a new UCM Activity
642              
643             Parameters:
644              
645             =for html
646              
647             =over
648              
649             =item UCM Stream(required)
650              
651             UCM stream this activities is to be created on
652              
653             =item PVOB (Required)
654              
655             Project Vob
656              
657             =item headline
658              
659             Headline to associate with this activity
660              
661             =back
662              
663             =for html
664              
665             Returns:
666              
667             =for html
668              
669             =over
670              
671             =item $status
672              
673             Status from cleartool
674              
675             =item @output
676              
677             Ouput from cleartool
678              
679             =back
680              
681             =for html
682              
683             =cut
684              
685 0 0         if ($self->exists) {
686 0           $self->updateActivityInfo;
687              
688 0           return (0, ());
689             } # if
690              
691             # Fill in opts
692 0   0       $opts ||= '';
693              
694 0 0         if ($headline) {
695 0           $self->{headline} = $headline;
696              
697 0           $opts .= " -headline '$headline'";
698             } # if
699              
700 0           $self->{stream} = Clearcase::UCM::Stream->new ($stream, $self->{pvob});
701              
702             return $Clearcase::CC->execute ("mkactivity $opts -in "
703             . $stream->{name} . '@'
704             . $self->pvob->{tag} . ' '
705             . $self->{name} . '@'
706 0           . $self->pvob->{tag});
707             } # create
708              
709             sub remove() {
710 0     0 1   my ($self) = @_;
711              
712             =pod
713              
714             =head2 remove
715              
716             Removes UCM Activity
717              
718             Parameters:
719              
720             =for html
721              
722             =over
723              
724             =item none
725              
726             =back
727              
728             =for html
729              
730             Returns:
731              
732             =for html
733              
734             =over
735              
736             =item $status
737              
738             Status from cleartool
739              
740             =item @output
741              
742             Ouput from cleartool
743              
744             =back
745              
746             =for html
747              
748             =cut
749              
750             return $Clearcase::CC->execute (
751 0           'rmactivity -f ' . $self->{name} . "\@" . $self->{pvob}->name);
752             } # remove
753              
754             sub attributes(;%) {
755 0     0 1   my ($self, %newAttribs) = @_;
756              
757             =pod
758              
759             =head2 attributes
760              
761             Returns a hash of the attributes associated with an activity
762              
763             Parameters:
764              
765             =for html
766              
767             =over
768              
769             =item none
770              
771             =back
772              
773             =for html
774              
775             Returns:
776              
777             =for html
778              
779             =over
780              
781             =item %attributes
782              
783             Hash of attributes for this activity
784              
785             =back
786              
787             =for html
788              
789             =cut
790              
791             return $self->Clearcase::attributes ('activity',
792 0           "$self->{name}\@" . $self->{pvob}->name, %newAttribs,);
793             } # attributes
794              
795             =pod
796              
797             =head2 updateActivityInfo()
798              
799             Update the activity info
800              
801             Parameters:
802              
803             =for html
804              
805             =over
806              
807             =item none
808              
809             =back
810              
811             =for html
812              
813             Returns:
814              
815             =for html
816              
817             =over
818              
819             =item nothing
820              
821             =back
822              
823             =for html
824              
825             =cut
826              
827             =pod
828              
829             =head2 updateActivityInfo()
830              
831             Update the activity info
832              
833             Parameters:
834              
835             =for html
836              
837             =over
838              
839             =item none
840              
841             =back
842              
843             =for html
844              
845             Returns:
846              
847             =for html
848              
849             =over
850              
851             =item nothing
852              
853             =back
854              
855             =for html
856              
857             =cut
858              
859             sub updateActivityInfo() {
860 0     0 1   my ($self) = @_;
861              
862             # Get all information that can be gotten using -fmt
863 0           my $fmt .= '%[crm_record_id]p==';
864 0           $fmt .= '%[crm_record_type]p==';
865 0           $fmt .= '%[crm_state]p==';
866 0           $fmt .= '%[headline]p==';
867 0           $fmt .= '%[name_resolver_view]p==';
868 0           $fmt .= '%[stream]Xp==';
869 0           $fmt .= '%[view]p';
870              
871 0 0         if ($self->type eq 'integration') {
872 0           $fmt = '%[contrib_acts]CXp==';
873             } # if
874              
875             $Clearcase::CC->execute (
876 0           "lsactivity -fmt \"$fmt\" $self->{name}@" . $self->{pvob}->name);
877              
878             # Assuming this activity is an empty shell of an object that the user may
879             # possibly use the create method on, return our blessings...
880 0 0         return if $Clearcase::CC->status;
881              
882             # We need to make sure that fields are filled in or empty because we are using
883             # undef as an indication that we have not called updateActivityInfo yet.
884 0           my @fields = split '==', $Clearcase::CC->output;
885              
886 0           $self->{crm_record_id} = $fields[0];
887 0           $self->{crm_record_type} = $fields[1];
888 0           $self->{crm_state} = $fields[2];
889 0           $self->{headline} = $fields[3];
890 0           $self->{name_resolver_view} = $fields[4];
891 0           $self->{stream} = $fields[5];
892 0           $self->{view} = $fields[6];
893              
894 0           $self->{contrib_acts} = ();
895              
896 0 0         if ($self->type eq 'integration') {
897 0           for (split ', ', $fields[7]) {
898 0           push @{$self->{contrib_acts}}, Clearcase::UCM::Activity->new ($_);
  0            
899             } # for
900             } # if
901              
902 0           return;
903             } # updateActivityInfo
904              
905             1;
906              
907             =head1 DEPENDENCIES
908              
909             =head2 Modules
910              
911             =over
912              
913             =item L
914              
915             =back
916              
917             =head1 INCOMPATABILITIES
918              
919             None
920              
921             =head1 BUGS AND LIMITATIONS
922              
923             There are no known bugs in this module.
924              
925             Please report problems to Andrew DeFaria .
926              
927             =head1 COPYRIGHT AND LICENSE
928              
929             Copyright (C) 2020 by Andrew@DeFaria.com
930              
931             This library is free software; you can redistribute it and/or modify
932             it under the same terms as Perl itself, either Perl version 5.38.0 or,
933             at your option, any later version of Perl 5 you may have available.
934              
935             =cut