From 8549b3c510657e8ba2332720ad6f7950aa229c89 Mon Sep 17 00:00:00 2001 From: Rubin Simons Date: Thu, 22 Jun 2017 13:28:56 +0200 Subject: [PATCH 1/3] Unhinged jabba.ps1 from install.ps1, added fetching of jabba.bat, added message about bat and path to completed message. --- install.ps1 | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/install.ps1 b/install.ps1 index 1b144cb3..eb8ec4a4 100644 --- a/install.ps1 +++ b/install.ps1 @@ -42,22 +42,11 @@ If the problem persists - please create a ticket at https://github.com/shyiko/ja exit 1 } -echo @" -`$env:JABBA_HOME="$jabbaHome" +# Get the jabba powershell wrapper. +Invoke-WebRequest -Uri https://raw.githubusercontent.com/shyiko/jabba/$jabbaVersion/jabba.ps1 -OutFile $jabbaHome/jabba.ps1 -function jabba -{ - `$fd3=`$([System.IO.Path]::GetTempFileName()) - `$command="$jabbaHome\bin\jabba.exe `$args --fd3 `$fd3" - & { `$env:JABBA_SHELL_INTEGRATION="ON"; Invoke-Expression `$command } - `$fd3content=`$(cat `$fd3) - if (`$fd3content) { - `$expression=`$fd3content.replace("export ","```$env:") -join "``n" - if (-not `$expression -eq "") { Invoke-Expression `$expression } - } - rm -Force `$fd3 -} -"@ > $jabbaHome/jabba.ps1 +# Get the jabba batchscript wrapper. +Invoke-WebRequest -Uri https://raw.githubusercontent.com/shyiko/jabba/$jabbaVersion/jabba.bat -OutFile $jabbaHome/jabba.bat $sourceJabba="if (Test-Path `"$jabbaHome\jabba.ps1`") { . `"$jabbaHome\jabba.ps1`" }" @@ -79,5 +68,10 @@ else . "$jabbaHome\jabba.ps1" echo "" -echo "Installation completed` -(if you have any problems please report them at https://github.com/shyiko/jabba/issue)" +echo "Installation completed!" +echo "" +echo "You will be able to use jabba directly from your PowerShell environment." +echo "if you want to use jabba from a cmd.exe command prompt, copy $jabbaHome\jabba.bat" +echo "to a directory on your PATH or add $jabbaHome to your PATH environment variable." +echo "" +echo "(if you have any problems please report them at https://github.com/shyiko/jabba/issue)" From 63306afb898a5402609e84ec0da749147952e1cc Mon Sep 17 00:00:00 2001 From: Rubin Simons Date: Thu, 22 Jun 2017 13:29:43 +0200 Subject: [PATCH 2/3] Added a more PowerShell-y compliant jabba.ps1, based on the previously embedded one in install.ps1. --- jabba.ps1 | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 jabba.ps1 diff --git a/jabba.ps1 b/jabba.ps1 new file mode 100644 index 00000000..2a7296a8 --- /dev/null +++ b/jabba.ps1 @@ -0,0 +1,39 @@ +<# +.SYNOPSIS +A powershell wrapper for the Jabba JVM manager, commonly aliased as "jabba". +.DESCRIPTION +Jabba makes it possible to manage multiple JVMs on your system; you can list available JVMs, install remotely-available JVMs and most importantly, select a JVM to work with. Selecting a JVM in this case means manipulating the PATH and JAVA_HOME variables. + +.EXAMPLE +Invoke-Jabba help + +Show the help output for the jabba executable. + +.EXAMPLE +Invoke-Jabba ls + +List currently known and available JVMs. + +.EXAMPLE +Invoke-Jabba link system@1.8.131 """C:\Program Files\Java\oracle-jdk8""" + +Tells Jabba about an already-installed JVM. + +.EXAMPLE +Invoke-Jabba use system@1.8.131 + +Tells jabba to activate the system installed JDK version 1.8.131. +#> +function Invoke-Jabba +{ + $env:JABBA_HOME=$env:USERPROFILE + "\.jabba" + $fd3=$([System.IO.Path]::GetTempFileName()) + $command=$env:JABBA_HOME + "\bin\jabba.exe $args --fd3 $fd3" + & { $env:JABBA_SHELL_INTEGRATION="ON"; Invoke-Expression $command } + $fd3content=$(Get-Content $fd3) + if ($fd3content) { + $expression=$fd3content.replace("export ","`$env:") -join "`n" + if (-not $expression -eq "") { Invoke-Expression $expression } + } + Remove-Item -Force $fd3 +} From dee61aefd86892d75c4b9c28ee6528d0c6e839fb Mon Sep 17 00:00:00 2001 From: Rubin Simons Date: Thu, 22 Jun 2017 13:30:46 +0200 Subject: [PATCH 3/3] Added a batch wrapper (still requires powershell for find/replace) which can be used from regular cmd.exe. --- jabba.bat | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 jabba.bat diff --git a/jabba.bat b/jabba.bat new file mode 100644 index 00000000..67a6b337 --- /dev/null +++ b/jabba.bat @@ -0,0 +1,28 @@ +@echo off + +:: Set environment variables. +set "JABBA_HOME=%USERPROFILE%\.jabba" +set "TEMP_ENV=%TEMP%\jabba.env" +set "TEMP_REP=%TEMP%\jabba.rep" +set "TEMP_BAT=%TEMP%\jabba.bat" + +:: Run jabba, write to TEMP_ENV. +"%JABBA_HOME%\bin\jabba.exe" %1 %2 %3 %4 %5 --fd3 "%TEMP_ENV%" + +if exist "%TEMP_ENV%" ( + :: Convert from powershell to batch environment schript. + powershell -Command "(gc %TEMP_ENV%) -replace 'export ', 'set \"' ^| Out-File -encoding ASCII %TEMP_REP%" + powershell -Command "(gc %TEMP_REP%) -replace '=\"', '=' ^| Out-File -encoding ASCII %TEMP_BAT%" + + :: Exectute within current shell (i.e, no call). + "%TEMP_BAT%" + + :: Clean up files. + del "%TEMP_ENV%" "%TEMP_REP%" "%TEMP_BAT%" +) + +:: Unset used environment variables. +set JABBA_HOME= +set TEMP_ENV= +set TEMP_REP= +set TEMP_BAT=