Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerLeonhardt committed Sep 22, 2018
1 parent d6a6af0 commit 4ac1a84
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"cwd": ""
}
]
}
}
2 changes: 1 addition & 1 deletion PSDepend/PSDependMap.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

DotnetSdk = @{
Script = 'DotnetSdk.ps1'
Description = "Install's the .NET Core SDK"
Description = "Installs the .NET Core SDK"
Supports = 'windows', 'core', 'macos', 'linux'
}

Expand Down
17 changes: 8 additions & 9 deletions PSDepend/PSDependScripts/DotnetSdk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
# Full syntax
# DependencyName (key) uses (unique) name 'gitbook-cli'
# DependencyName (key) uses (unique) channel name 'release'
# Specify a version to install
# Ensure the package is installed locally in a .dotnet folder.
Expand All @@ -44,11 +44,10 @@
}
# Simple syntax
# The example package, 'gitbook-cli' will be installed
at the latest verion from the LTS channel globally.
# The .NET SDK will be installed with the latest verion from the LTS channel, globally.
#>
[cmdletbinding()]
[CmdletBinding()]
param(
[PSTypeName('PSDepend.Dependency')]
[psobject[]]
Expand All @@ -62,12 +61,12 @@ param(
# Users can specify 'Global which will use the default global path of
# "$env:LocalAppData\Microsoft\dotnet" on Windows or "$env:HOME/.dotnet" elsewhere
# Since Global is the default behavior, we ingore the fact that the Target was set.
$InstallDir = if($Dependency.Target -and $Dependency.Target -ne 'Global') { $Dependency.Target }
$InstallDir = if ($Dependency.Target -and $Dependency.Target -ne 'Global') { $Dependency.Target }
$Version = $Dependency.Version
$Channel = if($Dependency.DependencyName) { $Dependency.DependencyName } else { "release" }
$Channel = if ($Dependency.DependencyName) { $Dependency.DependencyName } else { "release" }

# The 'global' install location is different per platform
$IsWindowsEnv = [RuntimeInformation]::IsOSPlatform([OSPlatform]::Windows)
$IsWindowsEnv = !$PSVersionTable.Platform -or $PSVersionTable.Platform -eq "Win32NT"
$globalDotnetSdkLocation = if ($IsWindowsEnv) { "$env:LocalAppData\Microsoft\dotnet" } else { "$env:HOME/.dotnet" }

# Handle 'Test'
Expand Down Expand Up @@ -97,8 +96,8 @@ if ($PSDependAction -contains 'Import') {
} else {
# Test if it's in the path already and if it's not check if it's in the 'global' location
$dotnetInPath = Get-Command 'dotnet' -ErrorAction SilentlyContinue
if(!$dotnetInPath) {
if(!(Test-Dotnet -Version $Version -InstallDir $globalDotnetSdkLocation)) {
if (!$dotnetInPath) {
if (!(Test-Dotnet -Version $Version -InstallDir $globalDotnetSdkLocation)) {
throw ".NET SDK cannot be located. Try installing using PSDepend."
} else {
$env:PATH = "$globalDotnetSdkLocation$([IO.Path]::PathSeparator)$env:PATH"
Expand Down
4 changes: 1 addition & 3 deletions PSDepend/Private/Install-Dotnet.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This installs the .NET SDK that satisfies the Channel, Version, and InstallDir that is passed in
# If on Windows, it will download the .NET SDK PowerShell install script (dotnet-install.ps1)
# On all other platforms, it will download the .NET SDK shell script (dotnet-install.sh)
using namespace System.Runtime.InteropServices

function Install-Dotnet {
[CmdletBinding()]
param(
Expand All @@ -19,7 +17,7 @@ function Install-Dotnet {
$InstallDir
)

$IsWindowsEnv = [RuntimeInformation]::IsOSPlatform([OSPlatform]::Windows)
$IsWindowsEnv = !$PSVersionTable.Platform -or $PSVersionTable.Platform -eq "Win32NT"

$obtainUrl = "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain"

Expand Down
6 changes: 2 additions & 4 deletions PSDepend/Private/Test-Dotnet.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using namespace System.Runtime.InteropServices

# This tests if if the .NET SDK of the specified version exists
# If you specify the InstallDir, it will check if the .NET SDK exists there
# Otherwise it will use the global .NET SDK location.
Expand All @@ -15,6 +13,7 @@ function Test-Dotnet {
$InstallDir
)

$IsWindowsEnv = !$PSVersionTable.Platform -or $PSVersionTable.Platform -eq "Win32NT"
$dotnetFile = if ($IsWindowsEnv) { "dotnet.exe" } else { "dotnet" }

if ($InstallDir) {
Expand All @@ -26,7 +25,6 @@ function Test-Dotnet {
if ($dotnetInPath) {
$dotnetExePath = $dotnetInPath.Source
} else {
$IsWindowsEnv = [RuntimeInformation]::IsOSPlatform([OSPlatform]::Windows)
$LocalDotnetDirPath = if ($IsWindowsEnv) { "$env:LocalAppData\Microsoft\dotnet" } else { "$env:HOME/.dotnet" }
$dotnetExePath = Join-Path -Path $LocalDotnetDirPath -ChildPath $dotnetFile
}
Expand Down Expand Up @@ -64,4 +62,4 @@ function Get-DotnetVersion {
)

& $dotnetExePath --version
}
}
2 changes: 1 addition & 1 deletion Tests/DependFiles/dotnetsdk.complex.depend.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
Version = '2.1.300'
Target = '.dotnet'
}
}
}
2 changes: 1 addition & 1 deletion Tests/DependFiles/dotnetsdk.simple.depend.psd1
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@{
'DotnetSdk::bar' = '2.1.330-rc2'
}
}
10 changes: 5 additions & 5 deletions Tests/PSModuleGallery.Type.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -944,25 +944,25 @@ InModuleScope 'PSDepend' {
Mock Get-Command { return $false } -ParameterFilter { $Name -eq 'dotnet' }

BeforeAll {
$originalPath = "$env:PATH"
$originalPath = $env:PATH
}

It 'Can add the Target of the .NET Core SDK to the PATH' {
Mock Test-Dotnet { return $true }
Invoke-PSDepend @Verbose -Path "$TestDepends\dotnetsdk.complex.depend.psd1" -Force -Import -ErrorAction Stop

$env:PATH | Should -Match "$SavePath*"
($env:PATH -split [IO.Path]::PathSeparator)[0] | Should -Be $SavePath
}
It 'Can add the global path of the .NET Core SDK to the PATH' {
Mock Test-Dotnet { return $true }
Invoke-PSDepend @Verbose -Path "$TestDepends\dotnetsdk.simple.depend.psd1" -Force -Import -ErrorAction Stop

$env:PATH | Should -Match "$globalDotnetSdkLocation*"
($env:PATH -split [IO.Path]::PathSeparator)[0] | Should -Be $globalDotnetSdkLocation
}
It 'Throws if the path cannot be found' {
Mock Test-Dotnet { return $false }
{ Invoke-PSDepend @Verbose -Path "$TestDepends\dotnetsdk.simple.depend.psd1" -Force -Import -ErrorAction Stop } | Should -Throw `
-ExpectedMessage ".NET SDK cannot be located. Try installing using PSDepend."
{ Invoke-PSDepend @Verbose -Path "$TestDepends\dotnetsdk.simple.depend.psd1" -Force -Import -ErrorAction Stop } |
Should -Throw -ExpectedMessage ".NET SDK cannot be located. Try installing using PSDepend."
}
AfterEach {
$env:PATH = $originalPath
Expand Down

0 comments on commit 4ac1a84

Please sign in to comment.