1- #! /usr/ bin/env sh
1+ #! /bin/sh
22
33#
4- # Copyright 2015 the original author or authors.
4+ # Copyright © 2015-2021 the original authors.
55#
66# SPDX-License-Identifier: Apache-2.0
77#
1919#
2020
2121# #############################################################################
22- # #
23- # # Gradle start up script for UN*X
24- # #
22+ #
23+ # Gradle start up script for POSIX generated by Gradle.
24+ #
25+ # Important for running:
26+ #
27+ # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28+ # noncompliant, but you have some other compliant shell such as ksh or
29+ # bash, then to run this script, type that shell name before the whole
30+ # command line, like:
31+ #
32+ # ksh Gradle
33+ #
34+ # Busybox and similar reduced shells will NOT work, because this script
35+ # requires all of these POSIX shell features:
36+ # * functions;
37+ # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38+ # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39+ # * compound commands having a testable exit status, especially «case»;
40+ # * various built-in commands including «command», «set», and «ulimit».
41+ #
42+ # Important for patching:
43+ #
44+ # (2) This script targets any POSIX shell, so it avoids extensions provided
45+ # by Bash, Ksh, etc; in particular arrays are avoided.
46+ #
47+ # The "traditional" practice of packing multiple parameters into a
48+ # space-separated string is a well documented source of bugs and security
49+ # problems, so this is (mostly) avoided, by progressively accumulating
50+ # options in "$@", and eventually passing that to Java.
51+ #
52+ # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53+ # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54+ # see the in-line comments for details.
55+ #
56+ # There are tweaks for specific operating systems such as AIX, CygWin,
57+ # Darwin, MinGW, and NonStop.
58+ #
59+ # (3) This script is generated from the Groovy template
60+ # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61+ # within the Gradle project.
62+ #
63+ # You can find Gradle at https://github.com/gradle/gradle/.
64+ #
2565# #############################################################################
2666
2767# Attempt to set APP_HOME
68+
2869# Resolve links: $0 may be a link
29- PRG=" $0 "
30- # Need this for relative symlinks.
31- while [ -h " $PRG " ] ; do
32- ls=` ls -ld " $PRG " `
33- link=` expr " $ls " : ' .*-> \(.*\)$' `
34- if expr " $link " : ' /.*' > /dev/null; then
35- PRG=" $link "
36- else
37- PRG=` dirname " $PRG " ` " /$link "
38- fi
70+ app_path=$0
71+
72+ # Need this for daisy-chained symlinks.
73+ while
74+ APP_HOME=${app_path% " ${app_path##*/ } " } # leaves a trailing /; empty if no leading path
75+ [ -h " $app_path " ]
76+ do
77+ ls=$( ls -ld " $app_path " )
78+ link=${ls#* ' -> ' }
79+ case $link in # (
80+ /* ) app_path=$link ;; # (
81+ * ) app_path=$APP_HOME$link ;;
82+ esac
3983done
40- SAVED=" ` pwd` "
41- cd " ` dirname \" $PRG \" ` /" > /dev/null
42- APP_HOME=" ` pwd -P` "
43- cd " $SAVED " > /dev/null
84+
85+ APP_HOME=$( cd " ${APP_HOME:- ./ } " && pwd -P ) || exit
4486
4587APP_NAME=" Gradle"
46- APP_BASE_NAME=` basename " $0 " `
88+ APP_BASE_NAME=${0 ##*/ }
4789
4890# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
4991DEFAULT_JVM_OPTS=' "-Xmx64m" "-Xms64m"'
5092
5193# Use the maximum available, or set MAX_FD != -1 to use that value.
52- MAX_FD=" maximum"
94+ MAX_FD=maximum
5395
5496warn () {
5597 echo " $* "
56- }
98+ } >&2
5799
58100die () {
59101 echo
60102 echo " $* "
61103 echo
62104 exit 1
63- }
105+ } >&2
64106
65107# OS specific support (must be 'true' or 'false').
66108cygwin=false
67109msys=false
68110darwin=false
69111nonstop=false
70- case " ` uname` " in
71- CYGWIN* )
72- cygwin=true
73- ;;
74- Darwin* )
75- darwin=true
76- ;;
77- MINGW* )
78- msys=true
79- ;;
80- NONSTOP* )
81- nonstop=true
82- ;;
112+ case " $( uname ) " in # (
113+ CYGWIN* ) cygwin=true ;; # (
114+ Darwin* ) darwin=true ;; # (
115+ MSYS* | MINGW* ) msys=true ;; # (
116+ NONSTOP* ) nonstop=true ;;
83117esac
84118
85119CLASSPATH=$APP_HOME /gradle/wrapper/gradle-wrapper.jar
@@ -89,9 +123,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
89123if [ -n " $JAVA_HOME " ] ; then
90124 if [ -x " $JAVA_HOME /jre/sh/java" ] ; then
91125 # IBM's JDK on AIX uses strange locations for the executables
92- JAVACMD=" $JAVA_HOME /jre/sh/java"
126+ JAVACMD=$JAVA_HOME /jre/sh/java
93127 else
94- JAVACMD=" $JAVA_HOME /bin/java"
128+ JAVACMD=$JAVA_HOME /bin/java
95129 fi
96130 if [ ! -x " $JAVACMD " ] ; then
97131 die " ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@@ -100,88 +134,103 @@ Please set the JAVA_HOME variable in your environment to match the
100134location of your Java installation."
101135 fi
102136else
103- JAVACMD=" java"
137+ JAVACMD=java
104138 which java > /dev/null 2>&1 || die " ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
105139
106140Please set the JAVA_HOME variable in your environment to match the
107141location of your Java installation."
108142fi
109143
110144# Increase the maximum file descriptors if we can.
111- if [ " $cygwin " = " false" -a " $darwin " = " false" -a " $nonstop " = " false" ] ; then
112- MAX_FD_LIMIT=` ulimit -H -n`
113- if [ $? -eq 0 ] ; then
114- if [ " $MAX_FD " = " maximum" -o " $MAX_FD " = " max" ] ; then
115- MAX_FD=" $MAX_FD_LIMIT "
116- fi
117- ulimit -n $MAX_FD
118- if [ $? -ne 0 ] ; then
119- warn " Could not set maximum file descriptor limit: $MAX_FD "
120- fi
121- else
122- warn " Could not query maximum file descriptor limit: $MAX_FD_LIMIT "
123- fi
145+ if ! " $cygwin " && ! " $darwin " && ! " $nonstop " ; then
146+ case $MAX_FD in # (
147+ max* )
148+ MAX_FD=$( ulimit -H -n ) ||
149+ warn " Could not query maximum file descriptor limit"
150+ esac
151+ case $MAX_FD in # (
152+ ' ' | soft) : ;; # (
153+ * )
154+ ulimit -n " $MAX_FD " ||
155+ warn " Could not set maximum file descriptor limit to $MAX_FD "
156+ esac
124157fi
125158
126- # For Darwin, add options to specify how the application appears in the dock
127- if $darwin ; then
128- GRADLE_OPTS=" $GRADLE_OPTS \" -Xdock:name=$APP_NAME \" \" -Xdock:icon=$APP_HOME /media/gradle.icns\" "
129- fi
159+ # Collect all arguments for the java command, stacking in reverse order:
160+ # * args from the command line
161+ # * the main class name
162+ # * -classpath
163+ # * -D...appname settings
164+ # * --module-path (only if needed)
165+ # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
130166
131167# For Cygwin or MSYS, switch paths to Windows format before running java
132- if [ " $cygwin " = " true" -o " $msys " = " true" ] ; then
133- APP_HOME=` cygpath --path --mixed " $APP_HOME " `
134- CLASSPATH=` cygpath --path --mixed " $CLASSPATH " `
135-
136- JAVACMD=` cygpath --unix " $JAVACMD " `
137-
138- # We build the pattern for arguments to be converted via cygpath
139- ROOTDIRSRAW=` find -L / -maxdepth 1 -mindepth 1 -type d 2> /dev/null`
140- SEP=" "
141- for dir in $ROOTDIRSRAW ; do
142- ROOTDIRS=" $ROOTDIRS$SEP$dir "
143- SEP=" |"
144- done
145- OURCYGPATTERN=" (^($ROOTDIRS ))"
146- # Add a user-defined pattern to the cygpath arguments
147- if [ " $GRADLE_CYGPATTERN " != " " ] ; then
148- OURCYGPATTERN=" $OURCYGPATTERN |($GRADLE_CYGPATTERN )"
149- fi
168+ if " $cygwin " || " $msys " ; then
169+ APP_HOME=$( cygpath --path --mixed " $APP_HOME " )
170+ CLASSPATH=$( cygpath --path --mixed " $CLASSPATH " )
171+
172+ JAVACMD=$( cygpath --unix " $JAVACMD " )
173+
150174 # Now convert the arguments - kludge to limit ourselves to /bin/sh
151- i=0
152- for arg in " $@ " ; do
153- CHECK=` echo " $arg " | egrep -c " $OURCYGPATTERN " -`
154- CHECK2=` echo " $arg " | egrep -c " ^-" ` # ## Determine if an option
155-
156- if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then # ## Added a condition
157- eval ` echo args$i ` =` cygpath --path --ignore --mixed " $arg " `
158- else
159- eval ` echo args$i ` =" \" $arg \" "
175+ for arg do
176+ if
177+ case $arg in # (
178+ -* ) false ;; # don't mess with options #(
179+ /?* ) t=${arg#/ } t=/${t%%/* } # looks like a POSIX filepath
180+ [ -e " $t " ] ;; # (
181+ * ) false ;;
182+ esac
183+ then
184+ arg=$( cygpath --path --ignore --mixed " $arg " )
160185 fi
161- i=` expr $i + 1`
186+ # Roll the args list around exactly as many times as the number of
187+ # args, so each arg winds up back in the position where it started, but
188+ # possibly modified.
189+ #
190+ # NB: a `for` loop captures its iteration list before it begins, so
191+ # changing the positional parameters here affects neither the number of
192+ # iterations, nor the values presented in `arg`.
193+ shift # remove old arg
194+ set -- " $@ " " $arg " # push replacement arg
162195 done
163- case $i in
164- 0) set -- ;;
165- 1) set -- " $args0 " ;;
166- 2) set -- " $args0 " " $args1 " ;;
167- 3) set -- " $args0 " " $args1 " " $args2 " ;;
168- 4) set -- " $args0 " " $args1 " " $args2 " " $args3 " ;;
169- 5) set -- " $args0 " " $args1 " " $args2 " " $args3 " " $args4 " ;;
170- 6) set -- " $args0 " " $args1 " " $args2 " " $args3 " " $args4 " " $args5 " ;;
171- 7) set -- " $args0 " " $args1 " " $args2 " " $args3 " " $args4 " " $args5 " " $args6 " ;;
172- 8) set -- " $args0 " " $args1 " " $args2 " " $args3 " " $args4 " " $args5 " " $args6 " " $args7 " ;;
173- 9) set -- " $args0 " " $args1 " " $args2 " " $args3 " " $args4 " " $args5 " " $args6 " " $args7 " " $args8 " ;;
174- esac
175196fi
176197
177- # Escape application args
178- save () {
179- for i do printf %s\\ n " $i " | sed " s/'/'\\\\ ''/g;1s/^/'/;\$ s/\$ /' \\\\ /" ; done
180- echo " "
181- }
182- APP_ARGS=` save " $@ " `
198+ # Collect all arguments for the java command;
199+ # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
200+ # shell script including quotes and variable substitutions, so put them in
201+ # double quotes to make sure that they get re-expanded; and
202+ # * put everything else in single quotes, so that it's not re-expanded.
203+
204+ set -- \
205+ " -Dorg.gradle.appname=$APP_BASE_NAME " \
206+ -classpath " $CLASSPATH " \
207+ org.gradle.wrapper.GradleWrapperMain \
208+ " $@ "
209+
210+ # Use "xargs" to parse quoted args.
211+ #
212+ # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
213+ #
214+ # In Bash we could simply go:
215+ #
216+ # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
217+ # set -- "${ARGS[@]}" "$@"
218+ #
219+ # but POSIX shell has neither arrays nor command substitution, so instead we
220+ # post-process each arg (as a line of input to sed) to backslash-escape any
221+ # character that might be a shell metacharacter, then use eval to reverse
222+ # that process (while maintaining the separation between arguments), and wrap
223+ # the whole thing up as a single "set" statement.
224+ #
225+ # This will of course break if any of these variables contains a newline or
226+ # an unmatched quote.
227+ #
183228
184- # Collect all arguments for the java command, following the shell quoting and substitution rules
185- eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS " \" -Dorg.gradle.appname=$APP_BASE_NAME \" " -classpath " \" $CLASSPATH \" " org.gradle.wrapper.GradleWrapperMain " $APP_ARGS "
229+ eval " set -- $(
230+ printf ' %s\n' " $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS " |
231+ xargs -n1 |
232+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
233+ tr ' \n' ' '
234+ ) " ' "$@"'
186235
187236exec " $JAVACMD " " $@ "
0 commit comments