Various changes and additions for UCM and testing things
[clearscm.git] / lib / Clearcase / UCM / Stream.pm
index 0cdc198..496bee3 100644 (file)
@@ -28,9 +28,9 @@ $Date: 2011/11/15 02:00:58 $
 
 =head1 SYNOPSIS
 
-Provides access to information about Clearcase Elements.
+Provides access to information about Clearcase Streams.
 
-  my $stream= new Clearcase::UCM::Stream ($name, $pvob);
+  my $stream = new Clearcase::UCM::Stream ($name, $pvob);
 
 =head1 DESCRIPTION
 
@@ -47,11 +47,8 @@ package Clearcase::UCM::Stream;
 use strict;
 use warnings;
 
-use Clearcase;
-use Clearcase::UCM::Baseline;
-
 sub new ($$) {
-  my ($class, $stream, $pvob) = @_;
+  my ($class, $name, $pvob) = @_;
 
 =pod
 
@@ -65,10 +62,14 @@ Parameters:
 
 =over
 
-=item stream name
+=item name
 
 Name of stream
 
+=item pvob
+
+Associated pvob
+
 =back
 
 =for html </blockquote>
@@ -87,12 +88,12 @@ Returns:
 
 =cut
 
-  my $self = bless {
-    name => $stream,
-    pvob => Clearcase::vobtag $pvob,
+  $class = bless {
+    name => $name,
+    pvob => $pvob,
   }, $class; # bless
     
-  return $self
+  return $class
 } # new
   
 sub name () {
@@ -171,8 +172,8 @@ Returns:
   return $self->{pvob};
 } # pvob
   
-sub create ($$;$$) {
-  my ($self, $project, $pvob, $baseline, $opts) = @_;
+sub create ($;$) {
+  my ($self, $project, $opts) = @_;
 
 =pod
 
@@ -186,21 +187,13 @@ Parameters:
 
 =over
 
-=item UCM Project (required)
-
-UCM Project this stream belongs to
-
-=item PVOB (Required)
-
-Project Vob
-
-=item baseline
+=item project
 
-Baseline to set this stream to
+Project that this stream will be created in
 
 =item opts
 
-Options: Additional options to use (e.g. -readonly)
+Options: Additional options to use (e.g. -baseline/-readonly)
 
 =back
 
@@ -226,30 +219,17 @@ Ouput from cleartool
 
 =cut
 
-  # Fill in object members
-  $self->{project}  = $project;
-  $self->{pvob}     = $pvob;
-    
-  # Fill in opts   
+  return (0, ()) if $self->exists;
+
   $opts ||= '';
-  $opts .= " -baseline $baseline"
-    if $baseline;  
-      
+
   $self->{readonly} = $opts =~ /-readonly/;
-  
-  # TODO: This should call the exists function
-  # Return the stream name if the stream already exists
-  my ($status, @output) = 
-    $Clearcase::CC->execute ('lsstream -short ' . $self->{name}); 
 
-  return ($status, @output)
-    unless $status;
-    
-  # Need to create the stream
-  return $Clearcase::CC->execute 
-    ("mkstream $opts -in " . $self->{project} .
-     "\@"                  . $self->{pvob}    .
-     ' '                   . $self->{name});
+  return $Clearcase::CC->execute(
+    "mkstream $opts -in "
+       . $project->name . '@' . $self->{pvob}->tag . ' '
+       . $self->name    . '@' . $self->{pvob}->tag
+  );
 } # create
 
 sub remove () {
@@ -267,21 +247,56 @@ Parameters:
 
 =over
 
-=item UCM Project (required)
+=back
+
+=for html </blockquote>
+
+Returns:
+
+=for html <blockquote>
+
+=over
+
+=item $status
+
+Status from cleartool
+
+=item @output
+
+Ouput from cleartool
+
+=back
+
+=for html </blockquote>
+
+=cut
+
+  return $Clearcase::CC->execute 
+    ('rmstream -f ' . $self->{name} . '@' . $self->{pvob}->name);
+} # rmStream
+
+sub rebase($;$) {
+  my ($self, $baseline, $opts) = @_;
+
+=pod
+
+=head2 rebase
 
-UCM Project this stream belongs to
+Rebases a UCM Stream
 
-=item PVOB (Required)
+Parameters:
 
-Project Vob
+=for html <blockquote>
+
+=over
 
 =item baseline
 
-Baseline to set this stream to
+Baseline to rebase to
 
 =item opts
 
-Options: Additional options to use (e.g. -readonly)
+Any additional opts
 
 =back
 
@@ -307,9 +322,61 @@ Ouput from cleartool
 
 =cut
 
-  return $Clearcase::CC->execute 
-    ('rmstream -f ' . $self->{name} . "\@" . $self->{pvob});
-} # rmStream
+  $opts ||= '';
+
+  $opts .= ' -baseline ' . $baseline  .
+           ' -stream '   . $self->name . '@' . $self->{pvob}->name;
+
+  return $Clearcase::CC->execute("rebase $opts");
+} # rebase
+
+sub recommend($) {
+  my ($self, $baseline) = @_;
+
+=pod
+
+=head2 recommend
+
+Recommends a baseline in a UCM Stream
+
+Parameters:
+
+=for html <blockquote>
+
+=over
+
+=item baseline
+
+Baseline to recommend
+
+=back
+
+=for html </blockquote>
+
+Returns:
+
+=for html <blockquote>
+
+=over
+
+=item $status
+
+Status from cleartool
+
+=item @output
+
+Ouput from cleartool
+
+=back
+
+=for html </blockquote>
+
+=cut
+
+  return $Clearcase::CC->execute(
+    "chstream -recommended $baseline " . $self->name . '@' . $self->{pvob}->tag
+  );
+} # recommend
 
 sub baselines () {
   my ($self) = @_;
@@ -356,15 +423,57 @@ An array of baseline objects for this stream
 
   my @baselines;
   
-  foreach ($Clearcase::CC->output) {
+  for ($Clearcase::CC->output) {
     my $baseline = Clearcase::UCM::Baseline->new ($_, $self->{pvob});
     
     push @baselines, $baseline;
-  } # foreach
+  } # for
   
   return @baselines;
 } # baselines
 
+sub exists() {
+  my ($self) = @_;
+
+=pod
+
+=head3 exists
+
+Return true if the stream exists - false otherwise
+
+Paramters:
+
+=for html <blockquote>
+
+=over 
+
+=item none
+
+=back
+
+=for html </blockquote>
+
+Returns:
+
+=for html <blockquote>
+
+=over
+
+=item boolean
+
+=back
+
+=for html </blockquote>
+
+=cut
+
+  my ($status, @output) = $Clearcase::CC->execute(
+    'lsstream ' . $self->{name} . '@' . $self->{pvob}->name
+  );
+
+  return !$status;
+} # exists
+
 1;
 
 =head1 DEPENDENCIES
@@ -374,6 +483,7 @@ An array of baseline objects for this stream
 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
 
 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase/UCM/Baseline.pm">Clearcase::UCM::Baseline</a></p>
+=for html <p><a href="/php/scm_man.php?file=lib/Clearcase/UCM/Project.pm">Clearcase::UCM::Project</a></p>
 
 =head1 INCOMPATABILITIES