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

Commit f298a60

Browse files
committed
pass MainClass arguments with spaces correctly to the java exec // fixes #58
1 parent 793919e commit f298a60

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

src/universalJavaApplicationStub

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,11 @@ if [ $exitcode -eq 0 ]; then
219219
JVMDefaultOptions+=" -XstartOnFirstThread"
220220
fi
221221

222-
# read the JVM Arguments
223-
MainArgs=$(plist_get_java ':Arguments')
224-
# replace occurences of $APP_ROOT with its content
225-
MainArgs=$(eval echo "${MainArgs}")
222+
# read the JVM Arguments as an array and retain spaces
223+
IFS=$'\t\n'
224+
MainArgs=($(xargs -n1 <<<$(plist_get_java ':Arguments')))
225+
unset IFS
226+
# post processing of the array follows further below...
226227

227228
# read the Java version we want to find
228229
JVMVersion=$(plist_get_java ':JVMVersion' | xargs)
@@ -278,13 +279,22 @@ else
278279
# read the JVM Default Options
279280
JVMDefaultOptions=$(plist_get ':JVMDefaultOptions' | grep -o " \-.*" | tr -d '\n' | xargs)
280281

281-
# read the Main Arguments from JVMArguments key (see #46 for naming details)
282-
MainArgs=$(plist_get ':JVMArguments' | tr -d '\n' | sed -E 's/Array \{ *(.*) *\}/\1/g' | sed 's/ */ /g' | xargs)
283-
# replace occurences of $APP_ROOT with its content
284-
MainArgs=$(eval echo "${MainArgs}")
282+
# read the Main Arguments from JVMArguments key as an array and retain spaces (see #46 for naming details)
283+
IFS=$'\t\n'
284+
MainArgs=($(xargs -n1 <<<$(plist_get ':JVMArguments' | tr -d '\n' | sed -E 's/Array \{ *(.*) *\}/\1/g' | sed 's/ */ /g')))
285+
unset IFS
286+
# post processing of the array follows below...
285287
fi
286288

287289

290+
# MainArgs: replace occurences of $APP_ROOT with its content
291+
MainArgsArr=()
292+
for i in "${MainArgs[@]}"
293+
do
294+
MainArgsArr+=("$(eval echo "$i")")
295+
done
296+
297+
288298

289299
# internationalized messages
290300
############################################
@@ -735,7 +745,7 @@ stub_logger "[WorkingDirectory] ${WorkingDirectory}"
735745
# - main class
736746
# - main arguments
737747
# - passthru arguments
738-
stub_logger "[Exec] \"$JAVACMD\" -cp \"${JVMClassPath}\" -splash:\"${ResourcesFolder}/${JVMSplashFile}\" -Xdock:icon=\"${ResourcesFolder}/${CFBundleIconFile}\" -Xdock:name=\"${CFBundleName}\" ${JVMOptions:+$JVMOptions }${JVMDefaultOptions:+$JVMDefaultOptions }${JVMMainClass}${MainArgs:+ $MainArgs}${ArgsPassthru:+ $(printf "'%s' " "${ArgsPassthru[@]}")}"
748+
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[@]}")}"
739749
exec "${JAVACMD}" \
740750
-cp "${JVMClassPath}" \
741751
-splash:"${ResourcesFolder}/${JVMSplashFile}" \
@@ -744,5 +754,5 @@ exec "${JAVACMD}" \
744754
${JVMOptions:+$JVMOptions }\
745755
${JVMDefaultOptions:+$JVMDefaultOptions }\
746756
${JVMMainClass}\
747-
${MainArgs:+ $MainArgs}\
757+
${MainArgsArr:+ "${MainArgsArr[@]}"}\
748758
${ArgsPassthru:+ "${ArgsPassthru[@]}"}

0 commit comments

Comments
 (0)