3 # save args and first parameter
4 $myArgs = $args.Clone()
6 # setup for powershell version < 6.0
7 [bool] $myIsWindows = 0
9 if ( $IsWindows -eq $null ) {
10 # for powershell version < 6.0 let's assume Windows
14 $myIsWindows = $IsWindows
22 Switch -Regex ($args) {
23 "--help|--help-|--version|-h" {
42 # --help takes precedence
45 # --gui takes precedence over --headless
49 # actual path of this script (which should be the getdown appdir/bin). Follow all symlinks. Like GNU readlink -f
52 [Parameter(mandatory=$true, ValueFromPipeline=$true)]$Link,
53 [Parameter()]$iteration_count = 1
55 if ( $iteration_count -ge 100 ) {
56 Write-Error "Readlink-f iterated 100 times"
59 if ( $Link -eq "" -or $Link -eq $null ) {
62 $path_components = @()
64 while ( $dir -ne $null ) {
65 while ( $dir.Target -ne $null ) {
66 # [System.IO.Path]::Combine caters for a multitude of sins that it's almost impossible to deal with with Join-Path
67 $dir = Get-Item ([System.IO.Path]::GetFullPath( [System.IO.Path]::Combine( (Split-Path $dir -Parent), $dir.Target )))
69 $parent = Split-Path -Path $dir -Parent
70 $path_components = @( (Split-Path -Path $dir -Leaf) ) + $path_components
71 $dir = Readlink-f $parent ($iteration_count + 1)
74 foreach ( $component in $path_components) {
75 # [System.IO.Path]::Combine caters for a multitude of sins that it's almost impossible to deal with with Join-Path
76 $real = Get-Item ([System.IO.Path]::GetFullPath( [System.IO.Path]::Combine( $real, $component )))
81 # Avert problem with unix version of powershell and tell user the reason (Windows must always have .ps1 extension)
82 if ( $MyInvocation.MyCommand.Path -eq $null ) {
83 throw "Script or link to script must have extension .ps1"
89 $CMDPATH = ( Get-Item $MyInvocation.MyCommand.Path )
90 $SCRIPTPATH = Readlink-f -Link $CMDPATH
92 $DIR = Split-Path -Path $SCRIPTPATH -Parent
93 $APPDIR = If ( ( Split-Path -Path $DIR -Leaf ) -eq "bin" ) { Split-Path -Path $DIR -Parent } Else { $DIR }
94 $JAVAEXE = If ( $myIsWindows ) { "java.exe" } Else { "java" }
95 $JAVA = Join-Path -Path $APPDIR -ChildPath ( "jre/" + $( If ( $myIsMacOS ) { "Contents/Home/" } Else { "" } ) + "bin/${JAVAEXE}" )
98 # not setting java.awt.headless in java invocation of running jalview due to problem with Jmol
100 $JVMARGS += "-Djava.awt.headless=true"
102 # this suppresses the Java icon appearing in the macOS Dock
104 $JVMARGS += "-Dapple.awt.UIElement=true"
108 $GETDOWNTXT = Join-Path -Path $APPDIR -ChildPath "getdown.txt"
110 # look for getdown.txt -- needed to create classpath
111 if ( -not ( Test-Path -Path "${GETDOWNTXT}" ) ) {
112 throw "Cannot find ${GETDOWNTXT}"
115 # launching Jalview with jalview.bin.Launcher instead of getdown-launcher.jar
116 $CLASS = "jalview.bin.Launcher"
118 # get CLASSPATH from the code= entries in getdown.txt
119 $CLASSPATH = ( Select-String -Path "${GETDOWNTXT}" -AllMatches -Pattern "code\s*=\s*(.*)$" | foreach { Join-Path -Path $APPDIR -ChildPath $($_.Matches.Groups[1].Value ) } ) -join $( If ( $myIsWindows ) { ";" } Else { ":" } )
122 $COLUMNS = $Host.UI.RawUI.WindowSize.Width
123 $JVMARGS += "-DCONSOLEWIDTH=${COLUMNS}"
124 $JVMARGS += "-Dgetdownappdir=${APPDIR}"
125 $JVMARGS += "-Dinstaller.appdir=${APPDIR}"
126 $JVMARGS += "-Dlauncher.script=${SCRIPT}"
128 # look for bundled JRE. Might not be there if unix installer used in which case just invoke "java"
129 if ( -not ( Test-Path -Path "${JAVA}" ) ) {
130 Write-Host "Cannot find bundled ${JAVA}. Using system ${JAVAEXE} and hoping for the best!"
134 # we should always have at least one JVMARGS so this is okay
135 $myJvmArgsString = '"' + $($JVMARGS -join '" "') + '"'
137 # quote the args and the command (in case of spaces) with escape chars (`) and precede with & to indicate a command not string
138 if ( $myArgs.count -eq 0 ) {
139 $COMMAND = "& `"${JAVA}`" ${myJvmArgsString} -cp `"${CLASSPATH}`" $CLASS"
141 $myArgsString = '"' + $($myArgs -join '" "') + '"'
142 $COMMAND = "& `"${JAVA}`" ${myJvmArgsString} -cp `"${CLASSPATH}`" $CLASS ${myArgsString}"
145 if ( $debug -or $help ) {
146 Write-Error -Message "Shell running: ${COMMAND}"
149 Invoke-Expression -Command ${COMMAND}