Skip to content

Commit 8d7bead

Browse files
committed
feat(core): future-proof Java version validation with dynamic fallback ranges
- Replace hardcoded Java version lists in R/onLoad.R with dynamic ranges (up to 100). - Fix test failure in test-java_valid_versions. by correctly mocking `read_json_url`. - Update tests to verify support for current (26) and future (50, 100) Java versions. - Ensure package remains functional when the API is unreachable or when new versions are released.
1 parent c809ef7 commit 8d7bead

File tree

2 files changed

+43
-98
lines changed

2 files changed

+43
-98
lines changed

R/onLoad.R

Lines changed: 37 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -17,106 +17,47 @@
1717
rJavaEnv.valid_versions_cache = NULL,
1818
rJavaEnv.valid_versions_timestamp = NULL,
1919
# Fallback lists for various platforms
20-
rJavaEnv.fallback_valid_versions_macos_aarch64 = c(
21-
"8",
22-
"11",
23-
"17",
24-
"18",
25-
"19",
26-
"20",
27-
"21",
28-
"22",
29-
"23",
30-
"24",
31-
"25"
32-
),
33-
rJavaEnv.fallback_valid_versions_macos_x64 = c(
34-
"8",
35-
"11",
36-
"15",
37-
"16",
38-
"17",
39-
"18",
40-
"19",
41-
"20",
42-
"21",
43-
"22",
44-
"23",
45-
"24",
46-
"25"
47-
),
48-
rJavaEnv.fallback_valid_versions_linux_aarch64 = c(
49-
"8",
50-
"11",
51-
"15",
52-
"16",
53-
"17",
54-
"18",
55-
"19",
56-
"20",
57-
"21",
58-
"22",
59-
"23",
60-
"24",
61-
"25"
62-
),
63-
rJavaEnv.fallback_valid_versions_linux_x64 = c(
64-
"8",
65-
"11",
66-
"15",
67-
"16",
68-
"17",
69-
"18",
70-
"19",
71-
"20",
72-
"21",
73-
"22",
74-
"23",
75-
"24",
76-
"25"
77-
),
78-
rJavaEnv.fallback_valid_versions_windows_x64 = c(
79-
"8",
80-
"11",
81-
"15",
82-
"16",
83-
"17",
84-
"18",
85-
"19",
86-
"20",
87-
"21",
88-
"22",
89-
"23",
90-
"24",
91-
"25"
92-
),
20+
rJavaEnv.fallback_valid_versions_macos_aarch64 = as.character(c(
21+
8,
22+
11,
23+
17:100
24+
)),
25+
rJavaEnv.fallback_valid_versions_macos_x64 = as.character(c(
26+
8,
27+
11,
28+
15:100
29+
)),
30+
rJavaEnv.fallback_valid_versions_linux_aarch64 = as.character(c(
31+
8,
32+
11,
33+
17:100
34+
)),
35+
rJavaEnv.fallback_valid_versions_linux_x64 = as.character(c(
36+
8,
37+
11,
38+
15:100
39+
)),
40+
rJavaEnv.fallback_valid_versions_windows_x64 = as.character(c(
41+
8,
42+
11,
43+
15:100
44+
)),
9345
rJavaEnv.fallback_valid_versions_windows_x86 = c(
9446
"8",
9547
"11"
9648
),
97-
rJavaEnv.fallback_valid_versions_temurin = c(
98-
"8",
99-
"11",
100-
"17",
101-
"21",
102-
"22",
103-
"23",
104-
"24",
105-
"25"
106-
),
107-
rJavaEnv.fallback_valid_versions_zulu = c(
108-
"8",
109-
"11",
110-
"13",
111-
"15",
112-
"17",
113-
"19",
114-
"21",
115-
"22",
116-
"23",
117-
"24",
118-
"25"
119-
)
49+
rJavaEnv.fallback_valid_versions_temurin = as.character(c(
50+
8,
51+
11,
52+
17:100
53+
)),
54+
rJavaEnv.fallback_valid_versions_zulu = as.character(c(
55+
8,
56+
11,
57+
13,
58+
15,
59+
17:100
60+
))
12061
)
12162

12263
# Only set the options that haven't been defined yet

tests/testthat/test-java_valid_versions.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ test_that("java_valid_versions returns a character vector with required versions
1515
expect_true("8" %in% versions)
1616
expect_true("11" %in% versions)
1717
expect_true("24" %in% versions)
18+
expect_true("26" %in% versions)
1819
})
1920

2021
test_that("force parameter bypasses the cache", {
@@ -44,13 +45,16 @@ test_that("fallback is used when the API call fails", {
4445
)
4546

4647
local_mocked_bindings(
47-
read_json = function(...) stop("Simulated API failure"),
48-
.package = "jsonlite"
48+
read_json_url = function(...) stop("Simulated API failure"),
49+
.package = "rJavaEnv"
4950
)
5051

5152
fallback <- getOption("rJavaEnv.fallback_valid_versions_current_platform")
5253
versions <- java_valid_versions(force = TRUE)
5354

5455
## When the API call fails, the fallback list should be returned.
5556
expect_equal(versions, fallback)
57+
expect_true("26" %in% versions)
58+
expect_true("50" %in% versions)
59+
expect_true("100" %in% versions)
5660
})

0 commit comments

Comments
 (0)