It's all about the answers!

Ask a question

How to get modified dates of remote files in baseline using the command line (scm)


Richard Good (872159) | asked Jan 14 '16, 11:16 a.m.

Trying to get a list of the files in a particular baselines along with their version numbers and last changed dates, think I need a combination of the following commands: - 

lscm list remotefiles

lscm list changesets

lscm list changes

Seems like this should be easier, am I missing a trick, really hoping for some sort of date parameter on the lscm list remotefiles command or some way to get the changeset from the each file listed in the list remotefiles command. Any top tips ;-)

Thanks

Richard

3 answers



permanent link
Surya Tripathi (65017) | answered Jan 14 '16, 7:41 p.m.
edited Jan 14 '16, 7:42 p.m.
The only way I can think of getting what you need is by following these commands, similar to what you have suggested -

1. Get the baseline.
You can run the command
>lscm list baselines -C <component id> -r <repository> -P <password> -u <userid>

2. Use a baseline to get all changesets in it
>lscm list changesets -C <component id> -b <baseline id> -r <repository> -P <password> -u <userid>
The result will look like this -
Change sets:
  (1079) ----$ Surya Tripathi "abc.def.ghj" 14-Jan-2016 03:18 PM
  (1080) ----$ Surya Tripathi "Share" 17-Dec-2015 10:57 PM
  (1081) ----$ Surya Tripathi "Share" 17-Dec-2015 10:52 PM
  (1082) ----$ Surya Tripathi "Initial for Comp1" 17-Dec-2015 10:48 PM


3. You can get changes for multiple changesets in one command-
>lscm list changes 1079 1080 1081 1082 -r <repository> -P <password> -u <userid> -i
The result will look like this -
Change sets:
  (1079) ----$ Surya Tripathi "abc.def.ghj"
    Component: (1076) "Comp1"
    Modified: 14-Jan-2016 03:18 PM
    Changes:
      --a-- (1083) \<unresolved>\.project  [ -> 1]
      --a-- (1084) \<unresolved>\.project  [ -> 1]
      ---c- (1085) \<unresolved>\Form1.cs  [1 -> 2]
      ---c- (1086) \<unresolved>\Form1.Designer.cs  [1 -> 2]
      --a-- (1087) \<unresolved>\Form1.resx  [ -> 1]
  (1080) ----$ Surya Tripathi "Share"
    Component: (1076) "Comp1"
    Modified: 17-Dec-2015 10:57 PM
    Changes:
      --a-- (1088) \<unresolved>\.jazzignore  [ -> 1]
      --a-- (1089) \<unresolved>\.jazzignore  [ -> 1]
      --a-- (1090) \<unresolved>\.jazzignore  [ -> 1]
      --a-- (1091) \<unresolved>\App.config  [ -> 1]
      --a-- (1092) \<unresolved>\AssemblyInfo.cs  [ -> 1]

   .
   .
   .
   .






permanent link
Richard Good (872159) | answered Mar 03 '16, 11:43 a.m.

I have come back to this problem after being taken away to do other things. I have managed to create a powershell script that processes the JSON output of the commands similar to those mentioned by Surya to give the required output. i.e filename, modification date, version number for each file in the baseline.

I now ideally wish to have this on an eclipse menu item

So a corollary to this issue is:  

How best would I integrate this tool with rtc / is it possible. I really want to right click on a baseline in a component in a stream and have a menu item that comes up saying "output listing with dates and version" or similar. Is this possible, some sort of plugin/ extension maybe or is it best for it to be an external tool?


Comments
Don Yang commented Mar 03 '16, 5:43 p.m.

Hi, Richard

Can you check if this feature from v5.0.1 works for you?
https://jazz.net/downloads/rational-team-concert/releases/5.0.1?p=news#AddByInfoInHistoryView


Richard Good commented Mar 04 '16, 4:42 a.m.

Thanks, but not really what I want, I'm after a listing of the contents of a baseline along with their last modified date and version number, not really interested in changeset numbers for this task


permanent link
Richard Good (872159) | answered Mar 08 '16, 4:44 a.m.
edited Mar 10 '16, 5:45 a.m.

Might as well add my solution for completeness! I think this forum should allow file attachments, you lose something by having to paste things in the old fashioned way

The following is the batchfile I use to fire my powershell script: -

::Example Invocation remember quotes even if there are no spaces
::runProcRemoteFiles.bat "DXL-Build-Workspace" "snapshot.B20151217-1742" "MODULE_ADDINS_STREAM_2" "https://server:9443/ccm" "userName" "pass"
::runProcRemoteFiles.bat "<wspaceOrStream>" "<baseline>" "<component>" "<repository>" "<userName>" "<password>"
::change scmLoc for your own environment and change start time for the inception date
setlocal
set scmLoc=C:\Richards-Programs\RTC-5-0-2\jazz\scmtools\eclipse\scm
set startTime=02-Jan-2015 12:00 PM
powershell -NoProfile -ExecutionPolicy Bypass -file "processRemoteFiles.ps1" %* "%scmLoc%" "%startTime%"
endlocal

And the powershell script processRemoteFiles.ps1 is as follows (edited to fix school boy error regarding spaces in component/ baseline/ stream names): -

#send workspace, baseline, component, repository url, username, userPassword  and  on the command line and process in this powershell script
#batch file should live in the same directory as the script
#batch file should be one line similar to the following (assumes powershell v3 or higher (need JSON processing) and powershell on the path): -
#powershell -NoProfile -ExecutionPolicy Bypass -file "processRemoteFiles.ps1" "DXL-Build-Workspace" "snapshot.B20151217-1742" "MODULE_ADDINS_STREAM_2" "https://server:9443/ccm" "user" "pass" "C:\Richards-Programs\RTC-5-0-2\jazz\scmtools\eclipse\scm", "02-Jan-2015 12:00 PM";

#this could be fired by calling listBaselineDetails.bat providing just the required details
#such that you get listBaselineDetails "DXL-Build-Workspace" "snapshot.B20151217-1742" "MODULE_ADDINS_STREAM_2" "https://server:9443/ccm" "pass" "pass"
#so you would then have the following line in the batch file
#powershell -NoProfile -ExecutionPolicy Bypass -file "processRemoteFiles.ps1" %* %scmLoc% %startTime%
#alternatively I can learn how o write an eclipse plugin and have any one wanting to use this install my tool as they do any other plugin
#this is the kind of thing I can do in dimensions, works differrently in RTC so have to learn new techniques!

#for debugging: -
#$args="Review Database System Stream", "Baseline December 2015", "RDS Source Code", "https://server:port/ccm", "user", "pass", "C:\Richards-Programs\RTC-5-0-2\jazz\scmtools\eclipse\scm", "02-Jan-2015 12:00 PM";
#$scmLocation ="C:\Richards-Programs\RTC-5-0-2\jazz\scmtools\eclipse\scm";

$scmLocation =$args[6]
$startTime = $args[7]


#I'm going to fire scm multiple times we will use the following process setup multiple times with differrent arguments
#easier to understand if we write the arguments in here and split into arrays
#can't seem to use lscm some sort of issue with powershell firing batch files with arguments, the daemon I start may achieve nothing!
$psi=New-Object System.Diagnostics.ProcessStartInfo;
$psi.CreateNoWindow =$true;
$psi.UseShellExecute = $false;
$psi.ReDirectStandardOutput = $true;
$psi.RedirectStandardError = $true;
$psi.FileName = $scmLocation;
$psi.Arguments = $comLineArgs;
$process = New-Object System.Diagnostics.Process;
$process.StartInfo = $psi;
[void]$process.Start();
$loginMess = $process.StandardOutput.ReadToEnd();
$process.WaitForExit(10000);
#Write-Output "got passed logon " $loginMess;


#cope with spaces in names - I never use them so made school boy error in first version
$commands ="list remotefiles --show-versionid --depth - -b replaceWithBaseline replaceWithComponent ""/"" -j -r $($args[3]) -u $($args[4]) -P $($args[5])";
$comLineArgs = $commands.Split(" ");
$comLineArgs[6]="""$($args[1])"""
$comLineArgs[7]="""$($args[2])"""
#Write-Output $comLineArgs;
$psi.FileName = $scmLocation;
$psi.Arguments = $comLineArgs;
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $psi;
[void]$process.Start();
$jsonObject = $process.StandardOutput.ReadToEnd();
$theseErrs = $process.StandardError.ReadToEnd();
$process.WaitForExit(20000);
$remFiles = ConvertFrom-Json -InputObject $jsonObject;
#Write-Output "got passed remote file";


#declare a hashtable and add items for all files
$fileModTime = @{}

#remote file hashtable used to avoid adding deleted files to the listing
$remFileList= @{}
foreach ($line in $remFiles."remote-files") {
    $thisPath = $line.path.Replace("/","\");
    $remFileList[$thisPath]=$true;
}

#List changesets in baseline we want the modification date and the UUID of each item need to cope with spaces in component and baseline name
#$commands = "& C:\Richards-Programs\RTC-5-0-2\jazz\scmtools\eclipse\lscm.bat list changesets -C MODULE_ADDINS_STREAM_2 -b snapshot.B20151217-1742 -j -r https://server:9443/ccm -u user -P pass";
$commands = "list changesets -C replaceWithComponent -b replaceWithBaseline -j  -r $($args[3]) -u $($args[4]) -P $($args[5])";
$comLineArgs = $commands.Split(" ");
$comLineArgs[3]="""$($args[2])"""
$comLineArgs[5]="""$($args[1])"""

$psi.Arguments = $comLineArgs;
$process = New-Object System.Diagnostics.Process;
$process.StartInfo = $psi;
[void]$process.Start();
$jsonObject = $process.StandardOutput.ReadToEnd();
$process.WaitForExit(10000);
$changeSets = ConvertFrom-Json -InputObject $jsonObject;


#list changes in each changeset in turn latest changesets appear first so if an entry exists just skip over it
foreach ($cs in $changeSets.changes) {
    #run changes command on each changeset, latest is always first need to cope with spaces in stream and baseline name
    $commands = "list changes $($cs.uuid) -w replaceWithStream -b replaceWithBaseline -j -r $($args[3]) -u $($args[4]) -P $($args[5])";
    $comLineArgs = $commands.Split(" ");
    $comLineArgs[4]="""$($args[0])"""
    $comLineArgs[6]="""$($args[1])"""


    $psi.Arguments = $comLineArgs;
    $process = New-Object System.Diagnostics.Process;
    $process.StartInfo = $psi;
    [void]$process.Start();
    $jsonObject = $process.StandardOutput.ReadToEnd();
    $process.WaitForExit(10000);
    $changes = ConvertFrom-Json -InputObject $jsonObject;   
   
    foreach ($thisChange in $changes.changes) {
        foreach($thisFile in $thisChange.changes) {
            if(! $fileModTime.contains($thisFile.path)) {
                #avoid adding entries for files that have been deleted!
                if($remFileList.Contains($thisFile.path)) {
                    $fileModTime[$thisFile.path]= $cs.modified
                }
            }
        }
    }  
}


#fill in blanks for files that have never changed, could be component inception date, RTC doesn't record this so not easy to guess/ query!
foreach ($line in $remFiles."remote-files") {
   $thisPath = $line.path.Replace("/","\");
   if(! $fileModTime.contains($thisPath)) {
        #this is an arbitary start time, if the file hasn't changed then we need a ground zero
        $fileModTime[$thisPath]= $startTime
   }
   #avoid adding version to folders
    if($line.version."short-id" -ne $null) {
        $fileModTime[$thisPath]= $fileModTime[$thisPath] + ";" + $line.version."short-id"
    }
}


#print out baseline details in hashtable sort hashtable on name
$fileModTime=$fileModTime.GetEnumerator() | Sort-Object -Property Name

#need to specify width of line, if running from batch file else command window settings anomaly truncates line length to 60 (depends on your PC)
#so I hardcode the width setting to a high number to solve it, then send the file to the temp directory
$fileModTime.GetEnumerator()| Format-Table -Property Name,Value -AutoSize -Wrap -HideTableHeaders| Out-File -Width 600 -Force $env:TEMP\filesInBaselineListing.txt
#open listing with notepad
& notepad.exe $env:TEMP\filesInBaselineListing.txt


Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.