-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from rubin55/develop
Added batch wrapper to support cmd.exe, slight powershell rework
- Loading branch information
Showing
3 changed files
with
78 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 [email protected] """C:\Program Files\Java\oracle-jdk8""" | ||
Tells Jabba about an already-installed JVM. | ||
.EXAMPLE | ||
Invoke-Jabba use [email protected] | ||
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 | ||
} |