blob: 8d6f5fc635dd120b49df7582c16054ab37fdb6f0 [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"
84
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070085# Determine the Java command to use to start the JVM.
86if [ -n "$JAVA_HOME" ] ; then
87 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
88 # IBM's JDK on AIX uses strange locations for the executables
89 JAVACMD="$JAVA_HOME/jre/sh/java"
90 else
91 JAVACMD="$JAVA_HOME/bin/java"
92 fi
93 if [ ! -x "$JAVACMD" ] ; then
94 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
95
96Please set the JAVA_HOME variable in your environment to match the
97location of your Java installation."
98 fi
99else
100 JAVACMD="java"
101 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
102
103Please set the JAVA_HOME variable in your environment to match the
104location of your Java installation."
105fi
106
107# Increase the maximum file descriptors if we can.
108if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
109 MAX_FD_LIMIT=`ulimit -H -n`
110 if [ $? -eq 0 ] ; then
111 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
112 MAX_FD="$MAX_FD_LIMIT"
113 fi
114 ulimit -n $MAX_FD
115 if [ $? -ne 0 ] ; then
116 warn "Could not set maximum file descriptor limit: $MAX_FD"
117 fi
118 else
119 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
120 fi
121fi
122
123# For Darwin, add options to specify how the application appears in the dock
124if $darwin; then
125 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
126fi
127
128# For Cygwin, switch paths to Windows format before running java
129if $cygwin ; then
130 APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
Yigit Boyarf77697d2016-08-16 10:55:36 -0700132 JAVACMD=`cygpath --unix "$JAVACMD"`
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700133
134 # We build the pattern for arguments to be converted via cygpath
135 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
136 SEP=""
137 for dir in $ROOTDIRSRAW ; do
138 ROOTDIRS="$ROOTDIRS$SEP$dir"
139 SEP="|"
140 done
141 OURCYGPATTERN="(^($ROOTDIRS))"
142 # Add a user-defined pattern to the cygpath arguments
143 if [ "$GRADLE_CYGPATTERN" != "" ] ; then
144 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
145 fi
146 # Now convert the arguments - kludge to limit ourselves to /bin/sh
147 i=0
148 for arg in "$@" ; do
149 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
150 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
151
152 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
153 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
154 else
155 eval `echo args$i`="\"$arg\""
156 fi
157 i=$((i+1))
158 done
159 case $i in
160 (0) set -- ;;
161 (1) set -- "$args0" ;;
162 (2) set -- "$args0" "$args1" ;;
163 (3) set -- "$args0" "$args1" "$args2" ;;
164 (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
170 esac
171fi
172
173# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
174function splitJvmOpts() {
175 JVM_OPTS=("$@")
176}
177eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
178JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
179
Jeff Gaston9998eae2018-10-11 15:17:48 -0400180exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"