|
| 1 | +:: |
| 2 | +:: ---------------------------------------------------------------------------------------------------- |
| 3 | +:: |
| 4 | +:: Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved. |
| 5 | +:: DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 6 | +:: |
| 7 | +:: This code is free software; you can redistribute it and/or modify it |
| 8 | +:: under the terms of the GNU General Public License version 2 only, as |
| 9 | +:: published by the Free Software Foundation. Oracle designates this |
| 10 | +:: particular file as subject to the "Classpath" exception as provided |
| 11 | +:: by Oracle in the LICENSE file that accompanied this code. |
| 12 | +:: |
| 13 | +:: This code is distributed in the hope that it will be useful, but WITHOUT |
| 14 | +:: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 | +:: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 16 | +:: version 2 for more details (a copy is included in the LICENSE file that |
| 17 | +:: accompanied this code). |
| 18 | +:: |
| 19 | +:: You should have received a copy of the GNU General Public License version |
| 20 | +:: 2 along with this work; if not, write to the Free Software Foundation, |
| 21 | +:: Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | +:: |
| 23 | +:: Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 24 | +:: or visit www.oracle.com if you need additional information or have any |
| 25 | +:: questions. |
| 26 | +:: |
| 27 | +:: ---------------------------------------------------------------------------------------------------- |
| 28 | +@echo off |
| 29 | + |
| 30 | +setlocal enabledelayedexpansion |
| 31 | + |
| 32 | +call :getScriptLocation location |
| 33 | + |
| 34 | + |
| 35 | +:: The two white lines above this comment are significant. |
| 36 | + |
| 37 | +set "jvm_args=--add-modules=ALL-DEFAULT" |
| 38 | +set "javac_args=" |
| 39 | + |
| 40 | +call :escape_args %* |
| 41 | +for %%a in (%args%) do ( |
| 42 | + call :unescape_arg %%a |
| 43 | + call :process_arg !arg! |
| 44 | + if errorlevel 1 exit /b 1 |
| 45 | +) |
| 46 | + |
| 47 | +if "%VERBOSE_GRAALVM_LAUNCHERS%"=="true" echo on |
| 48 | + |
| 49 | +"%location%\espresso" %jvm_args% -m jdk.compiler/com.sun.tools.javac.Main %javac_args% |
| 50 | + |
| 51 | +exit /b %errorlevel% |
| 52 | +:: Function are defined via labels, so have to be defined at the end of the file and skipped |
| 53 | +:: in order not to be executed. |
| 54 | + |
| 55 | +:escape_args |
| 56 | + set "args=%*" |
| 57 | + :: Without early exit on empty contents, substitutions fail. |
| 58 | + if "!args!"=="" exit /b 0 |
| 59 | + set "args=%args:,=##GR_ESC_COMMA##%" |
| 60 | + set "args=%args:;=##GR_ESC_SEMI##%" |
| 61 | + :: Temporarily, so that args are split on '=' only. |
| 62 | + set "args=%args: =##GR_ESC_SPACE##%" |
| 63 | + :: Temporarily, otherwise we won't split on '=' inside quotes. |
| 64 | + set "args=%args:"=##GR_ESC_QUOTE##%" |
| 65 | + :: We can't replace equal using the variable substitution syntax. |
| 66 | + call :replace_equals %args% |
| 67 | + set "args=%args:##GR_ESC_SPACE##= %" |
| 68 | + set "args=%args:##GR_ESC_QUOTE##="%" |
| 69 | + exit /b 0 |
| 70 | + |
| 71 | +:replace_equals |
| 72 | + setlocal |
| 73 | + :: The argument passed to this function was split on =, because all other |
| 74 | + :: delimiters were replaced in escape_args. |
| 75 | + set "arg=%1" |
| 76 | + if "!arg!"=="" goto :end_replace_equals |
| 77 | + set "args=%1" |
| 78 | + shift |
| 79 | + :loop_replace_equals |
| 80 | + set "arg=%1" |
| 81 | + if "!arg!"=="" goto :end_replace_equals |
| 82 | + set "args=%args%##GR_ESC_EQUAL##%arg%" |
| 83 | + shift |
| 84 | + goto :loop_replace_equals |
| 85 | + :end_replace_equals |
| 86 | + endlocal & ( set "args=%args%" ) |
| 87 | + exit /b 0 |
| 88 | + |
| 89 | +:unescape_arg |
| 90 | + set "arg=%*" |
| 91 | + set "arg=%arg:##GR_ESC_COMMA##=,%" |
| 92 | + set "arg=%arg:##GR_ESC_SEMI##=;%" |
| 93 | + set "arg=%arg:##GR_ESC_EQUAL##==%" |
| 94 | + exit /b 0 |
| 95 | + |
| 96 | +:is_quoted |
| 97 | + setlocal |
| 98 | + set "args=%*" |
| 99 | + set /a argslen=0 |
| 100 | + for %%a in (%args%) do set /a argslen+=1 |
| 101 | + if %argslen% gtr 1 ( |
| 102 | + set "quoted=false" |
| 103 | + ) else ( |
| 104 | + if "!args:~0,1!!args:~-1!"=="""" ( set "quoted=true" ) else ( set "quoted=false" ) |
| 105 | + ) |
| 106 | + endlocal & ( set "quoted=%quoted%" ) |
| 107 | + exit /b 0 |
| 108 | + |
| 109 | +:unquote_arg |
| 110 | + :: Sets %arg% to a version of the argument with outer quotes stripped, if present. |
| 111 | + call :is_quoted %* |
| 112 | + setlocal |
| 113 | + set "maybe_quoted=%*" |
| 114 | + if %quoted%==true ( set "arg=%~1" ) else ( set "arg=!maybe_quoted!" ) |
| 115 | + endlocal & ( set "arg=%arg%" ) |
| 116 | + exit /b 0 |
| 117 | + |
| 118 | +:process_vm_arg |
| 119 | + if %arg_quoted%==false ( |
| 120 | + call :is_quoted %* |
| 121 | + set "arg_quoted=%quoted%" |
| 122 | + ) |
| 123 | + call :unquote_arg %* |
| 124 | + set "vm_arg=%arg%" |
| 125 | + |
| 126 | + if %arg_quoted%==true ( set "arg="%vm_arg%"" ) else ( set "arg=%vm_arg%" ) |
| 127 | + set "jvm_args=%jvm_args% !arg!" |
| 128 | + exit /b 0 |
| 129 | + |
| 130 | +:process_arg |
| 131 | + set "original_arg=%*" |
| 132 | + call :unquote_arg !original_arg! |
| 133 | + set "arg_quoted=%quoted%" |
| 134 | + |
| 135 | + if "!arg:~0,2!"=="-J" ( |
| 136 | + set prefix=vm |
| 137 | + call :unquote_arg !arg:~2! |
| 138 | + call :process_vm_arg !arg! |
| 139 | + if errorlevel 1 exit /b 1 |
| 140 | + ) else ( |
| 141 | + :: Use !original_arg! instead of !arg! to preserve surrounding quotes if present. |
| 142 | + set "launcher_args=%launcher_args% !original_arg!" |
| 143 | + ) |
| 144 | + exit /b 0 |
| 145 | + |
| 146 | +:: If this script is in `%PATH%` and called quoted without a full path (e.g., `"java"`), `%~dp0` is expanded to `cwd` |
| 147 | +:: rather than the path to the script. |
| 148 | +:: This does not happen if `%~dp0` is accessed in a subroutine. |
| 149 | +:getScriptLocation variableName |
| 150 | + set "%~1=%~dp0" |
| 151 | + exit /b 0 |
| 152 | + |
| 153 | +endlocal |
0 commit comments