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

Commit 23bb5e2

Browse files
committed
[refactoring] move functions and add a function to generate comparable version numbers
1 parent c5cbbf1 commit 23bb5e2

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/universalJavaApplicationStub

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646

4747

4848

49-
5049
#
5150
# resolve symlinks
5251
############################################
@@ -68,7 +67,6 @@ PROGDIR=`dirname "$PRG"`
6867

6968

7069

71-
7270
#
7371
# set files and folders
7472
############################################
@@ -101,7 +99,6 @@ JVMVersion=""
10199

102100

103101

104-
105102
#
106103
# read Info.plist and extract JVM options
107104
############################################
@@ -235,6 +232,7 @@ else
235232
fi
236233

237234

235+
238236
#
239237
# internationalized messages
240238
#
@@ -280,6 +278,30 @@ else
280278
fi
281279

282280

281+
282+
#
283+
# function: extract Java major version
284+
# from java -version command
285+
############################################
286+
287+
function extractJavaMajorVersion() {
288+
"$1" -version
289+
echo `"$1" -version 2>&1 | awk '/version/{print $NF}' | sed -E 's/"([0-9.]{3})[0-9_.]{5,6}"/\1/g'`
290+
}
291+
292+
293+
294+
#
295+
# function: generate comparable Java version
296+
# number from java version string
297+
############################################
298+
299+
function comparableJavaVersionNumber() {
300+
echo $1 | sed -E 's/[[:punct:]]//g'
301+
}
302+
303+
304+
283305
#
284306
# function: Java version tester
285307
############################################
@@ -300,8 +322,8 @@ function JavaVersionSatisfiesRequirement() {
300322

301323
# e.g. 1.8+
302324
elif [[ ${java_req} =~ ^[0-9]\.[0-9]\+$ ]] ; then
303-
java_req_num=`echo ${java_req} | sed -E 's/[[:punct:]]//g'`
304-
java_ver_num=`echo ${java_ver} | sed -E 's/[[:punct:]]//g'`
325+
java_req_num=$(comparableJavaVersionNumber ${java_req})
326+
java_ver_num=$(comparableJavaVersionNumber ${java_ver})
305327
if [ ${java_ver_num} -ge ${java_req_num} ] ; then
306328
return 0
307329
else
@@ -323,16 +345,6 @@ function JavaVersionSatisfiesRequirement() {
323345
}
324346

325347

326-
#
327-
# function: extract Java major version
328-
# from java -version command
329-
############################################
330-
331-
function extractJavaMajorVersion() {
332-
echo `"$1" -version 2>&1 | awk '/version/{print $NF}' | sed -E 's/"([0-9.]{3})[0-9_.]{5,6}"/\1/g'`
333-
}
334-
335-
336348

337349
#
338350
# find installed Java versions
@@ -391,7 +403,6 @@ fi
391403

392404

393405

394-
395406
#
396407
# execute JAVA commandline and do some pre-checks
397408
####################################################

0 commit comments

Comments
 (0)