Skip to content

Commit f3d12f9

Browse files
committed
Update StartScriptGenerator templates for Grace Shell
Closes gh-1290
1 parent 279be59 commit f3d12f9

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

grace-shell/src/main/resources/unixStartScript.txt

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
#
4-
# Copyright © 2015-2024 the original authors.
4+
# Copyright © 2015-2025 the original authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
#
1820

1921
##############################################################################
2022
#
@@ -43,10 +45,8 @@ done
4345
# This is normally unused
4446
# shellcheck disable=SC2034
4547
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
5050

5151
# Use the maximum available, or set MAX_FD != -1 to use that value.
5252
MAX_FD=maximum
@@ -100,26 +100,29 @@ location of your Java installation."
100100
fi
101101
else
102102
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.
104106
105107
Please set the JAVA_HOME variable in your environment to match the
106108
location of your Java installation."
109+
fi
107110
fi
108111

109112
# Increase the maximum file descriptors if we can.
110113
if ! "\$cygwin" && ! "\$darwin" && ! "\$nonstop" ; then
111114
case \$MAX_FD in #(
112115
max*)
113116
# 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
115118
MAX_FD=\$( ulimit -H -n ) ||
116119
warn "Could not query maximum file descriptor limit"
117120
esac
118121
case \$MAX_FD in #(
119122
'' | soft) :;; #(
120123
*)
121124
# 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
123126
ulimit -n "\$MAX_FD" ||
124127
warn "Could not set maximum file descriptor limit to \$MAX_FD"
125128
esac
@@ -164,19 +167,26 @@ if "\$cygwin" || "\$msys" ; then
164167
done
165168
fi
166169

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.
172182

173183
set -- \\
174184
<% if ( appNameSystemProperty ) {
175185
%> "-D${appNameSystemProperty}=\$APP_BASE_NAME" \\
176186
<% } %> -classpath "\$CLASSPATH" \\
177187
<% if ( mainClassName.startsWith('--module ') ) {
178188
%> --module-path "\$MODULE_PATH" \\
179-
<% } %> ${mainClassName} \\
189+
<% } %> ${mainClassName ?: entryPointArgs} \\
180190
"\$@"
181191

182192
# Stop when "xargs" is not available.

grace-shell/src/main/resources/windowsStartScript.txt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@rem
2-
@rem Copyright 2015-2024 the original author or authors.
2+
@rem Copyright 2015-2025 the original author or authors.
33
@rem
44
@rem Licensed under the Apache License, Version 2.0 (the "License");
55
@rem you may not use this file except in compliance with the License.
@@ -13,6 +13,8 @@
1313
@rem See the License for the specific language governing permissions and
1414
@rem limitations under the License.
1515
@rem
16+
@rem SPDX-License-Identifier: Apache-2.0
17+
@rem
1618

1719
@if "%DEBUG%"=="" @echo off
1820
@rem ##########################################################################
@@ -44,11 +46,11 @@ set JAVA_EXE=java.exe
4446
%JAVA_EXE% -version >NUL 2>&1
4547
if %ERRORLEVEL% equ 0 goto execute
4648

47-
echo.
48-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
49-
echo.
50-
echo Please set the JAVA_HOME variable in your environment to match the
51-
echo location of your Java installation.
49+
echo. 1>&2
50+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
51+
echo. 1>&2
52+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
53+
echo location of your Java installation. 1>&2
5254

5355
goto fail
5456

@@ -58,11 +60,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5860

5961
if exist "%JAVA_EXE%" goto execute
6062

61-
echo.
62-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
63-
echo.
64-
echo Please set the JAVA_HOME variable in your environment to match the
65-
echo location of your Java installation.
63+
echo. 1>&2
64+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
65+
echo. 1>&2
66+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
67+
echo location of your Java installation. 1>&2
6668

6769
goto fail
6870

@@ -77,7 +79,7 @@ for %%i in ("%APP_HOME%\\lib\\ext\\*") do (
7779
<% if ( mainClassName.startsWith('--module ') ) { %>set MODULE_PATH=$modulePath<% } %>
7880

7981
@rem Execute ${applicationName}
80-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %${optsEnvironmentVar}% <% if ( appNameSystemProperty ) { %>"-D${appNameSystemProperty}=%APP_BASE_NAME%"<% } %> -classpath "%CLASSPATH%" <% if ( mainClassName.startsWith('--module ') ) { %>--module-path "%MODULE_PATH%" <% } %>${mainClassName} %*
82+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %${optsEnvironmentVar}% <% if ( appNameSystemProperty ) { %>"-D${appNameSystemProperty}=%APP_BASE_NAME%"<% } %> -classpath "%CLASSPATH%" <% if ( mainClassName.startsWith('--module ') ) { %>--module-path "%MODULE_PATH%" <% } %>${mainClassName ?: entryPointArgs} %*
8183

8284
:end
8385
@rem End local scope for the variables with windows NT shell

0 commit comments

Comments
 (0)