From de7e94884bc309814f6af79d68d664efb513e093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Fri, 7 Apr 2023 15:40:23 +0200 Subject: [PATCH] fix(java): wrong version number when using Android Studio JDK (#4966) The regular expression would get the revision number found in: with gcc Android (7284624, based on r416183b) so it would print "7284624". --- src/modules/java.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/java.rs b/src/modules/java.rs index 1e1eadf7..362cd1af 100644 --- a/src/modules/java.rs +++ b/src/modules/java.rs @@ -5,7 +5,8 @@ use crate::utils::get_command_string_output; use std::path::PathBuf; use regex::Regex; -const JAVA_VERSION_PATTERN: &str = "(?:JRE.*\\(|OpenJ9 )(?P[\\d]+(?:\\.\\d+){0,2})"; +const JAVA_VERSION_PATTERN: &str = + "(?:JRE.*\\(|OpenJ9 )(?P\\d+(?:\\.\\d+){0,2}).*, built on"; /// Creates a module with the current Java version pub fn module<'a>(context: &'a Context) -> Option> { @@ -154,6 +155,12 @@ mod tests { assert_eq!(parse_java_version(java_11), Some("11.0.4".to_string())); } + #[test] + fn test_parse_java_version_android_studio_jdk() { + let java_11 = "OpenJDK 64-Bit Server VM (11.0.15+0-b2043.56-8887301) for linux-amd64 JRE (11.0.15+0-b2043.56-8887301), built on Jul 29 2022 22:12:21 by \"androidbuild\" with gcc Android (7284624, based on r416183b) Clang 12.0.5 (https://android.googlesource.com/toolchain/llvm-project c935d99d7cf2016289302412d708641d52d2f7ee)}"; + assert_eq!(parse_java_version(java_11), Some("11.0.15".to_string())); + } + #[test] fn test_parse_java_version_unknown() { let unknown_jre = "Unknown JRE";