blob: a096da05d59430912d43c5f9604cdb806d58f625 [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"
13fi
14
15# ----------------------------------------------------------------------------
16
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070017# 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 -070018
19APP_NAME="Gradle"
20APP_BASE_NAME=`basename "$0"`
21
22# Use the maximum available, or set MAX_FD != -1 to use that value.
23MAX_FD="maximum"
24
25warn ( ) {
26 echo "$*"
27}
28
29die ( ) {
30 echo
31 echo "$*"
32 echo
33 exit 1
34}
35
36# OS specific support (must be 'true' or 'false').
37cygwin=false
38msys=false
39darwin=false
40case "`uname`" in
41 CYGWIN* )
42 cygwin=true
43 ;;
44 Darwin* )
45 darwin=true
46 ;;
47 MINGW* )
48 msys=true
49 ;;
50esac
51
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070052# Attempt to set APP_HOME
53# Resolve links: $0 may be a link
54PRG="$0"
55# Need this for relative symlinks.
56while [ -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
64done
65SAVED="`pwd`"
Yigit Boyarf77697d2016-08-16 10:55:36 -070066cd "`dirname \"$PRG\"`/" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070067APP_HOME="`pwd -P`"
Yigit Boyarf77697d2016-08-16 10:55:36 -070068cd "$SAVED" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070069
70CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
71
Alan Viveretted38b36c2017-02-01 16:45:31 -050072# Pick the correct fullsdk for this OS.
Alan Viverette7df63ff2017-03-06 13:12:24 -050073if [ $darwin == "true" ]; then
Alan Viveretted38b36c2017-02-01 16:45:31 -050074 plat="darwin"
75else
76 plat="linux"
77fi
78DEFAULT_JVM_OPTS="-DLINT_API_DATABASE=$APP_HOME/../../prebuilts/fullsdk-$plat/platform-tools/api/api-versions.xml"
79
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070080# Determine the Java command to use to start the JVM.
81if [ -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
91Please set the JAVA_HOME variable in your environment to match the
92location of your Java installation."
93 fi
94else
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
98Please set the JAVA_HOME variable in your environment to match the
99location of your Java installation."
100fi
101
102# Increase the maximum file descriptors if we can.
103if [ "$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
116fi
117
118# For Darwin, add options to specify how the application appears in the dock
119if $darwin; then
120 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
121fi
122
123# For Cygwin, switch paths to Windows format before running java
124if $cygwin ; then
125 APP_HOME=`cygpath --path --mixed "$APP_HOME"`
126 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
Yigit Boyarf77697d2016-08-16 10:55:36 -0700127 JAVACMD=`cygpath --unix "$JAVACMD"`
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700128
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
166fi
167
168# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
169function splitJvmOpts() {
170 JVM_OPTS=("$@")
171}
172eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
173JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
174
Yigit Boyarf77697d2016-08-16 10:55:36 -0700175exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"