|
1 | 1 | #' Unpack a Java distribution file into cache directory
|
2 |
| -#' |
| 2 | +#' |
3 | 3 | #' @description
|
4 | 4 | #' Unpack the Java distribution file into cache directory and return the path to the unpacked Java directory with Java binaries.
|
5 |
| -#' |
6 |
| -#' |
| 5 | +#' |
| 6 | +#' |
7 | 7 | #' @inheritParams java_install
|
8 | 8 | #' @inheritParams global_quiet_param
|
9 | 9 | #' @return A `character` vector containing of length 1 containing the path to the unpacked Java directory.
|
10 | 10 | #' @export
|
11 | 11 | #' @examples
|
12 | 12 | #' \dontrun{
|
13 |
| -#' |
| 13 | +#' |
14 | 14 | #' # set cache dir to temporary directory
|
15 | 15 | #' options(rJavaEnv.cache_path = tempdir())
|
16 |
| -#' |
| 16 | +#' |
17 | 17 | #' # download Java 17 distrib and unpack it into cache dir
|
18 | 18 | #' java_17_distrib <- java_download(version = "17")
|
19 | 19 | #' java_home <- java_unpack(java_distrib_path = java_17_distrib)
|
20 |
| -#' |
| 20 | +#' |
21 | 21 | #' # set the JAVA_HOME environment variable in the current session
|
22 | 22 | #' # to the cache dir without touching any files in the current project directory
|
23 | 23 | #' java_env_set(where = "session", java_home = java_home)
|
24 | 24 | #' }
|
25 |
| -#' |
| 25 | +#' |
26 | 26 | java_unpack <- function(
|
27 | 27 | java_distrib_path,
|
28 | 28 | quiet = FALSE
|
29 | 29 | ) {
|
30 | 30 | platforms <- c("windows", "linux", "macos")
|
31 | 31 | architectures <- c("x64", "aarch64", "arm64")
|
32 |
| - java_versions <- getOption("rJavaEnv.valid_major_java_versions") |
| 32 | + java_versions <- java_valid_versions() |
33 | 33 |
|
34 | 34 | # Extract information from the file name
|
35 | 35 | filename <- basename(java_distrib_path)
|
36 | 36 | parts <- strsplit(gsub("\\.tar\\.gz|\\.zip", "", filename), "-")[[1]]
|
37 | 37 |
|
38 | 38 | # Guess the version, architecture, and platform
|
39 |
| - version <- parts[parts %in% java_versions][1] |
40 |
| - arch <- parts[parts %in% architectures][1] |
41 |
| - platform <- parts[parts %in% platforms][1] |
| 39 | + version <- parts[parts %in% java_versions][1] |
| 40 | + arch <- parts[parts %in% architectures][1] |
| 41 | + platform <- parts[parts %in% platforms][1] |
42 | 42 |
|
43 |
| - if (is.na(version)) cli::cli_abort("Unable to detect Java version from filename.") |
44 |
| - if (is.na(arch)) cli::cli_abort("Unable to detect architecture from filename.") |
45 |
| - if (is.na(platform)) cli::cli_abort("Unable to detect platform from filename.") |
| 43 | + if (is.na(version)) |
| 44 | + cli::cli_abort("Unable to detect Java version from filename.") |
| 45 | + if (is.na(arch)) |
| 46 | + cli::cli_abort("Unable to detect architecture from filename.") |
| 47 | + if (is.na(platform)) |
| 48 | + cli::cli_abort("Unable to detect platform from filename.") |
46 | 49 |
|
47 | 50 | # Create the installation path in the package cache
|
48 | 51 | cache_path <- getOption("rJavaEnv.cache_path")
|
@@ -87,12 +90,19 @@ java_unpack <- function(
|
87 | 90 | }
|
88 | 91 |
|
89 | 92 | # Move the extracted files to the installation path
|
90 |
| - file.copy(list.files(extracted_dir, full.names = TRUE), installed_path, recursive = TRUE) |
| 93 | + file.copy( |
| 94 | + list.files(extracted_dir, full.names = TRUE), |
| 95 | + installed_path, |
| 96 | + recursive = TRUE |
| 97 | + ) |
91 | 98 |
|
92 | 99 | # Clean up temporary directory
|
93 | 100 | unlink(temp_dir, recursive = TRUE)
|
94 | 101 | } else {
|
95 |
| - if (!quiet) cli::cli_inform("Java distribution {filename} already unpacked at {.path {installed_path}}") |
| 102 | + if (!quiet) |
| 103 | + cli::cli_inform( |
| 104 | + "Java distribution {filename} already unpacked at {.path {installed_path}}" |
| 105 | + ) |
96 | 106 | }
|
97 | 107 | return(installed_path)
|
98 | 108 | }
|
0 commit comments