Subversion Repositories DevTools

Rev

Blame | Last modification | View Log | RSS feed

########################################################################
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
#
# Module name   : rmMerge_process.pl
# Module type   : JATS Utility
# Compiler(s)   : Perl
# Environment(s): jats
#
# Description   : Transfer a package from rmNew to rmOld with a bunch
#                 of assumptions
#                 
#
# Usage         : See POD at the end of this file
#
#......................................................................#

require 5.008_002;
use strict;
use warnings;

use Pod::Usage;
use Getopt::Long;

use JatsError;
use JatsRmApi;
use JatsSystem;
use FileUtils;
use ConfigurationFile;
use JatsProperties;
use File::Copy;
use DBI;
my $RM_DB;

my $opt_help=0;
my $opt_verbose=0;
my $opt_debug=0;
my $opt_replace;

my $VERSION = "1.0";
my @oldRMCred = ('OLD', 'jdbc:oracle:thin:@auawsards001:1521:RELEASEM', 'RM_READONLY', 'RM_READONLY');
my @newRMCred = ('NEW', 'jdbc:oracle:thin:@auawsards002:1521:RELEASEM', 'RM_READONLY', 'Tp8WmmDKMq2Z');

my $pname;
my $pversion;
my %oldData;
my %newData;
my $data;

#-------------------------------------------------------------------------------
# Function        : Mainline Entry Point
#
# Description     :
#
# Inputs          :
#
my $result = GetOptions (
                "help:+"        => \$opt_help,
                "manual:3"      => \$opt_help,
                "verbose:+"     => \$opt_verbose,
                "debug:+"       => \$opt_debug,
                "replace!"      => \$opt_replace,
                );

                #
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
                #

#
#   Process help and manual options
#
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
pod2usage(-verbose => 1) if ( $opt_help == 2 );
pod2usage(-verbose => 2) if ( $opt_help > 2 );
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ( $#ARGV != 1 );

#
#   Configure the error reporting rmMerge_process now that we have the user options
#
ErrorConfig( 'name'    =>'TRANSFER',
             'verbose' => $opt_verbose,
             'debug' => $opt_debug,
            );

#
# 
$pname = $ARGV[0];  
$pversion = $ARGV[1];

#
#   Determine matching Release Names
#
getReleaseData(\%oldData, @oldRMCred);
getReleaseData(\%newData, @newRMCred);

DebugDumpData("oldData", \%oldData);
DebugDumpData("newData", \%newData);

#
#   Sanity tests
Error ("Package version not found in old RM") unless exists $oldData{PV_ID};
Error ("Package version not found in new RM") unless exists $newData{PV_ID};
Error ("Package looks as though its been transferred. Source path contains a valid SVN server name") if (($oldData{SRC_PATH} =~ m~AUPERASVN01~) && !$opt_replace);

#
#   Extract the 'new' package files into a known area
#   Don't need the .svn info - just the files
# 
my $newWs = "${pname}_${pversion}.new";
$newWs =~ s~[()]~_~g;

RmDirTree($newWs);
my $rv = JatsCmd('-logfile', "${pname}_${pversion}.new.log",'jats_vcsrelease.pl', '-extractfiles', '-noprefix', '-root=.', '-view', $newWs ,'-label', $newData{VCS_TAG} );
Error ("Cound not extract package from New RM") if $rv;

#
#   Extract the 'old' package files into a known area
#   Need svn info
#   Need to massage the newVcs to extract the tip of the package in the old system
#       Assume its in the same location
#       Assume we are simply appending the new version to the tip of the old version
#       
my $oldVcs = $newData{VCS_TAG};
$oldVcs =~ s~AUPERASVN02~AUPERASVN01~;
$oldVcs =~ m~SVN::(.*)::~;
$oldVcs = $1;
$oldVcs =~ s~/trunk$~~;

#
#   Use the 'jats svn import' utility
#       It will do most of the hard work as it was developed to support the ClearCase to Subversion migration
#
my $dataFile = "${pname}_${pversion}.dat";

my @args;
push (@args, '-replace') if $opt_replace;

if ($oldData{COMMENTS}) {
    push @args, '-log', $oldData{COMMENTS}
}

if ($oldData{MODIFIER_NAME}) {
    push @args, '-author', $oldData{MODIFIER_NAME}
}

my $created = $oldData{MODIFIED_STAMP};
if ( $created )
{
    $created =~ s~ ~T~;
    $created .= '00000Z';
    push @args, '-date', $created;
}

if ($oldVcs =~ m~(.*)/branches/(.*)~) {
    $oldVcs = $1;
    push @args, '-branch', $2;
}


Message ('-logfile', "${pname}_${pversion}.old.log", 'jats_svn', 'import', $oldVcs, '-dir' , $newWs, '-datafile' ,  $dataFile, '-label', "${pname}_${pversion}", @args);
$rv = JatsCmd ('-logfile', "${pname}_${pversion}.old.log", 'jats_svn', 'import', $oldVcs, '-dir' , $newWs, '-datafile' ,  $dataFile, '-label', "${pname}_${pversion}", @args);
Error ("Cound not import package from OLD RM") if $rv;

#
#   Extract the Release Manager tag
#   Needs to be inserted into the database
#   
if ( -f $dataFile  )
{
    my $rmData = JatsProperties::New($dataFile);
    if ( $rmData->getProperty('subversion.tag') ) {
        $data->{rmRef} = 'SVN::' . $rmData->getProperty('subversion.tag');
    } else {
        Warning ("Property files has no subversion.tag");
    }
    $data->{fileCount}    = $rmData->getProperty('files.base', 0);
    $data->{filesRemoved} = $rmData->getProperty('files.removed',0);
    $data->{filesAdded}   = $rmData->getProperty('files.added',0);
}

unless ( $data->{rmRef}  )
{
    $data->{errStr} = 'Failed to determine Rm Reference';
    Error ($data->{errStr});
}
intoReleaseManager( $oldData{PV_ID}, "${pname}_${pversion}", $data->{rmRef}, @oldRMCred);

#-------------------------------------------------------------------------------
# Function        : intoReleaseManager
#
# Description     : Update VCS tags in RM
#
# Inputs          : $pvid           - PVId
#                   $pvname         - Package Version (text)
#                   $tag            - New Tag
#
# Returns         : 
#
sub intoReleaseManager
{
    my ($pvid, $pvname, $new_tag, $id, $url, $name, $passwd ) = @_;
    my @row;
    my $user = 3768;            # buildadm

    $ENV{GBE_RM_LOCATION} = $url;
    $ENV{GBE_RM_USERNAME} = $name;
    $ENV{GBE_RM_PASSWORD} = $passwd;
    connectRM(\$RM_DB, $opt_verbose) unless $RM_DB;

    Message ("ToRm: $pvid, $pvname  - $new_tag");
    my $m_sqlstr =  "begin release_manager.PK_RMAPI.update_vcs_details($pvid, '$new_tag', $user); end;";
    my $sth = $RM_DB->prepare($m_sqlstr);
    if ( defined($sth) )
    {
        if ( $sth->execute( ) )
        {
            if ( $sth->rows )
            {
                while ( @row = $sth->fetchrow_array )
                {
                    print "Data: @row\n";
                }
            }
            $sth->finish();
        }
        else
        {
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
        }
    }
    else
    {
        Error("Prepare failure" );
    }
    disconnectRM(\$RM_DB);
}

#-------------------------------------------------------------------------------
# Function        : getReleaseData 
#
# Description     : Get some essential data
#
# Inputs          : dataRef
#                   RmCredentails 
#
# Returns         : 
#
sub getReleaseData
{
    my ($dataRef, $id, $url, $name, $passwd) = @_;

    my (@row);

    Message ("Extract data for $id: $pname $pversion");

    $ENV{GBE_RM_LOCATION} = $url;
    $ENV{GBE_RM_USERNAME} = $name;
    $ENV{GBE_RM_PASSWORD} = $passwd;

    connectRM(\$RM_DB);

    # First get details from pv_id

    my $m_sqlstr = <<"SQL_END";
        SELECT
            pv.pv_id,
            pv.src_path,
            pv.pkg_label,
            release_manager.PK_RMAPI.return_vcs_tag(PV_ID) as vcsTag,
            pv.comments,
            u.user_name,
            pv.modified_stamp
        FROM
            package_versions pv,
            packages p,
            users u
        WHERE
            p.pkg_id = pv.pkg_id
            AND p.pkg_name = ':pname'
            AND pv.pkg_version = ':pversion'
            AND pv.modifier_id = u.user_id
SQL_END
    $m_sqlstr =~ s~:pname~$pname~g;
    $m_sqlstr =~ s~:pversion~$pversion~g;
    #Debug0("getReleaseData", $m_sqlstr);
    my $sth = $RM_DB->prepare($m_sqlstr);
    if ( defined($sth) )
    {
        if ( $sth->execute( ) )
        {
            if ( $sth->rows )
            {
                while ( @row = $sth->fetchrow_array )
                {
                    $dataRef->{PV_ID} = $row[0]; 
                    $dataRef->{SRC_PATH} = $row[1]; 
                    $dataRef->{PKG_LABEL} = $row[2]; 
                    $dataRef->{VCS_TAG} = $row[3]; 
                    $dataRef->{COMMENTS} = $row[4]; 
                    $dataRef->{MODIFIER_NAME} = $row[5]; 
                    $dataRef->{MODIFIED_STAMP} = $row[6]; 
                }
            }
            $sth->finish();
        }
        else
        {
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
        }
    }
    else
    {
        Error("Prepare failure" );
    }

    disconnectRM(\$RM_DB);
}