gradlew 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. #!/bin/sh
  2. #
  3. # Copyright © 2015-2021 the original authors.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # https://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. ##############################################################################
  18. #
  19. # Gradle start up script for POSIX generated by Gradle.
  20. #
  21. # Important for running:
  22. #
  23. # (1)
  24. You need
  25. a POSIX
  26. -
  27. compliant shell
  28. to run
  29. this script.
  30. If your
  31. /bin/
  32. sh is
  33. # noncompliant, but you have some other compliant shell such as ksh or
  34. # bash, then to run this script, type that shell name before the whole
  35. # command line, like:
  36. #
  37. # ksh Gradle
  38. #
  39. # Busybox and similar reduced shells will NOT work, because this script
  40. # requires all of these POSIX shell features:
  41. # *
  42. functions;
  43. # * expansions «$var», «${
  44. var}», «${
  45. var:-default}», «${
  46. var+SET}»,
  47. # «${
  48. var#prefix}», «${
  49. var%suffix}», and «
  50. $( cmd )
  51. »;
  52. # *
  53. compound commands
  54. having a
  55. testable exit
  56. status, especially «case»;
  57. # *
  58. various built
  59. -
  60. in commands
  61. including «command», «set», and «ulimit».
  62. #
  63. # Important for patching:
  64. #
  65. # (2)
  66. This script
  67. targets any
  68. POSIX shell, so
  69. it avoids
  70. extensions provided
  71. # by Bash, Ksh, etc; in particular arrays are avoided.
  72. #
  73. # The "traditional" practice of packing multiple parameters into a
  74. # space-separated string is a well documented source of bugs and security
  75. # problems, so this is (mostly) avoided, by progressively accumulating
  76. # options in "$@", and eventually passing that to Java.
  77. #
  78. # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
  79. # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
  80. # see the in-line comments for details.
  81. #
  82. # There are tweaks for specific operating systems such as AIX, CygWin,
  83. # Darwin, MinGW, and NonStop.
  84. #
  85. # (3)
  86. This script
  87. is generated
  88. from the
  89. Groovy
  90. template
  91. # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
  92. # within the Gradle project.
  93. #
  94. # You can find Gradle at https://github.com/gradle/gradle/.
  95. #
  96. ##############################################################################
  97. # Attempt to set APP_HOME
  98. # Resolve links: $0 may be a link
  99. app_path = $0
  100. # Need this for daisy-chained symlinks.
  101. while
  102. APP_HOME = ${app_path % "${app_path##*/}"}
  103. #
  104. leaves a
  105. trailing /; empty if
  106. no leading
  107. path
  108. [ -h "$app_path" ]
  109. do
  110. ls = $(ls - ld
  111. "$app_path" )
  112. link = ${ls#
  113. *' -> '}
  114. case
  115. $link in
  116. #(
  117. /*) app_path=$link ;; #(
  118. *) app_path=$APP_HOME$link ;;
  119. esac
  120. done
  121. APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
  122. APP_NAME="Gradle"
  123. APP_BASE_NAME=${0##*/}
  124. # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
  125. DEFAULT_JVM_OPTS = '"-Xmx64m" "-Xms64m"'
  126. # Use the maximum available, or set MAX_FD != -1 to use that value.
  127. MAX_FD = maximum
  128. warn() {
  129. echo
  130. "$*"
  131. }
  132. >&2
  133. die() {
  134. echo
  135. echo
  136. "$*"
  137. echo
  138. exit
  139. 1
  140. }
  141. >&2
  142. # OS specific support (must be 'true' or 'false').
  143. cygwin = false
  144. msys = false
  145. darwin = false
  146. nonstop = false
  147. case "$( uname )" in #(
  148. CYGWIN* )
  149. cygwin = true;; #(
  150. Darwin* )
  151. darwin = true;; #(
  152. MSYS* | MINGW* )
  153. msys = true;; #(
  154. NONSTOP* )
  155. nonstop = true;;
  156. esac
  157. CLASSPATH = $APP_HOME / gradle / wrapper / gradle - wrapper.jar
  158. # Determine the Java command to use to start the JVM.
  159. if [ -n "$JAVA_HOME" ]; then
  160. if [ -x "$JAVA_HOME/jre/sh/java" ];
  161. then
  162. # IBM's JDK on AIX uses strange locations for the executables
  163. JAVACMD = $JAVA_HOME / jre / sh / java
  164. else
  165. JAVACMD = $JAVA_HOME / bin / java
  166. fi
  167. if [ ! -x "$JAVACMD" ];
  168. then
  169. die
  170. "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
  171. Please set
  172. the JAVA_HOME
  173. variable in
  174. your environment
  175. to match
  176. the
  177. location
  178. of your
  179. Java installation
  180. ."
  181. fi
  182. else
  183. JAVACMD = java
  184. which java
  185. >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
  186. Please set
  187. the JAVA_HOME
  188. variable in
  189. your environment
  190. to match
  191. the
  192. location
  193. of your
  194. Java installation
  195. ."
  196. fi
  197. # Increase the maximum file descriptors if we can.
  198. if ! "$cygwin" && ! "$darwin" && ! "$nonstop"; then
  199. case
  200. $MAX_FD in
  201. #(
  202. max*)
  203. MAX_FD = $(ulimit - H - n) ||
  204. warn
  205. "Could not query maximum file descriptor limit"
  206. esac
  207. case
  208. $MAX_FD in
  209. #(
  210. '' | soft) :;; #(
  211. *)
  212. ulimit -n "$MAX_FD" ||
  213. warn "Could not set maximum file descriptor limit to $MAX_FD"
  214. esac
  215. fi
  216. # Collect all arguments for the java command, stacking in reverse order:
  217. # *
  218. args from
  219. the command
  220. line
  221. # *
  222. the main
  223. class name
  224. # * -classpath
  225. # * -
  226. D...appname
  227. settings
  228. # * --module-
  229. path (only
  230. if needed)
  231. # * DEFAULT_JVM_OPTS, JAVA_OPTS, and
  232. GRADLE_OPTS environment
  233. variables.
  234. # For Cygwin or MSYS, switch paths to Windows format before running java
  235. if "$cygwin" || "$msys";
  236. then
  237. APP_HOME = $(cygpath--
  238. path --mixed "$APP_HOME" )
  239. CLASSPATH = $(cygpath--
  240. path --mixed "$CLASSPATH" )
  241. JAVACMD = $(cygpath--
  242. unix "$JAVACMD" )
  243. # Now convert the arguments - kludge to limit ourselves to /bin/sh
  244. for arg do
  245. if
  246. case
  247. $arg in
  248. #(
  249. -*) false;; # don't mess with options #(
  250. /?*)
  251. t = ${arg#
  252. /}
  253. t =
  254. /${
  255. t%%/*} # looks like a POSIX filepath
  256. [ -e "$t" ] ;; #(
  257. *) false ;;
  258. esac
  259. then
  260. arg=$( cygpath --path --ignore --mixed "$arg" )
  261. fi
  262. # Roll the args list around exactly as many times as the number of
  263. # args, so each arg winds up back in the position where it started, but
  264. # possibly modified.
  265. #
  266. # NB: a `for` loop captures its iteration list before it begins, so
  267. # changing the positional parameters here affects neither the number of
  268. # iterations, nor the values presented in `arg`.
  269. shift # remove old arg
  270. set -- "$@" "$arg" # push replacement arg
  271. done
  272. fi
  273. # Collect all arguments for the java command;
  274. # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
  275. # shell script including quotes and variable substitutions, so put them in
  276. # double quotes to make sure that they get re-expanded; and
  277. # * put everything else in single quotes, so that it's not re-expanded.
  278. set -- \
  279. "-Dorg.gradle.appname=$APP_BASE_NAME" \
  280. -classpath "$CLASSPATH" \
  281. org.gradle.wrapper.GradleWrapperMain \
  282. "$@"
  283. # Use "xargs" to parse quoted args.
  284. #
  285. # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
  286. #
  287. # In Bash we could simply go:
  288. #
  289. # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
  290. # set -- "${ARGS[@]}" "$@"
  291. #
  292. # but POSIX shell has neither arrays nor command substitution, so instead we
  293. # post-process each arg (as a line of input to sed) to backslash-escape any
  294. # character that might be a shell metacharacter, then use eval to reverse
  295. # that process (while maintaining the separation between arguments), and wrap
  296. # the whole thing up as a single "set" statement.
  297. #
  298. # This will of course break if any of these variables contains a newline or
  299. # an unmatched quote.
  300. #
  301. eval "set -- $(
  302. printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
  303. xargs -n1 |
  304. sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
  305. tr '\n' ' '
  306. )" '"$@"'
  307. exec "$JAVACMD" "$@"