11#! /bin/sh
2+ #! /bin/sh
23
34#
45# Copyright © 2015-2021 the original authors.
6+ # Copyright © 2015-2021 the original authors.
57#
68# Licensed under the Apache License, Version 2.0 (the "License");
79# you may not use this file except in compliance with the License.
6062#
6163# You can find Gradle at https://github.com/gradle/gradle/.
6264#
65+ #
66+ # Gradle start up script for POSIX generated by Gradle.
67+ #
68+ # Important for running:
69+ #
70+ # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
71+ # noncompliant, but you have some other compliant shell such as ksh or
72+ # bash, then to run this script, type that shell name before the whole
73+ # command line, like:
74+ #
75+ # ksh Gradle
76+ #
77+ # Busybox and similar reduced shells will NOT work, because this script
78+ # requires all of these POSIX shell features:
79+ # * functions;
80+ # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
81+ # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
82+ # * compound commands having a testable exit status, especially «case»;
83+ # * various built-in commands including «command», «set», and «ulimit».
84+ #
85+ # Important for patching:
86+ #
87+ # (2) This script targets any POSIX shell, so it avoids extensions provided
88+ # by Bash, Ksh, etc; in particular arrays are avoided.
89+ #
90+ # The "traditional" practice of packing multiple parameters into a
91+ # space-separated string is a well documented source of bugs and security
92+ # problems, so this is (mostly) avoided, by progressively accumulating
93+ # options in "$@", and eventually passing that to Java.
94+ #
95+ # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
96+ # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
97+ # see the in-line comments for details.
98+ #
99+ # There are tweaks for specific operating systems such as AIX, CygWin,
100+ # Darwin, MinGW, and NonStop.
101+ #
102+ # (3) This script is generated from the Groovy template
103+ # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
104+ # within the Gradle project.
105+ #
106+ # You can find Gradle at https://github.com/gradle/gradle/.
107+ #
63108# #############################################################################
64109
65110# Attempt to set APP_HOME
66111
112+
67113# Resolve links: $0 may be a link
68114app_path=$0
69115
116+ # Need this for daisy-chained symlinks.
117+ while
118+ APP_HOME=${app_path% " ${app_path##*/ } " } # leaves a trailing /; empty if no leading path
119+ [ -h " $app_path " ]
120+ do
121+ ls=$( ls -ld " $app_path " )
122+ link=${ls#* ' -> ' }
123+ case $link in # (
124+ /* ) app_path=$link ;; # (
125+ * ) app_path=$APP_HOME$link ;;
126+ esac
127+ app_path=$0
128+
70129# Need this for daisy-chained symlinks.
71130while
72131 APP_HOME=${app_path% " ${app_path##*/ } " } # leaves a trailing /; empty if no leading path
@@ -82,31 +141,42 @@ done
82141
83142APP_HOME=$( cd " ${APP_HOME:- ./ } " && pwd -P ) || exit
84143
144+ APP_HOME=$( cd " ${APP_HOME:- ./ } " && pwd -P ) || exit
145+
85146APP_NAME=" Gradle"
86147APP_BASE_NAME=${0##*/ }
148+ APP_BASE_NAME=${0##*/ }
87149
88150# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89151DEFAULT_JVM_OPTS=' "-Xmx64m" "-Xms64m"'
90152
91153# Use the maximum available, or set MAX_FD != -1 to use that value.
92154MAX_FD=maximum
155+ MAX_FD=maximum
93156
94157warn () {
95158 echo " $* "
96159} >&2
160+ } >&2
97161
98162die () {
99163 echo
100164 echo " $* "
101165 echo
102166 exit 1
103167} >&2
168+ } >&2
104169
105170# OS specific support (must be 'true' or 'false').
106171cygwin=false
107172msys=false
108173darwin=false
109174nonstop=false
175+ case " $( uname ) " in # (
176+ CYGWIN* ) cygwin=true ;; # (
177+ Darwin* ) darwin=true ;; # (
178+ MSYS* | MINGW* ) msys=true ;; # (
179+ NONSTOP* ) nonstop=true ;;
110180case " $( uname ) " in #(
111181 CYGWIN* ) cygwin=true ;; # (
112182 Darwin* ) darwin=true ;; # (
@@ -117,13 +187,16 @@ esac
117187CLASSPATH=$APP_HOME /gradle/wrapper/gradle-wrapper.jar
118188
119189
190+
120191# Determine the Java command to use to start the JVM.
121192if [ -n " $JAVA_HOME " ] ; then
122193 if [ -x " $JAVA_HOME /jre/sh/java" ] ; then
123194 # IBM's JDK on AIX uses strange locations for the executables
124195 JAVACMD=$JAVA_HOME /jre/sh/java
196+ JAVACMD=$JAVA_HOME /jre/sh/java
125197 else
126198 JAVACMD=$JAVA_HOME /bin/java
199+ JAVACMD=$JAVA_HOME /bin/java
127200 fi
128201 if [ ! -x " $JAVACMD " ] ; then
129202 die " ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@@ -132,6 +205,7 @@ Please set the JAVA_HOME variable in your environment to match the
132205location of your Java installation."
133206 fi
134207else
208+ JAVACMD=java
135209 JAVACMD=java
136210 which java > /dev/null 2>&1 || die " ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137211
@@ -140,6 +214,18 @@ location of your Java installation."
140214fi
141215
142216# Increase the maximum file descriptors if we can.
217+ if ! " $cygwin " && ! " $darwin " && ! " $nonstop " ; then
218+ case $MAX_FD in # (
219+ max* )
220+ MAX_FD=$( ulimit -H -n ) ||
221+ warn " Could not query maximum file descriptor limit"
222+ esac
223+ case $MAX_FD in # (
224+ ' ' | soft) : ;; # (
225+ * )
226+ ulimit -n " $MAX_FD " ||
227+ warn " Could not set maximum file descriptor limit to $MAX_FD "
228+ esac
143229if ! " $cygwin " && ! " $darwin " && ! " $nonstop " ; then
144230 case $MAX_FD in # (
145231 max* )
@@ -154,6 +240,13 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
154240 esac
155241fi
156242
243+ # Collect all arguments for the java command, stacking in reverse order:
244+ # * args from the command line
245+ # * the main class name
246+ # * -classpath
247+ # * -D...appname settings
248+ # * --module-path (only if needed)
249+ # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
157250# Collect all arguments for the java command, stacking in reverse order:
158251# * args from the command line
159252# * the main class name
@@ -168,8 +261,23 @@ if "$cygwin" || "$msys" ; then
168261 CLASSPATH=$( cygpath --path --mixed " $CLASSPATH " )
169262
170263 JAVACMD=$( cygpath --unix " $JAVACMD " )
264+ if " $cygwin " || " $msys " ; then
265+ APP_HOME=$( cygpath --path --mixed " $APP_HOME " )
266+ CLASSPATH=$( cygpath --path --mixed " $CLASSPATH " )
267+
268+ JAVACMD=$( cygpath --unix " $JAVACMD " )
171269
172270 # Now convert the arguments - kludge to limit ourselves to /bin/sh
271+ for arg do
272+ if
273+ case $arg in # (
274+ -* ) false ;; # don't mess with options #(
275+ /?* ) t=${arg#/ } t=/${t%%/* } # looks like a POSIX filepath
276+ [ -e " $t " ] ;; # (
277+ * ) false ;;
278+ esac
279+ then
280+ arg=$( cygpath --path --ignore --mixed " $arg " )
173281 for arg do
174282 if
175283 case $arg in # (
@@ -190,6 +298,15 @@ if "$cygwin" || "$msys" ; then
190298 # iterations, nor the values presented in `arg`.
191299 shift # remove old arg
192300 set -- " $@ " " $arg " # push replacement arg
301+ # Roll the args list around exactly as many times as the number of
302+ # args, so each arg winds up back in the position where it started, but
303+ # possibly modified.
304+ #
305+ # NB: a `for` loop captures its iteration list before it begins, so
306+ # changing the positional parameters here affects neither the number of
307+ # iterations, nor the values presented in `arg`.
308+ shift # remove old arg
309+ set -- " $@ " " $arg " # push replacement arg
193310 done
194311fi
195312
@@ -211,6 +328,18 @@ then
211328 die " xargs is not available"
212329fi
213330
331+ # Collect all arguments for the java command;
332+ # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
333+ # shell script including quotes and variable substitutions, so put them in
334+ # double quotes to make sure that they get re-expanded; and
335+ # * put everything else in single quotes, so that it's not re-expanded.
336+
337+ set -- \
338+ " -Dorg.gradle.appname=$APP_BASE_NAME " \
339+ -classpath " $CLASSPATH " \
340+ org.gradle.wrapper.GradleWrapperMain \
341+ " $@ "
342+
214343# Use "xargs" to parse quoted args.
215344#
216345# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
230359# an unmatched quote.
231360#
232361
362+ eval " set -- $(
363+ printf ' %s\n' " $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS " |
364+ xargs -n1 |
365+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
366+ tr ' \n' ' '
367+ ) " ' "$@"'
233368eval " set -- $(
234369 printf ' %s\n' " $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS " |
235370 xargs -n1 |
0 commit comments