• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2
3# Copyright 2018 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17##############################################################################
18##
19##  Gradle start up script for UN*X
20##
21##############################################################################
22
23# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
24DEFAULT_JVM_OPTS=""
25
26APP_NAME="Gradle"
27APP_BASE_NAME=`basename "$0"`
28
29# Use the maximum available, or set MAX_FD != -1 to use that value.
30MAX_FD="maximum"
31
32warn ( ) {
33    echo "$*"
34}
35
36die ( ) {
37    echo
38    echo "$*"
39    echo
40    exit 1
41}
42
43# OS specific support (must be 'true' or 'false').
44cygwin=false
45msys=false
46darwin=false
47case "`uname`" in
48  CYGWIN* )
49    cygwin=true
50    ;;
51  Darwin* )
52    darwin=true
53    ;;
54  MINGW* )
55    msys=true
56    ;;
57esac
58
59# For Cygwin, ensure paths are in UNIX format before anything is touched.
60if $cygwin ; then
61    [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
62fi
63
64# Attempt to set APP_HOME
65# Resolve links: $0 may be a link
66PRG="$0"
67# Need this for relative symlinks.
68while [ -h "$PRG" ] ; do
69    ls=`ls -ld "$PRG"`
70    link=`expr "$ls" : '.*-> \(.*\)$'`
71    if expr "$link" : '/.*' > /dev/null; then
72        PRG="$link"
73    else
74        PRG=`dirname "$PRG"`"/$link"
75    fi
76done
77SAVED="`pwd`"
78cd "`dirname \"$PRG\"`/" >&-
79APP_HOME="`pwd -P`"
80cd "$SAVED" >&-
81
82CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
83
84# Determine the Java command to use to start the JVM.
85if [ -n "$JAVA_HOME" ] ; then
86    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
87        # IBM's JDK on AIX uses strange locations for the executables
88        JAVACMD="$JAVA_HOME/jre/sh/java"
89    else
90        JAVACMD="$JAVA_HOME/bin/java"
91    fi
92    if [ ! -x "$JAVACMD" ] ; then
93        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
94
95Please set the JAVA_HOME variable in your environment to match the
96location of your Java installation."
97    fi
98else
99    JAVACMD="java"
100    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
101
102Please set the JAVA_HOME variable in your environment to match the
103location of your Java installation."
104fi
105
106# Increase the maximum file descriptors if we can.
107if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
108    MAX_FD_LIMIT=`ulimit -H -n`
109    if [ $? -eq 0 ] ; then
110        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
111            MAX_FD="$MAX_FD_LIMIT"
112        fi
113        ulimit -n $MAX_FD
114        if [ $? -ne 0 ] ; then
115            warn "Could not set maximum file descriptor limit: $MAX_FD"
116        fi
117    else
118        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
119    fi
120fi
121
122# For Darwin, add options to specify how the application appears in the dock
123if $darwin; then
124    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
125fi
126
127# For Cygwin, switch paths to Windows format before running java
128if $cygwin ; then
129    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
130    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
131
132    # We build the pattern for arguments to be converted via cygpath
133    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
134    SEP=""
135    for dir in $ROOTDIRSRAW ; do
136        ROOTDIRS="$ROOTDIRS$SEP$dir"
137        SEP="|"
138    done
139    OURCYGPATTERN="(^($ROOTDIRS))"
140    # Add a user-defined pattern to the cygpath arguments
141    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
142        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
143    fi
144    # Now convert the arguments - kludge to limit ourselves to /bin/sh
145    i=0
146    for arg in "$@" ; do
147        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
148        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
149
150        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
151            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
152        else
153            eval `echo args$i`="\"$arg\""
154        fi
155        i=$((i+1))
156    done
157    case $i in
158        (0) set -- ;;
159        (1) set -- "$args0" ;;
160        (2) set -- "$args0" "$args1" ;;
161        (3) set -- "$args0" "$args1" "$args2" ;;
162        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
163        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
164        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
165        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
166        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
167        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
168    esac
169fi
170
171# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
172function splitJvmOpts() {
173    JVM_OPTS=("$@")
174}
175eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
176JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
177
178exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
179