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

Commit 1e80f12

Browse files
committed
Experimental support for Java 9 // refs #43
1 parent 060fcd7 commit 1e80f12

3 files changed

Lines changed: 275 additions & 115 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
ChangeLog
22
---------
33

4+
### v2.1.0 (2017-xx-xx)
5+
* Support for Java 9 with new version number schema (fixes #43)
6+
47
### v2.0.2 (2017-04-23)
58
* Bugfix: do NOT expand/evaluate the default Oracle Classpath (`App.app/Contents/Java/*`) (PR #42, Thanks to @mguessan for his contribution)
69

src/universalJavaApplicationStub

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# #
1414
# @author Tobias Fischer #
1515
# @url https://github.com/tofi86/universalJavaApplicationStub #
16-
# @date 2017-11-27 #
17-
# @version 2.0.2 #
16+
# @date 2017-06-12 #
17+
# @version 2.1.0 #
1818
# #
1919
# #
2020
##################################################################################
@@ -289,58 +289,69 @@ fi
289289

290290

291291

292-
# helper
293-
# function: extract Java version string
294-
# from java -version command
295-
############################################
296-
292+
# helper function:
293+
# extract Java version string from `java -version` command
294+
# works for both old (1.8) and new (9) version schema
295+
##########################################################
297296
function extractJavaVersionString() {
298-
echo `"$1" -version 2>&1 | awk '/version/{print $NF}' | sed -E 's/"//g'`
297+
# second sed command strips " and -ea from the version string
298+
echo `"$1" -version 2>&1 | awk '/version/{print $NF}' | sed -E 's/"//g;s/-ea//g'`
299299
}
300300

301-
# helper
302-
# function: extract Java major version
303-
# from java version string
304-
############################################
305301

302+
# helper function:
303+
# extract Java major version from java version string
304+
# - input '1.7.0_76' returns '7'
305+
# - input '1.8.0_121' returns '8'
306+
# - input '9-ea' returns '9'
307+
# - input '9.0.3' returns '9'
308+
##########################################################
306309
function extractJavaMajorVersion() {
307-
version_str=$(extractJavaVersionString "$1")
308-
echo ${version_str} | sed -E 's/([0-9.]{3})[0-9_.]{5,6}/\1/g'
310+
java_ver=$1
311+
# Java 6, 7, 8 starts with 1.x
312+
if [ ${java_ver:0:2} == "1." ] ; then
313+
echo ${java_ver} | sed -E 's/1\.([0-9])[0-9_.]{2,6}/\1/g'
314+
else
315+
# Java 9+ starts with x using semver versioning
316+
echo ${java_ver} | sed -E 's/([0-9]+)(-ea|(\.[0-9]+)*)/\1/g'
317+
fi
309318
}
310319

311-
# helper
312-
# function: generate comparable Java version
313-
# number from java version string
314-
############################################
315320

321+
# helper function:
322+
# return comparable version for java version string
323+
# basically just strip punctuation and leading '1.'
324+
##########################################################
316325
function comparableJavaVersionNumber() {
317-
echo $1 | sed -E 's/[[:punct:]]//g'
326+
echo $1 | sed -E 's/^1\.//g;s/[[:punct:]]//g'
318327
}
319328

320329

321-
322-
#
323-
# function: Java version tester
324-
# check whether a given java version
325-
# satisfies the given requirement
326-
############################################
327-
330+
# function:
331+
# Java version tester checks whether a given java version
332+
# satisfies the given requirement
333+
# - parameter1: the java major version (6, 7, 8, 9, etc.)
334+
# - parameter2: the java requirement (1.6, 1.7+, etc.)
335+
# - return: 0 (satiesfies), 1 (does not), 2 (error)
336+
##########################################################
328337
function JavaVersionSatisfiesRequirement() {
329338
java_ver=$1
330339
java_req=$2
331340

332-
# e.g. 1.8*
333-
if [[ ${java_req} =~ ^[0-9]\.[0-9]\*$ ]] ; then
334-
java_req_num=${java_req:0:3}
335-
java_ver_num=${java_ver:0:3}
336-
if [ ${java_ver_num} == ${java_req_num} ] ; then
341+
# matches requirements with * modifier
342+
# e.g. 1.8*, 9*, 9.1*, 9.2.4*, 10*, 10.1*, 10.1.35*
343+
if [[ ${java_req} =~ ^[0-9]+(\.[0-9]+)*\*$ ]] ; then
344+
# remove last char (*) from requirement string for comparison
345+
java_req_num=${java_req::${#java_req}-1}
346+
if [ ${java_ver} == ${java_req_num} ] ; then
337347
return 0
338348
else
339349
return 1
340350
fi
341351

342-
# e.g. 1.8+
343-
elif [[ ${java_req} =~ ^[0-9]\.[0-9]\+$ ]] ; then
352+
# matches requirements with + modifier
353+
# e.g. 1.8+, 9+, 9.1+, 9.2.4+, 10+, 10.1+, 10.1.35+
354+
elif [[ ${java_req} =~ ^[0-9]+(\.[0-9]+)*\+$ ]] ; then
344355
java_req_num=$(comparableJavaVersionNumber ${java_req})
345356
java_ver_num=$(comparableJavaVersionNumber ${java_ver})
346357
if [ ${java_ver_num} -ge ${java_req_num} ] ; then
@@ -349,15 +360,17 @@ function JavaVersionSatisfiesRequirement() {
349360
return 1
350361
fi
351362

352-
# e.g. 1.8
353-
elif [[ ${java_req} =~ ^[0-9]\.[0-9]$ ]] ; then
363+
# matches standard requirements without modifier
364+
# e.g. 1.8, 9, 9.1, 9.2.4, 10, 10.1, 10.1.35
365+
elif [[ ${java_req} =~ ^[0-9]+(\.[0-9]+)*$ ]] ; then
354366
if [ ${java_ver} == ${java_req} ] ; then
355367
return 0
356368
else
357369
return 1
358370
fi
359371

360372
# not matching any of the above patterns
373+
# results in an error
361374
else
362375
return 2
363376
fi
@@ -370,9 +383,9 @@ function JavaVersionSatisfiesRequirement() {
370383
############################################
371384

372385
apple_jre_plugin="/Library/Java/Home/bin/java"
373-
apple_jre_version=`extractJavaMajorVersion "${apple_jre_plugin}"`
386+
apple_jre_version=$(extractJavaMajorVersion $(extractJavaVersionString "${apple_jre_plugin}"))
374387
oracle_jre_plugin="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java"
375-
oracle_jre_version=`extractJavaMajorVersion "${oracle_jre_plugin}"`
388+
oracle_jre_version=$(extractJavaMajorVersion $(extractJavaVersionString "${oracle_jre_plugin}"))
376389

377390
# first check system variable "$JAVA_HOME"
378391
if [ -n "$JAVA_HOME" ] ; then

0 commit comments

Comments
 (0)