|
1 | 1 | .onLoad <- function(libname, pkgname) {
|
2 |
| - # Detect the current platform (OS and architecture) |
3 |
| - platform <- platform_detect(quiet = TRUE) |
4 |
| - |
5 |
| - # Select the fallback valid Java versions based on the detected platform |
6 |
| - fallback_current <- switch( |
7 |
| - paste(platform$os, platform$arch, sep = "_"), |
8 |
| - "macos_aarch64" = c( |
| 2 | + # First, set all the base rJavaEnv options |
| 3 | + op <- options() |
| 4 | + op.rJavaEnv <- list( |
| 5 | + # Default folder choice (in line with renv package) |
| 6 | + rJavaEnv.cache_path = tools::R_user_dir("rJavaEnv", which = "cache"), |
| 7 | + rJavaEnv.valid_versions_cache = NULL, |
| 8 | + rJavaEnv.valid_versions_timestamp = NULL, |
| 9 | + # Fallback lists for various platforms |
| 10 | + rJavaEnv.fallback_valid_versions_macos_aarch64 = c( |
9 | 11 | "8",
|
10 | 12 | "11",
|
11 | 13 | "17",
|
|
17 | 19 | "23",
|
18 | 20 | "24"
|
19 | 21 | ),
|
20 |
| - "macos_x64" = c( |
| 22 | + rJavaEnv.fallback_valid_versions_macos_x64 = c( |
21 | 23 | "8",
|
22 | 24 | "11",
|
23 | 25 | "15",
|
|
31 | 33 | "23",
|
32 | 34 | "24"
|
33 | 35 | ),
|
34 |
| - "linux_aarch64" = c( |
| 36 | + rJavaEnv.fallback_valid_versions_linux_aarch64 = c( |
35 | 37 | "8",
|
36 | 38 | "11",
|
37 | 39 | "15",
|
|
45 | 47 | "23",
|
46 | 48 | "24"
|
47 | 49 | ),
|
48 |
| - "linux_x64" = c( |
| 50 | + rJavaEnv.fallback_valid_versions_linux_x64 = c( |
49 | 51 | "8",
|
50 | 52 | "11",
|
51 | 53 | "15",
|
|
59 | 61 | "23",
|
60 | 62 | "24"
|
61 | 63 | ),
|
62 |
| - stop("Unsupported platform/architecture combination") |
63 |
| - ) |
64 |
| - |
65 |
| - # Get current options |
66 |
| - op <- options() |
67 |
| - |
68 |
| - # Create list of rJavaEnv options including the current platform valid versions |
69 |
| - op.rJavaEnv <- list( |
70 |
| - # Default folder choice (in line with renv package) |
71 |
| - rJavaEnv.cache_path = tools::R_user_dir("rJavaEnv", which = "cache"), |
72 |
| - rJavaEnv.valid_versions_cache = NULL, |
73 |
| - rJavaEnv.valid_versions_timestamp = NULL, |
74 |
| - # Fallback lists for various platforms |
75 |
| - rJavaEnv.fallback_valid_versions_current_platform_macos_aarch64 = c( |
76 |
| - "8", |
77 |
| - "11", |
78 |
| - "17", |
79 |
| - "18", |
80 |
| - "19", |
81 |
| - "20", |
82 |
| - "21", |
83 |
| - "22", |
84 |
| - "23", |
85 |
| - "24" |
86 |
| - ), |
87 |
| - rJavaEnv.fallback_valid_versions_current_platform_macos_x64 = c( |
| 64 | + rJavaEnv.fallback_valid_versions_windows_x64 = c( |
88 | 65 | "8",
|
89 | 66 | "11",
|
90 | 67 | "15",
|
|
98 | 75 | "23",
|
99 | 76 | "24"
|
100 | 77 | ),
|
101 |
| - rJavaEnv.fallback_valid_versions_current_platform_linux_aarch64 = c( |
| 78 | + rJavaEnv.fallback_valid_versions_windows_x86 = c( |
102 | 79 | "8",
|
103 |
| - "11", |
104 |
| - "15", |
105 |
| - "16", |
106 |
| - "17", |
107 |
| - "18", |
108 |
| - "19", |
109 |
| - "20", |
110 |
| - "21", |
111 |
| - "22", |
112 |
| - "23", |
113 |
| - "24" |
114 |
| - ), |
115 |
| - rJavaEnv.fallback_valid_versions_current_platform_linux_x64 = c( |
116 |
| - "8", |
117 |
| - "11", |
118 |
| - "15", |
119 |
| - "16", |
120 |
| - "17", |
121 |
| - "18", |
122 |
| - "19", |
123 |
| - "20", |
124 |
| - "21", |
125 |
| - "22", |
126 |
| - "23", |
127 |
| - "24" |
128 |
| - ), |
129 |
| - # Current platform valid versions |
130 |
| - rJavaEnv.fallback_valid_versions_current_platform_current_platform = fallback_current |
| 80 | + "11" |
| 81 | + ) |
131 | 82 | )
|
132 | 83 |
|
133 |
| - # Only set the options that haven't been set yet |
| 84 | + # Only set the options that haven't been defined yet |
134 | 85 | toset <- !(names(op.rJavaEnv) %in% names(op))
|
135 | 86 | if (any(toset)) options(op.rJavaEnv[toset])
|
136 | 87 |
|
| 88 | + # Now, detect the current platform (OS and architecture) |
| 89 | + platform <- platform_detect(quiet = TRUE) |
| 90 | + |
| 91 | + # Build the option name dynamically based on platform$os and platform$arch. |
| 92 | + # For example, for macOS on x64, this results in "rJavaEnv.fallback_valid_versions_macos_x64" |
| 93 | + fallback_option_name <- paste0( |
| 94 | + "rJavaEnv.fallback_valid_versions_", |
| 95 | + platform$os, |
| 96 | + "_", |
| 97 | + platform$arch |
| 98 | + ) |
| 99 | + |
| 100 | + # Retrieve the corresponding fallback list using getOption() |
| 101 | + fallback_current <- getOption(fallback_option_name) |
| 102 | + |
| 103 | + # Set the current platform valid versions option |
| 104 | + options(rJavaEnv.fallback_valid_versions_current_platform = fallback_current) |
| 105 | + |
137 | 106 | invisible()
|
138 | 107 | }
|
0 commit comments