Skip to content

Commit 5b9a68d

Browse files
authored
Merge pull request #60 from enriquemondragon/java_download_argument
Closes #55 Force argument for Java download
2 parents 1de37c0 + 48bef75 commit 5b9a68d

File tree

6 files changed

+70
-35
lines changed

6 files changed

+70
-35
lines changed

CITATION.cff

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ license: MIT
1010
title: 'rJavaEnv: ''Java'' Environments for R Projects'
1111
version: 0.2.2
1212
doi: 10.32614/CRAN.package.rJavaEnv
13+
identifiers:
14+
- type: doi
15+
value: 10.32614/CRAN.package.rJavaEnv
1316
abstract: 'Quickly install ''Java Development Kit (JDK)'' without administrative privileges
1417
and set environment variables in current R session or project to solve common issues
1518
with ''Java'' environment management in ''R''. Recommended to users of ''Java''/''rJava''-dependent
@@ -67,7 +70,7 @@ references:
6770
institution:
6871
name: R Foundation for Statistical Computing
6972
address: Vienna, Austria
70-
year: '2024'
73+
year: '2025'
7174
version: '>= 4.0'
7275
- type: software
7376
title: checkmate
@@ -80,7 +83,8 @@ references:
8083
given-names: Michel
8184
8285
orcid: https://orcid.org/0000-0001-9754-0393
83-
year: '2024'
86+
year: '2025'
87+
doi: 10.32614/CRAN.package.checkmate
8488
- type: software
8589
title: cli
8690
abstract: 'cli: Helpers for Developing Command Line Interfaces'
@@ -90,8 +94,9 @@ references:
9094
authors:
9195
- family-names: Csárdi
9296
given-names: Gábor
93-
94-
year: '2024'
97+
98+
year: '2025'
99+
doi: 10.32614/CRAN.package.cli
95100
- type: software
96101
title: curl
97102
abstract: 'curl: A Modern and Flexible Web Client for R'
@@ -101,9 +106,10 @@ references:
101106
authors:
102107
- family-names: Ooms
103108
given-names: Jeroen
104-
109+
105110
orcid: https://orcid.org/0000-0002-4035-0289
106-
year: '2024'
111+
year: '2025'
112+
doi: 10.32614/CRAN.package.curl
107113
- type: software
108114
title: jsonlite
109115
abstract: 'jsonlite: A Simple and Robust JSON Parser and Generator for R'
@@ -113,9 +119,10 @@ references:
113119
authors:
114120
- family-names: Ooms
115121
given-names: Jeroen
116-
122+
117123
orcid: https://orcid.org/0000-0002-4035-0289
118-
year: '2024'
124+
year: '2025'
125+
doi: 10.32614/CRAN.package.jsonlite
119126
- type: software
120127
title: utils
121128
abstract: 'R: A Language and Environment for Statistical Computing'
@@ -125,23 +132,7 @@ references:
125132
institution:
126133
name: R Foundation for Statistical Computing
127134
address: Vienna, Austria
128-
year: '2024'
129-
- type: software
130-
title: quarto
131-
abstract: 'quarto: R Interface to ''Quarto'' Markdown Publishing System'
132-
notes: Suggests
133-
url: https://quarto-dev.github.io/quarto-r/
134-
repository: https://CRAN.R-project.org/package=quarto
135-
authors:
136-
- family-names: Allaire
137-
given-names: JJ
138-
139-
orcid: https://orcid.org/0000-0003-0174-9868
140-
- family-names: Dervieux
141-
given-names: Christophe
142-
143-
orcid: https://orcid.org/0000-0003-4474-2498
144-
year: '2024'
135+
year: '2025'
145136
- type: software
146137
title: testthat
147138
abstract: 'testthat: Unit Testing for R'
@@ -152,6 +143,7 @@ references:
152143
- family-names: Wickham
153144
given-names: Hadley
154145
155-
year: '2024'
146+
year: '2025'
147+
doi: 10.32614/CRAN.package.testthat
156148
version: '>= 3.0.0'
157149

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Authors@R: c(
77
person("Mauricio", "Vargas", , "[email protected]", role = "ctb",
88
comment = c(ORCID = "0000-0003-1017-7574")),
99
person("Hadley", "Wickham", , "[email protected]", role = "ctb",
10-
comment = "use_java feature suggestion and PR review")
10+
comment = "use_java feature suggestion and PR review"),
11+
person("Enrique", "Mondragon-Estrada", , "[email protected]", role = "ctb",
12+
comment = c(ORCID = "0009-0004-5592-1728"))
1113
)
1214
Description: Quickly install 'Java Development Kit (JDK)' without
1315
administrative privileges and set environment variables in current R

R/java_download.R

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#' @param cache_path The destination directory to download the Java distribution to. Defaults to a user-specific data directory.
66
#' @param platform The platform for which to download the Java distribution. Defaults to the current platform.
77
#' @param arch The architecture for which to download the Java distribution. Defaults to the current architecture.
8+
#' @param force A logical. Whether the distribution file should be overwritten or not. Defaults to `FALSE`.
89
#' @param temp_dir A logical. Whether the file should be saved in a temporary directory. Defaults to `FALSE`.
910
#' @inheritParams global_quiet_param
1011
#'
@@ -13,10 +14,10 @@
1314
#'
1415
#' @examples
1516
#' \dontrun{
16-
#'
17+
#'
1718
#' # download distribution of Java version 17
1819
#' java_download(version = "17", temp_dir = TRUE)
19-
#'
20+
#'
2021
#' # download default Java distribution (version 21)
2122
#' java_download(temp_dir = TRUE)
2223
#' }
@@ -27,9 +28,10 @@ java_download <- function(
2728
platform = platform_detect()$os,
2829
arch = platform_detect()$arch,
2930
quiet = FALSE,
31+
force = FALSE,
3032
temp_dir = FALSE
3133
) {
32-
34+
3335
# override cache_path if temp_dir is set to TRUE
3436
if (temp_dir) {
3537
temp_dir <- tempdir()
@@ -64,6 +66,7 @@ java_download <- function(
6466
checkmate::assert_choice(platform, valid_platforms)
6567
checkmate::assert_choice(arch, valid_architectures)
6668
checkmate::assert_flag(quiet)
69+
checkmate::assert_flag(force)
6770

6871
# Print out the detected platform and architecture
6972
if (!quiet) {
@@ -98,11 +101,32 @@ java_download <- function(
98101
cli::cli_inform("Downloading Java {version} ({distribution}) for {platform} {arch} to {dest_file}", .envir = environment())
99102
}
100103

101-
if (file.exists(dest_file)) {
104+
if (file.exists(dest_file) & !force) {
102105
if (!quiet) {
103106
cli::cli_inform("File already exists. Skipping download.", .envir = environment())
104107
}
105-
} else {
108+
} else if(file.exists(dest_file) & force){
109+
if (!quiet) {
110+
cli::cli_inform("Removing existing installation.", .envir = environment())
111+
}
112+
file.remove(dest_file)
113+
curl::curl_download(url, dest_file, quiet = FALSE)
114+
curl::curl_download(url_md5, dest_file_md5, quiet = TRUE)
115+
if (!quiet) {
116+
cli::cli_inform("Download completed.", .envir = environment())
117+
118+
md5sum <- tools::md5sum(dest_file)
119+
md5sum_expected <- readLines(dest_file_md5, warn = FALSE)
120+
121+
if (md5sum != md5sum_expected) {
122+
cli::cli_alert_danger("MD5 checksum mismatch. Please try downloading the file again.", .envir = environment())
123+
unlink(dest_file)
124+
return(NULL)
125+
} else {
126+
cli::cli_inform("MD5 checksum verified.", .envir = environment())
127+
}
128+
}
129+
} else if (!file.exists(dest_file)){
106130
curl::curl_download(url, dest_file, quiet = FALSE)
107131
curl::curl_download(url_md5, dest_file_md5, quiet = TRUE)
108132
if (!quiet) {

codemeta.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"name": "R",
1515
"url": "https://r-project.org"
1616
},
17-
"runtimePlatform": "R version 4.4.1 (2024-06-14)",
17+
"runtimePlatform": "R version 4.4.1 (2024-06-14 ucrt)",
1818
"provider": {
1919
"@id": "https://cran.r-project.org",
2020
"@type": "Organization",
@@ -43,6 +43,13 @@
4343
"givenName": "Hadley",
4444
"familyName": "Wickham",
4545
"email": "[email protected]"
46+
},
47+
{
48+
"@type": "Person",
49+
"givenName": "Enrique",
50+
"familyName": "Mondragon-Estrada",
51+
"email": "[email protected]",
52+
"@id": "https://orcid.org/0009-0004-5592-1728"
4653
}
4754
],
4855
"copyrightHolder": [
@@ -164,7 +171,7 @@
164171
},
165172
"SystemRequirements": null
166173
},
167-
"fileSize": "219.775KB",
174+
"fileSize": "224.631KB",
168175
"citation": [
169176
{
170177
"@type": "SoftwareSourceCode",

inst/schemaorg.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
"email": "[email protected]",
2121
"familyName": "Wickham",
2222
"givenName": "Hadley"
23+
},
24+
{
25+
"id": "https://orcid.org/0009-0004-5592-1728",
26+
"type": "Person",
27+
"email": "[email protected]",
28+
"familyName": "Mondragon-Estrada",
29+
"givenName": "Enrique"
2330
}
2431
],
2532
"copyrightHolder": {
@@ -43,7 +50,7 @@
4350
"name": "Comprehensive R Archive Network (CRAN)",
4451
"url": "https://cran.r-project.org"
4552
},
46-
"runtimePlatform": "R version 4.4.1 (2024-06-14)",
53+
"runtimePlatform": "R version 4.4.1 (2024-06-14 ucrt)",
4754
"version": "0.2.2"
4855
},
4956
{

man/java_download.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)