blob: 1cf59b69edfb4abf654a6657dd39f00842e4a61d [file] [log] [blame]
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -07001#!/usr/bin/env bash
2
3##############################################################################
4##
5## Gradle start up script for UN*X
6##
7##############################################################################
8
Aurimas Liutikas9979d072018-03-13 15:38:56 -07009# --------- androidx specific code needed for build server. ------------------
10
11if [ -n "$OUT_DIR" ] ; then
12 export GRADLE_USER_HOME="$OUT_DIR/.gradle"
Aurimas Liutikasc5f4f982018-05-17 14:03:04 -070013 export LINT_PRINT_STACKTRACE=true
Jeff Gastoncc694ab2019-04-11 16:51:36 -040014else
15 SCRIPT_PATH="$(cd $(dirname $0) && pwd)"
16 CHECKOUT_ROOT="$(cd $SCRIPT_PATH/../.. && pwd)"
17 export OUT_DIR="$CHECKOUT_ROOT/out"
Aurimas Liutikas9979d072018-03-13 15:38:56 -070018fi
19
20# ----------------------------------------------------------------------------
21
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070022# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070023
24APP_NAME="Gradle"
25APP_BASE_NAME=`basename "$0"`
26
27# Use the maximum available, or set MAX_FD != -1 to use that value.
28MAX_FD="maximum"
29
30warn ( ) {
31 echo "$*"
32}
33
34die ( ) {
35 echo
36 echo "$*"
37 echo
38 exit 1
39}
40
41# OS specific support (must be 'true' or 'false').
42cygwin=false
43msys=false
44darwin=false
45case "`uname`" in
46 CYGWIN* )
47 cygwin=true
48 ;;
49 Darwin* )
50 darwin=true
51 ;;
52 MINGW* )
53 msys=true
54 ;;
55esac
56
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070057# Attempt to set APP_HOME
58# Resolve links: $0 may be a link
59PRG="$0"
60# Need this for relative symlinks.
61while [ -h "$PRG" ] ; do
62 ls=`ls -ld "$PRG"`
63 link=`expr "$ls" : '.*-> \(.*\)$'`
64 if expr "$link" : '/.*' > /dev/null; then
65 PRG="$link"
66 else
67 PRG=`dirname "$PRG"`"/$link"
68 fi
69done
70SAVED="`pwd`"
Yigit Boyarf77697d2016-08-16 10:55:36 -070071cd "`dirname \"$PRG\"`/" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070072APP_HOME="`pwd -P`"
Yigit Boyarf77697d2016-08-16 10:55:36 -070073cd "$SAVED" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070074
75CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
76
Jeff Gaston79a43f22019-04-09 16:19:12 -040077# --------- androidx specific code needed for lint and java. ------------------
78
Alan Viveretted38b36c2017-02-01 16:45:31 -050079# Pick the correct fullsdk for this OS.
Alan Viverette7df63ff2017-03-06 13:12:24 -050080if [ $darwin == "true" ]; then
Alan Viveretted38b36c2017-02-01 16:45:31 -050081 plat="darwin"
82else
83 plat="linux"
84fi
85DEFAULT_JVM_OPTS="-DLINT_API_DATABASE=$APP_HOME/../../prebuilts/fullsdk-$plat/platform-tools/api/api-versions.xml"
86
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -050087# Temporary solution for custom, private lint rules https://issuetracker.google.com/issues/65248347
88# Gradle automatically invokes 'jar' task on 'buildSrc/' projects so this will always be available.
Jeff Gaston79a43f22019-04-09 16:19:12 -040089export ANDROID_LINT_JARS="$OUT_DIR/buildSrc/lint-checks/build/libs/lint-checks.jar"
Sergey Vasilinetsefab5eb2019-01-04 12:38:06 +000090# override JAVA_HOME, because CI machines have it and it points to very old JDK
91export JAVA_HOME="$APP_HOME/../../prebuilts/jdk/jdk8/$plat-x86"
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -050092
Jeff Gaston79a43f22019-04-09 16:19:12 -040093# ----------------------------------------------------------------------------
94
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070095# Determine the Java command to use to start the JVM.
96if [ -n "$JAVA_HOME" ] ; then
97 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
98 # IBM's JDK on AIX uses strange locations for the executables
99 JAVACMD="$JAVA_HOME/jre/sh/java"
100 else
101 JAVACMD="$JAVA_HOME/bin/java"
102 fi
103 if [ ! -x "$JAVACMD" ] ; then
104 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
105
106Please set the JAVA_HOME variable in your environment to match the
107location of your Java installation."
108 fi
109else
110 JAVACMD="java"
111 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
112
113Please set the JAVA_HOME variable in your environment to match the
114location of your Java installation."
115fi
116
117# Increase the maximum file descriptors if we can.
118if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
119 MAX_FD_LIMIT=`ulimit -H -n`
120 if [ $? -eq 0 ] ; then
121 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
122 MAX_FD="$MAX_FD_LIMIT"
123 fi
124 ulimit -n $MAX_FD
125 if [ $? -ne 0 ] ; then
126 warn "Could not set maximum file descriptor limit: $MAX_FD"
127 fi
128 else
129 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
130 fi
131fi
132
133# For Darwin, add options to specify how the application appears in the dock
134if $darwin; then
135 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
136fi
137
138# For Cygwin, switch paths to Windows format before running java
139if $cygwin ; then
140 APP_HOME=`cygpath --path --mixed "$APP_HOME"`
141 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
Yigit Boyarf77697d2016-08-16 10:55:36 -0700142 JAVACMD=`cygpath --unix "$JAVACMD"`
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700143
144 # We build the pattern for arguments to be converted via cygpath
145 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
146 SEP=""
147 for dir in $ROOTDIRSRAW ; do
148 ROOTDIRS="$ROOTDIRS$SEP$dir"
149 SEP="|"
150 done
151 OURCYGPATTERN="(^($ROOTDIRS))"
152 # Add a user-defined pattern to the cygpath arguments
153 if [ "$GRADLE_CYGPATTERN" != "" ] ; then
154 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
155 fi
156 # Now convert the arguments - kludge to limit ourselves to /bin/sh
157 i=0
158 for arg in "$@" ; do
159 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
160 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
161
162 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
163 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
164 else
165 eval `echo args$i`="\"$arg\""
166 fi
167 i=$((i+1))
168 done
169 case $i in
170 (0) set -- ;;
171 (1) set -- "$args0" ;;
172 (2) set -- "$args0" "$args1" ;;
173 (3) set -- "$args0" "$args1" "$args2" ;;
174 (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
175 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
176 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
177 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
178 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
179 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
180 esac
181fi
182
183# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
184function splitJvmOpts() {
185 JVM_OPTS=("$@")
186}
187eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
188JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
189
Jeff Gaston9998eae2018-10-11 15:17:48 -0400190exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"