Skip to content

Commit 1d7e5d5

Browse files
committed
Implemented jenv link. #26 #29
1 parent d11f372 commit 1d7e5d5

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/jenv-link.psm1

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function Invoke-Link {
2+
param (
3+
[Parameter(Mandatory = $true)][object]$config,
4+
[Parameter(Mandatory = $true)][boolean]$help,
5+
[Parameter(Mandatory = $true)][string]$executable
6+
)
7+
8+
if ($help) {
9+
Write-Host '"jenv link" <executable>'
10+
Write-Host With this command you can create shortcuts for executables inside JAVA_HOME
11+
Write-Host '<executable> is the name of the binary file for example "javac" or "javaw"'
12+
Write-Host 'For example enable javac with: "jenv link javac"'
13+
Write-Host 'List all registered java versions with "jenv list"'
14+
}
15+
else {
16+
17+
$payload = @'
18+
@echo off
19+
for /f "delims=" %%i in ('jenv getjava') do set "var=%%i"
20+
21+
if exist "%var%/bin/{0}.exe" (
22+
"%var%/bin/{0}.exe" %*
23+
) else (
24+
echo There was an error:
25+
echo %var%
26+
)
27+
'@ -f $executable
28+
29+
Set-Content ((get-item $PSScriptRoot).parent.fullname + "/$executable.bat") $payload
30+
31+
}
32+
}

src/jenv.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ param (
1818
"jenv use <name>" Applys the given Java-Version locally for the current shell
1919
"jenv local <name>" Will use the given Java-Version whenever in this folder. Will set the Java-version for all subfolders as well
2020
#>
21-
[Parameter(Position = 0)][validateset("list", "add", "change", "use", "remove", "local", "getjava")] [string]$action,
21+
[Parameter(Position = 0)][validateset("list", "add", "change", "use", "remove", "local", "getjava", "link")] [string]$action,
2222

2323
# Displays this helpful message
2424
[Alias("h")]
@@ -39,6 +39,7 @@ Import-Module $PSScriptRoot\jenv-change.psm1 -Force
3939
Import-Module $PSScriptRoot\jenv-use.psm1 -Force
4040
Import-Module $PSScriptRoot\jenv-local.psm1 -Force
4141
Import-Module $PSScriptRoot\jenv-getjava.psm1 -Force
42+
Import-Module $PSScriptRoot\jenv-link.psm1 -Force
4243
#endregion
4344

4445
#region Installation
@@ -122,6 +123,7 @@ if ($help -and $action -eq "") {
122123
Write-Host '"jenv change <name>" Applys the given Java-Version globaly for all restarted shells and this one'
123124
Write-Host '"jenv use <name>" Applys the given Java-Version locally for the current shell'
124125
Write-Host '"jenv local <name>" Will use the given Java-Version whenever in this folder. Will set the Java-version for all subfolders as well'
126+
Write-Host '"jenv link <executable>" Creates shortcuts for executables inside JAVA_HOME. For example "javac"'
125127
Write-Host 'Get help for individual commands using "jenv <list/add/remove/change/use/local> --help"'
126128
}
127129
else {
@@ -136,6 +138,7 @@ else {
136138
change { Invoke-Change $config $help $output @arguments }
137139
local { Invoke-Local $config $help $output @arguments }
138140
getjava { Get-Java $config }
141+
link { Invoke-Link $config $help @arguments }
139142
}
140143

141144
#region Save the config

0 commit comments

Comments
 (0)