Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 9e7cada

Browse files
committed
pass JVMOptions with spaces correctly to the java exec // fixes #14
1 parent 50d24bf commit 9e7cada

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

src/universalJavaApplicationStub

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
# #
1212
# @author Tobias Fischer #
1313
# @url https://github.com/tofi86/universalJavaApplicationStub #
14+
# @date 2018-02-18 #
1415
# @version 2.1.0 #
15-
# @date 2018-02-17 #
1616
# #
1717
##################################################################################
1818
# #
@@ -190,10 +190,11 @@ if [ $exitcode -eq 0 ]; then
190190
# read the SplashFile name
191191
JVMSplashFile=$(plist_get_java ':SplashFile')
192192

193-
# read the JVM Properties
194-
JVMOptions=$(plist_get_java ':Properties' | grep " =" | sed 's/^ */-D/g' | tr '\n' ' ' | sed 's/ */ /g' | sed 's/ = /=/g' | xargs)
195-
# replace occurences of $APP_ROOT with its content
196-
JVMOptions=$(eval echo "${JVMOptions}")
193+
# read the JVM Properties as an array and retain spaces
194+
IFS=$'\t\n'
195+
JVMOptions=($(xargs -n1 <<<$(plist_get_java ':Properties' | grep " =" | sed 's/^ */-D/g' | sed -E 's/ = (.*)$/="\1"/g')))
196+
unset IFS
197+
# post processing of the array follows further below...
197198

198199
# read the ClassPath in either Array or String style
199200
JVMClassPath_RAW=$(plist_get_java ':ClassPath' | xargs)
@@ -247,10 +248,11 @@ else
247248
# read the SplashFile name
248249
JVMSplashFile=$(plist_get ':JVMSplashFile')
249250

250-
# read the JVM Options
251-
JVMOptions=$(plist_get ':JVMOptions' | grep " -" | tr -d '\n' | sed 's/ */ /g' | xargs)
252-
# replace occurences of $APP_ROOT with its content
253-
JVMOptions=$(eval echo "${JVMOptions}")
251+
# read the JVM Options as an array and retain spaces
252+
IFS=$'\t\n'
253+
JVMOptions=($(plist_get ':JVMOptions' | grep " " | sed 's/^ *//g'))
254+
unset IFS
255+
# post processing of the array follows further below...
254256

255257
# read the ClassPath in either Array or String style
256258
JVMClassPath_RAW=$(plist_get ':JVMClassPath')
@@ -302,6 +304,12 @@ do
302304
MainArgsArr+=("$(eval echo "$i")")
303305
done
304306

307+
# JVMOptions: replace occurences of $APP_ROOT with its content
308+
JVMOptionsArr=()
309+
for i in "${JVMOptions[@]}"
310+
do
311+
JVMOptionsArr+=("$(eval echo "$i")")
312+
done
305313

306314

307315
# internationalized messages
@@ -753,13 +761,13 @@ stub_logger "[WorkingDirectory] ${WorkingDirectory}"
753761
# - main class
754762
# - main arguments
755763
# - passthru arguments
756-
stub_logger "[Exec] \"$JAVACMD\" -cp \"${JVMClassPath}\" -splash:\"${ResourcesFolder}/${JVMSplashFile}\" -Xdock:icon=\"${ResourcesFolder}/${CFBundleIconFile}\" -Xdock:name=\"${CFBundleName}\" ${JVMOptions:+$JVMOptions }${JVMDefaultOptions:+$JVMDefaultOptions }${JVMMainClass}${MainArgsArr:+ $(printf "'%s' " "${MainArgsArr[@]}")}${ArgsPassthru:+ $(printf "'%s' " "${ArgsPassthru[@]}")}"
764+
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[@]}")}"
757765
exec "${JAVACMD}" \
758766
-cp "${JVMClassPath}" \
759767
-splash:"${ResourcesFolder}/${JVMSplashFile}" \
760768
-Xdock:icon="${ResourcesFolder}/${CFBundleIconFile}" \
761769
-Xdock:name="${CFBundleName}" \
762-
${JVMOptions:+$JVMOptions }\
770+
${JVMOptions:+"$JVMOptions[@]}" }\
763771
${JVMDefaultOptions:+$JVMDefaultOptions }\
764772
"${JVMMainClass}"\
765773
${MainArgsArr:+ "${MainArgsArr[@]}"}\

0 commit comments

Comments
 (0)