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

Commit 3f8e6c1

Browse files
committed
bugfix for java version number detection // fixes #61
1 parent 4eea734 commit 3f8e6c1

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/universalJavaApplicationStub

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ function get_java_version_from_cmd() {
399399
# @return the major version (e.g. '7', '8' or '9', etc.)
400400
################################################################################
401401
function extract_java_major_version() {
402-
echo $(echo "$1" | sed -E 's/^1\.//;s/^([0-9]+)(-ea|(\.[0-9_.]{1,7})?)[+*]?$/\1/')
402+
echo $(echo "$1" | sed -E 's/^1\.//;s/^([0-9]+)(-ea|(\.[0-9_.]{1,7})?)(-b[0-9]+-[0-9]+)?[+*]?$/\1/')
403403
}
404404

405405

@@ -411,8 +411,8 @@ function extract_java_major_version() {
411411
# @return an 8 digit numeral ('1.8.0_45'->'08000045'; '9.1.13'->'09001013')
412412
################################################################################
413413
function get_comparable_java_version() {
414-
# cleaning: 1) remove leading '1.'; 2) remove 'a-Z' and '-*+' (e.g. '-ea'); 3) replace '_' with '.'
415-
local cleaned=$(echo "$1" | sed -E 's/^1\.//g;s/[a-zA-Z+*\-]//g;s/_/./g')
414+
# cleaning: 1) remove leading '1.'; 2) remove build string (e.g. '-b14-468'); 3) remove 'a-Z' and '-*+' (e.g. '-ea'); 4) replace '_' with '.'
415+
local cleaned=$(echo "$1" | sed -E 's/^1\.//g;s/-b[0-9]+-[0-9]+$//g;s/[a-zA-Z+*\-]//g;s/_/./g')
416416
# splitting at '.' into an array
417417
local arr=( ${cleaned//./ } )
418418
# echo a string with left padded version numbers

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
# Tests for the functions used in universalJavaApplicationStub script
4-
# tofi86 @ 2018-02-12
4+
# tofi86 @ 2018-03-10
55

66

77

@@ -27,7 +27,7 @@ function get_java_version_from_cmd() {
2727
# @return the major version (e.g. '7', '8' or '9', etc.)
2828
################################################################################
2929
function extract_java_major_version() {
30-
echo $(echo "$1" | sed -E 's/^1\.//;s/^([0-9]+)(-ea|(\.[0-9_.]{1,7})?)[+*]?$/\1/')
30+
echo $(echo "$1" | sed -E 's/^1\.//;s/^([0-9]+)(-ea|(\.[0-9_.]{1,7})?)(-b[0-9]+-[0-9]+)?[+*]?$/\1/')
3131
}
3232

3333

@@ -39,8 +39,8 @@ function extract_java_major_version() {
3939
# @return an 8 digit numeral ('1.8.0_45'->'08000045'; '9.1.13'->'09001013')
4040
################################################################################
4141
function get_comparable_java_version() {
42-
# cleaning: 1) remove leading '1.'; 2) remove 'a-Z' and '-*+' (e.g. '-ea'); 3) replace '_' with '.'
43-
local cleaned=$(echo "$1" | sed -E 's/^1\.//g;s/[a-zA-Z+*\-]//g;s/_/./g')
42+
# cleaning: 1) remove leading '1.'; 2) remove build string (e.g. '-b14-468'); 3) remove 'a-Z' and '-*+' (e.g. '-ea'); 4) replace '_' with '.'
43+
local cleaned=$(echo "$1" | sed -E 's/^1\.//g;s/-b[0-9]+-[0-9]+$//g;s/[a-zA-Z+*\-]//g;s/_/./g')
4444
# splitting at '.' into an array
4545
local arr=( ${cleaned//./ } )
4646
# echo a string with left padded version numbers
@@ -181,6 +181,7 @@ testExtractMajor "1.6+" "6"
181181
testExtractMajor "1.6.0" "6"
182182
testExtractMajor "1.6.0_07" "6"
183183
testExtractMajor "1.6.0_45" "6"
184+
testExtractMajor "1.6.0_65-b14-468" "6"
184185
echo ""
185186
echo "Tests with Java 1.7:"
186187
testExtractMajor "1.7" "7"
@@ -245,6 +246,7 @@ echo "Tests with Java 1.6:"
245246
testComparable "1.6" "06000000"
246247
testComparable "1.6+" "06000000"
247248
testComparable "1.6.0_45" "06000045"
249+
testComparable "1.6.0_65-b14-468" "06000065"
248250
testComparable "1.6.0_100" "06000100"
249251
testComparable "1.6.1_87" "06001087"
250252
echo ""

0 commit comments

Comments
 (0)