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 for 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;
57 # We should really inherit these from a more generic super class...
59 my ($self, %opts) = @_;
64 if ($_ eq 'cq' or $_ eq 'cqe' or $_ eq 'force' or $_ eq 'nc') {
66 } elsif ($_ eq 'c' or $_ eq 'cfile') {
67 $opts .= "-$_ $opts{$_}";
75 my ($class, $activity, $pvob) = @_;
81 Construct a new Clearcase Activity object.
85 =for html <blockquote>
95 =for html </blockquote>
99 =for html <blockquote>
103 =item Clearcase Activity object
107 =for html </blockquote>
114 type => $activity =~ /^(deliver|rebase)./ ? 'integration' : 'regular',
127 Returns the name of the activity
131 =for html <blockquote>
139 =for html </blockquote>
143 =for html <blockquote>
147 =item activity's name
151 =for html </blockquote>
155 return $self->{name};
165 Returns the pvob of the activity
169 =for html <blockquote>
177 =for html </blockquote>
181 =for html <blockquote>
185 =item activity's pvob
189 =for html </blockquote>
193 return $self->{pvob};
203 Returns the type of the activity
207 =for html <blockquote>
215 =for html </blockquote>
219 =for html <blockquote>
223 =item activity's type
227 =for html </blockquote>
231 return $self->{type};
241 Returns the contributing activities
245 =for html <blockquote>
253 =for html </blockquote>
257 =for html <blockquote>
261 =item Array of contributing activities
265 =for html </blockquote>
269 $self->updateActivityInfo() unless $self->{contrib_acts};
271 return $self->{contrib_acts};
274 sub crm_record_id() {
281 Returns the crm_record_id of the activity
285 =for html <blockquote>
293 =for html </blockquote>
297 =for html <blockquote>
301 =item activity's crm_record_id
305 =for html </blockquote>
309 $self->updateActivityInfo() unless $self->{crm_record_id};
311 return $self->{crm_record_id};
314 sub crm_record_type() {
319 =head2 crm_record_type
321 Returns the crm_record_type of the activity
325 =for html <blockquote>
333 =for html </blockquote>
337 =for html <blockquote>
341 =item activity's crm_record_type
345 =for html </blockquote>
349 $self->updateActivityInfo() unless $self->{crm_record_type};
351 return $self->{crm_record_type};
361 Returns the crm_state of the activity
365 =for html <blockquote>
373 =for html </blockquote>
377 =for html <blockquote>
381 =item activity's crm_state
385 =for html </blockquote>
389 $self->updateActivityInfo() unless $self->{crm_state};
391 return $self->{crm_state};
401 Returns the headline of the activity
405 =for html <blockquote>
413 =for html </blockquote>
417 =for html <blockquote>
421 =item activity's headline
425 =for html </blockquote>
429 $self->updateActivityInfo() unless $self->{headline};
431 return $self->{headline};
434 sub name_resolver_view() {
439 =head2 name_resolver_view
441 Returns the name_resolver_view of the activity
445 =for html <blockquote>
453 =for html </blockquote>
457 =for html <blockquote>
461 =item activity's name_resolver_view
465 =for html </blockquote>
469 $self->updateActivityInfo() unless $self->{name_resolver_view};
471 return $self->{name_resolver_view};
472 } # name_resolver_view
481 Returns the stream of the activity
485 =for html <blockquote>
493 =for html </blockquote>
497 =for html <blockquote>
501 =item activity's stream
505 =for html </blockquote>
509 $self->updateActivityInfo() unless $self->{stream};
511 return $self->{stream};
515 my ($self, $recalc) = @_;
521 Returns the changeset of the activity
525 =for html <blockquote>
533 =for html </blockquote>
537 =for html <blockquote>
541 =item An array containing Clearcase::Element objects.
545 =for html </blockquote>
549 if ($self->{changeset}) {
550 return $self->{changeset} unless ($recalc);
553 my $pvob = Clearcase::vobtag $self->{pvob};
555 my $cmd = "lsact -fmt \"%[versions]CQp\" $self->{name}\@$pvob";
557 my ($status, @output) = $Clearcase::CC->execute($cmd);
559 return ($status, @output)
562 # Need to split up change set. It's presented to us as quoted and space
563 # separated however the change set elements themselves can have spaces in
566 # "/vob/foo/file name with spaces@@/main/1", "/vob/foo/file name2@@/main/2"
568 # So we'll split on '", ""'! Note that this will leave us with the first
569 # element with a leading '"' and the last element with a trailing '"' which
570 # we will have to handle.
572 # Additionally we will call collapseOverExtendedViewPathname to normalize
573 # the over extended pathnames to element hashes.
576 @output = split /\", \"/, $output[0]
580 # Skip any cleartool warnings. We are getting warnings of the form:
581 # "A version in the change set of activity "63332.4" is currently
582 # unavailable". Probably some sort of subtle corruption that we can ignore.
583 # (It should be fixed but we aren't going to be doing that here!)
584 next if /cleartool: Warning/;
586 # Strip any remaining '"'s
589 my %element = Clearcase::Element::collapseOverExtendedVersionPathname $_;
590 my $element = Clearcase::Element->new ($element{name});
592 # Sometimes $element{name} refers to a long path name we can't easily see
593 # in our current view. In such cases the above Clearcase::Element->new will
594 # return us an element where the version is missing. Since we already have
595 # the version information we will replace it here.
597 # The following may look odd since we use similar names against different
598 # Perl variables. $element->{version} means look into the $element object
599 # returned from new above at the member version. $element{version} says
600 # refer to the %element hash defined above for the version key. And finally
601 # $element->version says call the method version of the element object.
602 # So we are saying, if the version member of the element object is not
603 # defined (i.e. $element->version) then set it (i.e. $element->{version})
604 # by using the value of the hash %element with the key version.
605 $element->{version} = $element{version}
606 unless $element->version;
608 # Additionally we will set into the $element object the extended name. This
609 # is the long pathname that we need to use from our current context to be
610 # able to access the element.
611 #$element->setExtendedName($_);
613 push @changeset, $element;
616 $self->{changeset} = \@changeset;
624 my ($status, @output) = $Clearcase::CC->execute(
625 'lsactivity ' . $self->{name} . '@' . $self->pvob->tag
632 my ($self, $stream, $headline, $opts) = @_;
638 Creates a new UCM Activity
642 =for html <blockquote>
646 =item UCM Stream(required)
648 UCM stream this activities is to be created on
650 =item PVOB (Required)
656 Headline to associate with this activity
660 =for html </blockquote>
664 =for html <blockquote>
670 Status from cleartool
678 =for html </blockquote>
683 $self->updateActivityInfo;
692 $self->{headline} = $headline;
694 $opts .= " -headline '$headline'";
697 $self->{stream} = Clearcase::UCM::Stream->new($stream, $self->{pvob});
699 return $Clearcase::CC->execute
700 ("mkactivity $opts -in " . $stream->{name} .
701 '@' . $self->pvob->{tag} .
702 ' ' . $self->{name} .
703 '@' . $self->pvob->{tag});
717 =for html <blockquote>
725 =for html </blockquote>
729 =for html <blockquote>
735 Status from cleartool
743 =for html </blockquote>
747 return $Clearcase::CC->execute
748 ('rmactivity -f ' . $self->{name} . "\@" . $self->{pvob}->name);
752 my ($self, %newAttribs) = @_;
758 Returns a hash of the attributes associated with an activity
762 =for html <blockquote>
770 =for html </blockquote>
774 =for html <blockquote>
780 Hash of attributes for this activity
784 =for html </blockquote>
788 return $self->Clearcase::attributes(
790 "$self->{name}\@" . $self->{pvob}->name,
795 sub updateActivityInfo() {
798 # Get all information that can be gotten using -fmt
799 my $fmt .= '%[crm_record_id]p==';
800 $fmt .= '%[crm_record_type]p==';
801 $fmt .= '%[crm_state]p==';
802 $fmt .= '%[headline]p==';
803 $fmt .= '%[name_resolver_view]p==';
804 $fmt .= '%[stream]Xp==';
807 if ($self->type eq 'integration') {
808 $fmt = '%[contrib_acts]CXp==';
811 $Clearcase::CC->execute(
812 "lsactivity -fmt \"$fmt\" $self->{name}@" . $self->{pvob}->name
815 # Assuming this activity is an empty shell of an object that the user may
816 # possibly use the create method on, return our blessings...
817 return if $Clearcase::CC->status;
819 # We need to make sure that fields are filled in or empty because we are using
820 # undef as an indication that we have not called updateActivityInfo yet.
821 my @fields = split '==', $Clearcase::CC->output;
823 $self->{crm_record_id} = $fields[0];
824 $self->{crm_record_type} = $fields[1];
825 $self->{crm_state} = $fields[2];
826 $self->{headline} = $fields[3];
827 $self->{name_resolver_view} = $fields[4];
828 $self->{stream} = $fields[5];
829 $self->{view} = $fields[6];
831 $self->{contrib_acts} = ();
833 if ($self->type eq 'integration') {
834 for (split ', ', $fields[7]) {
835 push @{$self->{contrib_acts}}, Clearcase::UCM::Activity->new($_);
840 } # updateActivityInfo
846 =head2 ClearSCM Perl Modules
848 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
850 =head1 INCOMPATABILITIES
854 =head1 BUGS AND LIMITATIONS
856 There are no known bugs in this module.
858 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
860 =head1 LICENSE AND COPYRIGHT
862 Copyright (c) 2007, ClearSCM, Inc. All rights reserved.