Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop Please Help me #762

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}