1#!/usr/bin/env bash 2 3############################################################################## 4## 5## Gradle start up script for UN*X 6## 7############################################################################## 8 9# --------- androidx specific code needed for build server. ------------------ 10 11if [ -n "$OUT_DIR" ] ; then 12 export GRADLE_USER_HOME="$OUT_DIR/.gradle" 13 export LINT_PRINT_STACKTRACE=true 14fi 15 16# ---------------------------------------------------------------------------- 17 18# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 19 20APP_NAME="Gradle" 21APP_BASE_NAME=`basename "$0"` 22 23# Use the maximum available, or set MAX_FD != -1 to use that value. 24MAX_FD="maximum" 25 26warn ( ) { 27 echo "$*" 28} 29 30die ( ) { 31 echo 32 echo "$*" 33 echo 34 exit 1 35} 36 37# OS specific support (must be 'true' or 'false'). 38cygwin=false 39msys=false 40darwin=false 41case "`uname`" in 42 CYGWIN* ) 43 cygwin=true 44 ;; 45 Darwin* ) 46 darwin=true 47 ;; 48 MINGW* ) 49 msys=true 50 ;; 51esac 52 53# Attempt to set APP_HOME 54# Resolve links: $0 may be a link 55PRG="$0" 56# Need this for relative symlinks. 57while [ -h "$PRG" ] ; do 58 ls=`ls -ld "$PRG"` 59 link=`expr "$ls" : '.*-> \(.*\)$'` 60 if expr "$link" : '/.*' > /dev/null; then 61 PRG="$link" 62 else 63 PRG=`dirname "$PRG"`"/$link" 64 fi 65done 66SAVED="`pwd`" 67cd "`dirname \"$PRG\"`/" >/dev/null 68APP_HOME="`pwd -P`" 69cd "$SAVED" >/dev/null 70 71CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 72 73# Pick the correct fullsdk for this OS. 74if [ $darwin == "true" ]; then 75 plat="darwin" 76else 77 plat="linux" 78fi 79DEFAULT_JVM_OPTS="-DLINT_API_DATABASE=$APP_HOME/../../prebuilts/fullsdk-$plat/platform-tools/api/api-versions.xml" 80 81# Determine the Java command to use to start the JVM. 82if [ -n "$JAVA_HOME" ] ; then 83 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 84 # IBM's JDK on AIX uses strange locations for the executables 85 JAVACMD="$JAVA_HOME/jre/sh/java" 86 else 87 JAVACMD="$JAVA_HOME/bin/java" 88 fi 89 if [ ! -x "$JAVACMD" ] ; then 90 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 91 92Please set the JAVA_HOME variable in your environment to match the 93location of your Java installation." 94 fi 95else 96 JAVACMD="java" 97 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 98 99Please set the JAVA_HOME variable in your environment to match the 100location of your Java installation." 101fi 102 103# Increase the maximum file descriptors if we can. 104if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 105 MAX_FD_LIMIT=`ulimit -H -n` 106 if [ $? -eq 0 ] ; then 107 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 108 MAX_FD="$MAX_FD_LIMIT" 109 fi 110 ulimit -n $MAX_FD 111 if [ $? -ne 0 ] ; then 112 warn "Could not set maximum file descriptor limit: $MAX_FD" 113 fi 114 else 115 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 116 fi 117fi 118 119# For Darwin, add options to specify how the application appears in the dock 120if $darwin; then 121 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 122fi 123 124# For Cygwin, switch paths to Windows format before running java 125if $cygwin ; then 126 APP_HOME=`cygpath --path --mixed "$APP_HOME"` 127 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 128 JAVACMD=`cygpath --unix "$JAVACMD"` 129 130 # We build the pattern for arguments to be converted via cygpath 131 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 132 SEP="" 133 for dir in $ROOTDIRSRAW ; do 134 ROOTDIRS="$ROOTDIRS$SEP$dir" 135 SEP="|" 136 done 137 OURCYGPATTERN="(^($ROOTDIRS))" 138 # Add a user-defined pattern to the cygpath arguments 139 if [ "$GRADLE_CYGPATTERN" != "" ] ; then 140 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 141 fi 142 # Now convert the arguments - kludge to limit ourselves to /bin/sh 143 i=0 144 for arg in "$@" ; do 145 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 146 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 147 148 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 149 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 150 else 151 eval `echo args$i`="\"$arg\"" 152 fi 153 i=$((i+1)) 154 done 155 case $i in 156 (0) set -- ;; 157 (1) set -- "$args0" ;; 158 (2) set -- "$args0" "$args1" ;; 159 (3) set -- "$args0" "$args1" "$args2" ;; 160 (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 161 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 162 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 163 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 164 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 165 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 166 esac 167fi 168 169# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 170function splitJvmOpts() { 171 JVM_OPTS=("$@") 172} 173eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 174JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 175 176exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 177