|
1 | 1 | #!/bin/sh |
2 | 2 |
|
3 | 3 | # |
4 | | -# Copyright © 2015-2024 the original authors. |
| 4 | +# Copyright © 2015-2025 the original authors. |
5 | 5 | # |
6 | 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
7 | 7 | # you may not use this file except in compliance with the License. |
|
15 | 15 | # See the License for the specific language governing permissions and |
16 | 16 | # limitations under the License. |
17 | 17 | # |
| 18 | +# SPDX-License-Identifier: Apache-2.0 |
| 19 | +# |
18 | 20 |
|
19 | 21 | ############################################################################## |
20 | 22 | # |
|
43 | 45 | # This is normally unused |
44 | 46 | # shellcheck disable=SC2034 |
45 | 47 | APP_BASE_NAME=\${0##*/} |
46 | | -APP_HOME=\$( cd "\${APP_HOME:-./}${appHomeRelativePath}" && pwd -P ) || exit |
47 | | - |
48 | | -# Add default JVM options here. You can also use JAVA_OPTS and ${optsEnvironmentVar} to pass JVM options to this script. |
49 | | -DEFAULT_JVM_OPTS=${defaultJvmOpts} |
| 48 | +# Discard cd standard output in case \$CDPATH is set (https://github.com/gradle/gradle/issues/25036) |
| 49 | +APP_HOME=\$( cd -P "\${APP_HOME:-./}${appHomeRelativePath}" > /dev/null && printf '%s\\n' "\$PWD" ) || exit |
50 | 50 |
|
51 | 51 | # Use the maximum available, or set MAX_FD != -1 to use that value. |
52 | 52 | MAX_FD=maximum |
@@ -100,26 +100,29 @@ location of your Java installation." |
100 | 100 | fi |
101 | 101 | else |
102 | 102 | JAVACMD=java |
103 | | - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. |
| 103 | + if ! command -v java >/dev/null 2>&1 |
| 104 | + then |
| 105 | + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. |
104 | 106 |
|
105 | 107 | Please set the JAVA_HOME variable in your environment to match the |
106 | 108 | location of your Java installation." |
| 109 | + fi |
107 | 110 | fi |
108 | 111 |
|
109 | 112 | # Increase the maximum file descriptors if we can. |
110 | 113 | if ! "\$cygwin" && ! "\$darwin" && ! "\$nonstop" ; then |
111 | 114 | case \$MAX_FD in #( |
112 | 115 | max*) |
113 | 116 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. |
114 | | - # shellcheck disable=SC3045 |
| 117 | + # shellcheck disable=SC2039,SC3045 |
115 | 118 | MAX_FD=\$( ulimit -H -n ) || |
116 | 119 | warn "Could not query maximum file descriptor limit" |
117 | 120 | esac |
118 | 121 | case \$MAX_FD in #( |
119 | 122 | '' | soft) :;; #( |
120 | 123 | *) |
121 | 124 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. |
122 | | - # shellcheck disable=SC3045 |
| 125 | + # shellcheck disable=SC2039,SC3045 |
123 | 126 | ulimit -n "\$MAX_FD" || |
124 | 127 | warn "Could not set maximum file descriptor limit to \$MAX_FD" |
125 | 128 | esac |
@@ -164,19 +167,26 @@ if "\$cygwin" || "\$msys" ; then |
164 | 167 | done |
165 | 168 | fi |
166 | 169 |
|
167 | | -# Collect all arguments for the java command; |
168 | | -# * \$DEFAULT_JVM_OPTS, \$JAVA_OPTS, and \$${optsEnvironmentVar} can contain fragments of |
169 | | -# shell script including quotes and variable substitutions, so put them in |
170 | | -# double quotes to make sure that they get re-expanded; and |
171 | | -# * put everything else in single quotes, so that it's not re-expanded. |
| 170 | +<% /* |
| 171 | +# The DEFAULT_JVM_OPTS variable is intentionally defined here to allow using cygwin-processed APP_HOME. |
| 172 | +# So far the only way to inject APP_HOME reference into DEFAULT_JVM_OPTS is to post-process the start script; the declaration is a good anchor to do that. |
| 173 | +*/ %> |
| 174 | +# Add default JVM options here. You can also use JAVA_OPTS and ${optsEnvironmentVar} to pass JVM options to this script. |
| 175 | +DEFAULT_JVM_OPTS=${defaultJvmOpts} |
| 176 | + |
| 177 | +# Collect all arguments for the java command: |
| 178 | +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, |
| 179 | +# and any embedded shellness will be escaped. |
| 180 | +# * For example: A user cannot expect \${Hostname} to be expanded, as it is an environment variable and will be |
| 181 | +# treated as '\${Hostname}' itself on the command line. |
172 | 182 |
|
173 | 183 | set -- \\ |
174 | 184 | <% if ( appNameSystemProperty ) { |
175 | 185 | %> "-D${appNameSystemProperty}=\$APP_BASE_NAME" \\ |
176 | 186 | <% } %> -classpath "\$CLASSPATH" \\ |
177 | 187 | <% if ( mainClassName.startsWith('--module ') ) { |
178 | 188 | %> --module-path "\$MODULE_PATH" \\ |
179 | | -<% } %> ${mainClassName} \\ |
| 189 | +<% } %> ${mainClassName ?: entryPointArgs} \\ |
180 | 190 | "\$@" |
181 | 191 |
|
182 | 192 | # Stop when "xargs" is not available. |
|
0 commit comments