Using Powershell to access IBM Rational ClearCase data gives (as with just about everything that you use with PS) enormous enhancements. Here's just an example: since you can interface with COM objects from Powershell and ClearCase has a (rather useful) COM application, you gain a much more flexible and powerful access to ClearCase data and commands than with the usual cleartool commands. And it's faster.
Here's a replacement for the cleartool command, using the COM interface instead. I haven't done any real tests, but a simple "eye-measure" test with an advanced search told me it's about three times faster:
function Invoke-Cleartool
{
$CCCleartool = New-Object -COM ClearCase.Cleartool #Get all arguments as one command-line
$command = ""
$MyInvocation.UnboundArguments | Foreach-Object {
if ($_ -eq ".") {$command += " $pwd"}
else { $command += " $_" }
}
# Create a "real" array to store the result in
$result = New-Object System.Collections.ArrayList
#Parse the output and store as items in the array
($CCCleartool.CmdExec($command)).replace($pwd,".").split("`n") | Foreach-Object { $result.Add($_) >$null}
#Remove the last item (which will always be an empty string)
$result.RemoveAt($result.Count - 1)
$result
}
Update: Just noted that there's a bug here when cleartool requires quotations around the arguments (for example when calling find -name). Powershell is good at stripping any unneeded quotations from arguments, but in this case that doesn't suit me very well...
No comments:
Post a Comment