Skip to content

Commit

Permalink
(GH-976) PowerShell Functions Use Log Call Method
Browse files Browse the repository at this point in the history
In all of the appropriate methods, ensure they log that they have been
called. Many of them had a debug message already that was outdated and
needed replaced. Update them to use the function that provides the
logging by inspecting the invocation and bound parameters.
  • Loading branch information
ferventcoder committed Sep 23, 2016
1 parent be9309a commit caa3850
Show file tree
Hide file tree
Showing 32 changed files with 63 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ param(
[parameter(Mandatory=$false, Position=3)][string] $originalUrl = '',
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'Get-ChecksumValid' with file:'$file', checksum: '$checksum', checksumType: '$checksumType', originalUrl: '$originalUrl'";

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

if ($env:ChocolateyIgnoreChecksums -eq 'true') {
Write-Warning "Ignoring checksums due to feature checksumFiles turned off or option --ignore-checksums set."
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ param(
$fileFullPath=join-path $fileFullPath $specificFolder
}

Write-Debug "Running 'Get-ChocolateyUnzip' with fileFullPath:`'$fileFullPath`'', destination: `'$destination`', specificFolder: `'$specificFolder``, packageName: `'$packageName`'";
Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

if ($packageName) {
$packagelibPath = $env:ChocolateyPackageFolder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ param(
[parameter(Mandatory=$false)][switch] $forceDownload,
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'Get-ChocolateyWebFile' for $packageName with url:`'$url`', fileFullPath:`'$fileFullPath`', url64bit:`'$url64bit`', checksum: `'$checksum`', checksumType: `'$checksumType`', checksum64: `'$checksum64`', checksumType64: `'$checksumType64`'";

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

$url32bit = $url

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ param(
[Parameter(Mandatory=$false)][switch] $PreserveVariables = $false,
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

[string] $MACHINE_ENVIRONMENT_REGISTRY_KEY_NAME = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment\";
[Microsoft.Win32.RegistryKey] $win32RegistryKey = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($MACHINE_ENVIRONMENT_REGISTRY_KEY_NAME)
if ($Scope -eq [System.EnvironmentVariableTarget]::User) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Get-EnvironmentVariable
Set-EnvironmentVariable
#>

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

# HKCU:\Environment may not exist in all Windows OSes (such as Server Core).
switch ($Scope) {
'User' { Get-Item 'HKCU:\Environment' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Property }
Expand Down
2 changes: 1 addition & 1 deletion src/chocolatey.resources/helpers/functions/Get-FtpFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ param(
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)

Write-Debug "Running 'Get-FtpFile' for $fileName with url:'$url', userName: '$userName', password: '$password'";
Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

if ($url -eq $null -or $url -eq '') {
Write-Warning "Url parameter is empty, Get-FtpFile has nothing to do."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ depending on wether or not the bit width matches.
param(
$compare
)
Write-Debug "Running 'Get-OSArchitectureWidth'"

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

$bits = 64
if (([System.IntPtr]::Size -eq 4) -and (Test-Path env:\PROCESSOR_ARCHITEW6432)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ None
.OUTPUTS
None
#>
Write-Debug "Running 'Get-ToolsLocation'";

$invocation = $MyInvocation
Write-FunctionCallLogMessage -Invocation $invocation -Parameters $PSBoundParameters

if ($invocation -ne $null -and $invocation.InvocationName -ne $null -and $invocation.InvocationName.ToLower() -eq 'get-binroot') {
Write-Host "Get-BinRoot is going to be deprecated in v1 and removed in v2. It is being replaced with Get-ToolsLocation, however many packages no longer require a special separate directory since package folders no longer have versions on them. Some do though and should continue to use Get-ToolsLocation."
}
Expand Down
4 changes: 2 additions & 2 deletions src/chocolatey.resources/helpers/functions/Get-UACEnabled.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ None
System.Boolean
#>

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

$uacRegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
$uacRegValue = "EnableLUA"
$uacEnabled = $false

Write-Debug "Running 'Get-UACEnabled'"

# http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx
$osVersion = [Environment]::OSVersion.Version
if ($osVersion -ge [Version]'6.0')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ param(
[string] $softwareName,
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'Get-UninstallRegistryKey' for `'$env:ChocolateyPackageName`' with SoftwareName:`'$softwareName`'";

if ($softwareName -eq $null -or $softwareName -eq '') {
Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

if ($softwareName -eq $null -or $softwareName -eq '') {
throw "$SoftwareName cannot be empty for Get-UninstallRegistryKey"
}

Expand Down
4 changes: 2 additions & 2 deletions src/chocolatey.resources/helpers/functions/Get-WebFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ param(
[parameter(Mandatory=$false)][hashtable] $options = @{Headers=@{}},
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'Get-WebFile' for $fileName with url:`'$url`', userAgent: `'$userAgent`' ";
#if ($url -eq '' return)

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

try {
$uri = [System.Uri]$url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ param(
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)

Write-Debug "Running 'Get-WebFileName' to determine name with url:'$url', defaultName:'$defaultName'";
Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

$originalFileName = $defaultName
$fileName = $null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ param(
[parameter(Mandatory=$false, Position=1)][string] $userAgent = 'chocolatey command line',
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'Get-WebHeaders' with url:`'$url`', userAgent: `'$userAgent`'";

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

if ($url -eq '') { return @{} }

$request = [System.Net.HttpWebRequest]::Create($url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ param(
[parameter(Mandatory=$false)][string] $command = '',
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'Install-BinFile' for $name with path:`'$path`'|`$useStart:$useStart|`$command:$command";

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

$nugetPath = [System.IO.Path]::GetFullPath((Join-Path "$helpersPath" '..\'))
$nugetExePath = Join-Path "$nugetPath" 'bin'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ param(
[parameter(Mandatory=$true, Position=0)][string] $targetFilePath,
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'Install-ChocolateyDesktopLink' with targetFilePath:`'$targetFilePath`'";

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

if (!$targetFilePath) {
throw "Install-ChocolateyDesktopLink - `$targetFilePath can not be null."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ param(
[System.EnvironmentVariableTarget] $variableType = [System.EnvironmentVariableTarget]::User,
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'Install-ChocolateyEnvironmentVariable' with variableName:`'$variableName`' and variableValue:`'$variableValue`'";

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

if ($variableType -eq [System.EnvironmentVariableTarget]::Machine) {
if (Test-ProcessAdminRights) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ param(
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
try {
Write-Debug "Running 'Install-ChocolateyExplorerMenuItem' with menuKey:'$menuKey', menuLabel:'$menuLabel', command:'$command', type '$type'"

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

if($type -eq "file") {$key = "*"} elseif($type -eq "directory") {$key="directory"} else{ return 1}
$elevated = "`
if( -not (Test-Path -path HKCR:) ) {New-PSDrive -Name HKCR -PSProvider registry -Root Hkey_Classes_Root};`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ param(
[parameter(Mandatory=$true, Position=1)][string] $executable,
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'Install-ChocolateyFileAssociation' associating $extension with `'$executable`'";

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters
if(-not(Test-Path $executable)){
$errorMessage = "`'$executable`' does not exist, not able to create association"
Write-Error $errorMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ param(
)
[string]$silentArgs = $silentArgs -join ' '

Write-Debug "Running 'Install-ChocolateyInstallPackage' for $packageName with file:`'$file`', args: `'$silentArgs`', fileType: `'$fileType`', validExitCodes: `'$validExitCodes`', useOnlyPackageSilentArguments: '$($useOnlyPackageSilentArguments.IsPresent)'";
Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

$installMessage = "Installing $packageName..."
Write-Host $installMessage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ param(
)
[string]$silentArgs = $silentArgs -join ' '

Write-Debug "Running 'Install-ChocolateyPackage' for $packageName with url:'$url', args:'$silentArgs', fileType:'$fileType', url64bit:'$url64bit', checksum:'$checksum', checksumType:'$checksumType', checksum64:'$checksum64', checksumType64:'$checksumType64', validExitCodes:'$validExitCodes'";
Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

$chocTempDir = $env:TEMP
$tempDir = Join-Path $chocTempDir "$($env:chocolateyPackageName)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ param(
[parameter(Mandatory=$false)][hashtable] $options = @{Headers=@{}},
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'Install-ChocolateyZipPackage' for $packageName with url:`'$url`', unzipLocation: `'$unzipLocation`', url64bit: `'$url64bit`', specificFolder: `'$specificFolder`', checksum: `'$checksum`', checksumType: `'$checksumType`', checksum64: `'$checksum64`', checksumType64: `'$checksumType64`' ";

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

$fileType = 'zip'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ param (
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)

Write-Debug "Running 'Install-Vsix' with installer:'$installer', installFile: '$installFile'";
Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

if ($env:chocolateyPackageName -ne $null -and $env:chocolateyPackageName -eq $env:ChocolateyInstallDirectoryPackage) {
Write-Warning "Install Directory override not available for VSIX packages."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ param (
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)

Write-Debug "Calling Set-EnvironmentVariable with `$Name = '$Name', `$Value = '$Value', `$Scope = '$Scope'"
Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

if ($Scope -eq [System.EnvironmentVariableTarget]::Process -or $Value -eq $null -or $Value -eq '') {
return [Environment]::SetEnvironmentVariable($Name, $Value, $Scope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ param(
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
[string]$statements = $statements -join ' '
Write-Debug "Running 'Start-ChocolateyProcessAsAdmin' with exeToRun:'$exeToRun', statements: '$statements', workingDirectory: '$workingDirectory' ";

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

try{
if ($exeToRun -ne $null) { $exeToRun = $exeToRun -replace "`0", "" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ param(
[parameter(Mandatory=$true, Position=1)][string] $zipFileName,
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'UnInstall-ChocolateyZipPackage' for $packageName $zipFileName "

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

$packagelibPath=$env:chocolateyPackageFolder
$zipContentFile=(join-path $packagelibPath $zipFileName) + ".txt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ param(
[parameter(Mandatory=$false, Position=1)][string] $path,
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'Uninstall-BinFile' for $name with path:`'$path`'";

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

$nugetPath = [System.IO.Path]::GetFullPath((Join-Path "$helpersPath" '..\'))
$nugetExePath = Join-Path "$nugetPath" 'bin'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ param(
[System.EnvironmentVariableTarget] $variableType = [System.EnvironmentVariableTarget]::User,
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'Uninstall-ChocolateyEnvironmentVariable' with variableName:'$variableName' and variableType:'$variableType'";

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

if ($variableType -eq [System.EnvironmentVariableTarget]::Machine) {
if (Test-ProcessAdminRights) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ param(
)
[string]$silentArgs = $silentArgs -join ' '

Write-Debug "Running 'Uninstall-ChocolateyPackage' for $packageName with fileType:`'$fileType`', silentArgs: `'$silentArgs`', file: `'$file`'";
Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

$installMessage = "Uninstalling $packageName..."
write-host $installMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ None
None
#>

Write-Debug "Running 'Update-SessionEnvironment'"
Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

$refreshEnv = $false
$invocation = $MyInvocation
if ($invocation.InvocationName -eq 'refreshenv') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ param(
[string] $failureMessage,
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters
Write-Warning "Write-ChocolateyFailure is deprecated and will be removed in v2. If you are the package maintainer, please use 'throw `$_.Exception' instead."

$error | %{ $_.Exception | fl * | Out-String }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ param(
[string] $packageName,
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters
Write-Warning "Write-ChocolateySuccess is deprecated and will be removed in v2. If you are the maintainer, please remove it from your package file."
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ param (
[object[]] $argumentList,
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
Write-Debug "Running 'Write-FileUpdateLog' with logFilePath:`'$logFilePath`'', locationToMonitor:$locationToMonitor, Operation: `'$scriptToRun`'";

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

Write-Warning "Write-FileUpdateLog has been deprecated and will be removed in v1."

Expand Down

0 comments on commit caa3850

Please sign in to comment.