d3bde6aec80a1e2093b81e91793888ec6bbc79f7
[jalview.git] / utils / getdown / jalviewc.ps1
1 #!/usr/bin/env pwsh
2
3 # save args and first parameter
4 $ARGS = $args
5 $ARG1 = $args[0]
6 # parent dir of this script (should be the getdown app dir). Follow symlinks.
7 $TARGET = ( Get-Item $MyInvocation.MyCommand.Path ).Target
8 $DIR = ( $TARGET -eq $null ) ? ( Split-Path $MyInvocation.MyCommand.Path -Parent ) : ( Split-Path $TARGET -Parent )
9
10 # insert an "-open" parameter to Jalview's ARGS if ARG1 is non-zero-length, and not "open" or starts with a "-"
11 if ( $ARG1.length -gt 0 -and ( -not $ARG1.StartsWith("-") ) -and $ARG1 -cne "open" ) {
12   $ARGS = "-open " + $ARGS
13 }
14
15 $APPDIR = $DIR
16 $JAVAEXE = ( $IsWindows ? "java.exe" : "java" )
17 $JAVA = Join-Path -Path $APPDIR -ChildPath ( "jre/" + ( $IsMacOs ? "Contents/Home/" : "" ) + "bin/${JAVAEXE}" )
18 $GETDOWNTXT = Join-Path -Path $APPDIR -ChildPath "getdown.txt"
19
20 # look for getdown.txt -- needed to create classpath
21 if ( -not ( Test-Path -Path "${GETDOWNTXT}" ) ) {
22   throw "Cannot find getdown.txt"
23 }
24
25 # look for bundled JRE. Might not be there if unix installer used in which case just invoke "java"
26 if ( -not ( Test-Path -Path "${JAVA}" ) ) {
27   Write-Host "Cannot find bundled ${JAVAEXE}. Using system ${JAVAEXE} and hoping for the best!"
28   $JAVA = $JAVAEXE
29 }
30
31 $CLASSPATH = ( Select-String -Path "${GETDOWNTXT}" -AllMatches -Pattern "code\s*=\s*(.*)$" | foreach { Join-Path -Path $DIR -ChildPath $($_.Matches.Groups[1].Value ) } ) -join ( $IsWindows ? ";" : ":" )
32
33 Invoke-Expression -Command "${JAVA} -cp '${CLASSPATH}' jalview.bin.Launcher $ARGS"
34