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