1 #!/usr/bin/env bash 2 3 ############################################################################## 4 ## 5 ## Gradle start up script for UN*X 6 ## 7 ############################################################################## 8 9 # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 DEFAULT_JVM_OPTS="" 11 12 APP_NAME="Gradle" 13 APP_BASE_NAME=`basename "$0"` 14 15 # Use the maximum available, or set MAX_FD != -1 to use that value. 16 MAX_FD="maximum" 17 18 warn ( ) { 19 echo "$*" 20 } 21 22 die ( ) { 23 echo 24 echo "$*" 25 echo 26 exit 1 27 } 28 29 # OS specific support (must be 'true' or 'false'). 30 cygwin=false 31 msys=false 32 darwin=false 33 case "`uname`" in 34 CYGWIN* ) 35 cygwin=true 36 ;; 37 Darwin* ) 38 darwin=true 39 ;; 40 MINGW* ) 41 msys=true 42 ;; 43 esac 44 45 # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 if $cygwin ; then 47 [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 fi 49 50 # Attempt to set APP_HOME 51 # Resolve links: $0 may be a link 52 PRG="$0" 53 # Need this for relative symlinks. 54 while [ -h "$PRG" ] ; do 55 ls=`ls -ld "$PRG"` 56 link=`expr "$ls" : '.*-> \(.*\)$'` 57 if expr "$link" : '/.*' > /dev/null; then 58 PRG="$link" 59 else 60 PRG=`dirname "$PRG"`"/$link" 61 fi 62 done 63 SAVED="`pwd`" 64 cd "`dirname \"$PRG\"`/" >&- 65 APP_HOME="`pwd -P`" 66 cd "$SAVED" >&- 67 68 if [ $(basename `pwd`) == "gradle" ]; then 69 echo "This cannot be run here. It should be copied to the root of the platform." 70 exit 71 else 72 CLASSPATH=./gradle/wrapper/gradle-wrapper.jar 73 fi 74 75 # Determine the Java command to use to start the JVM. 76 if [ -n "$JAVA_HOME" ] ; then 77 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 78 # IBM's JDK on AIX uses strange locations for the executables 79 JAVACMD="$JAVA_HOME/jre/sh/java" 80 else 81 JAVACMD="$JAVA_HOME/bin/java" 82 fi 83 if [ ! -x "$JAVACMD" ] ; then 84 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 85 86 Please set the JAVA_HOME variable in your environment to match the 87 location of your Java installation." 88 fi 89 else 90 JAVACMD="java" 91 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 92 93 Please set the JAVA_HOME variable in your environment to match the 94 location of your Java installation." 95 fi 96 97 # Increase the maximum file descriptors if we can. 98 if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 99 MAX_FD_LIMIT=`ulimit -H -n` 100 if [ $? -eq 0 ] ; then 101 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 102 MAX_FD="$MAX_FD_LIMIT" 103 fi 104 ulimit -n $MAX_FD 105 if [ $? -ne 0 ] ; then 106 warn "Could not set maximum file descriptor limit: $MAX_FD" 107 fi 108 else 109 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 110 fi 111 fi 112 113 # For Darwin, add options to specify how the application appears in the dock 114 if $darwin; then 115 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 116 fi 117 118 # For Cygwin, switch paths to Windows format before running java 119 if $cygwin ; then 120 APP_HOME=`cygpath --path --mixed "$APP_HOME"` 121 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 122 123 # We build the pattern for arguments to be converted via cygpath 124 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 125 SEP="" 126 for dir in $ROOTDIRSRAW ; do 127 ROOTDIRS="$ROOTDIRS$SEP$dir" 128 SEP="|" 129 done 130 OURCYGPATTERN="(^($ROOTDIRS))" 131 # Add a user-defined pattern to the cygpath arguments 132 if [ "$GRADLE_CYGPATTERN" != "" ] ; then 133 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 134 fi 135 # Now convert the arguments - kludge to limit ourselves to /bin/sh 136 i=0 137 for arg in "$@" ; do 138 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 139 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 140 141 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 142 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 143 else 144 eval `echo args$i`="\"$arg\"" 145 fi 146 i=$((i+1)) 147 done 148 case $i in 149 (0) set -- ;; 150 (1) set -- "$args0" ;; 151 (2) set -- "$args0" "$args1" ;; 152 (3) set -- "$args0" "$args1" "$args2" ;; 153 (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 154 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 155 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 156 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 157 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 158 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 159 esac 160 fi 161 162 # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 163 function splitJvmOpts() { 164 JVM_OPTS=("$@") 165 } 166 eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 167 JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 168 169 # For reproducible builds, always use the SDKs stored in source control 170 if $darwin; then 171 ANDROID_HOME="$APP_HOME/prebuilts/fullsdk/darwin" 172 else 173 ANDROID_HOME="$APP_HOME/prebuilts/fullsdk/linux" 174 fi 175 export ANDROID_HOME 176 177 # Also, blow away lint's API cache, since it can easily become out of date 178 # if we're building against pre-release SDKs 179 (cd "$HOME/.android/cache" && rm -f api-versions*) 2> /dev/null 180 181 # Change the project's .gradle to the android out dir. 182 ANDROID_OUT_ROOT="$APP_HOME/out" 183 if [[ -n "$OUT_DIR" ]]; then 184 ANDROID_OUT_ROOT="$OUT_DIR" 185 fi 186 187 ANDROID_CACHE_DIR="$ANDROID_OUT_ROOT/gradle/.gradle" 188 189 # Change the local user directories to be under the android out dir 190 export GRADLE_USER_HOME="$ANDROID_OUT_ROOT/gradle/.gradle" 191 export M2_HOME="$ANDROID_OUT_ROOT/gradle/.m2" 192 193 # NewRatio is the ratio of the total heap size to new generation size the JVM tries to maintain. 194 # Higher values mean smaller new generations. 195 # The default is 2. Setting this to 3. 196 # Higher values should "stabalize" heap usage somewhat and helps keep the total heap 197 # size from growing too quickly (the JVM is more willing to grow the new generation than the old). 198 # Also, the old generation is more "friendly" to being swapped out to disk than the new generation. 199 # This should help out on lower memory machines. 200 # Profiling has shown that the extra GCs done because of this are trivial in added time. 201 exec "$JAVACMD" "${JVM_OPTS[@]}" \ 202 -classpath "$CLASSPATH" \ 203 org.gradle.wrapper.GradleWrapperMain \ 204 --project-cache-dir=$ANDROID_CACHE_DIR \ 205 --configure-on-demand \ 206 "$@" 207