1
- #! /bin/sh
1
+ #! /usr/ bin/env 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 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
- #
39
+ # #
40
+ # # Gradle start up script for UN*X
41
+ # #
82
42
# #############################################################################
83
43
84
44
# Attempt to set APP_HOME
85
-
86
45
# Resolve links: $0 may be a link
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
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
100
56
done
101
-
102
- APP_HOME=$( cd " ${APP_HOME:- ./ } " && pwd -P ) || exit
57
+ SAVED=" ` pwd` "
58
+ cd " ` dirname \" $PRG \" ` /" > /dev/null
59
+ APP_HOME=" ` pwd -P` "
60
+ cd " $SAVED " > /dev/null
103
61
104
62
APP_NAME=" Gradle"
105
- APP_BASE_NAME=${0 ##*/ }
63
+ APP_BASE_NAME=` basename " $0 " `
106
64
107
65
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
108
66
DEFAULT_JVM_OPTS=' "-Xmx64m" "-Xms64m"'
109
67
110
68
# Use the maximum available, or set MAX_FD != -1 to use that value.
111
- MAX_FD=maximum
69
+ MAX_FD=" maximum"
112
70
113
71
warn () {
114
72
echo " $* "
115
- } >&2
73
+ }
116
74
117
75
die () {
118
76
echo
119
77
echo " $* "
120
78
echo
121
79
exit 1
122
- } >&2
80
+ }
123
81
124
82
# OS specific support (must be 'true' or 'false').
125
83
cygwin=false
126
84
msys=false
127
85
darwin=false
128
86
nonstop=false
129
- case " $( uname ) " in # (
130
- CYGWIN* ) cygwin=true ;; # (
131
- Darwin* ) darwin=true ;; # (
132
- MSYS* | MINGW* ) msys=true ;; # (
133
- NONSTOP* ) nonstop=true ;;
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
+ ;;
134
100
esac
135
101
136
102
CLASSPATH=$APP_HOME /gradle/wrapper/gradle-wrapper.jar
@@ -140,9 +106,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
140
106
if [ -n " $JAVA_HOME " ] ; then
141
107
if [ -x " $JAVA_HOME /jre/sh/java" ] ; then
142
108
# IBM's JDK on AIX uses strange locations for the executables
143
- JAVACMD=$JAVA_HOME /jre/sh/java
109
+ JAVACMD=" $JAVA_HOME /jre/sh/java"
144
110
else
145
- JAVACMD=$JAVA_HOME /bin/java
111
+ JAVACMD=" $JAVA_HOME /bin/java"
146
112
fi
147
113
if [ ! -x " $JAVACMD " ] ; then
148
114
die " ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@@ -151,103 +117,88 @@ Please set the JAVA_HOME variable in your environment to match the
151
117
location of your Java installation."
152
118
fi
153
119
else
154
- JAVACMD=java
120
+ JAVACMD=" java"
155
121
which java > /dev/null 2>&1 || die " ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
156
122
157
123
Please set the JAVA_HOME variable in your environment to match the
158
124
location of your Java installation."
159
125
fi
160
126
161
127
# Increase the maximum file descriptors if we can.
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
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
174
141
fi
175
142
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.
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
183
147
184
148
# For Cygwin or MSYS, switch paths to Windows format before running java
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
-
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
191
167
# Now convert the arguments - kludge to limit ourselves to /bin/sh
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 " )
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 \" "
202
177
fi
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
178
+ i=` expr $i + 1`
212
179
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
213
192
fi
214
193
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
- #
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 " $@ " `
245
200
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
- ) " ' "$@"'
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 "
252
203
253
204
exec " $JAVACMD " " $@ "
0 commit comments