From c84ad06016da4dffd5efc74ad02d6a09a51cc7eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bere=C5=BCa=C5=84ski?= Date: Fri, 1 Dec 2017 21:50:44 +0100 Subject: [PATCH] chocolatey-visualstudio.extension: read manifests from layout, if present GitHub-Issue: GH-7 GH-8 GH-10 GH-26 --- .../extensions/Get-VSChannelManifest.ps1 | 7 +--- .../extensions/Get-VSComponentManifest.ps1 | 10 ++--- .../extensions/Resolve-VSLayoutPath.ps1 | 42 +++++++++++++++++++ 3 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 chocolatey-visualstudio.extension/extensions/Resolve-VSLayoutPath.ps1 diff --git a/chocolatey-visualstudio.extension/extensions/Get-VSChannelManifest.ps1 b/chocolatey-visualstudio.extension/extensions/Get-VSChannelManifest.ps1 index a20a575a..f01c838a 100644 --- a/chocolatey-visualstudio.extension/extensions/Get-VSChannelManifest.ps1 +++ b/chocolatey-visualstudio.extension/extensions/Get-VSChannelManifest.ps1 @@ -84,11 +84,8 @@ function Get-VSChannelManifest Write-Debug "Fallback: using hardcoded channel manifest URI: '$manifestUri'" } - # TODO: if bootstrapperPath present, check for existence of ChannelManifest.json instead of downloading the VS component manifest - # TODO: same for installLayoutPath - - # TODO: pass -LayoutPath - $manifest = Get-VSManifest -Description 'channel manifest' -Url $manifestUri -LayoutFileName 'ChannelManifest.json' + $layoutPath = Resolve-VSLayoutPath -PackageParameters $PackageParameters + $manifest = Get-VSManifest -Description 'channel manifest' -Url $manifestUri -LayoutFileName 'ChannelManifest.json' -LayoutPath $layoutPath return $manifest } diff --git a/chocolatey-visualstudio.extension/extensions/Get-VSComponentManifest.ps1 b/chocolatey-visualstudio.extension/extensions/Get-VSComponentManifest.ps1 index 972c93ba..7c973876 100644 --- a/chocolatey-visualstudio.extension/extensions/Get-VSComponentManifest.ps1 +++ b/chocolatey-visualstudio.extension/extensions/Get-VSComponentManifest.ps1 @@ -8,10 +8,12 @@ function Get-VSComponentManifest [System.Collections.IDictionary] $ChannelManifest ) + $layoutPath = Resolve-VSLayoutPath -PackageParameters $PackageParameters + if ($ChannelManifest -eq $null) { Write-Debug 'Obtaining the channel manifest' - $ChannelManifest = Get-VSChannelManifest -PackageParameters $PackageParameters -ProductReference $ProductReference + $ChannelManifest = Get-VSChannelManifest -PackageParameters $PackageParameters -ProductReference $ProductReference -LayoutPath $layoutPath } Write-Debug 'Parsing the channel manifest' @@ -23,12 +25,8 @@ function Get-VSComponentManifest return $null } - # TODO: if bootstrapperPath present, check for existence of Catalog.json instead of downloading the VS component manifest - # TODO: same for installLayoutPath - - # TODO: pass -LayoutPath # TODO: pass -Checksum and -ChecksumType - $catalogManifest = Get-VSManifest -Description 'catalog manifest' -Url $url -LayoutFileName 'Catalog.json' + $catalogManifest = Get-VSManifest -Description 'catalog manifest' -Url $url -LayoutFileName 'Catalog.json' -LayoutPath $layoutPath return $catalogManifest } diff --git a/chocolatey-visualstudio.extension/extensions/Resolve-VSLayoutPath.ps1 b/chocolatey-visualstudio.extension/extensions/Resolve-VSLayoutPath.ps1 new file mode 100644 index 00000000..eef44acc --- /dev/null +++ b/chocolatey-visualstudio.extension/extensions/Resolve-VSLayoutPath.ps1 @@ -0,0 +1,42 @@ +function Resolve-VSLayoutPath +{ + [CmdletBinding()] + Param + ( + [Parameter(Mandatory = $true)] [hashtable] $PackageParameters + ) + + Write-Debug 'Detecting if a layout path was provided via package parameters' + + if ($PackageParameters.ContainsKey('installLayoutPath')) + { + $installLayoutPath = $PackageParameters['installLayoutPath'] + if (-not [string]::IsNullOrEmpty($installLayoutPath)) + { + Write-Debug "Using installLayoutPath provided via package parameters: $installLayoutPath" + return $installLayoutPath + } + else + { + Write-Debug 'Package parameters contain installLayoutPath, but it is empty - ignoring' + } + } + + if ($PackageParameters.ContainsKey('bootstrapperPath')) + { + $bootstrapperPath = $PackageParameters['bootstrapperPath'] + if (-not [string]::IsNullOrEmpty($bootstrapperPath)) + { + $installLayoutPath = Split-Path -Path $bootstrapperPath + Write-Debug "Using installLayoutPath computed from bootstrapperPath provided via package parameters: $installLayoutPath" + return $installLayoutPath + } + else + { + Write-Debug 'Package parameters contain $bootstrapperPath, but it is empty - ignoring' + } + } + + Write-Debug 'A layout path was not provided via package parameters' + return $null +}