3 =head1 NAME $RCSfile: Activity.pm,v $
5 Object oriented interface to UCM Activities
13 Andrew DeFaria <Andrew@ClearSCM.com>
21 Fri May 14 18:16:16 PDT 2010
25 $Date: 2011/11/15 01:56:40 $
31 Provides access to information about Clearcase Activites.
33 my $activity = new Clearcase::UCM::Activity ($name, $pvob);
35 my @changeset = $activity->changeset;
37 foreach my $element (@changeset) {
38 display "Element name: " . $element->pname;
39 display "Element verison: " . $element->version;
44 This module implements a UCM Activity object
48 The following routines are exported:
52 package Clearcase::UCM::Activity;
60 use Clearcase::Element;
62 # We should really inherit these from a more generic super class...
63 sub _processOpts (%) {
64 my ($self, %opts) = @_;
68 foreach (keys %opts) {
69 if ($_ eq 'cq' or $_ eq 'cqe' or $_ eq 'force' or $_ eq 'nc') {
71 } elsif ($_ eq 'c' or $_ eq 'cfile') {
72 $opts .= "-$_ $opts{$_}";
80 my ($class, $activity, $pvob) = @_;
86 Construct a new Clearcase Activity object.
90 =for html <blockquote>
100 =for html </blockquote>
104 =for html <blockquote>
108 =item Clearcase Activity object
112 =for html </blockquote>
118 pvob => Clearcase::vobtag ($pvob),
119 type => $activity =~ /^(deliver|rebase)./ ? 'integration' : 'regular',
132 Returns the name of the activity
136 =for html <blockquote>
144 =for html </blockquote>
148 =for html <blockquote>
152 =item activity's name
156 =for html </blockquote>
160 return $self->{name};
170 Returns the pvob of the activity
174 =for html <blockquote>
182 =for html </blockquote>
186 =for html <blockquote>
190 =item activity's pvob
194 =for html </blockquote>
198 return $self->{pvob};
208 Returns the type of the activity
212 =for html <blockquote>
220 =for html </blockquote>
224 =for html <blockquote>
228 =item activity's type
232 =for html </blockquote>
236 return $self->{type};
239 sub contrib_acts () {
246 Returns the contributing activities
250 =for html <blockquote>
258 =for html </blockquote>
262 =for html <blockquote>
266 =item Array of contributing activities
270 =for html </blockquote>
274 $self->updateActivityInfo () unless $self->{contrib_acts};
276 return $self->{contrib_acts};
279 sub crm_record_id () {
286 Returns the crm_record_id of the activity
290 =for html <blockquote>
298 =for html </blockquote>
302 =for html <blockquote>
306 =item activity's crm_record_id
310 =for html </blockquote>
314 $self->updateActivityInfo () unless $self->{crm_record_id};
316 return $self->{crm_record_id};
319 sub crm_record_type () {
324 =head2 crm_record_type
326 Returns the crm_record_type of the activity
330 =for html <blockquote>
338 =for html </blockquote>
342 =for html <blockquote>
346 =item activity's crm_record_type
350 =for html </blockquote>
354 $self->updateActivityInfo () unless $self->{crm_record_type};
356 return $self->{crm_record_type};
366 Returns the crm_state of the activity
370 =for html <blockquote>
378 =for html </blockquote>
382 =for html <blockquote>
386 =item activity's crm_state
390 =for html </blockquote>
394 $self->updateActivityInfo () unless $self->{crm_state};
396 return $self->{crm_state};
406 Returns the headline of the activity
410 =for html <blockquote>
418 =for html </blockquote>
422 =for html <blockquote>
426 =item activity's headline
430 =for html </blockquote>
434 $self->updateActivityInfo () unless $self->{headline};
436 return $self->{headline};
439 sub name_resolver_view () {
444 =head2 name_resolver_view
446 Returns the name_resolver_view of the activity
450 =for html <blockquote>
458 =for html </blockquote>
462 =for html <blockquote>
466 =item activity's name_resolver_view
470 =for html </blockquote>
474 $self->updateActivityInfo () unless $self->{name_resolver_view};
476 return $self->{name_resolver_view};
477 } # name_resolver_view
486 Returns the stream of the activity
490 =for html <blockquote>
498 =for html </blockquote>
502 =for html <blockquote>
506 =item activity's stream
510 =for html </blockquote>
514 $self->updateActivityInfo () unless $self->{stream};
516 return $self->{stream};
520 my ($self, $recalc) = @_;
526 Returns the changeset of the activity
530 =for html <blockquote>
538 =for html </blockquote>
542 =for html <blockquote>
546 =item An array containing Clearcase::Element objects.
550 =for html </blockquote>
554 if ($self->{changeset}) {
555 return $self->{changeset} unless ($recalc);
558 my $pvob = Clearcase::vobtag $self->{pvob};
560 my $cmd = "lsact -fmt \"%[versions]CQp\" $self->{name}\@$pvob";
562 my ($status, @output) = $Clearcase::CC->execute ($cmd);
564 return ($status, @output)
567 # Need to split up change set. It's presented to us as quoted and space
568 # separated however the change set elements themselves can have spaces in
571 # "/vob/foo/file name with spaces@@/main/1", "/vob/foo/file name2@@/main/2"
573 # So we'll split on '", ""'! Note that this will leave us with the first
574 # element with a leading '"' and the last element with a trailing '"' which
575 # we will have to handle.
577 # Additionally we will call collapseOverExtendedViewPathname to normalize
578 # the over extended pathnames to element hashes.
581 @output = split /\", \"/, $output[0]
585 # Skip any cleartool warnings. We are getting warnings of the form:
586 # "A version in the change set of activity "63332.4" is currently
587 # unavailable". Probably some sort of subtle corruption that we can ignore.
588 # (It should be fixed but we aren't going to be doing that here!)
589 next if /cleartool: Warning/;
591 # Strip any remaining '"'s
594 my %element = Clearcase::Element::collapseOverExtendedVersionPathname $_;
595 my $element = Clearcase::Element->new ($element{name});
597 # Sometimes $element{name} refers to a long path name we can't easily see
598 # in our current view. In such cases the above Clearcase::Element->new will
599 # return us an element where the version is missing. Since we already have
600 # the version information we will replace it here.
602 # The following may look odd since we use similar names against different
603 # Perl variables. $element->{version} means look into the $element object
604 # returned from new above at the member version. $element{version} says
605 # refer to the %element hash defined above for the version key. And finally
606 # $element->version says call the method version of the element object.
607 # So we are saying, if the version member of the element object is not
608 # defined (i.e. $element->version) then set it (i.e. $element->{version})
609 # by using the value of the hash %element with the key version.
610 $element->{version} = $element{version}
611 unless $element->version;
613 # Additionally we will set into the $element object the extended name. This
614 # is the long pathname that we need to use from our current context to be
615 # able to access the element.
616 #$element->setExtendedName ($_);
618 push @changeset, $element;
621 $self->{changeset} = \@changeset;
627 my ($self, $stream, $pvob, $headline, $opts) = @_;
633 Creates a new UCM Activity
637 =for html <blockquote>
641 =item UCM Stream (required)
643 UCM stream this activities is to be created on
645 =item PVOB (Required)
651 Headline to associate with this activity
655 =for html </blockquote>
659 =for html <blockquote>
665 Status from cleartool
673 =for html </blockquote>
678 $self->{stream} = $stream;
679 $self->{pvob} = $pvob;
681 # TODO: Should quote $headline to protect from special characters
682 $self->{headline} = $headline;
686 $opts .= " -headline '$headline'"
689 # TODO: This should call the exists function
690 # Return the stream name if the stream already exists
691 my ($status, @output) =
692 $Clearcase::CC->execute ('lsact -short ' . $self->{name});
694 return ($status, @output)
697 # Need to create the stream
698 return $Clearcase::CC->execute
699 ("mkactivity $opts -in " . $stream .
701 ' ' . $self->{name});
715 =for html <blockquote>
723 =for html </blockquote>
727 =for html <blockquote>
733 Status from cleartool
741 =for html </blockquote>
745 return $Clearcase::CC->execute
746 ('rmactivity -f ' . $self->{name} . "\@" . $self->{pvob});
749 sub attributes (;%) {
750 my ($self, %newAttribs) = @_;
756 Returns a hash of the attributes associated with an activity
760 =for html <blockquote>
768 =for html </blockquote>
772 =for html <blockquote>
778 Hash of attributes for this activity
782 =for html </blockquote>
786 return $self->Clearcase::attributes (
788 "$self->{name}\@" . Clearcase::vobtag ($self->{pvob}),
793 sub updateActivityInfo () {
796 # Get all information that can be gotten using -fmt
797 my $fmt .= '%[crm_record_id]p==';
798 $fmt .= '%[crm_record_type]p==';
799 $fmt .= '%[crm_state]p==';
800 $fmt .= '%[headline]p==';
801 $fmt .= '%[name_resolver_view]p==';
802 $fmt .= '%[stream]Xp==';
805 if ($self->type eq 'integration') {
806 $fmt = '%[contrib_acts]CXp==';
809 $Clearcase::CC->execute (
810 "lsactivity -fmt \"$fmt\" $self->{name}@" . Clearcase::vobtag ($self->{pvob})
813 # Assuming this activity is an empty shell of an object that the user may
814 # possibly use the create method on, return our blessings...
815 return if $Clearcase::CC->status;
817 # We need to make sure that fields are filled in or empty because we are using
818 # undef as an indication that we have not called updateActivityInfo yet.
819 my @fields = split '==', $Clearcase::CC->output;
821 $self->{crm_record_id} = $fields[0];
822 $self->{crm_record_type} = $fields[1];
823 $self->{crm_state} = $fields[2];
824 $self->{headline} = $fields[3];
825 $self->{name_resolver_view} = $fields[4];
826 $self->{stream} = $fields[5];
827 $self->{view} = $fields[6];
829 $self->{contrib_acts} = ();
831 if ($self->type eq 'integration') {
832 foreach (split ', ', $fields[7]) {
833 push @{$self->{contrib_acts}}, Clearcase::UCM::Activity->new ($_);
838 } # updateActivityInfo
844 =head2 ClearSCM Perl Modules
846 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
848 =head1 INCOMPATABILITIES
852 =head1 BUGS AND LIMITATIONS
854 There are no known bugs in this module.
856 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
858 =head1 LICENSE AND COPYRIGHT
860 Copyright (c) 2007, ClearSCM, Inc. All rights reserved.