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

Commit e4f96e7

Browse files
authored
Release version 3.2.0 (PR #107)
2 parents 6c96e68 + 2dbbf92 commit e4f96e7

File tree

3 files changed

+110
-47
lines changed

3 files changed

+110
-47
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88

9+
## [3.2.0] - 2021-02-21
10+
### Added
11+
- Also expand variables `$APP_PACKAGE`, `$JAVAROOT` and `$USER_HOME` in Oracle style PList files
12+
- Also expand variable `$APP_ROOT` in Apple style PList files
13+
- Oracle JVMDefaultOptions key: expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOME (#99)
14+
15+
### Changed
16+
- Improved language detection by reading the user preferred languages from the macOS System Preferences instead of using the system locale (#101, thanks to @Flexperte for his valuable feedback)
17+
- Improved logging for JAVA_HOME detection (#100)
18+
19+
### Fixed
20+
- Fixed a crash when `/usr/libexec/java_home` returns no JVMs (#93)
21+
22+
923
## [3.1.0] - 2021-01-07
1024
### Added
1125
- Support for macOS 11.0 "Big Sur" (#91)

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,21 @@ You should get a fully functional Mac Application Bundle working with both Java
151151
Supported PList keys
152152
--------------------
153153

154-
| Function | Apple PList key | Oracle PList key |
155-
|---------------------------------|------------------------|-----------------------|
156-
| **App Name** (Dock Name) | `:CFBundleName` | `:CFBundleName` |
157-
| **App Icon** (Dock Icon) | `:CFBundleIconFile` | `:CFBundleIconFile` |
158-
| **Working Directory** | `:Java(X):WorkingDirectory`<br/>fallback to `name.app/`<br/>support for variables `$APP_PACKAGE`, `$JAVAROOT`, `$USER_HOME` | *not supported*<br/>default: `name.app/Contents/Java/` |
159-
| **Java Min/Max[*](https://github.com/tofi86/universalJavaApplicationStub/issues/51) Version Requirement** | `:Java(X):JVMVersion` | `:JVMVersion` |
160-
| **Java ClassPath** (`-cp …`) | `:Java(X):ClassPath` | `:JVMClassPath` |
161-
| **Java Main Class** | `:Java(X):MainClass` | `:JVMMainClassName` |
162-
| **Splash Image** (`-splash:…`) | `:Java(X):SplashFile` | `:JVMSplashFile` |
163-
| **Java VM Options** (`-X…`) | `:Java(X):VMOptions` | `:JVMDefaultOptions` |
164-
| **`-XstartOnFirstThread`** [*](https://stackoverflow.com/questions/28149634/what-does-the-xstartonfirstthread-vm-argument-do-mean) | `:Java(X):StartOnMainThread` | *not supported* |
165-
| **Java Properties** (`-D…`) | `:Java(X):Properties` | `:JVMOptions` |
166-
| **Main Class Arguments** | `:Java(X):Arguments` | `:JVMArguments` |
167-
154+
| Function | Apple PList key | Oracle PList key |
155+
|--------------------------------------------|------------------------|-----------------------|
156+
| **App Name** (Dock Name) | `:CFBundleName` | `:CFBundleName` |
157+
| **App Icon** (Dock Icon) | `:CFBundleIconFile` | `:CFBundleIconFile` |
158+
| **Working Directory** <sup>🌟</sup> | `:Java(X):WorkingDirectory`<br/>fallback to `name.app/ | *not supported*<br/>default: `name.app/Contents/Java/` |
159+
| **Java Min/Max<sup>[](https://github.com/tofi86/universalJavaApplicationStub/issues/51)</sup> Version Requirement** | `:Java(X):JVMVersion` | `:JVMVersion` |
160+
| **Java ClassPath** (`-cp …`) <sup>🌟</sup> | `:Java(X):ClassPath` | `:JVMClassPath` |
161+
| **Java Main Class** | `:Java(X):MainClass` | `:JVMMainClassName` |
162+
| **Splash Image** (`-splash:…`) | `:Java(X):SplashFile` | `:JVMSplashFile` |
163+
| **Java VM Options** (`-X…`) <sup>🌟</sup> | `:Java(X):VMOptions` | `:JVMDefaultOptions` |
164+
| **`-XstartOnFirstThread`** <sup>[](https://stackoverflow.com/questions/28149634/what-does-the-xstartonfirstthread-vm-argument-do-mean)</sup> | `:Java(X):StartOnMainThread` | *not supported* |
165+
| **Java Properties** (`-D…`) <sup>🌟</sup> | `:Java(X):Properties` | `:JVMOptions` |
166+
| **Main Class Arguments** <sup>🌟</sup> | `:Java(X):Arguments` | `:JVMArguments` |
167+
168+
<sup>🌟</sup> Variable placeholders `$APP_PACKAGE`, `$APP_ROOT`, `$JAVAROOT`, `$USER_HOME` get expanded in these contexts.
168169

169170
### Specify min/max Java requirement
170171

src/universalJavaApplicationStub

Lines changed: 81 additions & 33 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 2021-01-07 #
15-
# @version 3.1.0 #
14+
# @date 2021-02-21 #
15+
# @version 3.2.0 #
1616
# #
1717
##################################################################################
1818
# #
@@ -166,6 +166,8 @@ if [ $exitcode -eq 0 ]; then
166166
JavaFolder="${AppleJavaFolder}"
167167
ResourcesFolder="${AppleResourcesFolder}"
168168

169+
# set expandable variables
170+
APP_ROOT="${AppPackageFolder}"
169171
APP_PACKAGE="${AppPackageFolder}"
170172
JAVAROOT="${AppleJavaFolder}"
171173
USER_HOME="$HOME"
@@ -180,7 +182,7 @@ if [ $exitcode -eq 0 ]; then
180182
# AppPackageRoot is the standard WorkingDirectory when the script is started
181183
WorkingDirectory="${AppPackageRoot}"
182184
fi
183-
# expand variables $APP_PACKAGE, $JAVAROOT, $USER_HOME
185+
# expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOME
184186
WorkingDirectory=$(eval echo "${WorkingDirectory}")
185187

186188

@@ -203,7 +205,7 @@ if [ $exitcode -eq 0 ]; then
203205
else
204206
JVMClassPath=${JVMClassPath_RAW}
205207
fi
206-
# expand variables $APP_PACKAGE, $JAVAROOT, $USER_HOME
208+
# expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOME
207209
JVMClassPath=$(eval echo "${JVMClassPath}")
208210

209211
# read the JVM Options in either Array or String style
@@ -213,7 +215,7 @@ if [ $exitcode -eq 0 ]; then
213215
else
214216
JVMDefaultOptions=${JVMDefaultOptions_RAW}
215217
fi
216-
# expand variables $APP_PACKAGE, $JAVAROOT, $USER_HOME (#84)
218+
# expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOME (#84)
217219
JVMDefaultOptions=$(eval echo "${JVMDefaultOptions}")
218220

219221
# read StartOnMainThread and add as -XstartOnFirstThread
@@ -247,7 +249,11 @@ else
247249
ResourcesFolder="${OracleResourcesFolder}"
248250
WorkingDirectory="${OracleJavaFolder}"
249251

252+
# set expandable variables
250253
APP_ROOT="${AppPackageFolder}"
254+
APP_PACKAGE="${AppPackageFolder}"
255+
JAVAROOT="${OracleJavaFolder}"
256+
USER_HOME="$HOME"
251257

252258
# read the MainClass name
253259
JVMMainClass="$(plist_get ':JVMMainClassName')"
@@ -265,12 +271,12 @@ else
265271
JVMClassPath_RAW=$(plist_get ':JVMClassPath')
266272
if [[ $JVMClassPath_RAW == *Array* ]] ; then
267273
JVMClassPath=.$(plist_get ':JVMClassPath' | grep " " | sed 's/^ */:/g' | tr -d '\n' | xargs)
268-
# expand variables $APP_PACKAGE, $JAVAROOT, $USER_HOME
274+
# expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOME
269275
JVMClassPath=$(eval echo "${JVMClassPath}")
270276

271277
elif [[ ! -z ${JVMClassPath_RAW} ]] ; then
272278
JVMClassPath=${JVMClassPath_RAW}
273-
# expand variables $APP_PACKAGE, $JAVAROOT, $USER_HOME
279+
# expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOME
274280
JVMClassPath=$(eval echo "${JVMClassPath}")
275281

276282
else
@@ -279,8 +285,11 @@ else
279285
# Do NOT expand the default 'AppName.app/Contents/Java/*' classpath (#42)
280286
fi
281287

282-
# read the JVM Default Options
288+
# read the JVM Default Options by parsing the :JVMDefaultOptions <dict>
289+
# and pulling all <string> values starting with a dash (-)
283290
JVMDefaultOptions=$(plist_get ':JVMDefaultOptions' | grep -o " \-.*" | tr -d '\n' | xargs)
291+
# expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOME (#99)
292+
JVMDefaultOptions=$(eval echo "${JVMDefaultOptions}")
284293

285294
# read the Main Arguments from JVMArguments key as an array and retain spaces (see #46 for naming details)
286295
IFS=$'\t\n'
@@ -316,14 +325,14 @@ fi
316325
stub_logger "[JavaRequirement] JVM minimum version: ${JVMVersion}"
317326
stub_logger "[JavaRequirement] JVM maximum version: ${JVMMaxVersion}"
318327

319-
# MainArgs: replace occurences of $APP_ROOT with its content
328+
# MainArgs: expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOME
320329
MainArgsArr=()
321330
for i in "${MainArgs[@]}"
322331
do
323332
MainArgsArr+=("$(eval echo "$i")")
324333
done
325334

326-
# JVMOptions: replace occurences of $APP_ROOT with its content
335+
# JVMOptions: expand variables $APP_PACKAGE, $APP_ROOT, $JAVAROOT, $USER_HOME
327336
JVMOptionsArr=()
328337
for i in "${JVMOptions[@]}"
329338
do
@@ -334,11 +343,34 @@ done
334343
# internationalized messages
335344
############################################
336345

337-
LANG=$(defaults read -g AppleLocale)
338-
stub_logger "[Language] $LANG"
346+
# supported languages / available translations
347+
stubLanguages="^(fr|de|zh|es|en)-"
348+
349+
# read user preferred languages as defined in macOS System Preferences (#101)
350+
stub_logger '[LanguageSearch] Checking preferred languages in macOS System Preferences...'
351+
appleLanguages=($(defaults read -g AppleLanguages | grep '\s"' | tr -d ',' | xargs))
352+
stub_logger "[LanguageSearch] ... found [${appleLanguages[*]}]"
353+
354+
language=""
355+
for i in "${appleLanguages[@]}"
356+
do
357+
langValue="${i%-*}"
358+
if [[ "$i" =~ $stubLanguages ]]; then
359+
stub_logger "[LanguageSearch] ... selected '$i' ('$langValue') as the default language for the launcher stub"
360+
language=${langValue}
361+
break
362+
fi
363+
done
364+
if [ -z "${language}" ]; then
365+
language="en"
366+
stub_logger "[LanguageSearch] ... selected fallback 'en' as the default language for the launcher stub"
367+
fi
368+
stub_logger "[Language] $language"
369+
339370

340-
# French localization
341-
if [[ $LANG == fr* ]] ; then
371+
case "${language}" in
372+
# French
373+
fr)
342374
MSG_ERROR_LAUNCHING="ERREUR au lancement de '${CFBundleName}'."
343375
MSG_MISSING_MAINCLASS="'MainClass' n'est pas spécifié.\nL'application Java ne peut pas être lancée."
344376
MSG_JVMVERSION_REQ_INVALID="La syntaxe de la version de Java demandée est invalide: %s\nVeuillez contacter le développeur de l'application."
@@ -351,9 +383,10 @@ if [[ $LANG == fr* ]] ; then
351383
MSG_LATER="Plus tard"
352384
MSG_VISIT_JAVA_DOT_COM="Java by Oracle"
353385
MSG_VISIT_ADOPTOPENJDK="Java by AdoptOpenJDK"
386+
;;
354387

355-
# German localization
356-
elif [[ $LANG == de* ]] ; then
388+
# German
389+
de)
357390
MSG_ERROR_LAUNCHING="FEHLER beim Starten von '${CFBundleName}'."
358391
MSG_MISSING_MAINCLASS="Die 'MainClass' ist nicht spezifiziert!\nDie Java-Anwendung kann nicht gestartet werden!"
359392
MSG_JVMVERSION_REQ_INVALID="Die Syntax der angeforderten Java-Version ist ungültig: %s\nBitte kontaktieren Sie den Entwickler der App."
@@ -366,9 +399,10 @@ elif [[ $LANG == de* ]] ; then
366399
MSG_LATER="Später"
367400
MSG_VISIT_JAVA_DOT_COM="Java von Oracle"
368401
MSG_VISIT_ADOPTOPENJDK="Java von AdoptOpenJDK"
402+
;;
369403

370-
# Simplifyed Chinese localization
371-
elif [[ $LANG == zh* ]] ; then
404+
# Simplified Chinese
405+
zh)
372406
MSG_ERROR_LAUNCHING="无法启动 '${CFBundleName}'."
373407
MSG_MISSING_MAINCLASS="没有指定 'MainClass'!\nJava程序无法启动!"
374408
MSG_JVMVERSION_REQ_INVALID="Java版本参数语法错误: %s\n请联系该应用的开发者。"
@@ -381,9 +415,10 @@ elif [[ $LANG == zh* ]] ; then
381415
MSG_LATER="稍后"
382416
MSG_VISIT_JAVA_DOT_COM="Java by Oracle"
383417
MSG_VISIT_ADOPTOPENJDK="Java by AdoptOpenJDK"
418+
;;
384419

385-
# Spanish localization
386-
elif [[ $LANG == es* ]] ; then
420+
# Spanish
421+
es)
387422
MSG_ERROR_LAUNCHING="ERROR iniciando '${CFBundleName}'."
388423
MSG_MISSING_MAINCLASS="¡'MainClass' no especificada!\n¡La aplicación Java no puede iniciarse!"
389424
MSG_JVMVERSION_REQ_INVALID="La sintaxis de la versión Java requerida no es válida: %s\nPor favor, contacte con el desarrollador de la aplicación."
@@ -396,9 +431,10 @@ elif [[ $LANG == es* ]] ; then
396431
MSG_LATER="Más tarde"
397432
MSG_VISIT_JAVA_DOT_COM="Java de Oracle"
398433
MSG_VISIT_ADOPTOPENJDK="Java de AdoptOpenJDK"
434+
;;
399435

400-
# English default localization
401-
else
436+
# English default
437+
en|*)
402438
MSG_ERROR_LAUNCHING="ERROR launching '${CFBundleName}'."
403439
MSG_MISSING_MAINCLASS="'MainClass' isn't specified!\nJava application cannot be started!"
404440
MSG_JVMVERSION_REQ_INVALID="The syntax of the required Java version is invalid: %s\nPlease contact the App developer."
@@ -411,7 +447,8 @@ else
411447
MSG_LATER="Later"
412448
MSG_VISIT_JAVA_DOT_COM="Java by Oracle"
413449
MSG_VISIT_ADOPTOPENJDK="Java by AdoptOpenJDK"
414-
fi
450+
;;
451+
esac
415452

416453

417454

@@ -527,19 +564,27 @@ if [ -n "$JAVA_HOME" ] ; then
527564
if [[ $JAVA_HOME == /* ]] ; then
528565
# if "$JAVA_HOME" starts with a Slash it's an absolute path
529566
JAVACMD="$JAVA_HOME/bin/java"
567+
stub_logger "[JavaSearch] ... parsing JAVA_HOME as absolute path to the executable '$JAVACMD'"
530568
else
531569
# otherwise it's a relative path to "$AppPackageFolder"
532570
JAVACMD="$AppPackageFolder/$JAVA_HOME/bin/java"
571+
stub_logger "[JavaSearch] ... parsing JAVA_HOME as relative path inside the App bundle to the executable '$JAVACMD'"
533572
fi
534573
JAVACMD_version=$(get_comparable_java_version $(get_java_version_from_cmd "${JAVACMD}"))
535574
else
536-
stub_logger "[JavaSearch] ... didn't found JAVA_HOME"
575+
stub_logger "[JavaSearch] ... haven't found JAVA_HOME"
537576
fi
538577

539578

540579
# check for any other or a specific Java version
541580
# also if $JAVA_HOME exists but isn't executable
542581
if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then
582+
583+
# add a warning in the syslog if JAVA_HOME is not executable or not found (#100)
584+
if [ -n "$JAVA_HOME" ] ; then
585+
stub_logger "[JavaSearch] ... but no 'java' executable was found at the JAVA_HOME location!"
586+
fi
587+
543588
stub_logger "[JavaSearch] Searching for JavaVirtualMachines on the system ..."
544589
# reset variables
545590
JAVACMD=""
@@ -576,15 +621,18 @@ if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then
576621
javaCounter=$(/usr/libexec/PlistBuddy -c "Print" /dev/stdin <<< $javaXml | grep "Dict" | wc -l | tr -d ' ')
577622

578623
# iterate over all Dict entries
579-
for idx in $(seq 0 $((javaCounter - 1)))
580-
do
581-
version=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMVersion" /dev/stdin <<< $javaXml)
582-
path=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMHomePath" /dev/stdin <<< $javaXml)
583-
path+="/bin/java"
584-
allJVMs+=("$version:$path")
585-
done
586-
# unset for loop variables
587-
unset version path
624+
# but only if there are any JVMs at all (#93)
625+
if [ "$javaCounter" -gt "0" ] ; then
626+
for idx in $(seq 0 $((javaCounter - 1)))
627+
do
628+
version=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMVersion" /dev/stdin <<< $javaXml)
629+
path=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMHomePath" /dev/stdin <<< $javaXml)
630+
path+="/bin/java"
631+
allJVMs+=("$version:$path")
632+
done
633+
# unset for loop variables
634+
unset version path
635+
fi
588636

589637
# add SDKMAN! java versions (#95)
590638
if [ -d ~/.sdkman/candidates/java/ ] ; then

0 commit comments

Comments
 (0)