JAL-3830 powershell wrapper tested and fixed
[jalview.git] / utils / getdown / jalviewc.ps1
1 #!/usr/bin/env pwsh
2
3 # save first parameter
4 $ARGS = $args
5 $ARG1 = $args[0]
6 # parent dir of this script (should be the getdown app dir)
7 $DIR = Split-Path $MyInvocation.MyCommand.Path -Parent
8
9 # insert an "-open" parameter to Jalview's ARGS if ARG1 is non-zero-length, and not "open" or starts with a "-"
10 if ( $ARG1.length -gt 0 -and (-not $ARG1.StartsWith("-")) -and $ARG1 -ne "open" ) {
11   $ARGS = "-open " + $ARGS
12 }
13
14 $APPDIR = $DIR
15 $JAVA = "${APPDIR}\jre\bin\java.exe"
16 $GETDOWNTXT = "${APPDIR}\getdown.txt"
17
18 if (-not (Test-Path -Path "${GETDOWNTXT}")) {
19   throw "Cannot find getdown.txt"
20 }
21
22 if (-not (Test-Path -Path "${JAVA}")) {
23   Write-Host "Cannot find bundled java.exe. Using system and hoping for the best!"
24   $JAVA = "java.exe"
25 }
26
27 $CLASSPATH = (Select-String -Path "${GETDOWNTXT}" -AllMatches -Pattern "code\s*=\s*(.*)$" | foreach { "$DIR\$($_.Matches.Groups[1].Value -replace "/", "\")" }) -join ";"
28
29 Invoke-Expression -Command "${JAVA} -cp '${CLASSPATH}' jalview.bin.Launcher $ARGS"
30