Skip to content

Commit

Permalink
Merge pull request #86 from rubin55/develop
Browse files Browse the repository at this point in the history
Added batch wrapper to support cmd.exe, slight powershell rework
  • Loading branch information
shyiko authored Jun 22, 2017
2 parents 1987b6a + dee61ae commit f3b942e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 17 deletions.
28 changes: 11 additions & 17 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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`" }"

Expand All @@ -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)"
28 changes: 28 additions & 0 deletions jabba.bat
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=
39 changes: 39 additions & 0 deletions jabba.ps1
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
}

0 comments on commit f3b942e

Please sign in to comment.