1#!/usr/bin/env sh 2 3# 4# Copyright 2015 the original author or authors. 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# https://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19############################################################################## 20## 21## Gradle start up script for UN*X 22## 23############################################################################## 24 25# Attempt to set APP_HOME 26# Resolve links: $0 may be a link 27PRG="$0" 28# Need this for relative symlinks. 29while [ -h "$PRG" ] ; do 30 ls=`ls -ld "$PRG"` 31 link=`expr "$ls" : '.*-> \(.*\)$'` 32 if expr "$link" : '/.*' > /dev/null; then 33 PRG="$link" 34 else 35 PRG=`dirname "$PRG"`"/$link" 36 fi 37done 38SAVED="`pwd`" 39cd "`dirname \"$PRG\"`/" >/dev/null 40APP_HOME="`pwd -P`" 41cd "$SAVED" >/dev/null 42 43APP_NAME="Gradle" 44APP_BASE_NAME=`basename "$0"` 45 46# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47DEFAULT_JVM_OPTS='-Xmx64m -Xms64m -Djava.net.useSystemProxies=true' 48 49# Define this environment variable to override the default JVM options. 50if [ ! -n "$JAVA_OPTS" ] ; then 51 JAVA_OPTS="$DEFAULT_JVM_OPTS" 52fi 53 54# Use the maximum available, or set MAX_FD != -1 to use that value. 55MAX_FD="maximum" 56 57warn () { 58 echo "$*" 59} 60 61die () { 62 echo 63 echo "$*" 64 echo 65 exit 1 66} 67 68# OS specific support (must be 'true' or 'false'). 69cygwin=false 70msys=false 71darwin=false 72nonstop=false 73case "`uname`" in 74 CYGWIN* ) 75 cygwin=true 76 ;; 77 Darwin* ) 78 darwin=true 79 ;; 80 MINGW* ) 81 msys=true 82 ;; 83 NONSTOP* ) 84 nonstop=true 85 ;; 86esac 87 88# Determine the Java command to use to start the JVM. 89if [ -n "$JAVA_HOME" ] ; then 90 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 91 # IBM's JDK on AIX uses strange locations for the executables 92 JAVACMD="$JAVA_HOME/jre/sh/java" 93 else 94 JAVACMD="$JAVA_HOME/bin/java" 95 fi 96 if [ ! -x "$JAVACMD" ] ; then 97 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 98 99Please set the JAVA_HOME variable in your environment to match the 100location of your Java installation." 101 fi 102else 103 JAVACMD="java" 104 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 105 106Please set the JAVA_HOME variable in your environment to match the 107location of your Java installation." 108fi 109 110# LUCENE-9471: workaround for gradle leaving junk temp. files behind. 111GRADLE_TEMPDIR="$APP_HOME/.gradle/tmp" 112mkdir -p "$GRADLE_TEMPDIR" 113if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 114 GRADLE_TEMPDIR=`cygpath --path --mixed "$GRADLE_TEMPDIR"` 115fi 116DEFAULT_JVM_OPTS="$DEFAULT_JVM_OPTS \"-Djava.io.tmpdir=$GRADLE_TEMPDIR\"" 117 118# LUCENE-9266: verify and download the gradle wrapper jar if we don't have one. 119if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 120 APP_HOME=`cygpath --path --mixed "$APP_HOME"` 121fi 122 123GRADLE_WRAPPER_JAR="$APP_HOME/gradle/wrapper/gradle-wrapper.jar" 124"$JAVACMD" $JAVA_OPTS --source 11 "$APP_HOME/buildSrc/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java" "$GRADLE_WRAPPER_JAR" 125WRAPPER_STATUS=$? 126if [ "$WRAPPER_STATUS" -eq 1 ]; then 127 echo "ERROR: Something went wrong. Make sure you're using Java 17." 128 exit $WRAPPER_STATUS 129elif [ "$WRAPPER_STATUS" -ne 0 ]; then 130 exit $WRAPPER_STATUS 131fi 132 133CLASSPATH=$GRADLE_WRAPPER_JAR 134 135# Don't fork a daemon mode on initial run that generates local defaults. 136GRADLE_DAEMON_CTRL= 137if [ ! -e "$APP_HOME/gradle.properties" ]; then 138 GRADLE_DAEMON_CTRL=--no-daemon 139fi 140 141# Increase the maximum file descriptors if we can. 142if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 143 MAX_FD_LIMIT=`ulimit -H -n` 144 if [ $? -eq 0 ] ; then 145 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 146 MAX_FD="$MAX_FD_LIMIT" 147 fi 148 ulimit -n $MAX_FD 149 if [ $? -ne 0 ] ; then 150 warn "Could not set maximum file descriptor limit: $MAX_FD" 151 fi 152 else 153 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 154 fi 155fi 156 157# For Darwin, add options to specify how the application appears in the dock 158if $darwin; then 159 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 160fi 161 162# For Cygwin or MSYS, switch paths to Windows format before running java 163if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 164 JAVACMD=`cygpath --unix "$JAVACMD"` 165 166 # We build the pattern for arguments to be converted via cygpath 167 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 168 SEP="" 169 for dir in $ROOTDIRSRAW ; do 170 ROOTDIRS="$ROOTDIRS$SEP$dir" 171 SEP="|" 172 done 173 OURCYGPATTERN="(^($ROOTDIRS))" 174 # Add a user-defined pattern to the cygpath arguments 175 if [ "$GRADLE_CYGPATTERN" != "" ] ; then 176 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 177 fi 178 # Now convert the arguments - kludge to limit ourselves to /bin/sh 179 i=0 180 for arg in "$@" ; do 181 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 182 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 183 184 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 185 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 186 else 187 eval `echo args$i`="\"$arg\"" 188 fi 189 i=$((i+1)) 190 done 191 case $i in 192 (0) set -- ;; 193 (1) set -- "$args0" ;; 194 (2) set -- "$args0" "$args1" ;; 195 (3) set -- "$args0" "$args1" "$args2" ;; 196 (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 197 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 198 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 199 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 200 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 201 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 202 esac 203fi 204 205# Escape application args 206save () { 207 for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 208 echo " " 209} 210APP_ARGS=$(save "$@") 211 212# Collect all arguments for the java command, following the shell quoting and substitution rules 213eval set -- $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain $GRADLE_DAEMON_CTRL "$APP_ARGS" 214 215# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 216if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 217 cd "$(dirname "$0")" 218fi 219 220exec "$JAVACMD" "$@" 221