|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +############################################################################## |
| 4 | +## |
| 5 | +## ${applicationName} start up script for UN*X |
| 6 | +## |
| 7 | +############################################################################## |
| 8 | + |
| 9 | +# Attempt to set APP_HOME |
| 10 | +# Resolve links: \$0 may be a link |
| 11 | +PRG="\$0" |
| 12 | +# Need this for relative symlinks. |
| 13 | +while [ -h "\$PRG" ] ; do |
| 14 | + ls=`ls -ld "\$PRG"` |
| 15 | + link=`expr "\$ls" : '.*-> \\(.*\\)\$'` |
| 16 | + if expr "\$link" : '/.*' > /dev/null; then |
| 17 | + PRG="\$link" |
| 18 | + else |
| 19 | + PRG=`dirname "\$PRG"`"/\$link" |
| 20 | + fi |
| 21 | +done |
| 22 | +SAVED="`pwd`" |
| 23 | +cd "`dirname \"\$PRG\"`/${appHomeRelativePath}" >/dev/null |
| 24 | +APP_HOME="`pwd -P`" |
| 25 | +cd "\$SAVED" >/dev/null |
| 26 | + |
| 27 | +APP_NAME="${applicationName}" |
| 28 | +APP_BASE_NAME=`basename "\$0"` |
| 29 | + |
| 30 | +# Add default JVM options here. You can also use JAVA_OPTS and ${optsEnvironmentVar} to pass JVM options to this script. |
| 31 | +DEFAULT_JVM_OPTS=${defaultJvmOpts} |
| 32 | + |
| 33 | +# Use the maximum available, or set MAX_FD != -1 to use that value. |
| 34 | +MAX_FD="maximum" |
| 35 | + |
| 36 | +warn () { |
| 37 | + echo "\$*" |
| 38 | +} |
| 39 | + |
| 40 | +die () { |
| 41 | + echo |
| 42 | + echo "\$*" |
| 43 | + echo |
| 44 | + exit 1 |
| 45 | +} |
| 46 | + |
| 47 | +# OS specific support (must be 'true' or 'false'). |
| 48 | +cygwin=false |
| 49 | +msys=false |
| 50 | +darwin=false |
| 51 | +nonstop=false |
| 52 | +case "`uname`" in |
| 53 | + CYGWIN* ) |
| 54 | + cygwin=true |
| 55 | + ;; |
| 56 | + Darwin* ) |
| 57 | + darwin=true |
| 58 | + ;; |
| 59 | + MINGW* ) |
| 60 | + msys=true |
| 61 | + ;; |
| 62 | + NONSTOP* ) |
| 63 | + nonstop=true |
| 64 | + ;; |
| 65 | +esac |
| 66 | + |
| 67 | +CLASSPATH=$classpath |
| 68 | + |
| 69 | +# Determine the Java command to use to start the JVM. |
| 70 | +if [ -n "\$JAVA_HOME" ] ; then |
| 71 | + if [ -x "\$JAVA_HOME/jre/sh/java" ] ; then |
| 72 | + # IBM's JDK on AIX uses strange locations for the executables |
| 73 | + JAVACMD="\$JAVA_HOME/jre/sh/java" |
| 74 | + else |
| 75 | + JAVACMD="\$JAVA_HOME/bin/java" |
| 76 | + fi |
| 77 | + if [ ! -x "\$JAVACMD" ] ; then |
| 78 | + die "ERROR: JAVA_HOME is set to an invalid directory: \$JAVA_HOME |
| 79 | +Please set the JAVA_HOME variable in your environment to match the |
| 80 | +location of your Java installation." |
| 81 | + fi |
| 82 | +else |
| 83 | + JAVACMD="java" |
| 84 | + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. |
| 85 | +Please set the JAVA_HOME variable in your environment to match the |
| 86 | +location of your Java installation." |
| 87 | +fi |
| 88 | + |
| 89 | +# Increase the maximum file descriptors if we can. |
| 90 | +if [ "\$cygwin" = "false" -a "\$darwin" = "false" -a "\$nonstop" = "false" ] ; then |
| 91 | + MAX_FD_LIMIT=`ulimit -H -n` |
| 92 | + if [ \$? -eq 0 ] ; then |
| 93 | + if [ "\$MAX_FD" = "maximum" -o "\$MAX_FD" = "max" ] ; then |
| 94 | + MAX_FD="\$MAX_FD_LIMIT" |
| 95 | + fi |
| 96 | + ulimit -n \$MAX_FD |
| 97 | + if [ \$? -ne 0 ] ; then |
| 98 | + warn "Could not set maximum file descriptor limit: \$MAX_FD" |
| 99 | + fi |
| 100 | + else |
| 101 | + warn "Could not query maximum file descriptor limit: \$MAX_FD_LIMIT" |
| 102 | + fi |
| 103 | +fi |
| 104 | + |
| 105 | +# For Darwin, add options to specify how the application appears in the dock |
| 106 | +if \$darwin; then |
| 107 | + GRADLE_OPTS="\$GRADLE_OPTS \\"-Xdock:name=\$APP_NAME\\" \\"-Xdock:icon=\$APP_HOME/media/gradle.icns\\"" |
| 108 | +fi |
| 109 | + |
| 110 | +# For Cygwin, switch paths to Windows format before running java |
| 111 | +if \$cygwin ; then |
| 112 | + APP_HOME=`cygpath --path --mixed "\$APP_HOME"` |
| 113 | + CLASSPATH=`cygpath --path --mixed "\$CLASSPATH"` |
| 114 | + JAVACMD=`cygpath --unix "\$JAVACMD"` |
| 115 | + |
| 116 | + # We build the pattern for arguments to be converted via cygpath |
| 117 | + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` |
| 118 | + SEP="" |
| 119 | + for dir in \$ROOTDIRSRAW ; do |
| 120 | + ROOTDIRS="\$ROOTDIRS\$SEP\$dir" |
| 121 | + SEP="|" |
| 122 | + done |
| 123 | + OURCYGPATTERN="(^(\$ROOTDIRS))" |
| 124 | + # Add a user-defined pattern to the cygpath arguments |
| 125 | + if [ "\$GRADLE_CYGPATTERN" != "" ] ; then |
| 126 | + OURCYGPATTERN="\$OURCYGPATTERN|(\$GRADLE_CYGPATTERN)" |
| 127 | + fi |
| 128 | + # Now convert the arguments - kludge to limit ourselves to /bin/sh |
| 129 | + i=0 |
| 130 | + for arg in "\$@" ; do |
| 131 | + CHECK=`echo "\$arg"|egrep -c "\$OURCYGPATTERN" -` |
| 132 | + CHECK2=`echo "\$arg"|egrep -c "^-"` ### Determine if an option |
| 133 | + |
| 134 | + if [ \$CHECK -ne 0 ] && [ \$CHECK2 -eq 0 ] ; then ### Added a condition |
| 135 | + eval `echo args\$i`=`cygpath --path --ignore --mixed "\$arg"` |
| 136 | + else |
| 137 | + eval `echo args\$i`="\"\$arg\"" |
| 138 | + fi |
| 139 | + i=\$((i+1)) |
| 140 | + done |
| 141 | + case \$i in |
| 142 | + (0) set -- ;; |
| 143 | + (1) set -- "\$args0" ;; |
| 144 | + (2) set -- "\$args0" "\$args1" ;; |
| 145 | + (3) set -- "\$args0" "\$args1" "\$args2" ;; |
| 146 | + (4) set -- "\$args0" "\$args1" "\$args2" "\$args3" ;; |
| 147 | + (5) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" ;; |
| 148 | + (6) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" ;; |
| 149 | + (7) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" "\$args6" ;; |
| 150 | + (8) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" "\$args6" "\$args7" ;; |
| 151 | + (9) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" "\$args6" "\$args7" "\$args8" ;; |
| 152 | + esac |
| 153 | +fi |
| 154 | + |
| 155 | +# Escape application args |
| 156 | +save () { |
| 157 | + for i do printf %s\\\\n "\$i" | sed "s/'/'\\\\\\\\''/g;1s/^/'/;\\\$s/\\\$/' \\\\\\\\/" ; done |
| 158 | + echo " " |
| 159 | +} |
| 160 | +APP_ARGS=\$(save "\$@") |
| 161 | + |
| 162 | +EXPECTED_JAVA_VERSION=13 |
| 163 | +if [ type -p java ] ; then |
| 164 | + _java=java |
| 165 | +elif [[ -n "\$JAVA_HOME" ]] && [[ -x "\$JAVA_HOME/bin/java" ]] ; then |
| 166 | + echo "Java was found at JAVA_HOME" |
| 167 | + _java="\$JAVA_HOME/bin/java" |
| 168 | +else |
| 169 | + echo "Java was not found, please install OpenJDK 13+" |
| 170 | + exit 1 |
| 171 | +fi |
| 172 | + |
| 173 | +if [[ "\$_java" ]] ; then |
| 174 | + JAVA_VER=\$("\$_java" -version 2>&1 | awk -F '"' '/version/ {print \$2}' | cut -d '.' -f 1) |
| 175 | + if [[ "\$JAVA_VER" -eq "1" ]]; then |
| 176 | + JAVA_VER=\$("\$_java" -version 2>&1 | awk -F '"' '/version/ {print \$2}' | cut -d '.' -f 2) |
| 177 | + fi |
| 178 | + if [[ "\$JAVA_VER" -ge "\$EXPECTED_JAVA_VERSION" ]]; then |
| 179 | + echo "Correct version \${JAVA_VER}!" |
| 180 | + else |
| 181 | + echo "Wrong Java version \${JAVA_VER}! Minimum required: \${EXPECTED_JAVA_VERSION}" |
| 182 | + exit 1 |
| 183 | + fi |
| 184 | +fi |
| 185 | + |
| 186 | +# Collect all arguments for the java command, following the shell quoting and substitution rules |
| 187 | +eval set -- \$DEFAULT_JVM_OPTS \$JAVA_OPTS \$${optsEnvironmentVar} <% if ( appNameSystemProperty ) { %>"\"-D${appNameSystemProperty}=\$APP_BASE_NAME\"" <% } %>-classpath "\"\$CLASSPATH\"" ${mainClassName} "\$APP_ARGS" |
| 188 | + |
| 189 | +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong |
| 190 | +if [ "\$(uname)" = "Darwin" ] && [ "\$HOME" = "\$PWD" ]; then |
| 191 | + cd "\$(dirname "\$0")" |
| 192 | +fi |
| 193 | + |
| 194 | +"\$JAVACMD" "\$@" |
0 commit comments