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

Commit e926224

Browse files
committed
[refactoring] small changes
1 parent 0e6c117 commit e926224

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/universalJavaApplicationStub

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# #
1212
# @author Tobias Fischer #
1313
# @url https://github.com/tofi86/universalJavaApplicationStub #
14-
# @date 2017-11-01 #
14+
# @date 2018-01-07 #
1515
# @version 2.1.0 #
1616
# #
1717
##################################################################################
@@ -405,8 +405,10 @@ function get_comparable_java_version() {
405405
################################################################################
406406
function is_valid_requirement_pattern() {
407407
local java_req=$1
408-
# first test matches old Java versioning scheme (up to 1.8), second test matches new scheme (starting with 9)
409-
if [[ ${java_req} =~ ^1\.[4-8](\.0)?(\.0_[0-9]+)?[*+]?$ ]] || [[ ${java_req} =~ ^(9|1[0-9])(-ea|[*+]|(\.[0-9]+){1,2}[*+]?)?$ ]]; then
408+
java8pattern='1\.[4-8](\.0)?(\.0_[0-9]+)?[*+]?'
409+
java9pattern='(9|1[0-9])(-ea|[*+]|(\.[0-9]+){1,2}[*+]?)?'
410+
# test matches either old Java versioning scheme (up to 1.8) or new scheme (starting with 9)
411+
if [[ ${java_req} =~ ^(${java8pattern}|${java9pattern})$ ]]; then
410412
return 0
411413
else
412414
return 1
@@ -463,7 +465,7 @@ function does_java_version_satisfy_requirement() {
463465
return 1
464466
fi
465467

466-
# requirement ends with * modifier
468+
# requirement ends with + modifier
467469
# e.g. 1.8+, 9+, 9.1+, 9.2.4+, 10+, 10.1+, 10.1.35+
468470
elif [[ ${java_req} == *+ ]] ; then
469471
local java_req_num=$(get_comparable_java_version ${java_req})
@@ -539,7 +541,7 @@ elif [ ! -z ${JVMVersion} ] ; then
539541

540542
# then additionally check the Oracle JRE plugin whether it's a higher/newer compatible version
541543
if [ -x "${oracle_jre_plugin}" ] && does_java_version_satisfy_requirement ${oracle_jre_version} ${JVMVersion} ; then
542-
this_java_ver=$(get_comparable_java_version $(get_java_version_from_cmd "${oracle_jre_plugin}"))
544+
this_java_ver=$(get_comparable_java_version ${oracle_jre_version})
543545
# use this compatible version only if the above returned empty or if the version number is higher
544546
if [ -z "${JAVACMD}" ] || [ ${this_java_ver} -ge ${JAVACMD_version} ] ; then
545547
JAVACMD="${oracle_jre_plugin}"
@@ -549,7 +551,7 @@ elif [ ! -z ${JVMVersion} ] ; then
549551

550552
# then additionally check the Apple JRE plugin whether it's a higher/newer compatible version
551553
if [ -x "${apple_jre_plugin}" ] && does_java_version_satisfy_requirement ${apple_jre_version} ${JVMVersion} ; then
552-
this_java_ver=$(get_comparable_java_version $(get_java_version_from_cmd "${apple_jre_plugin}"))
554+
this_java_ver=$(get_comparable_java_version ${apple_jre_version})
553555
# use this compatible version only if the above returned empty or if the version number is higher
554556
if [ -z "${JAVACMD}" ] || [ ${this_java_ver} -ge ${JAVACMD_version} ] ; then
555557
JAVACMD="${apple_jre_plugin}"

test/java-version-tester.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
# Java JRE version tester
4-
# tofi86 @ 2017-11-01
4+
# tofi86 @ 2018-01-07
55

66

77

@@ -84,8 +84,10 @@ function get_comparable_java_version() {
8484
################################################################################
8585
function is_valid_requirement_pattern() {
8686
local java_req=$1
87-
# first test matches old Java versioning scheme (up to 1.8), second test matches new scheme (starting with 9)
88-
if [[ ${java_req} =~ ^1\.[4-8](\.0)?(\.0_[0-9]+)?[*+]?$ ]] || [[ ${java_req} =~ ^(9|1[0-9])(-ea|[*+]|(\.[0-9]+){1,2}[*+]?)?$ ]]; then
87+
java8pattern='1\.[4-8](\.0)?(\.0_[0-9]+)?[*+]?'
88+
java9pattern='(9|1[0-9])(-ea|[*+]|(\.[0-9]+){1,2}[*+]?)?'
89+
# test matches either old Java versioning scheme (up to 1.8) or new scheme (starting with 9)
90+
if [[ ${java_req} =~ ^(${java8pattern}|${java9pattern})$ ]]; then
8991
return 0
9092
else
9193
return 1
@@ -142,7 +144,7 @@ function does_java_version_satisfy_requirement() {
142144
return 1
143145
fi
144146

145-
# requirement ends with * modifier
147+
# requirement ends with + modifier
146148
# e.g. 1.8+, 9+, 9.1+, 9.2.4+, 10+, 10.1+, 10.1.35+
147149
elif [[ ${java_req} == *+ ]] ; then
148150
local java_req_num=$(get_comparable_java_version ${java_req})

0 commit comments

Comments
 (0)