gradlew 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #!/bin/sh
  2. #
  3. # Copyright 2019-2023 Mamoe Technologies and contributors.
  4. #
  5. # 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  6. # Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  7. #
  8. # https://github.com/mamoe/mirai/blob/dev/LICENSE
  9. #
  10. ##############################################################################
  11. #
  12. # Gradle start up script for POSIX generated by Gradle.
  13. #
  14. # Important for running:
  15. #
  16. # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
  17. # noncompliant, but you have some other compliant shell such as ksh or
  18. # bash, then to run this script, type that shell name before the whole
  19. # command line, like:
  20. #
  21. # ksh Gradle
  22. #
  23. # Busybox and similar reduced shells will NOT work, because this script
  24. # requires all of these POSIX shell features:
  25. # * functions;
  26. # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
  27. # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
  28. # * compound commands having a testable exit status, especially «case»;
  29. # * various built-in commands including «command», «set», and «ulimit».
  30. #
  31. # Important for patching:
  32. #
  33. # (2) This script targets any POSIX shell, so it avoids extensions provided
  34. # by Bash, Ksh, etc; in particular arrays are avoided.
  35. #
  36. # The "traditional" practice of packing multiple parameters into a
  37. # space-separated string is a well documented source of bugs and security
  38. # problems, so this is (mostly) avoided, by progressively accumulating
  39. # options in "$@", and eventually passing that to Java.
  40. #
  41. # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
  42. # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
  43. # see the in-line comments for details.
  44. #
  45. # There are tweaks for specific operating systems such as AIX, CygWin,
  46. # Darwin, MinGW, and NonStop.
  47. #
  48. # (3) This script is generated from the Groovy template
  49. # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
  50. # within the Gradle project.
  51. #
  52. # You can find Gradle at https://github.com/gradle/gradle/.
  53. #
  54. ##############################################################################
  55. # Attempt to set APP_HOME
  56. # Resolve links: $0 may be a link
  57. app_path=$0
  58. # Need this for daisy-chained symlinks.
  59. while
  60. APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
  61. [ -h "$app_path" ]
  62. do
  63. ls=$( ls -ld "$app_path" )
  64. link=${ls#*' -> '}
  65. case $link in #(
  66. /*) app_path=$link ;; #(
  67. *) app_path=$APP_HOME$link ;;
  68. esac
  69. done
  70. APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
  71. APP_NAME="Gradle"
  72. APP_BASE_NAME=${0##*/}
  73. # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
  74. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
  75. # Use the maximum available, or set MAX_FD != -1 to use that value.
  76. MAX_FD=maximum
  77. warn () {
  78. echo "$*"
  79. } >&2
  80. die () {
  81. echo
  82. echo "$*"
  83. echo
  84. exit 1
  85. } >&2
  86. # OS specific support (must be 'true' or 'false').
  87. cygwin=false
  88. msys=false
  89. darwin=false
  90. nonstop=false
  91. case "$( uname )" in #(
  92. CYGWIN* ) cygwin=true ;; #(
  93. Darwin* ) darwin=true ;; #(
  94. MSYS* | MINGW* ) msys=true ;; #(
  95. NONSTOP* ) nonstop=true ;;
  96. esac
  97. CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
  98. # Determine the Java command to use to start the JVM.
  99. if [ -n "$JAVA_HOME" ] ; then
  100. if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  101. # IBM's JDK on AIX uses strange locations for the executables
  102. JAVACMD=$JAVA_HOME/jre/sh/java
  103. else
  104. JAVACMD=$JAVA_HOME/bin/java
  105. fi
  106. if [ ! -x "$JAVACMD" ] ; then
  107. die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
  108. Please set the JAVA_HOME variable in your environment to match the
  109. location of your Java installation."
  110. fi
  111. else
  112. JAVACMD=java
  113. which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
  114. Please set the JAVA_HOME variable in your environment to match the
  115. location of your Java installation."
  116. fi
  117. # Increase the maximum file descriptors if we can.
  118. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
  119. case $MAX_FD in #(
  120. max*)
  121. MAX_FD=$( ulimit -H -n ) ||
  122. warn "Could not query maximum file descriptor limit"
  123. esac
  124. case $MAX_FD in #(
  125. '' | soft) :;; #(
  126. *)
  127. ulimit -n "$MAX_FD" ||
  128. warn "Could not set maximum file descriptor limit to $MAX_FD"
  129. esac
  130. fi
  131. # Collect all arguments for the java command, stacking in reverse order:
  132. # * args from the command line
  133. # * the main class name
  134. # * -classpath
  135. # * -D...appname settings
  136. # * --module-path (only if needed)
  137. # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
  138. # For Cygwin or MSYS, switch paths to Windows format before running java
  139. if "$cygwin" || "$msys" ; then
  140. APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
  141. CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
  142. JAVACMD=$( cygpath --unix "$JAVACMD" )
  143. # Now convert the arguments - kludge to limit ourselves to /bin/sh
  144. for arg do
  145. if
  146. case $arg in #(
  147. -*) false ;; # don't mess with options #(
  148. /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
  149. [ -e "$t" ] ;; #(
  150. *) false ;;
  151. esac
  152. then
  153. arg=$( cygpath --path --ignore --mixed "$arg" )
  154. fi
  155. # Roll the args list around exactly as many times as the number of
  156. # args, so each arg winds up back in the position where it started, but
  157. # possibly modified.
  158. #
  159. # NB: a `for` loop captures its iteration list before it begins, so
  160. # changing the positional parameters here affects neither the number of
  161. # iterations, nor the values presented in `arg`.
  162. shift # remove old arg
  163. set -- "$@" "$arg" # push replacement arg
  164. done
  165. fi
  166. # Collect all arguments for the java command;
  167. # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
  168. # shell script including quotes and variable substitutions, so put them in
  169. # double quotes to make sure that they get re-expanded; and
  170. # * put everything else in single quotes, so that it's not re-expanded.
  171. set -- \
  172. "-Dorg.gradle.appname=$APP_BASE_NAME" \
  173. -classpath "$CLASSPATH" \
  174. org.gradle.wrapper.GradleWrapperMain \
  175. "$@"
  176. # Use "xargs" to parse quoted args.
  177. #
  178. # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
  179. #
  180. # In Bash we could simply go:
  181. #
  182. # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
  183. # set -- "${ARGS[@]}" "$@"
  184. #
  185. # but POSIX shell has neither arrays nor command substitution, so instead we
  186. # post-process each arg (as a line of input to sed) to backslash-escape any
  187. # character that might be a shell metacharacter, then use eval to reverse
  188. # that process (while maintaining the separation between arguments), and wrap
  189. # the whole thing up as a single "set" statement.
  190. #
  191. # This will of course break if any of these variables contains a newline or
  192. # an unmatched quote.
  193. #
  194. eval "set -- $(
  195. printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
  196. xargs -n1 |
  197. sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
  198. tr '\n' ' '
  199. )" '"$@"'
  200. exec "$JAVACMD" "$@"