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