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