#! /usr/local/bin/perl # checkin_trigger ######################################################################## ######################################################################## # PURPOSE: CLEAR CASE CHECKIN TRIGGER # # Programmed by: David Weintraub # Date: February 4, 1997 # Description: This program uses the RCS strings and fills them # in. Certain strings can be marked as "required" # and checks will fail if they aren't found in the file. # ######################################################################## ######################################################################## # REQUIRE STRINGS # # A little backwards, but simple. If the value of the following is # zero, the RCS string is required, and a checkin won't procede if # not found. # $require{"Author"} = 1; #Name of User who Checked in Program $require{"Date"} = 1; #Date & Time (GMT) $require{"Header"} = 1; #$directory/$CLEARCASE_XPN Date Author $require{"Id"} = 0; #$CLEARCASE_XPN Date Author $require{"Name"} = 1; #Program's Name $require{"Revision"} = 1; #branch/revision $require{"Source"} = 1; #$CLEARCASE_XPN $require{"Log"} = 0; #This is where Checkin Comments go! $logLength = 10; #Minmum size required for comments. # ######################################################################## ######################################################################## # CONSTANTS # $Author = $author = "$ENV{CLEARCASE_USER}"; $Date = `date -u +"%h %d, 19%y %T GMT"`; $Name = "$ENV{CLEARCASE_PN}"; $Revision = "$ENV{CLEARCASE_ID_STR}"; $Source = $Name; $Log = $ENV{'CLEARCASE_COMMENT'}; chop($Date); #Remove NL from Date String $Name =~ s+.*/++; #Remove Directory Information @userName = getpwnam("$Author"); $userName = $userName[6]; $Author = "$userName ($Author)"; $Header = "${Source}\@\@$Revision ${Date} ${author}"; $Id = "${Name}\@\@${Revision} ${Date} ${author}"; $whatID="@(#)"; $workFile = "/tmp/ct.ci.$$"; # ######################################################################## ######################################################################## # CHECK COMMENT LENGTH # if (length($Log) < $logLength) { $message = "Your Checkin Comment must be at least $logLength character\n"; $message .= "long. Redo the Checkin with a longer comment\n"; error("$message"); } # ######################################################################## ######################################################################## # CHECK FILE TYPES # # Permit checkins on all non-text types of files # exit 0 if ("$ENV{CLEARCASE_ELTYPE}" !~ /text/); # ######################################################################## ######################################################################## # OPEN WORK FILE AND SOURCE FILE # open("SOURCE", "$Source") || &error("Could not open Source File \"$workFile\" for reading"); open("WORKFILE", ">$workFile") || &error ("Could not open Work File \"$workFile\" for writing"); # ######################################################################## ######################################################################## # LOOP THROUGH FILE AND FIND WHAT STRINGS # while () { $LogLineState = 0; if (/\$Author:?.*\$/) { s/\$Author:?.*\$/\$Author: $Author \$/; $require{"Author"} = 1; } if (/\$Date:?.*\$/) { s/\$Date:?.*\$/\$Date: $Date \$/; $require{"Date"} = 1; } if (/\$Header:?.*\$/) { s/\$Header:?.*\$/\$Header: $whatID $Header \$/; $require{"Header"} = 1; } if (/\$Id:?.*\$/) { s/\$Id:?.*\$/\$Id: $whatID $Id \$/; $require{"Id"} = 1; } if (/\$Name:?.*\$/) { s/\$Name:?.*\$/\$Name: $Name \$/; $require{"Name"} = 1; } if (/\$Revision:?.*\$/) { s/\$Revision:?.*\$/\$Revision: $Revision \$/; $require{"Revision"} = 1; } if (/\$Source:?.*\$/) { s/\$Source:?.*\$/\$Source: $Source \$/; $require{"Source"} = 1; } if (/\$Log:?.*\$/) { $LogLineState = 1; s/^(.*)\$Log:?.*\$/${1}\$Log: ${Name} \$/; $LogLinePrefix = $1; $require{"Log"} = 1; } print WORKFILE; if($LogLineState) { print WORKFILE "$LogLinePrefix $Revision $Date $Author\n"; # $wip = `cleartool desc -aattr WIP $Source | awk -F\= '/\"/ {print $2}'`; # $wip =~ s/.*"([^"]*)".*/$1/; print WORKFILE "${LogLinePrefix} * DDTs Ticket Number:$wip" if $wip; if ($Log) { $LogLine = "$Log"; $LogLine =~ s/^([^\n]*)/${LogLinePrefix} ${1}/; $LogLine =~ s/\n([^\n]*)/\n${LogLinePrefix} ${1}/g; print WORKFILE "$LogLine\n"; } } } # ######################################################################## ######################################################################## # CLOSE FILES # close WORKFILE; close SOURCE; # ######################################################################## ######################################################################## # CHECK TO SEE IF ALL REQUIRED FIELDS ARE FOUND # $requireFlag = 1; #Assume everything is okay $message = ""; foreach $RCSkeyword (keys(%require)) { if ($require{"$RCSkeyword"} == 0) { $requireFlag = 0; #Missing a Required Keyword! $message .= "RCS Keyword <$RCSkeyword> is required but not found\n"; } } if ($requireFlag == 0) { $message .= "\nRequired RCS Keywords are missing from file <$Name>.\n"; $message .= "Reedit this file and insert the missing RCS Keywords\n"; &error("$message"); } ######################################################################## # COPY FILE TO LOCATION # # I'd love just to use the "mv" command, but Windoze NT is a pain. # I'll have to do the whole thing manually; open (WORKFILE, "$workFile") || &error ("Could not open Work File \"$workFile\" for reading"); open (SOURCE, ">$Source") || &error ("Could not open Source File \"$workFile\" for writing"); while() { print SOURCE; } close(WORKFILE); close(SOURCEFILE); unlink($workFile); # ######################################################################## ######################################################################## # SUBROUTINE ERROR # sub error { local ($prompt = @_[0]); local ($errorProg="$ENV{ATRIAHOME}/bin/clearprompt"); local ($flags = "proceed -type error -default abort -mask abort"); system("$errorProg $flags -prompt \"$prompt\""); exit 2; }