blob: 81ab28aeb113eb4308f306d4f7f4e344c44740a1 [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
Aurimas Liutikas9979d072018-03-13 15:38:56 -070014fi
15
16# ----------------------------------------------------------------------------
17
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070018# 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 -070019
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
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070053# 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`"
Yigit Boyarf77697d2016-08-16 10:55:36 -070067cd "`dirname \"$PRG\"`/" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070068APP_HOME="`pwd -P`"
Yigit Boyarf77697d2016-08-16 10:55:36 -070069cd "$SAVED" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070070
71CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
72
Alan Viveretted38b36c2017-02-01 16:45:31 -050073# Pick the correct fullsdk for this OS.
Alan Viverette7df63ff2017-03-06 13:12:24 -050074if [ $darwin == "true" ]; then
Alan Viveretted38b36c2017-02-01 16:45:31 -050075 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
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -050081# Temporary solution for custom, private lint rules https://issuetracker.google.com/issues/65248347
82# Gradle automatically invokes 'jar' task on 'buildSrc/' projects so this will always be available.
83export ANDROID_LINT_JARS="$APP_HOME/buildSrc/lint-checks/build/libs/lint-checks.jar"
Sergey Vasilinetsefab5eb2019-01-04 12:38:06 +000084# override JAVA_HOME, because CI machines have it and it points to very old JDK
85export JAVA_HOME="$APP_HOME/../../prebuilts/jdk/jdk8/$plat-x86"
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -050086
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070087# Determine the Java command to use to start the JVM.
88if [ -n "$JAVA_HOME" ] ; then
89 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
90 # IBM's JDK on AIX uses strange locations for the executables
91 JAVACMD="$JAVA_HOME/jre/sh/java"
92 else
93 JAVACMD="$JAVA_HOME/bin/java"
94 fi
95 if [ ! -x "$JAVACMD" ] ; then
96 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
97
98Please set the JAVA_HOME variable in your environment to match the
99location of your Java installation."
100 fi
101else
102 JAVACMD="java"
103 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
104
105Please set the JAVA_HOME variable in your environment to match the
106location of your Java installation."
107fi
108
109# Increase the maximum file descriptors if we can.
110if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
111 MAX_FD_LIMIT=`ulimit -H -n`
112 if [ $? -eq 0 ] ; then
113 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
114 MAX_FD="$MAX_FD_LIMIT"
115 fi
116 ulimit -n $MAX_FD
117 if [ $? -ne 0 ] ; then
118 warn "Could not set maximum file descriptor limit: $MAX_FD"
119 fi
120 else
121 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
122 fi
123fi
124
125# For Darwin, add options to specify how the application appears in the dock
126if $darwin; then
127 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
128fi
129
130# For Cygwin, switch paths to Windows format before running java
131if $cygwin ; then
132 APP_HOME=`cygpath --path --mixed "$APP_HOME"`
133 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
Yigit Boyarf77697d2016-08-16 10:55:36 -0700134 JAVACMD=`cygpath --unix "$JAVACMD"`
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700135
136 # We build the pattern for arguments to be converted via cygpath
137 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 SEP=""
139 for dir in $ROOTDIRSRAW ; do
140 ROOTDIRS="$ROOTDIRS$SEP$dir"
141 SEP="|"
142 done
143 OURCYGPATTERN="(^($ROOTDIRS))"
144 # Add a user-defined pattern to the cygpath arguments
145 if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 fi
148 # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 i=0
150 for arg in "$@" ; do
151 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153
154 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 else
157 eval `echo args$i`="\"$arg\""
158 fi
159 i=$((i+1))
160 done
161 case $i in
162 (0) set -- ;;
163 (1) set -- "$args0" ;;
164 (2) set -- "$args0" "$args1" ;;
165 (3) set -- "$args0" "$args1" "$args2" ;;
166 (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 esac
173fi
174
175# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
176function splitJvmOpts() {
177 JVM_OPTS=("$@")
178}
179eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
180JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
181
Jeff Gaston9998eae2018-10-11 15:17:48 -0400182exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"