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