This repository has been archived by the owner on Feb 18, 2021. It is now read-only.
forked from flofreud/posh-gvm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInit.ps1
61 lines (50 loc) · 1.57 KB
/
Init.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#region Initialization
function Init-Posh-Gvm() {
Write-Verbose 'Init posh-gvm'
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
Check-JAVA-HOME
# Check if $Global:PGVM_DIR is available, if not create it
if ( !( Test-Path "$Global:PGVM_DIR\.meta" ) ) {
New-Item -ItemType Directory "$Global:PGVM_DIR\.meta" | Out-Null
}
# Load candidates cache
if ( ! (Test-Path $Script:PGVM_CANDIDATES_PATH) ) {
Update-Candidates-Cache
}
Init-Candidate-Cache
#Setup default paths
Foreach ( $candidate in $Script:GVM_CANDIDATES ) {
if ( !( Test-Path "$Global:PGVM_DIR\$candidate" ) ) {
New-Item -ItemType Directory "$Global:PGVM_DIR\$candidate" | Out-Null
}
Set-Env-Candidate-Version $candidate 'current'
}
# Check if we can use unzip (which is much faster)
Check-Unzip-On-Path
}
function Check-JAVA-HOME() {
# Check for JAVA_HOME, If not set, try to interfere it
if ( ! (Test-Path env:JAVA_HOME) ) {
try {
[Environment]::SetEnvironmentVariable('JAVA_HOME', (Get-Item (Get-Command 'javac').Path).Directory.Parent.FullName)
} catch {
throw "Could not find java, please set JAVA_HOME"
}
}
}
function Check-Unzip-On-Path() {
try {
Get-Command 'unzip.exe' | Out-Null
$Script:UNZIP_ON_PATH = $true
} catch {
$Script:UNZIP_ON_PATH = $false
}
try {
Get-Command '7z.exe' | Out-Null
$Script:SEVENZ_ON_PATH = $true
} catch {
$Script:SEVENZ_ON_PATH = $false
}
}
#endregion