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 11 if [ -n "$OUT_DIR" ] ; then 12 export GRADLE_USER_HOME="$OUT_DIR/.gradle" 13 export LINT_PRINT_STACKTRACE=true 14 fi 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 20 APP_NAME="Gradle" 21 APP_BASE_NAME=`basename "$0"` 22 23 # Use the maximum available, or set MAX_FD != -1 to use that value. 24 MAX_FD="maximum" 25 26 warn ( ) { 27 echo "$*" 28 } 29 30 die ( ) { 31 echo 32 echo "$*" 33 echo 34 exit 1 35 } 36 37 # OS specific support (must be 'true' or 'false'). 38 cygwin=false 39 msys=false 40 darwin=false 41 case "`uname`" in 42 CYGWIN* ) 43 cygwin=true 44 ;; 45 Darwin* ) 46 darwin=true 47 ;; 48 MINGW* ) 49 msys=true 50 ;; 51 esac 52 53 # Attempt to set APP_HOME 54 # Resolve links: $0 may be a link 55 PRG="$0" 56 # Need this for relative symlinks. 57 while [ -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 65 done 66 SAVED="`pwd`" 67 cd "`dirname \"$PRG\"`/" >/dev/null 68 APP_HOME="`pwd -P`" 69 cd "$SAVED" >/dev/null 70 71 CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 72 73 # Pick the correct fullsdk for this OS. 74 if [ $darwin == "true" ]; then 75 plat="darwin" 76 else 77 plat="linux" 78 fi 79 DEFAULT_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. 82 if [ -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 92 Please set the JAVA_HOME variable in your environment to match the 93 location of your Java installation." 94 fi 95 else 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 99 Please set the JAVA_HOME variable in your environment to match the 100 location of your Java installation." 101 fi 102 103 # Increase the maximum file descriptors if we can. 104 if [ "$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 117 fi 118 119 # For Darwin, add options to specify how the application appears in the dock 120 if $darwin; then 121 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 122 fi 123 124 # For Cygwin, switch paths to Windows format before running java 125 if $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 167 fi 168 169 # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 170 function splitJvmOpts() { 171 JVM_OPTS=("$@") 172 } 173 eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 174 JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 175 176 exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 177