Skip to content

Commit 6edf71e

Browse files
committed
U universalJavaApplicationStub to v3.1.0
1 parent defdb3e commit 6edf71e

File tree

2 files changed

+55
-20
lines changed

2 files changed

+55
-20
lines changed

src/main/resources/mac/Info.plist.vtl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
<key>WorkingDirectory</key>
6565
<string>$APP_PACKAGE/Contents/Resources</string>
6666
#end
67+
<key>JVMOptionsFile</key>
68+
<string>$APP_PACKAGE/Contents/Resources/${info.name}.l4j.ini</string>
6769
</dict>
6870
<key>LSEnvironment</key>
6971
<dict>

src/main/resources/mac/universalJavaApplicationStub

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
# #
1212
# @author Tobias Fischer #
1313
# @url https://github.com/tofi86/universalJavaApplicationStub #
14-
# @date 2020-03-19 #
15-
# @version 3.0.6 #
14+
# @date 2021-01-07 #
15+
# @version 3.1.0 #
1616
# #
1717
##################################################################################
1818
# #
1919
# The MIT License (MIT) #
2020
# #
21-
# Copyright (c) 2014-2020 Tobias Fischer #
21+
# Copyright (c) 2014-2021 Tobias Fischer #
2222
# #
2323
# Permission is hereby granted, free of charge, to any person obtaining a copy #
2424
# of this software and associated documentation files (the "Software"), to deal #
@@ -183,7 +183,6 @@ if [ $exitcode -eq 0 ]; then
183183
# expand variables $APP_PACKAGE, $JAVAROOT, $USER_HOME
184184
WorkingDirectory=$(eval echo "${WorkingDirectory}")
185185

186-
187186
# read the MainClass name
188187
JVMMainClass="$(plist_get_java ':MainClass')"
189188

@@ -213,7 +212,9 @@ if [ $exitcode -eq 0 ]; then
213212
else
214213
JVMDefaultOptions=${JVMDefaultOptions_RAW}
215214
fi
216-
215+
# expand variables $APP_PACKAGE, $JAVAROOT, $USER_HOME (#84)
216+
JVMDefaultOptions=$(eval echo "${JVMDefaultOptions}")
217+
217218
# read StartOnMainThread and add as -XstartOnFirstThread
218219
JVMStartOnMainThread=$(plist_get_java ':StartOnMainThread')
219220
if [ "${JVMStartOnMainThread}" == "true" ]; then
@@ -235,6 +236,8 @@ if [ $exitcode -eq 0 ]; then
235236
JVMVersion=$(plist_get_java ':JVMVersion' | xargs)
236237
# post processing of the version string follows below...
237238

239+
# read options file name
240+
JVMOptionsFile=$(plist_get_java ':JVMOptionsFile')
238241

239242
# read 'Info.plist' file in Oracle style
240243
else
@@ -279,7 +282,7 @@ else
279282

280283
# read the JVM Default Options
281284
JVMDefaultOptions=$(plist_get ':JVMDefaultOptions' | grep -o " \-.*" | tr -d '\n' | xargs)
282-
285+
283286
# read the Main Arguments from JVMArguments key as an array and retain spaces (see #46 for naming details)
284287
IFS=$'\t\n'
285288
MainArgs=($(xargs -n1 <<<$(plist_get ':JVMArguments' | tr -d '\n' | sed -E 's/Array \{ *(.*) *\}/\1/g' | sed 's/ */ /g')))
@@ -289,11 +292,15 @@ else
289292
# read the Java version we want to find
290293
JVMVersion=$(plist_get ':JVMVersion' | xargs)
291294
# post processing of the version string follows below...
295+
296+
# read options file name
297+
JVMOptionsFile=$(plist_get ':JVMOptionsFile')
298+
292299
fi
293300

294-
# read JVM options from ini file
295-
JVMOptionsFile="$ResourcesFolder/${info.name}.l4j.ini"
296-
[ -f $JVMOptionsFile ] && while read -r option; do JVMDefaultOptions+=" $option"; done <<< $(sed "/^#.*$/d" $JVMOptionsFile)
301+
# read JVM options from file
302+
JVMOptionsFile=$(eval echo "${JVMOptionsFile}")
303+
[ -f $JVMOptionsFile ] && while read -r option; do JVMDefaultOptions+=" $option"; done <<< $(sed "/^#.*$/d" $JVMOptionsFile)
297304

298305
# (#75) check for undefined icons or icon names without .icns extension and prepare
299306
# an osascript statement for those cases when the icon can be shown in the dialog
@@ -541,7 +548,7 @@ fi
541548
# check for any other or a specific Java version
542549
# also if $JAVA_HOME exists but isn't executable
543550
if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then
544-
stub_logger "[JavaSearch] Checking for JavaVirtualMachines on the system ..."
551+
stub_logger "[JavaSearch] Searching for JavaVirtualMachines on the system ..."
545552
# reset variables
546553
JAVACMD=""
547554
JAVACMD_version=""
@@ -570,16 +577,39 @@ if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then
570577

571578
# find installed JavaVirtualMachines (JDK + JRE)
572579
allJVMs=()
573-
# read JDK's from '/usr/libexec/java_home -V' command
574-
while read -r line; do
575-
version=$(echo $line | awk -F $',' '{print $1;}')
576-
path=$(echo $line | awk -F $'" ' '{print $2;}')
580+
581+
# read JDK's from '/usr/libexec/java_home --xml' command with PlistBuddy and a custom Dict iterator
582+
# idea: https://stackoverflow.com/a/14085460/1128689 and https://scriptingosx.com/2018/07/parsing-dscl-output-in-scripts/
583+
javaXml=$(/usr/libexec/java_home --xml)
584+
javaCounter=$(/usr/libexec/PlistBuddy -c "Print" /dev/stdin <<< $javaXml | grep "Dict" | wc -l | tr -d ' ')
585+
586+
# iterate over all Dict entries
587+
for idx in $(seq 0 $((javaCounter - 1)))
588+
do
589+
version=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMVersion" /dev/stdin <<< $javaXml)
590+
path=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMHomePath" /dev/stdin <<< $javaXml)
577591
path+="/bin/java"
578592
allJVMs+=("$version:$path")
579-
done < <(/usr/libexec/java_home -V 2>&1 | grep '^[[:space:]]')
580-
# unset while loop variables
593+
done
594+
# unset for loop variables
581595
unset version path
582596

597+
# add SDKMAN! java versions (#95)
598+
if [ -d ~/.sdkman/candidates/java/ ] ; then
599+
for sdkjdk in ~/.sdkman/candidates/java/*/
600+
do
601+
if [[ ${sdkjdk} =~ /current/$ ]] ; then
602+
continue
603+
fi
604+
605+
sdkjdkcmd="${sdkjdk}bin/java"
606+
version=$(get_java_version_from_cmd "${sdkjdkcmd}")
607+
allJVMs+=("$version:$sdkjdkcmd")
608+
done
609+
# unset for loop variables
610+
unset version
611+
fi
612+
583613
# add Apple JRE if available
584614
if [ -x "${apple_jre_plugin}" ] ; then
585615
allJVMs+=("$apple_jre_version:$apple_jre_plugin")
@@ -598,6 +628,9 @@ if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then
598628

599629

600630
# determine JVMs matching the min/max version requirement
631+
632+
stub_logger "[JavaSearch] Filtering the result list for JVMs matching the min/max version requirement ..."
633+
601634
minC=$(get_comparable_java_version ${JVMVersion})
602635
maxC=$(get_comparable_java_version ${JVMMaxVersion})
603636
matchingJVMs=()
@@ -682,7 +715,7 @@ if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then
682715
# debug output
683716
for i in "${matchingJVMs[@]}"
684717
do
685-
stub_logger "[JavaSearch] ... ... matches all requirements: $i"
718+
stub_logger "[JavaSearch] ... matches all requirements: $i"
686719
done
687720

688721

@@ -802,14 +835,14 @@ stub_logger "[WorkingDirectory] ${WorkingDirectory}"
802835
# - main class
803836
# - main class arguments
804837
# - passthrough arguments from Terminal or Drag'n'Drop to Finder icon
805-
stub_logger "[Exec] \"$JAVACMD\" -cp \"${JVMClassPath}\" -splash:\"${ResourcesFolder}/${JVMSplashFile}\" -Xdock:icon=\"${ResourcesFolder}/${CFBundleIconFile}\" -Xdock:name=\"${CFBundleName}\" ${JVMOptionsArr:+$(printf "'%s' " "${JVMOptionsArr[@]}") }${JVMDefaultOptions:+$JVMDefaultOptions }${JVMMainClass}${MainArgsArr:+ $(printf "'%s' " "${MainArgsArr[@]}")}${ArgsPassthru:+ $(printf "'%s' " "${ArgsPassthru[@]}")}"
838+
stub_logger "[Exec] \"$JAVACMD\" -cp \"${JVMClassPath}\" ${JVMSplashFile:+ -splash:\"${ResourcesFolder}/${JVMSplashFile}\"} -Xdock:icon=\"${ResourcesFolder}/${CFBundleIconFile}\" -Xdock:name=\"${CFBundleName}\" ${JVMOptionsArr:+$(printf "'%s' " "${JVMOptionsArr[@]}") }${JVMDefaultOptions:+$JVMDefaultOptions }${JVMMainClass}${MainArgsArr:+ $(printf "'%s' " "${MainArgsArr[@]}")}${ArgsPassthru:+ $(printf "'%s' " "${ArgsPassthru[@]}")}"
806839
exec "${JAVACMD}" \
807840
-cp "${JVMClassPath}" \
808-
-splash:"${ResourcesFolder}/${JVMSplashFile}" \
841+
${JVMSplashFile:+ -splash:"${ResourcesFolder}/${JVMSplashFile}"} \
809842
-Xdock:icon="${ResourcesFolder}/${CFBundleIconFile}" \
810843
-Xdock:name="${CFBundleName}" \
811844
${JVMOptionsArr:+"${JVMOptionsArr[@]}" }\
812845
${JVMDefaultOptions:+$JVMDefaultOptions }\
813846
"${JVMMainClass}"\
814847
${MainArgsArr:+ "${MainArgsArr[@]}"}\
815-
${ArgsPassthru:+ "${ArgsPassthru[@]}"}
848+
${ArgsPassthru:+ "${ArgsPassthru[@]}"}

0 commit comments

Comments
 (0)