diff --git a/src/universalJavaApplicationStub b/src/universalJavaApplicationStub index f54e823..8416408 100755 --- a/src/universalJavaApplicationStub +++ b/src/universalJavaApplicationStub @@ -11,7 +11,7 @@ # # # @author Tobias Fischer # # @url https://github.com/tofi86/universalJavaApplicationStub # -# @date 2018-02-11 # +# @date 2018-02-12 # # @version 2.1.0 # # # ################################################################################## @@ -230,9 +230,9 @@ if [ $exitcode -eq 0 ]; then minMaxArray=(${JVMVersion//;/ }) JVMVersion=$(echo ${minMaxArray[0]} | sed 's/+//') JVMMaxVersion=$(echo ${minMaxArray[1]} | sed 's/+//') - stub_logger "[JavaRequirement] JVM minimum version: ${JVMVersion}" - stub_logger "[JavaRequirement] JVM maximum version: ${JVMMaxVersion}" fi + stub_logger "[JavaRequirement] JVM minimum version: ${JVMVersion}" + stub_logger "[JavaRequirement] JVM maximum version: ${JVMMaxVersion}" # read 'Info.plist' file in Oracle style @@ -289,7 +289,7 @@ fi # internationalized messages ############################################ -LANG=`defaults read -g AppleLocale` +LANG=$(defaults read -g AppleLocale) stub_logger "[Language] $LANG" # French localization @@ -297,9 +297,10 @@ if [[ $LANG == fr* ]] ; then MSG_ERROR_LAUNCHING="ERREUR au lancement de '${CFBundleName}'." MSG_MISSING_MAINCLASS="'MainClass' n'est pas spécifié.\nL'application Java ne peut pas être lancée." MSG_JVMVERSION_REQ_INVALID="La syntaxe de la version Java demandée est invalide: %s\nVeuillez contacter le développeur de l'application." - MSG_NO_SUITABLE_JAVA="La version de Java installée sur votre système ne convient pas.\nCe programme nécessite Java %s." + MSG_NO_SUITABLE_JAVA="La version de Java installée sur votre système ne convient pas.\nCe programme nécessite Java %s" MSG_JAVA_VERSION_OR_LATER="ou ultérieur" MSG_JAVA_VERSION_LATEST="(dernière mise à jour)" + MSG_JAVA_VERSION_MAX="à %s" MSG_NO_SUITABLE_JAVA_CHECK="Merci de bien vouloir installer la version de Java requise." MSG_INSTALL_JAVA="Java doit être installé sur votre système.\nRendez-vous sur java.com et suivez les instructions d'installation..." MSG_LATER="Plus tard" @@ -310,9 +311,10 @@ elif [[ $LANG == de* ]] ; then MSG_ERROR_LAUNCHING="FEHLER beim Starten von '${CFBundleName}'." MSG_MISSING_MAINCLASS="Die 'MainClass' ist nicht spezifiziert!\nDie Java-Anwendung kann nicht gestartet werden!" MSG_JVMVERSION_REQ_INVALID="Die Syntax der angeforderten Java-Version ist ungültig: %s\nBitte kontaktieren Sie den Entwickler der App." - MSG_NO_SUITABLE_JAVA="Es wurde keine passende Java-Version auf Ihrem System gefunden!\nDieses Programm benötigt Java %s." + MSG_NO_SUITABLE_JAVA="Es wurde keine passende Java-Version auf Ihrem System gefunden!\nDieses Programm benötigt Java %s" MSG_JAVA_VERSION_OR_LATER="oder neuer" MSG_JAVA_VERSION_LATEST="(neuste Unterversion)" + MSG_JAVA_VERSION_MAX="bis %s" MSG_NO_SUITABLE_JAVA_CHECK="Stellen Sie sicher, dass die angeforderte Java-Version installiert ist." MSG_INSTALL_JAVA="Auf Ihrem System muss die 'Java'-Software installiert sein.\nBesuchen Sie java.com für weitere Installationshinweise." MSG_LATER="Später" @@ -323,9 +325,10 @@ else MSG_ERROR_LAUNCHING="ERROR launching '${CFBundleName}'." MSG_MISSING_MAINCLASS="'MainClass' isn't specified!\nJava application cannot be started!" MSG_JVMVERSION_REQ_INVALID="The syntax of the required Java version is invalid: %s\nPlease contact the App developer." - MSG_NO_SUITABLE_JAVA="No suitable Java version found on your system!\nThis program requires Java %s." + MSG_NO_SUITABLE_JAVA="No suitable Java version found on your system!\nThis program requires Java %s" MSG_JAVA_VERSION_OR_LATER="or later" MSG_JAVA_VERSION_LATEST="(latest update)" + MSG_JAVA_VERSION_MAX="up to %s" MSG_NO_SUITABLE_JAVA_CHECK="Make sure you install the required Java version." MSG_INSTALL_JAVA="You need to have JAVA installed on your Mac!\nVisit java.com for installation instructions..." MSG_LATER="Later" @@ -424,97 +427,22 @@ function is_valid_requirement_pattern() { } -# function 'pad_version_to_semver()' -# -# adds '.0' minor/bugfix version parts to a short version number (e.g. 9, 10) -# to make it semver compatible -# -# @param1 a Java version number in short form (9, 10, etc.) -# @return a right-padded semver version number (e.g. 9.0.0, 10.0.0) -################################################################################ -function pad_short_version_to_semver() { - local java_ver=$1 - if [[ ${java_ver} =~ ^[0-9]+$ ]] ; then - java_ver="${java_ver}.0.0" - elif [[ ${java_ver} =~ ^[0-9]+\.0$ ]] ; then - java_ver="${java_ver}.0" - fi - echo ${java_ver} -} - - -# function 'does_java_version_satisfy_requirement()' -# -# this function checks whether a given java version number -# satisfies the given requirement -# -# the function returns with an error (exit 2) if the requirement string -# is not supported -# -# @param1 the java version in plain form as 'java -version' returns it -# @param2 the java requirement (1.6, 1.7+, 9, 9.1*, 9.2.3, etc.) -# @return an exit code: 0 (satiesfies), 1 (does not), 2 (invalid requirement) -################################################################################ -function does_java_version_satisfy_requirement() { - # update short versions (9, 9.1, 10) to semver form (9.0.0, 9.1.0, 10.0.0) - local java_ver=$(pad_short_version_to_semver $1) - local java_req=$2 - - if ! is_valid_requirement_pattern ${java_req} ; then - return 2 - - # requirement ends with * modifier - # e.g. 1.8*, 9*, 9.1*, 9.2.4*, 10*, 10.1*, 10.1.35* - elif [[ ${java_req} == *\* ]] ; then - # use the * modifier from the requirement string as wildcard for a 'starts with' comparison - if [[ ${java_ver} == ${java_req} ]] ; then - return 0 - else - return 1 - fi - - # requirement ends with + modifier - # e.g. 1.8+, 9+, 9.1+, 9.2.4+, 10+, 10.1+, 10.1.35+ - elif [[ ${java_req} == *+ ]] ; then - local java_req_num=$(get_comparable_java_version ${java_req}) - local java_ver_num=$(get_comparable_java_version ${java_ver}) - if [ ${java_ver_num} -ge ${java_req_num} ] ; then - return 0 - else - return 1 - fi - - # matches standard requirements without modifier - # e.g. 1.8, 9, 9.1, 9.2.4, 10, 10.1, 10.1.35 - else - # java version equals requirement string (1.8.0_45 == 1.8.0.45) - if [ ${java_ver} == ${java_req} ] ; then - return 0 - # java version starts with requirement string (1.8.0_45 == 1.8) - elif [[ ${java_ver} == ${java_req}* ]] ; then - return 0 - else - return 1 - fi - - fi -} - - -# find installed Java versions +# determine which JVM to use ############################################ -# default Apple JRE plugin path +# default Apple JRE plugin path (< 1.6) apple_jre_plugin="/Library/Java/Home/bin/java" apple_jre_version=$(get_java_version_from_cmd "${apple_jre_plugin}") -# default Oracle JRE plugin path +# default Oracle JRE plugin path (>= 1.7) oracle_jre_plugin="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java" oracle_jre_version=$(get_java_version_from_cmd "${oracle_jre_plugin}") -# first check system variable "$JAVA_HOME" + +# first check system variable "$JAVA_HOME" -> has precedence over any other System JVM +stub_logger '[JavaSearch] Checking for $JAVA_HOME ...' if [ -n "$JAVA_HOME" ] ; then - stub_logger '[JavaSearch] Checking $JAVA_HOME' + stub_logger "[JavaSearch] ... found JAVA_HOME with value $JAVA_HOME" # PR 26: Allow specifying "$JAVA_HOME" relative to "$AppPackageFolder" # which allows for bundling a custom version of Java inside your app! @@ -525,13 +453,22 @@ if [ -n "$JAVA_HOME" ] ; then # otherwise it's a relative path to "$AppPackageFolder" JAVACMD="$AppPackageFolder/$JAVA_HOME/bin/java" fi + JAVACMD_version=$(get_comparable_java_version $(get_java_version_from_cmd "${JAVACMD}")) +else + stub_logger "[JavaSearch] ... didn't found JAVA_HOME" +fi -# check for a specific Java version, specified in JVMversion Plist key -elif [ ! -z ${JVMVersion} ] ; then - stub_logger "[JavaSearch] Checking for specific Java version '${JVMVersion}'" + +# check for any other or a specific Java version +# also if $JAVA_HOME exists but isn't executable +if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then + stub_logger "[JavaSearch] Checking for JavaVirtualMachines on the system ..." + # reset variables + JAVACMD="" + JAVACMD_version="" # first check whether JVMVersion string is a valid requirement string - if ! is_valid_requirement_pattern ${JVMVersion} ; then + if [ ! -z "${JVMVersion}" ] && ! is_valid_requirement_pattern ${JVMVersion} ; then MSG_JVMVERSION_REQ_INVALID_EXPANDED=$(printf "${MSG_JVMVERSION_REQ_INVALID}" "${JVMVersion}") # log exit cause stub_logger "[EXIT 4] ${MSG_JVMVERSION_REQ_INVALID_EXPANDED}" @@ -540,91 +477,212 @@ elif [ ! -z ${JVMVersion} ] ; then # exit with error exit 4 fi + # then check whether JVMMaxVersion string is a valid requirement string + if [ ! -z "${JVMMaxVersion}" ] && ! is_valid_requirement_pattern ${JVMMaxVersion} ; then + MSG_JVMVERSION_REQ_INVALID_EXPANDED=$(printf "${MSG_JVMVERSION_REQ_INVALID}" "${JVMMaxVersion}") + # log exit cause + stub_logger "[EXIT 5] ${MSG_JVMVERSION_REQ_INVALID_EXPANDED}" + # display error message with AppleScript + osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_JVMVERSION_REQ_INVALID_EXPANDED}\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1 with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)" + # exit with error + exit 5 + fi + + + # find installed JavaVirtualMachines (JDK + JRE) + allJVMs=() + # read JDK's from '/usr/libexec/java_home -V' command + while read line; do + version=$(echo $line | awk -F $',' '{print $1;}') + path=$(echo $line | awk -F $'" ' '{print $2;}') + path+="/bin/java" + allJVMs+=("$version:$path") + done < <(/usr/libexec/java_home -V 2>&1 | grep '^[[:space:]]') + # unset while loop variables + unset version path - # first check "/usr/libexec/java_home" symlinks - if [ -x /usr/libexec/java_home ] && /usr/libexec/java_home -F -v ${JVMVersion} > /dev/null 2>&1 ; then - JAVACMD="`/usr/libexec/java_home -F -v ${JVMVersion} 2> /dev/null`/bin/java" - JAVACMD_version=$(get_comparable_java_version $(get_java_version_from_cmd "${JAVACMD}")) + # add Apple JRE if available + if [ -x "${apple_jre_plugin}" ] ; then + allJVMs+=("$apple_jre_version:$apple_jre_plugin") fi - # then additionally check the Oracle JRE plugin whether it's a higher/newer compatible version - if [ -x "${oracle_jre_plugin}" ] && does_java_version_satisfy_requirement ${oracle_jre_version} ${JVMVersion} ; then - this_java_ver=$(get_comparable_java_version ${oracle_jre_version}) - # use this compatible version only if the above returned empty or if the version number is higher - if [ -z "${JAVACMD}" ] || [ ${this_java_ver} -ge ${JAVACMD_version} ] ; then - JAVACMD="${oracle_jre_plugin}" - JAVACMD_version=${this_java_ver} - fi + # add Oracle JRE if available + if [ -x "${oracle_jre_plugin}" ] ; then + allJVMs+=("$oracle_jre_version:$oracle_jre_plugin") fi - # then additionally check the Apple JRE plugin whether it's a higher/newer compatible version - if [ -x "${apple_jre_plugin}" ] && does_java_version_satisfy_requirement ${apple_jre_version} ${JVMVersion} ; then - this_java_ver=$(get_comparable_java_version ${apple_jre_version}) - # use this compatible version only if the above returned empty or if the version number is higher - if [ -z "${JAVACMD}" ] || [ ${this_java_ver} -ge ${JAVACMD_version} ] ; then - JAVACMD="${apple_jre_plugin}" - JAVACMD_version=${this_java_ver} + # debug output + for i in "${allJVMs[@]}" + do + stub_logger "[JavaSearch] ... found JVM: $i" + done + + + # determine JVMs matching the min/max version requirement + minC=$(get_comparable_java_version ${JVMVersion}) + maxC=$(get_comparable_java_version ${JVMMaxVersion}) + matchingJVMs=() + + for i in "${allJVMs[@]}" + do + # split JVM string at ':' delimiter to retain spaces in $path substring + IFS=: arr=($i) ; unset IFS + # [0] JVM version number + ver=${arr[0]} + # comparable JVM version number + comp=$(get_comparable_java_version $ver) + # [1] JVM path + path="${arr[1]}" + # construct string item for adding to the "matchingJVMs" array + item="$comp:$ver:$path" + + # pre-requisite: current version number needs to be greater than min version number + if [ "$comp" -ge "$minC" ] ; then + + # perform max version checks if max version requirement is present + if [ ! -z ${JVMMaxVersion} ] ; then + + # max version requirement ends with '*' modifier + if [[ ${JVMMaxVersion} == *\* ]] ; then + + # use the '*' modifier from the max version string as wildcard for a 'starts with' comparison + # and check whether the current version number starts with the max version wildcard string + if [[ ${ver} == ${JVMMaxVersion} ]]; then + matchingJVMs+=("$item") + + # or whether the current comparable version is lower than the comparable max version + elif [ "$comp" -le "$maxC" ] ; then + matchingJVMs+=("$item") + fi + + # max version requirement ends with '+' modifier -> always add this version if it's greater than $min + # because a max requirement with + modifier doesn't make sense + elif [[ ${JVMMaxVersion} == *+ ]] ; then + matchingJVMs+=("$item") + + # matches 6 zeros at the end of the max version string (e.g. for 1.8, 9) + # -> then the max version string should be treated like with a '*' modifier at the end + #elif [[ ${maxC} =~ ^[0-9]{2}0{6}$ ]] && [ "$comp" -le $(( ${maxC#0} + 999 )) ] ; then + # matchingJVMs+=("$item") + + # matches 3 zeros at the end of the max version string (e.g. for 9.1, 10.3) + # -> then the max version string should be treated like with a '*' modifier at the end + #elif [[ ${maxC} =~ ^[0-9]{5}0{3}$ ]] && [ "$comp" -le "${maxC}" ] ; then + # matchingJVMs+=("$item") + + # matches standard requirements without modifier + elif [ "$comp" -le "$maxC" ]; then + matchingJVMs+=("$item") + fi + + # no max version requirement: + + # min version requirement ends with '+' modifier + # -> always add the current version because it's greater than $min + elif [[ ${JVMVersion} == *+ ]] ; then + matchingJVMs+=("$item") + + # min version requirement ends with '*' modifier + # -> use the '*' modifier from the min version string as wildcard for a 'starts with' comparison + # and check whether the current version number starts with the min version wildcard string + elif [[ ${JVMVersion} == *\* ]] ; then + if [[ ${ver} == ${JVMVersion} ]] ; then + matchingJVMs+=("$item") + fi + + # compare the min version against the current version with an additional * wildcard for a 'starts with' comparison + # -> e.g. add 1.8.0_44 when the requirement is 1.8 + elif [[ ${ver} == ${JVMVersion}* ]] ; then + matchingJVMs+=("$item") + fi fi - fi + done + # unset for loop variables + unset arr ver comp path item + + # debug output + for i in "${matchingJVMs[@]}" + do + stub_logger "[JavaSearch] ... ... matches all requirements: $i" + done + + + # sort the matching JavaVirtualMachines by version number + # https://stackoverflow.com/a/11789688/1128689 + IFS=$'\n' matchingJVMs=($(sort -nr <<<"${matchingJVMs[*]}")) + unset IFS + + + # get the highest matching JVM + for ((i = 0; i < ${#matchingJVMs[@]}; i++)); + do + # split JVM string at ':' delimiter to retain spaces in $path substring + IFS=: arr=(${matchingJVMs[$i]}) ; unset IFS + # [0] comparable JVM version number + comp=${arr[0]} + # [1] JVM version number + ver=${arr[1]} + # [2] JVM path + path="${arr[2]}" + + # use current value as JAVACMD if it's executable + if [ -x "$path" ] ; then + JAVACMD="$path" + JAVACMD_version=$comp + break + fi + done + # unset for loop variables + unset arr comp ver path +fi + +# log the Java Command and the extracted version number +stub_logger "[JavaCommand] '$JAVACMD'" +stub_logger "[JavaVersion] $(get_java_version_from_cmd "${JAVACMD}")${JAVACMD_version:+ / $JAVACMD_version}" + + + +if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then - if [ -z "${JAVACMD}" ] ; then + # different error messages when a specific JVM was required + if [ ! -z "${JVMVersion}" ] ; then # display human readable java version (#28) java_version_hr=$(echo ${JVMVersion} | sed -E 's/^1\.([0-9+*]+)$/ \1/g' | sed "s/+/ ${MSG_JAVA_VERSION_OR_LATER}/;s/*/ ${MSG_JAVA_VERSION_LATEST}/") - MSG_NO_SUITABLE_JAVA_EXPANDED=$(printf "${MSG_NO_SUITABLE_JAVA}" "${java_version_hr}") + MSG_NO_SUITABLE_JAVA_EXPANDED=$(printf "${MSG_NO_SUITABLE_JAVA}" "${java_version_hr}"). + + if [ ! -z "${JVMMaxVersion}" ] ; then + java_version_hr=$(extract_java_major_version ${JVMVersion}) + java_version_max_hr=$(echo ${JVMMaxVersion} | sed -E 's/^1\.([0-9+*]+)$/ \1/g' | sed "s/+//;s/*/ ${MSG_JAVA_VERSION_LATEST}/") + MSG_NO_SUITABLE_JAVA_EXPANDED="$(printf "${MSG_NO_SUITABLE_JAVA}" "${java_version_hr}") $(printf "${MSG_JAVA_VERSION_MAX}" "${java_version_max_hr}")" + fi + # log exit cause stub_logger "[EXIT 3] ${MSG_NO_SUITABLE_JAVA_EXPANDED}" + # display error message with AppleScript osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_NO_SUITABLE_JAVA_EXPANDED}\n${MSG_NO_SUITABLE_JAVA_CHECK}\" with title \"${CFBundleName}\" buttons {\" OK \", \"${MSG_VISIT_JAVA_DOT_COM}\"} default button \"${MSG_VISIT_JAVA_DOT_COM}\" with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)" \ -e "set response to button returned of the result" \ -e "if response is \"${MSG_VISIT_JAVA_DOT_COM}\" then open location \"http://java.com\"" # exit with error exit 3 - fi -# otherwise check "/usr/libexec/java_home" and Oracle and Apple JRE paths and use highest version available -else - stub_logger "[JavaSearch] Checking for other Java versions" - - # first check "/usr/libexec/java_home" symlinks - if [ -x /usr/libexec/java_home ] && /usr/libexec/java_home -F > /dev/null 2>&1 ; then - JAVACMD="`/usr/libexec/java_home 2> /dev/null`/bin/java" - JAVACMD_version=$(get_comparable_java_version $(get_java_version_from_cmd "${JAVACMD}")) - fi - - # then additionally check the Oracle JRE plugin whether it's a higher/newer compatible version - if [ -x "${oracle_jre_plugin}" ] ; then - this_java_ver=$(get_comparable_java_version ${oracle_jre_version}) - # use this compatible version only if the above returned empty or if the version number is higher - if [ -z "${JAVACMD}" ] || [ ${this_java_ver} -ge ${JAVACMD_version} ] ; then - JAVACMD="${oracle_jre_plugin}" - JAVACMD_version=${this_java_ver} - fi - fi - - # then additionally check the Apple JRE plugin whether it's a higher/newer compatible version - if [ -x "${apple_jre_plugin}" ] ; then - this_java_ver=$(get_comparable_java_version ${apple_jre_version}) - # use this compatible version only if the above returned empty or if the version number is higher - if [ -z "${JAVACMD}" ] || [ ${this_java_ver} -ge ${JAVACMD_version} ] ; then - JAVACMD="${apple_jre_plugin}" - JAVACMD_version=${this_java_ver} - fi + else + # log exit cause + stub_logger "[EXIT 1] ${MSG_ERROR_LAUNCHING}" + # display error message with AppleScript + osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_INSTALL_JAVA}\" with title \"${CFBundleName}\" buttons {\"${MSG_LATER}\", \"${MSG_VISIT_JAVA_DOT_COM}\"} default button \"${MSG_VISIT_JAVA_DOT_COM}\" with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)" \ + -e "set response to button returned of the result" \ + -e "if response is \"${MSG_VISIT_JAVA_DOT_COM}\" then open location \"http://java.com\"" + # exit with error + exit 1 fi fi -# log the Java Command and the extracted version number -stub_logger "[JavaCommand] $JAVACMD" -stub_logger "[JavaVersion] $(get_java_version_from_cmd "${JAVACMD}")${JAVACMD_version:+ / $JAVACMD_version}" - -# fallback fallback: /usr/bin/java -# but this would prompt to install deprecated Apple Java 6 - -# execute $JAVACMD and do some pre-checks +# MainClass check ############################################ -# display error message if MainClassName is empty if [ -z ${JVMMainClass} ]; then # log exit cause stub_logger "[EXIT 2] ${MSG_MISSING_MAINCLASS}" @@ -632,55 +690,45 @@ if [ -z ${JVMMainClass} ]; then osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_MISSING_MAINCLASS}\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1 with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)" # exit with error exit 2 +fi -# check whether ${JAVACMD} is a file and executable -elif [ -f "${JAVACMD}" ] && [ -x "${JAVACMD}" ] ; then - - # enable drag&drop to the dock icon - export CFProcessPath="$0" - - # remove Apples ProcessSerialNumber from passthru arguments (#39) - if [[ $@ == -psn* ]] ; then - ArgsPassthru="" - else - ArgsPassthru=$@ - fi - # change to Working Directory based upon Apple/Oracle Plist info - cd "${WorkingDirectory}" - stub_logger "[WorkingDirectory] ${WorkingDirectory}" - - # execute Java and set - # - classpath - # - splash image - # - dock icon - # - app name - # - JVM options - # - JVM default options - # - main class - # - main arguments - # - passthru arguments - stub_logger "[Exec] \"$JAVACMD\" -cp \"${JVMClassPath}\" -splash:\"${ResourcesFolder}/${JVMSplashFile}\" -Xdock:icon=\"${ResourcesFolder}/${CFBundleIconFile}\" -Xdock:name=\"${CFBundleName}\" ${JVMOptions:+$JVMOptions }${JVMDefaultOptions:+$JVMDefaultOptions }${JVMMainClass}${MainArgs:+ $MainArgs}${ArgsPassthru:+ $ArgsPassthru}" - exec "${JAVACMD}" \ - -cp "${JVMClassPath}" \ - -splash:"${ResourcesFolder}/${JVMSplashFile}" \ - -Xdock:icon="${ResourcesFolder}/${CFBundleIconFile}" \ - -Xdock:name="${CFBundleName}" \ - ${JVMOptions:+$JVMOptions }\ - ${JVMDefaultOptions:+$JVMDefaultOptions }\ - ${JVMMainClass}\ - ${MainArgs:+ $MainArgs}\ - ${ArgsPassthru:+ $ArgsPassthru} +# execute $JAVACMD and do some preparation +############################################ +# enable drag&drop to the dock icon +export CFProcessPath="$0" +# remove Apples ProcessSerialNumber from passthru arguments (#39) +if [[ $@ == -psn* ]] ; then + ArgsPassthru="" else - # log exit cause - stub_logger "[EXIT 1] ${MSG_ERROR_LAUNCHING}" - # display error message with AppleScript - osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_INSTALL_JAVA}\" with title \"${CFBundleName}\" buttons {\"${MSG_LATER}\", \"${MSG_VISIT_JAVA_DOT_COM}\"} default button \"${MSG_VISIT_JAVA_DOT_COM}\" with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)" \ - -e "set response to button returned of the result" \ - -e "if response is \"${MSG_VISIT_JAVA_DOT_COM}\" then open location \"http://java.com\"" - # exit with error - exit 1 + ArgsPassthru=$@ fi + +# change to Working Directory based upon Apple/Oracle Plist info +cd "${WorkingDirectory}" +stub_logger "[WorkingDirectory] ${WorkingDirectory}" + +# execute Java and set +# - classpath +# - splash image +# - dock icon +# - app name +# - JVM options +# - JVM default options +# - main class +# - main arguments +# - passthru arguments +stub_logger "[Exec] \"$JAVACMD\" -cp \"${JVMClassPath}\" -splash:\"${ResourcesFolder}/${JVMSplashFile}\" -Xdock:icon=\"${ResourcesFolder}/${CFBundleIconFile}\" -Xdock:name=\"${CFBundleName}\" ${JVMOptions:+$JVMOptions }${JVMDefaultOptions:+$JVMDefaultOptions }${JVMMainClass}${MainArgs:+ $MainArgs}${ArgsPassthru:+ $ArgsPassthru}" +exec "${JAVACMD}" \ + -cp "${JVMClassPath}" \ + -splash:"${ResourcesFolder}/${JVMSplashFile}" \ + -Xdock:icon="${ResourcesFolder}/${CFBundleIconFile}" \ + -Xdock:name="${CFBundleName}" \ + ${JVMOptions:+$JVMOptions }\ + ${JVMDefaultOptions:+$JVMDefaultOptions }\ + ${JVMMainClass}\ + ${MainArgs:+ $MainArgs}\ + ${ArgsPassthru:+ $ArgsPassthru}