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