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