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